fix: Fix renderer issue for Safari/Firefox. (#241)
* fix: Fix renderer issue for Safari. * fix: fix compile for native. * chore: Improve flickering.
This commit is contained in:
@@ -9,6 +9,8 @@ bool lkPlatformIs(PlatformType type) => lkPlatform() == type;
|
|||||||
|
|
||||||
bool lkPlatformIsTest() => Platform.environment.containsKey('FLUTTER_TEST');
|
bool lkPlatformIsTest() => Platform.environment.containsKey('FLUTTER_TEST');
|
||||||
|
|
||||||
|
BrowserType lkBrowser() => lkBrowserImplementation();
|
||||||
|
|
||||||
enum PlatformType {
|
enum PlatformType {
|
||||||
web,
|
web,
|
||||||
windows,
|
windows,
|
||||||
@@ -18,3 +20,12 @@ enum PlatformType {
|
|||||||
fuchsia,
|
fuchsia,
|
||||||
iOS,
|
iOS,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum BrowserType {
|
||||||
|
chrome,
|
||||||
|
firefox,
|
||||||
|
safari,
|
||||||
|
internetExplorer,
|
||||||
|
wkWebView,
|
||||||
|
unknown,
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,3 +11,7 @@ PlatformType lkPlatformImplementation() {
|
|||||||
if (Platform.isAndroid) return PlatformType.android;
|
if (Platform.isAndroid) return PlatformType.android;
|
||||||
throw UnsupportedError('Unknown Platform');
|
throw UnsupportedError('Unknown Platform');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BrowserType lkBrowserImplementation() {
|
||||||
|
return BrowserType.unknown;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
import '../platform.dart';
|
import '../platform.dart';
|
||||||
|
|
||||||
|
import 'package:platform_detect/platform_detect.dart';
|
||||||
|
|
||||||
PlatformType lkPlatformImplementation() => PlatformType.web;
|
PlatformType lkPlatformImplementation() => PlatformType.web;
|
||||||
|
|
||||||
|
BrowserType lkBrowserImplementation() {
|
||||||
|
if (browser.isChrome) return BrowserType.chrome;
|
||||||
|
if (browser.isFirefox) return BrowserType.firefox;
|
||||||
|
if (browser.isSafari) return BrowserType.safari;
|
||||||
|
if (browser.isInternetExplorer) return BrowserType.internetExplorer;
|
||||||
|
if (browser.isWKWebView) return BrowserType.wkWebView;
|
||||||
|
return BrowserType.unknown;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
|
import 'package:livekit_client/src/support/platform.dart';
|
||||||
|
|
||||||
import '../events.dart';
|
import '../events.dart';
|
||||||
import '../extensions.dart';
|
import '../extensions.dart';
|
||||||
@@ -78,15 +79,18 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
|
|||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant VideoTrackRenderer oldWidget) {
|
void didUpdateWidget(covariant VideoTrackRenderer oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
//
|
|
||||||
if (widget.track != oldWidget.track) {
|
if (widget.track != oldWidget.track) {
|
||||||
oldWidget.track.removeViewKey(_internalKey);
|
oldWidget.track.removeViewKey(_internalKey);
|
||||||
_internalKey = widget.track.addViewKey();
|
_internalKey = widget.track.addViewKey();
|
||||||
// TODO: re-attach only if needed
|
|
||||||
(() async {
|
(() async {
|
||||||
await _attach();
|
await _attach();
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([BrowserType.safari, BrowserType.firefox].contains(lkBrowser()) &&
|
||||||
|
oldWidget.key != widget.key) {
|
||||||
|
_renderer.srcObject = widget.track.mediaStream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ dependencies:
|
|||||||
device_info_plus: ^8.0.0
|
device_info_plus: ^8.0.0
|
||||||
webrtc_interface: 1.0.11
|
webrtc_interface: 1.0.11
|
||||||
dart_webrtc: 1.0.15
|
dart_webrtc: 1.0.15
|
||||||
|
platform_detect: ^2.0.7
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user