From 060ccda066cd7f183cfb8078322785f5feb9b420 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Thu, 21 Dec 2023 16:33:03 +0800 Subject: [PATCH] fix: Prevent ReplayKitChannel related code from being executed on non-iOS platforms. (#432) --- example/lib/pages/room.dart | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index 3e8d5716..ee04b11e 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -49,7 +49,9 @@ class _RoomPageState extends State { Hardware.instance.setSpeakerphoneOn(true); } - ReplayKitChannel.listenMethodChannel(widget.room); + if (lkPlatformIs(PlatformType.iOS)) { + ReplayKitChannel.listenMethodChannel(widget.room); + } if (lkPlatformIsDesktop()) { onWindowShouldClose = () async { @@ -64,7 +66,9 @@ class _RoomPageState extends State { void dispose() { // always dispose listener (() async { - ReplayKitChannel.closeReplayKit(); + if (lkPlatformIs(PlatformType.iOS)) { + ReplayKitChannel.closeReplayKit(); + } widget.room.removeListener(_onRoomDidUpdate); await _listener.dispose(); await widget.room.dispose(); @@ -203,22 +207,25 @@ class _RoomPageState extends State { if (localParticipantTracks != null) { for (var t in localParticipantTracks) { if (t.isScreenShare) { - if (!_flagStartedReplayKit) { - _flagStartedReplayKit = true; + if (lkPlatformIs(PlatformType.iOS)) { + if (!_flagStartedReplayKit) { + _flagStartedReplayKit = true; - ReplayKitChannel.startReplayKit(); + ReplayKitChannel.startReplayKit(); + } } - screenTracks.add(ParticipantTrack( participant: widget.room.localParticipant!, videoTrack: t.track, isScreenShare: true, )); } else { - if (_flagStartedReplayKit) { - _flagStartedReplayKit = false; + if (lkPlatformIs(PlatformType.iOS)) { + if (_flagStartedReplayKit) { + _flagStartedReplayKit = false; - ReplayKitChannel.closeReplayKit(); + ReplayKitChannel.closeReplayKit(); + } } userMediaTracks.add(ParticipantTrack(