From 1aeedcc5e53cacdf248b35a8b08b023153ce38c6 Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Thu, 16 Nov 2023 02:55:48 +0530 Subject: [PATCH] Completed functionality for muting the room --- packages/hms_room_kit/example/pubspec.lock | 9 +++-- .../lib/src/meeting/meeting_header.dart | 33 +++++++++---------- .../lib/src/meeting/meeting_store.dart | 13 ++------ .../audio_settings_bottom_sheet.dart | 9 +++-- packages/hms_room_kit/pubspec.lock | 9 +++-- packages/hms_room_kit/pubspec.yaml | 3 +- .../hms/hmssdk_flutter/HmssdkFlutterPlugin.kt | 16 ++++++++- .../hmssdk_flutter/methods/HMSAudioAction.kt | 6 ++-- .../hmssdk_flutter/example/ios/Podfile.lock | 6 ++-- packages/hmssdk_flutter/example/pubspec.lock | 9 +++-- .../ios/Classes/Actions/HMSAudioAction.swift | 7 ++-- .../Classes/SwiftHmssdkFlutterPlugin.swift | 18 ++++++++++ 12 files changed, 82 insertions(+), 56 deletions(-) diff --git a/packages/hms_room_kit/example/pubspec.lock b/packages/hms_room_kit/example/pubspec.lock index 9595cc4d8..bebc464bd 100644 --- a/packages/hms_room_kit/example/pubspec.lock +++ b/packages/hms_room_kit/example/pubspec.lock @@ -226,11 +226,10 @@ packages: hmssdk_flutter: dependency: transitive description: - name: hmssdk_flutter - sha256: c560e8bbb938676fdfb3c5bbfc28d4fdd10454e0d56762042027624922d8fbf8 - url: "https://pub.dev" - source: hosted - version: "1.9.2" + path: "../../hmssdk_flutter" + relative: true + source: path + version: "1.9.3" http: dependency: transitive description: diff --git a/packages/hms_room_kit/lib/src/meeting/meeting_header.dart b/packages/hms_room_kit/lib/src/meeting/meeting_header.dart index 12102ead0..b544c57e1 100644 --- a/packages/hms_room_kit/lib/src/meeting/meeting_header.dart +++ b/packages/hms_room_kit/lib/src/meeting/meeting_header.dart @@ -1,6 +1,5 @@ ///Dart imports import 'dart:developer'; -import 'dart:io'; ///Package imports import 'package:flutter/material.dart'; @@ -252,28 +251,28 @@ class _MeetingHeaderState extends State { ///This renders the audio device selection button ///If the role is allowed to publish audio, we render the audio device selection button ///else we render an empty SizedBox - Selector>( - selector: (_, meetingStore) => - Tuple2(meetingStore.currentAudioDeviceMode,meetingStore.isSpeakerOn), + Selector>( + selector: (_, meetingStore) => Tuple2( + meetingStore.currentAudioDeviceMode, + meetingStore.isSpeakerOn), builder: (_, data, __) { return HMSEmbeddedButton( onTap: () { - showModalBottomSheet( - isScrollControlled: true, - backgroundColor: Colors.transparent, - context: context, - builder: (ctx) => - ChangeNotifierProvider.value( - value: context - .read(), - child: - const AudioSettingsBottomSheet())); - + showModalBottomSheet( + isScrollControlled: true, + backgroundColor: Colors.transparent, + context: context, + builder: (ctx) => + ChangeNotifierProvider.value( + value: context + .read(), + child: + const AudioSettingsBottomSheet())); }, onColor: HMSThemeColors.backgroundDim, isActive: true, - child: - SvgPicture.asset('packages/hms_room_kit/lib/src/assets/icons/${!data.item2?"speaker_state_off":Utilities.getAudioDeviceIconName(data.item1)}.svg', + child: SvgPicture.asset( + 'packages/hms_room_kit/lib/src/assets/icons/${!data.item2 ? "speaker_state_off" : Utilities.getAudioDeviceIconName(data.item1)}.svg', colorFilter: ColorFilter.mode( HMSThemeColors.onSurfaceHighEmphasis, BlendMode.srcIn), diff --git a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart index bf8207e67..49381c034 100644 --- a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart +++ b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart @@ -746,7 +746,7 @@ class MeetingStore extends ChangeNotifier } void switchAudioOutput({required HMSAudioDevice audioDevice}) { - if(!isSpeakerOn){ + if (!isSpeakerOn) { toggleSpeaker(); } selfChangeAudioDevice = true; @@ -931,15 +931,6 @@ class MeetingStore extends ChangeNotifier required HMSPeer peer}) { log("onTrackUpdate-> track: ${track.toString()} peer: ${peer.name} update: ${trackUpdate.name}"); - if (!isSpeakerOn && - track.kind == HMSTrackKind.kHMSTrackKindAudio && - trackUpdate == HMSTrackUpdate.trackAdded) { - if (track.runtimeType == HMSRemoteAudioTrack) { - HMSRemoteAudioTrack currentTrack = track as HMSRemoteAudioTrack; - currentTrack.setPlaybackAllowed(false); - } - } - if (peer.isLocal) { localPeer = peer; if (track.kind == HMSTrackKind.kHMSTrackKindAudio && @@ -1906,7 +1897,7 @@ class MeetingStore extends ChangeNotifier // } void switchAudioOutputUsingiOSUI() { - if(!isSpeakerOn){ + if (!isSpeakerOn) { toggleSpeaker(); } _hmsSDKInteractor.switchAudioOutputUsingiOSUI(); diff --git a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/audio_settings_bottom_sheet.dart b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/audio_settings_bottom_sheet.dart index a5dab14f0..4ce973721 100644 --- a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/audio_settings_bottom_sheet.dart +++ b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/audio_settings_bottom_sheet.dart @@ -96,9 +96,12 @@ class _AudioSettingsBottomSheetState extends State { child: ListView( children: [ GestureDetector( - onTap: () => context - .read() - .switchAudioOutputUsingiOSUI(), + onTap: () => { + Navigator.pop(context), + context + .read() + .switchAudioOutputUsingiOSUI() + }, child: ListTile( horizontalTitleGap: 2, enabled: false, diff --git a/packages/hms_room_kit/pubspec.lock b/packages/hms_room_kit/pubspec.lock index f8fb585a2..3794f307e 100644 --- a/packages/hms_room_kit/pubspec.lock +++ b/packages/hms_room_kit/pubspec.lock @@ -211,11 +211,10 @@ packages: hmssdk_flutter: dependency: "direct main" description: - name: hmssdk_flutter - sha256: c560e8bbb938676fdfb3c5bbfc28d4fdd10454e0d56762042027624922d8fbf8 - url: "https://pub.dev" - source: hosted - version: "1.9.2" + path: "../hmssdk_flutter" + relative: true + source: path + version: "1.9.3" http: dependency: transitive description: diff --git a/packages/hms_room_kit/pubspec.yaml b/packages/hms_room_kit/pubspec.yaml index 842b3e66e..07415a5e9 100644 --- a/packages/hms_room_kit/pubspec.yaml +++ b/packages/hms_room_kit/pubspec.yaml @@ -14,7 +14,8 @@ dependencies: flutter: sdk: flutter - hmssdk_flutter: ^1.9.2 + hmssdk_flutter: + path: ../hmssdk_flutter intl: ^0.18.1 permission_handler: ^11.0.0 provider: ^6.0.5 diff --git a/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt b/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt index 224b55a5d..a1538c9ad 100644 --- a/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt +++ b/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/HmssdkFlutterPlugin.kt @@ -76,7 +76,7 @@ class HmssdkFlutterPlugin : private var hmsSessionStore: HmsSessionStore? = null private var hmsKeyChangeObserverList = ArrayList() var hlsStreamUrl: String? = null - + private var isRoomAudioUnmutedLocally = true override fun onAttachedToEngine( @NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding, ) { @@ -919,6 +919,13 @@ class HmssdkFlutterPlugin : ) } + /** + * This acts as a setter for [isRoomAudioUnmutedLocally] variable + */ + fun setIsRoomAudioUnmutedLocally(isRoomAudioUnmuted:Boolean){ + isRoomAudioUnmutedLocally = isRoomAudioUnmuted + } + fun build( activity: Activity, call: MethodCall, @@ -1091,6 +1098,13 @@ class HmssdkFlutterPlugin : track: HMSTrack, peer: HMSPeer, ) { + /** + * Here we set the playback of the audio to false if the room is muted locally + */ + if(track is HMSRemoteAudioTrack && type == HMSTrackUpdate.TRACK_ADDED && !isRoomAudioUnmutedLocally){ + track.isPlaybackAllowed = false + } + val args = HashMap() args.put("event_name", "on_track_update") args.put("data", HMSTrackUpdateExtension.toDictionary(peer, track, type)) diff --git a/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/methods/HMSAudioAction.kt b/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/methods/HMSAudioAction.kt index d4fb852b2..ea63f733a 100644 --- a/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/methods/HMSAudioAction.kt +++ b/packages/hmssdk_flutter/android/src/main/kotlin/live/hms/hmssdk_flutter/methods/HMSAudioAction.kt @@ -22,10 +22,10 @@ class HMSAudioAction { result.success(isAudioMute(call, hmssdk)) } "mute_room_audio_locally" -> { - toggleAudioMuteAll(true, result, hmssdk) + toggleAudioMuteAll(true, result, hmssdk,hmssdkFlutterPlugin) } "un_mute_room_audio_locally" -> { - toggleAudioMuteAll(false, result, hmssdk) + toggleAudioMuteAll(false, result, hmssdk,hmssdkFlutterPlugin) } "set_volume" -> { setVolume(call, result, hmssdk) @@ -81,6 +81,7 @@ class HMSAudioAction { shouldMute: Boolean, result: Result, hmssdk: HMSSDK, + hmssdkFlutterPlugin: HmssdkFlutterPlugin? ) { val room: HMSRoom? = hmssdk.getRoom() if (room != null) { @@ -90,6 +91,7 @@ class HMSAudioAction { it.isPlaybackAllowed = (!shouldMute) } } + hmssdkFlutterPlugin?.setIsRoomAudioUnmutedLocally(!shouldMute) } } diff --git a/packages/hmssdk_flutter/example/ios/Podfile.lock b/packages/hmssdk_flutter/example/ios/Podfile.lock index 8490ac914..5b86b1c0a 100644 --- a/packages/hmssdk_flutter/example/ios/Podfile.lock +++ b/packages/hmssdk_flutter/example/ios/Podfile.lock @@ -100,7 +100,7 @@ PODS: - HMSSDK (1.2.0): - HMSAnalyticsSDK (= 0.0.2) - HMSWebRTC (= 1.0.5116) - - hmssdk_flutter (1.9.2): + - hmssdk_flutter (1.9.3): - Flutter - HMSBroadcastExtensionSDK (= 0.0.9) - HMSHLSPlayerSDK (= 0.0.2) @@ -236,7 +236,7 @@ SPEC CHECKSUMS: HMSBroadcastExtensionSDK: d80fe325f6c928bd8e5176290b5a4b7ae15d6fbb HMSHLSPlayerSDK: 6a54ad4d12f3dc2270d1ecd24019d71282a4f6a3 HMSSDK: 010fdd904b8d221bb297864800503132fd721d9e - hmssdk_flutter: 1d4cfbb745095ebf399eaf533b6cde0c2006d6e1 + hmssdk_flutter: 9f04957779c044f2256a576a03f961171b37f6f7 HMSWebRTC: ae54e9dd91b869051b283b43b14f57d43b7bf8e1 MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5 @@ -253,4 +253,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 919064996fff867cd85dbf9e7730ff45bac23884 -COCOAPODS: 1.14.2 +COCOAPODS: 1.13.0 diff --git a/packages/hmssdk_flutter/example/pubspec.lock b/packages/hmssdk_flutter/example/pubspec.lock index a870e2b33..72384a504 100644 --- a/packages/hmssdk_flutter/example/pubspec.lock +++ b/packages/hmssdk_flutter/example/pubspec.lock @@ -298,11 +298,10 @@ packages: hmssdk_flutter: dependency: transitive description: - name: hmssdk_flutter - sha256: c560e8bbb938676fdfb3c5bbfc28d4fdd10454e0d56762042027624922d8fbf8 - url: "https://pub.dev" - source: hosted - version: "1.9.2" + path: ".." + relative: true + source: path + version: "1.9.3" http: dependency: transitive description: diff --git a/packages/hmssdk_flutter/ios/Classes/Actions/HMSAudioAction.swift b/packages/hmssdk_flutter/ios/Classes/Actions/HMSAudioAction.swift index 747aa9c14..99fcf813f 100644 --- a/packages/hmssdk_flutter/ios/Classes/Actions/HMSAudioAction.swift +++ b/packages/hmssdk_flutter/ios/Classes/Actions/HMSAudioAction.swift @@ -18,10 +18,10 @@ class HMSAudioAction { isAudioMute(call, result, hmsSDK) case "mute_room_audio_locally": - toggleAudioMuteAll(result, hmsSDK, shouldMute: true) + toggleAudioMuteAll(result, hmsSDK, shouldMute: true,swiftHmssdkFlutterPlugin) case "un_mute_room_audio_locally": - toggleAudioMuteAll(result, hmsSDK, shouldMute: false) + toggleAudioMuteAll(result, hmsSDK, shouldMute: false,swiftHmssdkFlutterPlugin) case "set_volume": setVolume(call, result, hmsSDK) @@ -86,7 +86,7 @@ class HMSAudioAction { result(false) } - static private func toggleAudioMuteAll(_ result: @escaping FlutterResult, _ hmsSDK: HMSSDK?, shouldMute: Bool) { + static private func toggleAudioMuteAll(_ result: @escaping FlutterResult, _ hmsSDK: HMSSDK?, shouldMute: Bool, _ swiftHmssdkFlutterPlugin: SwiftHmssdkFlutterPlugin) { let room = hmsSDK?.room if room != nil { @@ -97,6 +97,7 @@ class HMSAudioAction { (track as! HMSRemoteAudioTrack).setPlaybackAllowed(!shouldMute) } } + swiftHmssdkFlutterPlugin.setIsRoomAudioUnmutedLocally(isRoomAudioUnmuted: !shouldMute) } result(nil) } diff --git a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift index c4a001ed0..cb5b881c2 100644 --- a/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift +++ b/packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift @@ -39,6 +39,8 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene private var sessionStoreChangeObservers = [HMSSessionStoreKeyChangeListener]() var hlsStreamUrl: String? + + private var isRoomAudioUnmutedLocally = true // MARK: - Flutter Setup @@ -1046,6 +1048,15 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene } } } + + + /** + * This acts as a setter for [isRoomAudioUnmutedLocally] variable + */ + func setIsRoomAudioUnmutedLocally(isRoomAudioUnmuted:Bool){ + isRoomAudioUnmutedLocally = isRoomAudioUnmuted + } + // MARK: - Logging private var logLevel = HMSLogLevel.off @@ -1256,6 +1267,13 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene public func on(track: HMSTrack, update: HMSTrackUpdate, for peer: HMSPeer) { + /** + * Here we set the playback of the audio to false if the room is muted locally + */ + if(track is HMSRemoteAudioTrack && update == .trackAdded && !isRoomAudioUnmutedLocally){ + (track as! HMSRemoteAudioTrack).setPlaybackAllowed(false) + } + let data = [ "event_name": "on_track_update", "data": [