Skip to content

Commit

Permalink
fix: video renderer dispose issue and correctly handle metadataMuted …
Browse files Browse the repository at this point in the history
…for TrackPublication. (#401)

* fix: video renderer dispose issue.

* remove strong-mode in analysis_options.yaml to compatible flutter 3.16.0.

* Correctly handle metadataMuted for TrackPublication.
  • Loading branch information
cloudwebrtc authored Nov 16, 2023
1 parent 1366ff2 commit f08556e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ analyzer:
# https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks
# https://dash-overflow.net/articles/getting_started/#step-3-disabling-_implicit-dynamic_--_implicit-cast_
#
strong-mode:

#
# exclude protobuf files
Expand Down
1 change: 0 additions & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ analyzer:
# https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks
# https://dash-overflow.net/articles/getting_started/#step-3-disabling-_implicit-dynamic_--_implicit-cast_
#
strong-mode:

#
# exclude protobuf files
Expand Down
5 changes: 4 additions & 1 deletion lib/src/publication/track_publication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class TrackPublication<T extends Track> extends Disposable {
final String name;
final lk_models.TrackType kind;
final TrackSource source;
bool _metadataMuted = false;

/// The current [Track] for this publication (readonly).
T? get track => _track;
Expand All @@ -40,7 +41,7 @@ abstract class TrackPublication<T extends Track> extends Disposable {
/// The [Participant] this publication belongs to.
abstract final Participant participant;

bool get muted => track?.muted ?? false;
bool get muted => _metadataMuted;

/// If the [Track] is published with simulcast, only for video. (readonly)
bool get simulcasted => _simulcasted;
Expand Down Expand Up @@ -72,6 +73,7 @@ abstract class TrackPublication<T extends Track> extends Disposable {
kind = info.type,
source = info.source.toLKType(),
_simulcasted = info.simulcast,
_metadataMuted = info.muted,
_mimeType = info.mimeType {
updateFromInfo(info);
}
Expand All @@ -84,6 +86,7 @@ abstract class TrackPublication<T extends Track> extends Disposable {
void updateFromInfo(lk_models.TrackInfo info) {
_simulcasted = info.simulcast;
_mimeType = info.mimeType;
_metadataMuted = info.muted;
if (info.type == lk_models.TrackType.VIDEO) {
_dimensions = VideoDimensions(info.width, info.height);
}
Expand Down
18 changes: 9 additions & 9 deletions lib/src/widgets/video_track_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class VideoTrackRenderer extends StatefulWidget {
}

class _VideoTrackRendererState extends State<VideoTrackRenderer> {
final _renderer = rtc.RTCVideoRenderer();
rtc.RTCVideoRenderer? _renderer;
bool _rendererReady = false;
EventsListener<TrackEvent>? _listener;
// Used to compute visibility information
Expand All @@ -60,9 +60,9 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
void initState() {
super.initState();
_internalKey = widget.track.addViewKey();

(() async {
await _renderer.initialize();
_renderer ??= rtc.RTCVideoRenderer();
await _renderer?.initialize();
await _attach();
setState(() => _rendererReady = true);
})();
Expand All @@ -72,18 +72,18 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
void dispose() {
widget.track.removeViewKey(_internalKey);
_listener?.dispose();
_renderer.srcObject = null;
_renderer.dispose();
_renderer?.srcObject = null;
_renderer?.dispose();
super.dispose();
}

Future<void> _attach() async {
_renderer.srcObject = widget.track.mediaStream;
_renderer?.srcObject = widget.track.mediaStream;
await _listener?.dispose();
_listener = widget.track.createListener()
..on<TrackStreamUpdatedEvent>((event) {
if (!mounted) return;
_renderer.srcObject = event.stream;
_renderer?.srcObject = event.stream;
})
..on<LocalTrackOptionsUpdatedEvent>((event) {
if (!mounted) return;
Expand All @@ -105,7 +105,7 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {

if ([BrowserType.safari, BrowserType.firefox].contains(lkBrowser()) &&
oldWidget.key != widget.key) {
_renderer.srcObject = widget.track.mediaStream;
_renderer?.srcObject = widget.track.mediaStream;
}
}

Expand All @@ -121,7 +121,7 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
widget.track.onVideoViewBuild?.call(_internalKey);
});
return rtc.RTCVideoView(
_renderer,
_renderer!,
mirror: _shouldMirror(),
filterQuality: FilterQuality.medium,
objectFit: widget.fit,
Expand Down

0 comments on commit f08556e

Please sign in to comment.