Fallback to MJPEG camera stream if streaming component is missing
This commit is contained in:
parent
022622522f
commit
68d14bd13d
@ -50,23 +50,34 @@ class _CameraStreamViewState extends State<CameraStreamView> {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catchError((e) {
|
.catchError((e) {
|
||||||
_loading.completeError(e);
|
if (e == 'start_stream_failed') {
|
||||||
Logger.e("[Camera Player] $e");
|
Logger.e("[Camera Player] Home Assistant failed starting stream. Forcing MJPEG: $e");
|
||||||
|
_loadMJPEG().then((_) {
|
||||||
|
_loading.complete();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
_loading.completeError(e);
|
||||||
|
Logger.e("[Camera Player] Error loading stream: $e");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_loadMJPEG().then((_) {
|
||||||
|
_loading.complete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return _loading.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future _loadMJPEG() async {
|
||||||
_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']}';
|
||||||
_jsMessageChannelName = 'HA_${_entity.entityId.replaceAll('.', '_')}';
|
_jsMessageChannelName = 'HA_${_entity.entityId.replaceAll('.', '_')}';
|
||||||
rootBundle.loadString('assets/html/cameraView.html').then((file) {
|
var file = await rootBundle.loadString('assets/html/cameraView.html');
|
||||||
_webViewHtml = Uri.dataFromString(
|
_webViewHtml = Uri.dataFromString(
|
||||||
file.replaceFirst('{{stream_url}}', _streamUrl).replaceFirst('{{message_channel}}', _jsMessageChannelName),
|
file.replaceFirst('{{stream_url}}', _streamUrl).replaceFirst('{{message_channel}}', _jsMessageChannelName),
|
||||||
mimeType: 'text/html',
|
mimeType: 'text/html',
|
||||||
encoding: Encoding.getByName('utf-8')
|
encoding: Encoding.getByName('utf-8')
|
||||||
).toString();
|
).toString();
|
||||||
_loading.complete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return _loading.future;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildScreen() {
|
Widget _buildScreen() {
|
||||||
|
Reference in New Issue
Block a user