diff --git a/example/lib/widgets/controls.dart b/example/lib/widgets/controls.dart index 421b1f265..8998888e8 100644 --- a/example/lib/widgets/controls.dart +++ b/example/lib/widgets/controls.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; @@ -203,7 +202,7 @@ class _ControlsWidgetState extends State { void _disableScreenShare() async { await participant.setScreenShareEnabled(false); - if (Platform.isAndroid) { + if (lkPlatformIs(PlatformType.android)) { // Android specific try { // await FlutterBackground.disableBackgroundExecution(); diff --git a/lib/src/internal/events.dart b/lib/src/internal/events.dart index 359d5d98b..f4fe608f9 100644 --- a/lib/src/internal/events.dart +++ b/lib/src/internal/events.dart @@ -408,3 +408,15 @@ class SubscriberDataChannelStateUpdatedEvent state: state, ); } + +@internal +class TrackEndedEvent with TrackEvent { + final Track track; + const TrackEndedEvent({ + required this.track, + }); + + @override + String toString() => '${runtimeType}' + '(track: ${track})'; +} diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index 23a379893..f1490ae52 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -24,6 +24,7 @@ import '../core/transport.dart'; import '../events.dart'; import '../exceptions.dart'; import '../extensions.dart'; +import '../internal/events.dart'; import '../logger.dart'; import '../options.dart'; import '../proto/livekit_models.pb.dart' as lk_models; @@ -108,6 +109,12 @@ class LocalParticipant extends Participant { await track.onPublish(); await room.applyAudioSpeakerSettings(); + var listener = track.createListener(); + listener.on((TrackEndedEvent event) { + logger.fine('TrackEndedEvent: ${event.track}'); + unpublishTrack(pub.sid); + }); + [events, room.events].emit(LocalTrackPublishedEvent( participant: this, publication: pub, @@ -300,6 +307,12 @@ class LocalParticipant extends Participant { // did publish await track.onPublish(); + var listener = track.createListener(); + listener.on((TrackEndedEvent event) { + logger.fine('TrackEndedEvent: ${event.track}'); + unpublishTrack(pub.sid); + }); + [events, room.events].emit(LocalTrackPublishedEvent( participant: this, publication: pub, @@ -471,6 +484,11 @@ class LocalParticipant extends Participant { } else { if (source == TrackSource.screenShareVideo) { await unpublishTrack(publication.sid); + final screenAudio = + getTrackPublicationBySource(TrackSource.screenShareAudio); + if (screenAudio != null) { + await unpublishTrack(screenAudio.sid); + } } else { await publication.mute(); } diff --git a/lib/src/track/local/local.dart b/lib/src/track/local/local.dart index f8df8625d..00fbea0af 100644 --- a/lib/src/track/local/local.dart +++ b/lib/src/track/local/local.dart @@ -80,7 +80,12 @@ abstract class LocalTrack extends Track { source, mediaStream, mediaStreamTrack, - ); + ) { + mediaStreamTrack.onEnded = () { + logger.fine('MediaStreamTrack.onEnded()'); + events.emit(TrackEndedEvent(track: this)); + }; + } /// Mutes this [LocalTrack]. This will stop the sending of track data /// and notify the [RemoteParticipant] with [TrackMutedEvent]. diff --git a/lib/src/widgets/video_track_renderer.dart b/lib/src/widgets/video_track_renderer.dart index cf1b281f5..301521667 100644 --- a/lib/src/widgets/video_track_renderer.dart +++ b/lib/src/widgets/video_track_renderer.dart @@ -24,6 +24,7 @@ import '../support/platform.dart'; import '../track/local/local.dart'; import '../track/local/video.dart'; import '../track/options.dart'; +import '../types/other.dart'; enum VideoViewMirrorMode { auto, @@ -129,6 +130,8 @@ class _VideoTrackRendererState extends State { ); bool _shouldMirror() { + // off for screen share + if (widget.track.source == TrackSource.screenShareVideo) return false; // on if (widget.mirrorMode == VideoViewMirrorMode.mirror) return true; // auto diff --git a/pubspec.yaml b/pubspec.yaml index 15b022359..a1058db08 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,7 +38,7 @@ dependencies: uuid: '>=3.0.6' synchronized: ^3.0.0+3 protobuf: ^3.0.0 - flutter_webrtc: 0.9.45 + flutter_webrtc: 0.9.46 flutter_window_close: ^0.2.2 device_info_plus: '>=8.0.0' js: ^0.6.4