diff --git a/assets/js/cameraImgViewHelper.js b/assets/js/cameraImgViewHelper.js new file mode 100644 index 0000000..9bc184a --- /dev/null +++ b/assets/js/cameraImgViewHelper.js @@ -0,0 +1,18 @@ +function fixCameraImgView() { + var img = document.getElementsByTagName('img'); + + if (img && img.length) { + img[0].setAttribute('width', document.body.clientWidth); + img[0].setAttribute('style', 'margin-top: ' + ((document.body.clientHeight - img[0].offsetHeight) / 2)); + } + var ovrl = document.getElementById('appOverlay'); + if (ovrl) { + ovrl.remove(); + } +} + +window.bodyDetectInterval = setInterval(function() { + if (document.body != null) { + setTimeout(fixCameraImgView, 1000); + } +}, 100); \ No newline at end of file diff --git a/lib/entities/camera/widgets/camera_stream_view.dart b/lib/entities/camera/widgets/camera_stream_view.dart index 9300100..fe08134 100644 --- a/lib/entities/camera/widgets/camera_stream_view.dart +++ b/lib/entities/camera/widgets/camera_stream_view.dart @@ -16,8 +16,8 @@ class _CameraStreamViewState extends State { } CameraEntity _entity; - bool started = false; String streamUrl = ""; + WebViewController webViewController; launchStream() { Launcher.launchURLInCustomTab( @@ -28,26 +28,28 @@ class _CameraStreamViewState extends State { @override Widget build(BuildContext context) { - if (!started) { - _entity = EntityModel + _entity = EntityModel .of(context) .entityWrapper .entity; - started = true; - } streamUrl = '${ConnectionManager().httpWebHost}/api/camera_proxy_stream/${_entity .entityId}?token=${_entity.attributes['access_token']}'; - return Column( - children: [ - Container( - padding: const EdgeInsets.all(20.0), - child: IconButton( - icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:monitor-screenshot"), color: Colors.amber), - iconSize: 50.0, - onPressed: () => launchStream(), - ) - ) - ], + return AspectRatio( + aspectRatio: 1.33, + child: WebView( + initialUrl: streamUrl, + initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow, + debuggingEnabled: Logger.isInDebugMode, + javascriptMode: JavascriptMode.unrestricted, + onWebViewCreated: (WebViewController controller) { + webViewController = controller; + }, + onPageStarted: (url) { + rootBundle.loadString('assets/js/cameraImgViewHelper.js').then((js){ + webViewController.evaluateJavascript(js); + }); + }, + ), ); } diff --git a/lib/main.dart b/lib/main.dart index 2e45d4c..cb65dca 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -30,6 +30,7 @@ import 'package:geolocator/geolocator.dart'; import 'package:battery/battery.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart' as standaloneWebview; +import 'package:webview_flutter/webview_flutter.dart'; import 'utils/logger.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 6b5f1b8..e49bbd3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,6 +22,7 @@ dependencies: in_app_purchase: ^0.3.0+3 flutter_custom_tabs: ^0.6.0 flutter_webview_plugin: ^0.3.10+1 + webview_flutter: ^0.3.19+7 firebase_messaging: ^6.0.9 flutter_secure_storage: ^3.3.1+1 device_info: ^0.4.1+4 @@ -49,6 +50,7 @@ flutter: assets: - images/hassio-192x192.png - assets/js/externalAuth.js + - assets/js/cameraImgViewHelper.js fonts: - family: "Material Design Icons"