diff --git a/example/lib/widgets/controls.dart b/example/lib/widgets/controls.dart index 421b1f265..1488cc31c 100644 --- a/example/lib/widgets/controls.dart +++ b/example/lib/widgets/controls.dart @@ -203,7 +203,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/events.dart b/lib/src/events.dart index 01237d665..04cf7fb54 100644 --- a/lib/src/events.dart +++ b/lib/src/events.dart @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import 'package:meta/meta.dart'; + import 'core/engine.dart'; import 'core/room.dart'; import 'core/signal_client.dart'; @@ -504,3 +506,15 @@ class VideoReceiverStatsEvent with TrackEvent { String toString() => '${runtimeType}' 'stats: ${stats})'; } + +@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 0570fa5e1..2bf049df8 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -108,6 +108,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 +306,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, 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].