8000 fix: race condition in RTCVideoRenderer for Web (#1805) · flutter-webrtc/flutter-webrtc@9a92d0b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a92d0b

Browse files
authored
fix: race condition in RTCVideoRenderer for Web (#1805)
sometimes video callbacks (onResize, onCanPlay) come before element is findable in DOM. This PR adds the created element as fallback fixes #1804
1 parent 3f10953 commit 9a92d0b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/src/web/rtc_video_renderer_impl.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue>
9292

9393
String get viewType => 'RTCVideoRenderer-$textureId';
9494

95-
void _updateAllValues() {
96-
final element = findHtmlView();
95+
void _updateAllValues(web.HTMLVideoElement fallback) {
96+
final element = findHtmlView() ?? fallback;
9797
value = value.copyWith(
9898
rotation: 0,
99-
width: element?.videoWidth.toDouble() ?? 0.0,
100-
height: element?.videoHeight.toDouble() ?? 0.0,
99+
width: element.videoWidth.toDouble(),
100+
height: element.videoHeight.toDouble(),
101101
renderVideo: renderVideo,
102102
);
103103
}
@@ -273,13 +273,13 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue>
273273

274274
_subscriptions.add(
275275
element.onCanPlay.listen((dynamic _) {
276-
_updateAllValues();
276+
_updateAllValues(element);
277277
}),
278278
);
279279

280280
_subscriptions.add(
281281
element.onResize.listen((dynamic _) {
282-
_updateAllValues();
282+
_updateAllValues(element);
283283
onResize?.call();
284284
}),
285285
);

0 commit comments

Comments
 (0)
0