Skip to content

Commit

Permalink
Merge pull request #935 from sarbagyastha/develop
Browse files Browse the repository at this point in the history
Sync with develop
  • Loading branch information
sarbagyastha committed Apr 12, 2024
2 parents f54469c + 7ca5e3d commit 91e29f7
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 53 deletions.
3 changes: 3 additions & 0 deletions packages/youtube_player_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 9.0.1
* Fixes issue with fullscreen pop.

## 9.0.0
* Bumps `flutter_inappwebview` to latest version.

Expand Down
2 changes: 1 addition & 1 deletion packages/youtube_player_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: youtube_player_flutter
description: Flutter plugin for playing or streaming inline YouTube videos using the official iFrame player API. This plugin supports both Android and iOS.
version: 9.0.0
version: 9.0.1
repository: https://github.com/sarbagyastha/youtube_player_flutter
homepage: https://github.com/sarbagyastha/youtube_player_flutter/tree/master/packages/youtube_player_flutter

Expand Down
5 changes: 5 additions & 0 deletions packages/youtube_player_iframe/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## 5.1.2
**Apr 12, 2024**
- Bumps dependency to latest version.
- Updates minimum supported SDK version to Flutter 3.19.0/Dart 3.3.0.

## 5.1.1
**Feb 21, 2024**
- Improves pub score.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ class _FullScreen extends StatefulWidget {

class _FullScreenState extends State<_FullScreen> with WidgetsBindingObserver {
Orientation? _previousOrientation;
bool canPop = false;

@override
void initState() {
super.initState();

canPop = Navigator.of(context).canPop();
if (widget.auto) WidgetsBinding.instance.addObserver(this);
SystemChrome.setPreferredOrientations(_deviceOrientations);
SystemChrome.setEnabledSystemUIMode(_uiMode);
Expand Down Expand Up @@ -201,7 +202,7 @@ class _FullScreenState extends State<_FullScreen> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
canPop: canPop,
onPopInvoked: _handleFullScreenBackAction,
child: widget.child,
);
Expand Down
14 changes: 7 additions & 7 deletions packages/youtube_player_iframe/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: youtube_player_iframe
description: Flutter port of the official YouTube iFrame player API. Supports web & mobile platforms.
version: 5.1.1
version: 5.1.2
repository: https://github.com/sarbagyastha/youtube_player_flutter
homepage: https://github.com/sarbagyastha/youtube_player_flutter/tree/master/packages/youtube_player_iframe

environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.18.0-0'
sdk: ^3.3.0
flutter: '>=3.19.0'

dependencies:
flutter:
sdk: flutter
meta: '>=1.7.0 <2.0.0'
webview_flutter: ^4.7.0
webview_flutter_android: ^3.15.0
webview_flutter_wkwebview: ^3.12.0
url_launcher: ^6.2.4
webview_flutter_android: ^3.16.0
webview_flutter_wkwebview: ^3.13.0
url_launcher: ^6.2.6
youtube_player_iframe_web: ^3.0.1

dev_dependencies:
flutter_lints: ^3.0.1
flutter_lints: ^3.0.2

flutter:
assets:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dart:ui_web';

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:web/helpers.dart';
import 'package:web/web.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

Expand Down Expand Up @@ -42,22 +41,8 @@ class WebYoutubePlayerIframeControllerCreationParams

/// The underlying element used as the WebView.
@visibleForTesting
final HTMLIFrameElement ytiFrame = HTMLIFrameElement()
..id = 'youtube-${_nextIFrameId++}'
..style.width = '100%'
..style.height = '100%'
..style.border = 'none'
..allow = 'autoplay;fullscreen'
..credentialless = true;
}

extension on HTMLIFrameElement {
// See
// https://developer.mozilla.org/en-US/docs/Web/Security/IFrame_credentialless
// https://developer.chrome.com/blog/anonymous-iframe-origin-trial
set credentialless(bool value) {
this['credentialless'] = value.toJS;
}
final YoutubeIframeElement ytiFrame =
YoutubeIframeElement(id: _nextIFrameId++)..credentialless = true;
}

/// An implementation of [PlatformWebViewController] using Flutter for Web API.
Expand All @@ -81,31 +66,17 @@ class WebYoutubePlayerIframeController extends PlatformWebViewController {
@override
Future<void> loadHtmlString(String html, {String? baseUrl}) {
_params.ytiFrame.srcdoc = html;

// Fallback for browser that doesn't support srcdoc.
_params.ytiFrame.src = Uri.dataFromString(
html,
mimeType: 'text/html',
encoding: utf8,
).toString();

return SynchronousFuture(null);
}

@override
Future<void> runJavaScript(String javaScript) {
final function = javaScript.replaceAll('"', '<<quote>>');
_params.ytiFrame.contentWindow?.postMessage(
'{"key": null, "function": "$function"}'.toJS,
'*'.toJS,
);

_params.ytiFrame.runFunction(javaScript.replaceAll('"', '<<quote>>'));
return SynchronousFuture(null);
}

@override
Future<String> runJavaScriptReturningResult(String javaScript) async {
final contentWindow = _params.ytiFrame.contentWindow;
final key = DateTime.now().millisecondsSinceEpoch.toString();
final function = javaScript.replaceAll('"', '<<quote>>');

Expand All @@ -120,10 +91,7 @@ class WebYoutubePlayerIframeController extends PlatformWebViewController {
},
);

contentWindow?.postMessage(
'{"key": "$key", "function": "$function"}'.toJS,
'*'.toJS,
);
_params.ytiFrame.runFunction(function, key: key);

final result = await completer.future;
subscription.cancel();
Expand Down Expand Up @@ -242,3 +210,50 @@ class YoutubePlayerIframeWeb extends PlatformWebViewWidget {
);
}
}

extension type YoutubeIframeElement._(HTMLIFrameElement element) {
/// A class that represents a YouTube iframe element.
YoutubeIframeElement({required int id})
: element = HTMLIFrameElement()
..id = 'youtube-$id'
..style.width = '100%'
..style.height = '100%'
..style.border = 'none'
..allow = 'autoplay;fullscreen';

/// The underlying [HTMLIFrameElement] used by the [YoutubeIframeElement].
String get id => element.id;

/// The URL of the page that the iframe will display.
set src(String value) => element.src = value;

/// The content of the page that the iframe will display.
set srcdoc(String value) {
element.srcdoc = value;

// Fallback for browser that doesn't support srcdoc.
element.src = Uri.dataFromString(
value,
mimeType: 'text/html',
encoding: utf8,
).toString();
}

/// Provides a mechanism for developers to load third-party resources in [HTMLIFrameElement]s using a new, ephemeral context.
/// This allows the third-party resources to be loaded without cookies, storage, or access to the parent frame.
///
/// See more at:
/// - [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/Security/IFrame_credentialless)
/// - [Chrome Developers](https://developer.chrome.com/blog/anonymous-iframe-origin-trial)
set credentialless(bool value) {
element['credentialless'] = value.toJS;
}

/// Runs a function in the [HTMLIFrameElement] using postMessage.
void runFunction(String function, {String? key}) {
element.contentWindow?.postMessage(
'{"key": "$key", "function": "$function"}'.toJS,
'*'.toJS,
);
}
}
2 changes: 1 addition & 1 deletion packages/youtube_player_iframe_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ dependencies:
webview_flutter_platform_interface: ^2.10.0

dev_dependencies:
flutter_lints: ^3.0.1
flutter_lints: ^3.0.2

0 comments on commit 91e29f7

Please sign in to comment.