Resolves #420 Camera view on entity page
This commit is contained in:
parent
92e008a380
commit
2f4c06e9b5
18
assets/js/cameraImgViewHelper.js
Normal file
18
assets/js/cameraImgViewHelper.js
Normal file
@ -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);
|
@ -16,8 +16,8 @@ class _CameraStreamViewState extends State<CameraStreamView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CameraEntity _entity;
|
CameraEntity _entity;
|
||||||
bool started = false;
|
|
||||||
String streamUrl = "";
|
String streamUrl = "";
|
||||||
|
WebViewController webViewController;
|
||||||
|
|
||||||
launchStream() {
|
launchStream() {
|
||||||
Launcher.launchURLInCustomTab(
|
Launcher.launchURLInCustomTab(
|
||||||
@ -28,26 +28,28 @@ class _CameraStreamViewState extends State<CameraStreamView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (!started) {
|
_entity = EntityModel
|
||||||
_entity = EntityModel
|
|
||||||
.of(context)
|
.of(context)
|
||||||
.entityWrapper
|
.entityWrapper
|
||||||
.entity;
|
.entity;
|
||||||
started = true;
|
|
||||||
}
|
|
||||||
streamUrl = '${ConnectionManager().httpWebHost}/api/camera_proxy_stream/${_entity
|
streamUrl = '${ConnectionManager().httpWebHost}/api/camera_proxy_stream/${_entity
|
||||||
.entityId}?token=${_entity.attributes['access_token']}';
|
.entityId}?token=${_entity.attributes['access_token']}';
|
||||||
return Column(
|
return AspectRatio(
|
||||||
children: <Widget>[
|
aspectRatio: 1.33,
|
||||||
Container(
|
child: WebView(
|
||||||
padding: const EdgeInsets.all(20.0),
|
initialUrl: streamUrl,
|
||||||
child: IconButton(
|
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
|
||||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:monitor-screenshot"), color: Colors.amber),
|
debuggingEnabled: Logger.isInDebugMode,
|
||||||
iconSize: 50.0,
|
javascriptMode: JavascriptMode.unrestricted,
|
||||||
onPressed: () => launchStream(),
|
onWebViewCreated: (WebViewController controller) {
|
||||||
)
|
webViewController = controller;
|
||||||
)
|
},
|
||||||
],
|
onPageStarted: (url) {
|
||||||
|
rootBundle.loadString('assets/js/cameraImgViewHelper.js').then((js){
|
||||||
|
webViewController.evaluateJavascript(js);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ import 'package:geolocator/geolocator.dart';
|
|||||||
import 'package:battery/battery.dart';
|
import 'package:battery/battery.dart';
|
||||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||||
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart' as standaloneWebview;
|
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart' as standaloneWebview;
|
||||||
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
|
|
||||||
import 'utils/logger.dart';
|
import 'utils/logger.dart';
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ dependencies:
|
|||||||
in_app_purchase: ^0.3.0+3
|
in_app_purchase: ^0.3.0+3
|
||||||
flutter_custom_tabs: ^0.6.0
|
flutter_custom_tabs: ^0.6.0
|
||||||
flutter_webview_plugin: ^0.3.10+1
|
flutter_webview_plugin: ^0.3.10+1
|
||||||
|
webview_flutter: ^0.3.19+7
|
||||||
firebase_messaging: ^6.0.9
|
firebase_messaging: ^6.0.9
|
||||||
flutter_secure_storage: ^3.3.1+1
|
flutter_secure_storage: ^3.3.1+1
|
||||||
device_info: ^0.4.1+4
|
device_info: ^0.4.1+4
|
||||||
@ -49,6 +50,7 @@ flutter:
|
|||||||
assets:
|
assets:
|
||||||
- images/hassio-192x192.png
|
- images/hassio-192x192.png
|
||||||
- assets/js/externalAuth.js
|
- assets/js/externalAuth.js
|
||||||
|
- assets/js/cameraImgViewHelper.js
|
||||||
|
|
||||||
fonts:
|
fonts:
|
||||||
- family: "Material Design Icons"
|
- family: "Material Design Icons"
|
||||||
|
Reference in New Issue
Block a user