Skip to content

Commit

Permalink
Completed functionality for muting the room
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Nov 15, 2023
1 parent 0efe85f commit 1aeedcc
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 56 deletions.
9 changes: 4 additions & 5 deletions packages/hms_room_kit/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 16 additions & 17 deletions packages/hms_room_kit/lib/src/meeting/meeting_header.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
///Dart imports
import 'dart:developer';
import 'dart:io';

///Package imports
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -252,28 +251,28 @@ class _MeetingHeaderState extends State<MeetingHeader> {
///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<MeetingStore, Tuple2<HMSAudioDevice?,bool>>(
selector: (_, meetingStore) =>
Tuple2(meetingStore.currentAudioDeviceMode,meetingStore.isSpeakerOn),
Selector<MeetingStore, Tuple2<HMSAudioDevice?, bool>>(
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<MeetingStore>(),
child:
const AudioSettingsBottomSheet()));

showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
context: context,
builder: (ctx) =>
ChangeNotifierProvider.value(
value: context
.read<MeetingStore>(),
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),
Expand Down
13 changes: 2 additions & 11 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ class MeetingStore extends ChangeNotifier
}

void switchAudioOutput({required HMSAudioDevice audioDevice}) {
if(!isSpeakerOn){
if (!isSpeakerOn) {
toggleSpeaker();
}
selfChangeAudioDevice = true;
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -1906,7 +1897,7 @@ class MeetingStore extends ChangeNotifier
// }

void switchAudioOutputUsingiOSUI() {
if(!isSpeakerOn){
if (!isSpeakerOn) {
toggleSpeaker();
}
_hmsSDKInteractor.switchAudioOutputUsingiOSUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ class _AudioSettingsBottomSheetState extends State<AudioSettingsBottomSheet> {
child: ListView(
children: [
GestureDetector(
onTap: () => context
.read<MeetingStore>()
.switchAudioOutputUsingiOSUI(),
onTap: () => {
Navigator.pop(context),
context
.read<MeetingStore>()
.switchAudioOutputUsingiOSUI()
},
child: ListTile(
horizontalTitleGap: 2,
enabled: false,
Expand Down
9 changes: 4 additions & 5 deletions packages/hms_room_kit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion packages/hms_room_kit/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class HmssdkFlutterPlugin :
private var hmsSessionStore: HmsSessionStore? = null
private var hmsKeyChangeObserverList = ArrayList<HMSKeyChangeObserver>()
var hlsStreamUrl: String? = null

private var isRoomAudioUnmutedLocally = true
override fun onAttachedToEngine(
@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding,
) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, Any?>()
args.put("event_name", "on_track_update")
args.put("data", HMSTrackUpdateExtension.toDictionary(peer, track, type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -81,6 +81,7 @@ class HMSAudioAction {
shouldMute: Boolean,
result: Result,
hmssdk: HMSSDK,
hmssdkFlutterPlugin: HmssdkFlutterPlugin?
) {
val room: HMSRoom? = hmssdk.getRoom()
if (room != null) {
Expand All @@ -90,6 +91,7 @@ class HMSAudioAction {
it.isPlaybackAllowed = (!shouldMute)
}
}
hmssdkFlutterPlugin?.setIsRoomAudioUnmutedLocally(!shouldMute)
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/hmssdk_flutter/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -236,7 +236,7 @@ SPEC CHECKSUMS:
HMSBroadcastExtensionSDK: d80fe325f6c928bd8e5176290b5a4b7ae15d6fbb
HMSHLSPlayerSDK: 6a54ad4d12f3dc2270d1ecd24019d71282a4f6a3
HMSSDK: 010fdd904b8d221bb297864800503132fd721d9e
hmssdk_flutter: 1d4cfbb745095ebf399eaf533b6cde0c2006d6e1
hmssdk_flutter: 9f04957779c044f2256a576a03f961171b37f6f7
HMSWebRTC: ae54e9dd91b869051b283b43b14f57d43b7bf8e1
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
Expand All @@ -253,4 +253,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 919064996fff867cd85dbf9e7730ff45bac23884

COCOAPODS: 1.14.2
COCOAPODS: 1.13.0
9 changes: 4 additions & 5 deletions packages/hmssdk_flutter/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -97,6 +97,7 @@ class HMSAudioAction {
(track as! HMSRemoteAudioTrack).setPlaybackAllowed(!shouldMute)
}
}
swiftHmssdkFlutterPlugin.setIsRoomAudioUnmutedLocally(isRoomAudioUnmuted: !shouldMute)
}
result(nil)
}
Expand Down
18 changes: 18 additions & 0 deletions packages/hmssdk_flutter/ios/Classes/SwiftHmssdkFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class SwiftHmssdkFlutterPlugin: NSObject, FlutterPlugin, HMSUpdateListene
private var sessionStoreChangeObservers = [HMSSessionStoreKeyChangeListener]()

var hlsStreamUrl: String?

private var isRoomAudioUnmutedLocally = true

// MARK: - Flutter Setup

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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": [
Expand Down

0 comments on commit 1aeedcc

Please sign in to comment.