@100mslive/react-native-hms 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +44 -29
  2. package/android/build.gradle +5 -1
  3. package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +23 -23
  4. package/android/src/main/java/com/reactnativehmssdk/HMSManager.kt +289 -32
  5. package/android/src/main/java/com/reactnativehmssdk/HMSRNSDK.kt +649 -548
  6. package/android/src/main/java/com/reactnativehmssdk/PipActionReceiver.kt +66 -0
  7. package/android/src/main/res/drawable/ic_call_end_24.xml +10 -0
  8. package/android/src/main/res/drawable/ic_camera_toggle_off.xml +11 -0
  9. package/android/src/main/res/drawable/ic_camera_toggle_on.xml +10 -0
  10. package/android/src/main/res/drawable/ic_mic_24.xml +10 -0
  11. package/android/src/main/res/drawable/ic_mic_off_24.xml +10 -0
  12. package/ios/HMSDecoder.swift +3 -5
  13. package/ios/HMSHelper.swift +18 -12
  14. package/ios/HMSManager.m +2 -0
  15. package/ios/HMSManager.swift +15 -0
  16. package/ios/HMSRNSDK.swift +36 -0
  17. package/lib/commonjs/classes/HMSPIPListenerActions.js +12 -0
  18. package/lib/commonjs/classes/HMSPIPListenerActions.js.map +1 -0
  19. package/lib/commonjs/classes/HMSSDK.js +60 -7
  20. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  21. package/lib/commonjs/index.js +12 -0
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/module/classes/HMSPIPListenerActions.js +5 -0
  24. package/lib/module/classes/HMSPIPListenerActions.js.map +1 -0
  25. package/lib/module/classes/HMSSDK.js +60 -7
  26. package/lib/module/classes/HMSSDK.js.map +1 -1
  27. package/lib/module/index.js +1 -0
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/typescript/classes/HMSPIPListenerActions.d.ts +3 -0
  30. package/lib/typescript/classes/HMSSDK.d.ts +41 -2
  31. package/lib/typescript/index.d.ts +1 -0
  32. package/package.json +1 -1
  33. package/react-native-hms.podspec +2 -1
  34. package/src/classes/HMSPIPListenerActions.ts +3 -0
  35. package/src/classes/HMSSDK.tsx +111 -7
  36. package/src/index.ts +1 -0
@@ -20,10 +20,10 @@ import live.hms.video.utils.HMSCoroutineScope
20
20
  import live.hms.video.utils.HmsUtilities
21
21
 
22
22
  class HMSRNSDK(
23
- data: ReadableMap?,
24
- HmsDelegate: HMSManager,
25
- sdkId: String,
26
- reactApplicationContext: ReactApplicationContext
23
+ data: ReadableMap?,
24
+ HmsDelegate: HMSManager,
25
+ sdkId: String,
26
+ reactApplicationContext: ReactApplicationContext
27
27
  ) {
28
28
  var hmsSDK: HMSSDK? = null
29
29
  var screenshareCallback: Promise? = null
@@ -81,15 +81,15 @@ class HMSRNSDK(
81
81
  private fun emitRequiredKeysError(message: String) {
82
82
  val data: WritableMap = Arguments.createMap()
83
83
  val hmsError =
84
- HMSException(
85
- 6002,
86
- "REQUIRED_KEYS_NOT_FOUND",
87
- "SEND_ALL_REQUIRED_KEYS",
88
- message,
89
- message,
90
- null,
91
- false
92
- )
84
+ HMSException(
85
+ 6002,
86
+ "REQUIRED_KEYS_NOT_FOUND",
87
+ "SEND_ALL_REQUIRED_KEYS",
88
+ message,
89
+ message,
90
+ null,
91
+ false
92
+ )
93
93
  data.putString("id", id)
94
94
  data.putMap("error", HMSDecoder.getError(hmsError))
95
95
  delegate.emitEvent("ON_ERROR", data)
@@ -108,7 +108,7 @@ class HMSRNSDK(
108
108
 
109
109
  fun emitHMSSuccess(message: HMSMessage? = null): ReadableMap {
110
110
  val hmsMessage =
111
- if (message !== null) message.message else "function call executed successfully"
111
+ if (message !== null) message.message else "function call executed successfully"
112
112
  val data: WritableMap = Arguments.createMap()
113
113
  data.putBoolean("success", true)
114
114
  data.putString("message", hmsMessage)
@@ -121,72 +121,72 @@ class HMSRNSDK(
121
121
  return
122
122
  }
123
123
  val requiredKeys =
124
- HMSHelper.getUnavailableRequiredKey(
125
- credentials,
126
- arrayOf(Pair("username", "String"), Pair("authToken", "String"))
127
- )
124
+ HMSHelper.getUnavailableRequiredKey(
125
+ credentials,
126
+ arrayOf(Pair("username", "String"), Pair("authToken", "String"))
127
+ )
128
128
  if (requiredKeys === null) {
129
129
  previewInProgress = true
130
130
  val config = HMSHelper.getHmsConfig(credentials)
131
131
 
132
132
  hmsSDK?.preview(
133
- config,
134
- object : HMSPreviewListener {
135
- override fun onError(error: HMSException) {
136
- self.emitHMSError(error)
137
- previewInProgress = false
138
- }
133
+ config,
134
+ object : HMSPreviewListener {
135
+ override fun onError(error: HMSException) {
136
+ self.emitHMSError(error)
137
+ previewInProgress = false
138
+ }
139
139
 
140
- override fun onPeerUpdate(type: HMSPeerUpdate, peer: HMSPeer) {
141
- if (type === HMSPeerUpdate.AUDIO_TOGGLED ||
142
- type === HMSPeerUpdate.VIDEO_TOGGLED ||
143
- type === HMSPeerUpdate.BECAME_DOMINANT_SPEAKER ||
144
- type === HMSPeerUpdate.NO_DOMINANT_SPEAKER ||
145
- type === HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER ||
146
- type === HMSPeerUpdate.STARTED_SPEAKING ||
147
- type === HMSPeerUpdate.STOPPED_SPEAKING
148
- ) {
149
- return
150
- }
151
- if (!networkQualityUpdatesAttached && type === HMSPeerUpdate.NETWORK_QUALITY_UPDATED
152
- ) {
153
- return
154
- }
155
- val updateType = type.name
156
- val hmsPeer = HMSDecoder.getHmsPeer(peer)
140
+ override fun onPeerUpdate(type: HMSPeerUpdate, peer: HMSPeer) {
141
+ if (type === HMSPeerUpdate.AUDIO_TOGGLED ||
142
+ type === HMSPeerUpdate.VIDEO_TOGGLED ||
143
+ type === HMSPeerUpdate.BECAME_DOMINANT_SPEAKER ||
144
+ type === HMSPeerUpdate.NO_DOMINANT_SPEAKER ||
145
+ type === HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER ||
146
+ type === HMSPeerUpdate.STARTED_SPEAKING ||
147
+ type === HMSPeerUpdate.STOPPED_SPEAKING
148
+ ) {
149
+ return
150
+ }
151
+ if (!networkQualityUpdatesAttached && type === HMSPeerUpdate.NETWORK_QUALITY_UPDATED
152
+ ) {
153
+ return
154
+ }
155
+ val updateType = type.name
156
+ val hmsPeer = HMSDecoder.getHmsPeer(peer)
157
157
 
158
- val data: WritableMap = Arguments.createMap()
158
+ val data: WritableMap = Arguments.createMap()
159
159
 
160
- data.putMap("peer", hmsPeer)
161
- data.putString("type", updateType)
162
- data.putString("id", id)
163
- delegate.emitEvent("ON_PEER_UPDATE", data)
164
- }
160
+ data.putMap("peer", hmsPeer)
161
+ data.putString("type", updateType)
162
+ data.putString("id", id)
163
+ delegate.emitEvent("ON_PEER_UPDATE", data)
164
+ }
165
165
 
166
- override fun onRoomUpdate(type: HMSRoomUpdate, hmsRoom: HMSRoom) {
167
- val updateType = type.name
168
- val roomData = HMSDecoder.getHmsRoom(hmsRoom)
166
+ override fun onRoomUpdate(type: HMSRoomUpdate, hmsRoom: HMSRoom) {
167
+ val updateType = type.name
168
+ val roomData = HMSDecoder.getHmsRoom(hmsRoom)
169
169
 
170
- val data: WritableMap = Arguments.createMap()
170
+ val data: WritableMap = Arguments.createMap()
171
171
 
172
- data.putString("type", updateType)
173
- data.putMap("room", roomData)
174
- data.putString("id", id)
175
- delegate.emitEvent("ON_ROOM_UPDATE", data)
176
- }
172
+ data.putString("type", updateType)
173
+ data.putMap("room", roomData)
174
+ data.putString("id", id)
175
+ delegate.emitEvent("ON_ROOM_UPDATE", data)
176
+ }
177
177
 
178
- override fun onPreview(room: HMSRoom, localTracks: Array<HMSTrack>) {
179
- val previewTracks = HMSDecoder.getPreviewTracks(localTracks)
180
- val hmsRoom = HMSDecoder.getHmsRoom(room)
181
- val data: WritableMap = Arguments.createMap()
178
+ override fun onPreview(room: HMSRoom, localTracks: Array<HMSTrack>) {
179
+ val previewTracks = HMSDecoder.getPreviewTracks(localTracks)
180
+ val hmsRoom = HMSDecoder.getHmsRoom(room)
181
+ val data: WritableMap = Arguments.createMap()
182
182
 
183
- data.putArray("previewTracks", previewTracks)
184
- data.putMap("room", hmsRoom)
185
- data.putString("id", id)
186
- delegate.emitEvent("ON_PREVIEW", data)
187
- previewInProgress = false
188
- }
183
+ data.putArray("previewTracks", previewTracks)
184
+ data.putMap("room", hmsRoom)
185
+ data.putString("id", id)
186
+ delegate.emitEvent("ON_PREVIEW", data)
187
+ previewInProgress = false
189
188
  }
189
+ }
190
190
  )
191
191
  } else {
192
192
  val errorMessage = "preview: $requiredKeys"
@@ -200,10 +200,10 @@ class HMSRNSDK(
200
200
  return
201
201
  }
202
202
  val requiredKeys =
203
- HMSHelper.getUnavailableRequiredKey(
204
- credentials,
205
- arrayOf(Pair("username", "String"), Pair("authToken", "String"))
206
- )
203
+ HMSHelper.getUnavailableRequiredKey(
204
+ credentials,
205
+ arrayOf(Pair("username", "String"), Pair("authToken", "String"))
206
+ )
207
207
  if (requiredKeys === null) {
208
208
  reconnectingStage = false
209
209
  val config = HMSHelper.getHmsConfig(credentials)
@@ -211,264 +211,266 @@ class HMSRNSDK(
211
211
  HMSCoroutineScope.launch {
212
212
  try {
213
213
  hmsSDK?.join(
214
- config,
215
- object : HMSUpdateListener {
216
- override fun onChangeTrackStateRequest(details: HMSChangeTrackStateRequest) {
217
- val decodedChangeTrackStateRequest =
218
- HMSDecoder.getHmsChangeTrackStateRequest(details, id)
219
- delegate.emitEvent(
220
- "ON_CHANGE_TRACK_STATE_REQUEST",
221
- decodedChangeTrackStateRequest
222
- )
223
- }
214
+ config,
215
+ object : HMSUpdateListener {
216
+ override fun onChangeTrackStateRequest(details: HMSChangeTrackStateRequest) {
217
+ val decodedChangeTrackStateRequest =
218
+ HMSDecoder.getHmsChangeTrackStateRequest(details, id)
219
+ delegate.emitEvent(
220
+ "ON_CHANGE_TRACK_STATE_REQUEST",
221
+ decodedChangeTrackStateRequest
222
+ )
223
+ }
224
224
 
225
- override fun onRemovedFromRoom(notification: HMSRemovedFromRoom) {
226
- super.onRemovedFromRoom(notification)
225
+ override fun onRemovedFromRoom(notification: HMSRemovedFromRoom) {
226
+ super.onRemovedFromRoom(notification)
227
227
 
228
- val data: WritableMap = Arguments.createMap()
229
- val requestedBy =
230
- HMSDecoder.getHmsRemotePeer(notification.peerWhoRemoved as HMSRemotePeer?)
231
- val roomEnded = notification.roomWasEnded
232
- val reason = notification.reason
228
+ val data: WritableMap = Arguments.createMap()
229
+ val requestedBy =
230
+ HMSDecoder.getHmsRemotePeer(notification.peerWhoRemoved as HMSRemotePeer?)
231
+ val roomEnded = notification.roomWasEnded
232
+ val reason = notification.reason
233
+
234
+ data.putMap("requestedBy", requestedBy)
235
+ data.putBoolean("roomEnded", roomEnded)
236
+ data.putString("reason", reason)
237
+ data.putString("id", id)
233
238
 
234
- data.putMap("requestedBy", requestedBy)
235
- data.putBoolean("roomEnded", roomEnded)
236
- data.putString("reason", reason)
237
- data.putString("id", id)
239
+ delegate.emitEvent("ON_REMOVED_FROM_ROOM", data)
240
+ }
238
241
 
239
- delegate.emitEvent("ON_REMOVED_FROM_ROOM", data)
240
- }
242
+ override fun onError(error: HMSException) {
243
+ self.emitHMSError(error)
244
+ }
241
245
 
242
- override fun onError(error: HMSException) {
243
- self.emitHMSError(error)
244
- }
246
+ override fun onJoin(room: HMSRoom) {
247
+ val roomData = HMSDecoder.getHmsRoom(room)
245
248
 
246
- override fun onJoin(room: HMSRoom) {
247
- val roomData = HMSDecoder.getHmsRoom(room)
249
+ val data: WritableMap = Arguments.createMap()
248
250
 
249
- val data: WritableMap = Arguments.createMap()
251
+ data.putMap("room", roomData)
252
+ data.putString("id", id)
253
+ delegate.emitEvent("ON_JOIN", data)
254
+ }
250
255
 
251
- data.putMap("room", roomData)
252
- data.putString("id", id)
253
- delegate.emitEvent("ON_JOIN", data)
256
+ override fun onPeerUpdate(type: HMSPeerUpdate, peer: HMSPeer) {
257
+ if (type === HMSPeerUpdate.AUDIO_TOGGLED ||
258
+ type === HMSPeerUpdate.VIDEO_TOGGLED ||
259
+ type === HMSPeerUpdate.BECAME_DOMINANT_SPEAKER ||
260
+ type === HMSPeerUpdate.NO_DOMINANT_SPEAKER ||
261
+ type === HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER ||
262
+ type === HMSPeerUpdate.STARTED_SPEAKING ||
263
+ type === HMSPeerUpdate.STOPPED_SPEAKING
264
+ ) {
265
+ return
254
266
  }
255
-
256
- override fun onPeerUpdate(type: HMSPeerUpdate, peer: HMSPeer) {
257
- if (type === HMSPeerUpdate.AUDIO_TOGGLED ||
258
- type === HMSPeerUpdate.VIDEO_TOGGLED ||
259
- type === HMSPeerUpdate.BECAME_DOMINANT_SPEAKER ||
260
- type === HMSPeerUpdate.NO_DOMINANT_SPEAKER ||
261
- type === HMSPeerUpdate.RESIGNED_DOMINANT_SPEAKER ||
262
- type === HMSPeerUpdate.STARTED_SPEAKING ||
263
- type === HMSPeerUpdate.STOPPED_SPEAKING
264
- ) {
265
- return
266
- }
267
- if (!networkQualityUpdatesAttached &&
268
- type === HMSPeerUpdate.NETWORK_QUALITY_UPDATED
269
- ) {
270
- return
271
- }
272
- val updateType = type.name
273
- val hmsPeer = HMSDecoder.getHmsPeer(peer)
274
-
275
- val data: WritableMap = Arguments.createMap()
276
-
277
- data.putMap("peer", hmsPeer)
278
- data.putString("type", updateType)
279
- data.putString("id", id)
280
- delegate.emitEvent("ON_PEER_UPDATE", data)
267
+ if (!networkQualityUpdatesAttached &&
268
+ type === HMSPeerUpdate.NETWORK_QUALITY_UPDATED
269
+ ) {
270
+ return
281
271
  }
272
+ val updateType = type.name
273
+ val hmsPeer = HMSDecoder.getHmsPeer(peer)
282
274
 
283
- override fun onRoomUpdate(type: HMSRoomUpdate, hmsRoom: HMSRoom) {
284
- val updateType = type.name
285
- val roomData = HMSDecoder.getHmsRoom(hmsRoom)
275
+ val data: WritableMap = Arguments.createMap()
286
276
 
287
- val data: WritableMap = Arguments.createMap()
277
+ data.putMap("peer", hmsPeer)
278
+ data.putString("type", updateType)
279
+ data.putString("id", id)
280
+ delegate.emitEvent("ON_PEER_UPDATE", data)
281
+ }
288
282
 
289
- data.putString("type", updateType)
290
- data.putMap("room", roomData)
291
- data.putString("id", id)
292
- delegate.emitEvent("ON_ROOM_UPDATE", data)
293
- }
283
+ override fun onRoomUpdate(type: HMSRoomUpdate, hmsRoom: HMSRoom) {
284
+ val updateType = type.name
285
+ val roomData = HMSDecoder.getHmsRoom(hmsRoom)
294
286
 
295
- override fun onTrackUpdate(type: HMSTrackUpdate, track: HMSTrack, peer: HMSPeer) {
296
- val updateType = type.name
297
- val hmsPeer = HMSDecoder.getHmsPeer(peer)
298
- val hmsTrack = HMSDecoder.getHmsTrack(track)
287
+ val data: WritableMap = Arguments.createMap()
299
288
 
300
- val data: WritableMap = Arguments.createMap()
289
+ data.putString("type", updateType)
290
+ data.putMap("room", roomData)
291
+ data.putString("id", id)
292
+ delegate.emitEvent("ON_ROOM_UPDATE", data)
293
+ }
301
294
 
302
- data.putMap("peer", hmsPeer)
303
- data.putMap("track", hmsTrack)
304
- data.putString("type", updateType)
305
- data.putString("id", id)
306
- delegate.emitEvent("ON_TRACK_UPDATE", data)
307
- }
295
+ override fun onTrackUpdate(type: HMSTrackUpdate, track: HMSTrack, peer: HMSPeer) {
296
+ val updateType = type.name
297
+ val hmsPeer = HMSDecoder.getHmsPeer(peer)
298
+ val hmsTrack = HMSDecoder.getHmsTrack(track)
308
299
 
309
- override fun onMessageReceived(message: HMSMessage) {
310
- val data: WritableMap = Arguments.createMap()
300
+ val data: WritableMap = Arguments.createMap()
311
301
 
312
- data.putMap("sender", HMSDecoder.getHmsPeer(message.sender))
313
- data.putString("message", message.message)
314
- data.putString("type", message.type)
315
- data.putString("time", message.serverReceiveTime.toString())
316
- data.putString("id", id)
317
- data.putMap("recipient", HMSDecoder.getHmsMessageRecipient(message.recipient))
302
+ data.putMap("peer", hmsPeer)
303
+ data.putMap("track", hmsTrack)
304
+ data.putString("type", updateType)
305
+ data.putString("id", id)
306
+ delegate.emitEvent("ON_TRACK_UPDATE", data)
307
+ }
318
308
 
319
- delegate.emitEvent("ON_MESSAGE", data)
320
- }
309
+ override fun onMessageReceived(message: HMSMessage) {
310
+ val data: WritableMap = Arguments.createMap()
321
311
 
322
- override fun onReconnected() {
323
- reconnectingStage = false
324
- val data: WritableMap = Arguments.createMap()
325
- data.putString("event", "RECONNECTED")
326
- data.putString("id", id)
327
- delegate.emitEvent("RECONNECTED", data)
328
- }
312
+ data.putMap("sender", HMSDecoder.getHmsPeer(message.sender))
313
+ data.putString("message", message.message)
314
+ data.putString("type", message.type)
315
+ data.putString("time", message.serverReceiveTime.toString())
316
+ data.putString("id", id)
317
+ data.putMap("recipient", HMSDecoder.getHmsMessageRecipient(message.recipient))
329
318
 
330
- override fun onReconnecting(error: HMSException) {
331
- reconnectingStage = true
332
- val data: WritableMap = Arguments.createMap()
333
- data.putMap("error", HMSDecoder.getError(error))
334
- data.putString("event", "RECONNECTING")
335
- data.putString("id", id)
336
- delegate.emitEvent("RECONNECTING", data)
337
- }
319
+ delegate.emitEvent("ON_MESSAGE", data)
320
+ }
338
321
 
339
- override fun onRoleChangeRequest(request: HMSRoleChangeRequest) {
340
- val decodedChangeRoleRequest = HMSDecoder.getHmsRoleChangeRequest(request, id)
341
- delegate.emitEvent("ON_ROLE_CHANGE_REQUEST", decodedChangeRoleRequest)
342
- recentRoleChangeRequest = request
343
- }
322
+ override fun onReconnected() {
323
+ reconnectingStage = false
324
+ val data: WritableMap = Arguments.createMap()
325
+ data.putString("event", "RECONNECTED")
326
+ data.putString("id", id)
327
+ delegate.emitEvent("RECONNECTED", data)
328
+ }
329
+
330
+ override fun onReconnecting(error: HMSException) {
331
+ reconnectingStage = true
332
+ val data: WritableMap = Arguments.createMap()
333
+ data.putMap("error", HMSDecoder.getError(error))
334
+ data.putString("event", "RECONNECTING")
335
+ data.putString("id", id)
336
+ delegate.emitEvent("RECONNECTING", data)
337
+ }
338
+
339
+ override fun onRoleChangeRequest(request: HMSRoleChangeRequest) {
340
+ val decodedChangeRoleRequest = HMSDecoder.getHmsRoleChangeRequest(request, id)
341
+ delegate.emitEvent("ON_ROLE_CHANGE_REQUEST", decodedChangeRoleRequest)
342
+ recentRoleChangeRequest = request
344
343
  }
344
+ }
345
345
  )
346
346
  } catch (e: HMSException) {
347
347
  self.emitHMSError(e)
348
348
  }
349
349
 
350
350
  hmsSDK?.addAudioObserver(
351
- object : HMSAudioListener {
352
- override fun onAudioLevelUpdate(speakers: Array<HMSSpeaker>) {
353
- val data: WritableMap = Arguments.createMap()
354
- data.putString("event", "ON_SPEAKER")
351
+ object : HMSAudioListener {
352
+ override fun onAudioLevelUpdate(speakers: Array<HMSSpeaker>) {
353
+ val data: WritableMap = Arguments.createMap()
354
+ data.putString("event", "ON_SPEAKER")
355
355
 
356
- val peers: WritableArray = Arguments.createArray()
357
- for (speaker in speakers) {
356
+ val peers: WritableArray = Arguments.createArray()
357
+ for (speaker in speakers) {
358
+ speaker.peer?.let {
358
359
  val speakerArray: WritableMap = Arguments.createMap()
359
- speakerArray.putMap("peer", HMSDecoder.getHmsPeer(speaker.peer))
360
+ speakerArray.putMap("peer", HMSDecoder.getHmsPeer(it))
360
361
  speakerArray.putInt("level", speaker.level)
361
362
  speakerArray.putMap("track", HMSDecoder.getHmsTrack(speaker.hmsTrack))
362
363
  peers.pushMap(speakerArray)
363
364
  }
364
- data.putArray("speakers", peers)
365
- data.putString("id", id)
366
- delegate.emitEvent("ON_SPEAKER", data)
367
365
  }
366
+ data.putArray("speakers", peers)
367
+ data.putString("id", id)
368
+ delegate.emitEvent("ON_SPEAKER", data)
368
369
  }
370
+ }
369
371
  )
370
372
 
371
373
  hmsSDK?.addRtcStatsObserver(
372
- object : HMSStatsObserver {
373
- override fun onLocalAudioStats(
374
- audioStats: HMSLocalAudioStats,
375
- hmsTrack: HMSTrack?,
376
- hmsPeer: HMSPeer?
377
- ) {
378
- if (!rtcStatsAttached) {
379
- return
380
- }
381
- val localAudioStats = HMSDecoder.getLocalAudioStats(audioStats)
382
- val track = HMSDecoder.getHmsLocalAudioTrack(hmsTrack as HMSLocalAudioTrack)
383
- val peer = HMSDecoder.getHmsPeer(hmsPeer)
374
+ object : HMSStatsObserver {
375
+ override fun onLocalAudioStats(
376
+ audioStats: HMSLocalAudioStats,
377
+ hmsTrack: HMSTrack?,
378
+ hmsPeer: HMSPeer?
379
+ ) {
380
+ if (!rtcStatsAttached) {
381
+ return
382
+ }
383
+ val localAudioStats = HMSDecoder.getLocalAudioStats(audioStats)
384
+ val track = HMSDecoder.getHmsLocalAudioTrack(hmsTrack as HMSLocalAudioTrack)
385
+ val peer = HMSDecoder.getHmsPeer(hmsPeer)
384
386
 
385
- val data: WritableMap = Arguments.createMap()
386
- data.putMap("localAudioStats", localAudioStats)
387
- data.putMap("track", track)
388
- data.putMap("peer", peer)
389
- data.putString("id", id)
390
- delegate.emitEvent("ON_LOCAL_AUDIO_STATS", data)
387
+ val data: WritableMap = Arguments.createMap()
388
+ data.putMap("localAudioStats", localAudioStats)
389
+ data.putMap("track", track)
390
+ data.putMap("peer", peer)
391
+ data.putString("id", id)
392
+ delegate.emitEvent("ON_LOCAL_AUDIO_STATS", data)
393
+ }
394
+
395
+ override fun onLocalVideoStats(
396
+ videoStats: HMSLocalVideoStats,
397
+ hmsTrack: HMSTrack?,
398
+ hmsPeer: HMSPeer?
399
+ ) {
400
+ if (!rtcStatsAttached) {
401
+ return
391
402
  }
392
403
 
393
- override fun onLocalVideoStats(
394
- videoStats: HMSLocalVideoStats,
395
- hmsTrack: HMSTrack?,
396
- hmsPeer: HMSPeer?
397
- ) {
398
- if (!rtcStatsAttached) {
399
- return
400
- }
404
+ val localVideoStats = HMSDecoder.getLocalVideoStats(videoStats)
405
+ val track = HMSDecoder.getHmsLocalVideoTrack(hmsTrack as HMSLocalVideoTrack)
406
+ val peer = HMSDecoder.getHmsPeer(hmsPeer)
401
407
 
402
- val localVideoStats = HMSDecoder.getLocalVideoStats(videoStats)
403
- val track = HMSDecoder.getHmsLocalVideoTrack(hmsTrack as HMSLocalVideoTrack)
404
- val peer = HMSDecoder.getHmsPeer(hmsPeer)
408
+ val data: WritableMap = Arguments.createMap()
409
+ data.putMap("localVideoStats", localVideoStats)
410
+ data.putMap("track", track)
411
+ data.putMap("peer", peer)
412
+ data.putString("id", id)
413
+ delegate.emitEvent("ON_LOCAL_VIDEO_STATS", data)
414
+ }
405
415
 
406
- val data: WritableMap = Arguments.createMap()
407
- data.putMap("localVideoStats", localVideoStats)
408
- data.putMap("track", track)
409
- data.putMap("peer", peer)
410
- data.putString("id", id)
411
- delegate.emitEvent("ON_LOCAL_VIDEO_STATS", data)
416
+ override fun onRTCStats(rtcStats: HMSRTCStatsReport) {
417
+ if (!rtcStatsAttached) {
418
+ return
412
419
  }
420
+ val video = HMSDecoder.getHMSRTCStats(rtcStats.video)
421
+ val audio = HMSDecoder.getHMSRTCStats(rtcStats.audio)
422
+ val combined = HMSDecoder.getHMSRTCStats(rtcStats.combined)
413
423
 
414
- override fun onRTCStats(rtcStats: HMSRTCStatsReport) {
415
- if (!rtcStatsAttached) {
416
- return
417
- }
418
- val video = HMSDecoder.getHMSRTCStats(rtcStats.video)
419
- val audio = HMSDecoder.getHMSRTCStats(rtcStats.audio)
420
- val combined = HMSDecoder.getHMSRTCStats(rtcStats.combined)
424
+ val data: WritableMap = Arguments.createMap()
425
+ data.putMap("video", video)
426
+ data.putMap("audio", audio)
427
+ data.putMap("combined", combined)
428
+ data.putString("id", id)
429
+ delegate.emitEvent("ON_RTC_STATS", data)
430
+ }
421
431
 
422
- val data: WritableMap = Arguments.createMap()
423
- data.putMap("video", video)
424
- data.putMap("audio", audio)
425
- data.putMap("combined", combined)
426
- data.putString("id", id)
427
- delegate.emitEvent("ON_RTC_STATS", data)
432
+ override fun onRemoteAudioStats(
433
+ audioStats: HMSRemoteAudioStats,
434
+ hmsTrack: HMSTrack?,
435
+ hmsPeer: HMSPeer?
436
+ ) {
437
+ if (!rtcStatsAttached) {
438
+ return
428
439
  }
429
440
 
430
- override fun onRemoteAudioStats(
431
- audioStats: HMSRemoteAudioStats,
432
- hmsTrack: HMSTrack?,
433
- hmsPeer: HMSPeer?
434
- ) {
435
- if (!rtcStatsAttached) {
436
- return
437
- }
441
+ val remoteAudioStats = HMSDecoder.getRemoteAudioStats(audioStats)
442
+ val track = HMSDecoder.getHmsRemoteAudioTrack(hmsTrack as HMSRemoteAudioTrack)
443
+ val peer = HMSDecoder.getHmsPeer(hmsPeer)
438
444
 
439
- val remoteAudioStats = HMSDecoder.getRemoteAudioStats(audioStats)
440
- val track = HMSDecoder.getHmsRemoteAudioTrack(hmsTrack as HMSRemoteAudioTrack)
441
- val peer = HMSDecoder.getHmsPeer(hmsPeer)
445
+ val data: WritableMap = Arguments.createMap()
446
+ data.putMap("remoteAudioStats", remoteAudioStats)
447
+ data.putMap("track", track)
448
+ data.putMap("peer", peer)
449
+ data.putString("id", id)
450
+ delegate.emitEvent("ON_REMOTE_AUDIO_STATS", data)
451
+ }
442
452
 
443
- val data: WritableMap = Arguments.createMap()
444
- data.putMap("remoteAudioStats", remoteAudioStats)
445
- data.putMap("track", track)
446
- data.putMap("peer", peer)
447
- data.putString("id", id)
448
- delegate.emitEvent("ON_REMOTE_AUDIO_STATS", data)
453
+ override fun onRemoteVideoStats(
454
+ videoStats: HMSRemoteVideoStats,
455
+ hmsTrack: HMSTrack?,
456
+ hmsPeer: HMSPeer?
457
+ ) {
458
+ if (!rtcStatsAttached) {
459
+ return
449
460
  }
450
461
 
451
- override fun onRemoteVideoStats(
452
- videoStats: HMSRemoteVideoStats,
453
- hmsTrack: HMSTrack?,
454
- hmsPeer: HMSPeer?
455
- ) {
456
- if (!rtcStatsAttached) {
457
- return
458
- }
462
+ val remoteVideoStats = HMSDecoder.getRemoteVideoStats(videoStats)
463
+ val track = HMSDecoder.getHmsRemoteVideoTrack(hmsTrack as HMSRemoteVideoTrack)
464
+ val peer = HMSDecoder.getHmsPeer(hmsPeer)
459
465
 
460
- val remoteVideoStats = HMSDecoder.getRemoteVideoStats(videoStats)
461
- val track = HMSDecoder.getHmsRemoteVideoTrack(hmsTrack as HMSRemoteVideoTrack)
462
- val peer = HMSDecoder.getHmsPeer(hmsPeer)
463
-
464
- val data: WritableMap = Arguments.createMap()
465
- data.putMap("remoteVideoStats", remoteVideoStats)
466
- data.putMap("track", track)
467
- data.putMap("peer", peer)
468
- data.putString("id", id)
469
- delegate.emitEvent("ON_REMOTE_VIDEO_STATS", data)
470
- }
466
+ val data: WritableMap = Arguments.createMap()
467
+ data.putMap("remoteVideoStats", remoteVideoStats)
468
+ data.putMap("track", track)
469
+ data.putMap("peer", peer)
470
+ data.putString("id", id)
471
+ delegate.emitEvent("ON_REMOTE_VIDEO_STATS", data)
471
472
  }
473
+ }
472
474
  )
473
475
  }
474
476
  } else {
@@ -493,49 +495,65 @@ class HMSRNSDK(
493
495
  }
494
496
  }
495
497
 
496
- fun leave(callback: Promise?) {
498
+ fun leave(callback: Promise?, fromPIP: Boolean = false) {
497
499
  if (reconnectingStage) {
498
- callback?.reject("101", "Still in reconnecting stage")
500
+ val errorMessage = "Still in reconnecting stage"
501
+
502
+ if (fromPIP) {
503
+ self.emitHMSError(HMSException(101, errorMessage, "PIP Action", "Leave called from PIP Window", "HMSRNSDK #Function leave"))
504
+ } else {
505
+ callback?.reject("101", errorMessage)
506
+ }
499
507
  } else {
500
508
  hmsSDK?.leave(
501
- object : HMSActionResultListener {
502
- override fun onSuccess() {
503
- isAudioSharing = false
504
- screenshareCallback = null
505
- audioshareCallback = null
506
- networkQualityUpdatesAttached = false
507
- rtcStatsAttached = false
509
+ object : HMSActionResultListener {
510
+ override fun onSuccess() {
511
+ isAudioSharing = false
512
+ screenshareCallback = null
513
+ audioshareCallback = null
514
+ networkQualityUpdatesAttached = false
515
+ rtcStatsAttached = false
516
+ if (fromPIP) {
517
+ context.currentActivity?.moveTaskToBack(false)
518
+
519
+ val map: WritableMap = Arguments.createMap()
520
+ map.putString("id", id)
521
+ delegate.emitEvent("ON_PIP_ROOM_LEAVE", map)
522
+ } else {
508
523
  callback?.resolve(emitHMSSuccess())
509
524
  }
525
+ }
510
526
 
511
- override fun onError(error: HMSException) {
527
+ override fun onError(error: HMSException) {
528
+ if (!fromPIP) {
512
529
  callback?.reject(error.code.toString(), error.message)
513
- self.emitHMSError(error)
514
530
  }
531
+ self.emitHMSError(error)
515
532
  }
533
+ }
516
534
  )
517
535
  }
518
536
  }
519
537
 
520
538
  fun sendBroadcastMessage(data: ReadableMap, callback: Promise?) {
521
539
  val requiredKeys =
522
- HMSHelper.getUnavailableRequiredKey(
523
- data,
524
- arrayOf(Pair("message", "String"), Pair("type", "String"))
525
- )
540
+ HMSHelper.getUnavailableRequiredKey(
541
+ data,
542
+ arrayOf(Pair("message", "String"), Pair("type", "String"))
543
+ )
526
544
  if (requiredKeys === null) {
527
545
  hmsSDK?.sendBroadcastMessage(
528
- data.getString("message") as String,
529
- data.getString("type") as String,
530
- object : HMSMessageResultListener {
531
- override fun onError(error: HMSException) {
532
- self.emitHMSError(error)
533
- callback?.reject(error.code.toString(), error.message)
534
- }
535
- override fun onSuccess(hmsMessage: HMSMessage) {
536
- callback?.resolve(emitHMSSuccess(hmsMessage))
537
- }
546
+ data.getString("message") as String,
547
+ data.getString("type") as String,
548
+ object : HMSMessageResultListener {
549
+ override fun onError(error: HMSException) {
550
+ self.emitHMSError(error)
551
+ callback?.reject(error.code.toString(), error.message)
552
+ }
553
+ override fun onSuccess(hmsMessage: HMSMessage) {
554
+ callback?.resolve(emitHMSSuccess(hmsMessage))
538
555
  }
556
+ }
539
557
  )
540
558
  } else {
541
559
  val errorMessage = "sendBroadcastMessage: $requiredKeys"
@@ -546,28 +564,28 @@ class HMSRNSDK(
546
564
 
547
565
  fun sendGroupMessage(data: ReadableMap, callback: Promise?) {
548
566
  val requiredKeys =
549
- HMSHelper.getUnavailableRequiredKey(
550
- data,
551
- arrayOf(Pair("message", "String"), Pair("roles", "Array"), Pair("type", "String"))
552
- )
567
+ HMSHelper.getUnavailableRequiredKey(
568
+ data,
569
+ arrayOf(Pair("message", "String"), Pair("roles", "Array"), Pair("type", "String"))
570
+ )
553
571
  if (requiredKeys === null) {
554
572
  val targetedRoles = data.getArray("roles")?.toArrayList() as? ArrayList<String>
555
573
  val roles = hmsSDK?.getRoles()
556
574
  val encodedTargetedRoles = HMSHelper.getRolesFromRoleNames(targetedRoles, roles)
557
575
 
558
576
  hmsSDK?.sendGroupMessage(
559
- data.getString("message") as String,
560
- data.getString("type") as String,
561
- encodedTargetedRoles,
562
- object : HMSMessageResultListener {
563
- override fun onError(error: HMSException) {
564
- self.emitHMSError(error)
565
- callback?.reject(error.code.toString(), error.message)
566
- }
567
- override fun onSuccess(hmsMessage: HMSMessage) {
568
- callback?.resolve(emitHMSSuccess(hmsMessage))
569
- }
577
+ data.getString("message") as String,
578
+ data.getString("type") as String,
579
+ encodedTargetedRoles,
580
+ object : HMSMessageResultListener {
581
+ override fun onError(error: HMSException) {
582
+ self.emitHMSError(error)
583
+ callback?.reject(error.code.toString(), error.message)
570
584
  }
585
+ override fun onSuccess(hmsMessage: HMSMessage) {
586
+ callback?.resolve(emitHMSSuccess(hmsMessage))
587
+ }
588
+ }
571
589
  )
572
590
  } else {
573
591
  val errorMessage = "sendGroupMessage: $requiredKeys"
@@ -578,27 +596,27 @@ class HMSRNSDK(
578
596
 
579
597
  fun sendDirectMessage(data: ReadableMap, callback: Promise?) {
580
598
  val requiredKeys =
581
- HMSHelper.getUnavailableRequiredKey(
582
- data,
583
- arrayOf(Pair("message", "String"), Pair("peerId", "String"), Pair("type", "String"))
584
- )
599
+ HMSHelper.getUnavailableRequiredKey(
600
+ data,
601
+ arrayOf(Pair("message", "String"), Pair("peerId", "String"), Pair("type", "String"))
602
+ )
585
603
  if (requiredKeys === null) {
586
604
  val peerId = data.getString("peerId")
587
605
  val peer = HMSHelper.getPeerFromPeerId(peerId, hmsSDK?.getRoom())
588
606
  if (peer != null) {
589
607
  hmsSDK?.sendDirectMessage(
590
- data.getString("message") as String,
591
- data.getString("type") as String,
592
- peer,
593
- object : HMSMessageResultListener {
594
- override fun onError(error: HMSException) {
595
- self.emitHMSError(error)
596
- callback?.reject(error.code.toString(), error.message)
597
- }
598
- override fun onSuccess(hmsMessage: HMSMessage) {
599
- callback?.resolve(emitHMSSuccess(hmsMessage))
600
- }
608
+ data.getString("message") as String,
609
+ data.getString("type") as String,
610
+ peer,
611
+ object : HMSMessageResultListener {
612
+ override fun onError(error: HMSException) {
613
+ self.emitHMSError(error)
614
+ callback?.reject(error.code.toString(), error.message)
601
615
  }
616
+ override fun onSuccess(hmsMessage: HMSMessage) {
617
+ callback?.resolve(emitHMSSuccess(hmsMessage))
618
+ }
619
+ }
602
620
  )
603
621
  } else {
604
622
  self.emitCustomError("PEER_NOT_FOUND")
@@ -611,12 +629,13 @@ class HMSRNSDK(
611
629
  }
612
630
  }
613
631
 
632
+ @kotlin.Deprecated("Use #Function changeRoleOfPeer instead")
614
633
  fun changeRole(data: ReadableMap, callback: Promise?) {
615
634
  val requiredKeys =
616
- HMSHelper.getUnavailableRequiredKey(
617
- data,
618
- arrayOf(Pair("peerId", "String"), Pair("role", "String"), Pair("force", "Boolean"))
619
- )
635
+ HMSHelper.getUnavailableRequiredKey(
636
+ data,
637
+ arrayOf(Pair("peerId", "String"), Pair("role", "String"), Pair("force", "Boolean"))
638
+ )
620
639
  if (requiredKeys === null) {
621
640
  val peerId = data.getString("peerId")
622
641
  val role = data.getString("role")
@@ -628,18 +647,18 @@ class HMSRNSDK(
628
647
 
629
648
  if (hmsRole != null && hmsPeer != null) {
630
649
  hmsSDK?.changeRole(
631
- hmsPeer,
632
- hmsRole,
633
- force,
634
- object : HMSActionResultListener {
635
- override fun onSuccess() {
636
- callback?.resolve(emitHMSSuccess())
637
- }
638
- override fun onError(error: HMSException) {
639
- self.emitHMSError(error)
640
- callback?.reject(error.code.toString(), error.message)
641
- }
650
+ hmsPeer,
651
+ hmsRole,
652
+ force,
653
+ object : HMSActionResultListener {
654
+ override fun onSuccess() {
655
+ callback?.resolve(emitHMSSuccess())
656
+ }
657
+ override fun onError(error: HMSException) {
658
+ self.emitHMSError(error)
659
+ callback?.reject(error.code.toString(), error.message)
642
660
  }
661
+ }
643
662
  )
644
663
  }
645
664
  }
@@ -650,29 +669,109 @@ class HMSRNSDK(
650
669
  }
651
670
  }
652
671
 
653
- fun changeTrackState(data: ReadableMap, callback: Promise?) {
672
+ fun changeRoleOfPeer(data: ReadableMap, promise: Promise?) {
654
673
  val requiredKeys =
655
- HMSHelper.getUnavailableRequiredKey(
656
- data,
657
- arrayOf(Pair("trackId", "String"), Pair("mute", "Boolean"))
658
- )
674
+ HMSHelper.getUnavailableRequiredKey(
675
+ data,
676
+ arrayOf(Pair("peerId", "String"), Pair("role", "String"), Pair("force", "Boolean"))
677
+ )
659
678
  if (requiredKeys === null) {
660
- val trackId = data.getString("trackId")
661
- val mute = data.getBoolean("mute")
662
- val track = HMSHelper.getTrackFromTrackId(trackId, hmsSDK?.getRoom())
663
- if (track != null) {
664
- hmsSDK?.changeTrackState(
665
- track,
666
- mute,
679
+ val peerId = data.getString("peerId")
680
+ val role = data.getString("role")
681
+ val force = data.getBoolean("force")
682
+
683
+ if (peerId !== null && role !== null) {
684
+ val hmsPeer = HMSHelper.getPeerFromPeerId(peerId, hmsSDK?.getRoom())
685
+ val hmsRole = HMSHelper.getRoleFromRoleName(role, hmsSDK?.getRoles())
686
+
687
+ if (hmsRole != null && hmsPeer != null) {
688
+ hmsSDK?.changeRoleOfPeer(
689
+ hmsPeer,
690
+ hmsRole,
691
+ force,
667
692
  object : HMSActionResultListener {
668
693
  override fun onSuccess() {
669
- callback?.resolve(emitHMSSuccess())
694
+ promise?.resolve(emitHMSSuccess())
670
695
  }
671
696
  override fun onError(error: HMSException) {
672
697
  self.emitHMSError(error)
673
- callback?.reject(error.code.toString(), error.message)
698
+ promise?.reject(error.code.toString(), error.message)
674
699
  }
675
700
  }
701
+ )
702
+ }
703
+ }
704
+ } else {
705
+ val errorMessage = "changeRoleOfPeer: $requiredKeys"
706
+ self.emitRequiredKeysError(errorMessage)
707
+ rejectCallback(promise, errorMessage)
708
+ }
709
+ }
710
+
711
+ fun changeRoleOfPeersWithRoles(data: ReadableMap, promise: Promise?) {
712
+ val requiredKeys =
713
+ HMSHelper.getUnavailableRequiredKey(
714
+ data,
715
+ arrayOf(Pair("ofRoles", "Array"), Pair("toRole", "String"))
716
+ )
717
+ if (requiredKeys === null) {
718
+ val ofRoles = data.getArray("ofRoles")
719
+ val toRole = data.getString("toRole")
720
+
721
+ if (ofRoles !== null && toRole !== null) {
722
+ val hmsRoles = hmsSDK?.getRoles()
723
+
724
+ val ofRolesArrayList = ArrayList(ofRoles.toArrayList().map { it.toString() })
725
+
726
+ val ofHMSRoles = HMSHelper.getRolesFromRoleNames(ofRolesArrayList, hmsRoles)
727
+ val toHMSRole = HMSHelper.getRoleFromRoleName(toRole, hmsRoles)
728
+
729
+ if (toHMSRole !== null) {
730
+ hmsSDK?.changeRoleOfPeersWithRoles(
731
+ ofHMSRoles,
732
+ toHMSRole,
733
+ object : HMSActionResultListener {
734
+ override fun onSuccess() {
735
+ promise?.resolve(emitHMSSuccess())
736
+ }
737
+ override fun onError(error: HMSException) {
738
+ self.emitHMSError(error)
739
+ promise?.reject(error.code.toString(), error.message)
740
+ }
741
+ }
742
+ )
743
+ }
744
+ }
745
+ } else {
746
+ val errorMessage = "changeRoleOfPeersWithRoles: $requiredKeys"
747
+ self.emitRequiredKeysError(errorMessage)
748
+ rejectCallback(promise, errorMessage)
749
+ }
750
+ }
751
+
752
+ fun changeTrackState(data: ReadableMap, callback: Promise?) {
753
+ val requiredKeys =
754
+ HMSHelper.getUnavailableRequiredKey(
755
+ data,
756
+ arrayOf(Pair("trackId", "String"), Pair("mute", "Boolean"))
757
+ )
758
+ if (requiredKeys === null) {
759
+ val trackId = data.getString("trackId")
760
+ val mute = data.getBoolean("mute")
761
+ val track = HMSHelper.getTrackFromTrackId(trackId, hmsSDK?.getRoom())
762
+ if (track != null) {
763
+ hmsSDK?.changeTrackState(
764
+ track,
765
+ mute,
766
+ object : HMSActionResultListener {
767
+ override fun onSuccess() {
768
+ callback?.resolve(emitHMSSuccess())
769
+ }
770
+ override fun onError(error: HMSException) {
771
+ self.emitHMSError(error)
772
+ callback?.reject(error.code.toString(), error.message)
773
+ }
774
+ }
676
775
  )
677
776
  }
678
777
  } else {
@@ -687,40 +786,43 @@ class HMSRNSDK(
687
786
  if (requiredKeys === null) {
688
787
  val mute: Boolean = data.getBoolean("mute")
689
788
  val type =
690
- if (HMSHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("type", "String")))) {
691
- if (data.getString("type") == HMSTrackType.AUDIO.toString()) HMSTrackType.AUDIO
692
- else HMSTrackType.VIDEO
789
+ if (HMSHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("type", "String")))) {
790
+ if (data.getString("type") == HMSTrackType.AUDIO.toString()) {
791
+ HMSTrackType.AUDIO
693
792
  } else {
694
- null
793
+ HMSTrackType.VIDEO
695
794
  }
795
+ } else {
796
+ null
797
+ }
696
798
  val source =
697
- if (HMSHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("source", "String")))) {
698
- data.getString("source")
699
- } else {
700
- null
701
- }
799
+ if (HMSHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("source", "String")))) {
800
+ data.getString("source")
801
+ } else {
802
+ null
803
+ }
702
804
  val targetedRoles =
703
- if (HMSHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("roles", "Array")))) {
704
- data.getArray("roles")?.toArrayList() as? ArrayList<String>
705
- } else {
706
- null
707
- }
805
+ if (HMSHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("roles", "Array")))) {
806
+ data.getArray("roles")?.toArrayList() as? ArrayList<String>
807
+ } else {
808
+ null
809
+ }
708
810
  val roles = hmsSDK?.getRoles()
709
811
  val encodedTargetedRoles = HMSHelper.getRolesFromRoleNames(targetedRoles, roles)
710
812
  hmsSDK?.changeTrackState(
711
- mute,
712
- type,
713
- source,
714
- encodedTargetedRoles,
715
- object : HMSActionResultListener {
716
- override fun onSuccess() {
717
- callback?.resolve(emitHMSSuccess())
718
- }
719
- override fun onError(error: HMSException) {
720
- self.emitHMSError(error)
721
- callback?.reject(error.code.toString(), error.message)
722
- }
813
+ mute,
814
+ type,
815
+ source,
816
+ encodedTargetedRoles,
817
+ object : HMSActionResultListener {
818
+ override fun onSuccess() {
819
+ callback?.resolve(emitHMSSuccess())
820
+ }
821
+ override fun onError(error: HMSException) {
822
+ self.emitHMSError(error)
823
+ callback?.reject(error.code.toString(), error.message)
723
824
  }
825
+ }
724
826
  )
725
827
  } else {
726
828
  val errorMessage = "changeTrackStateForRoles: $requiredKeys"
@@ -749,27 +851,27 @@ class HMSRNSDK(
749
851
 
750
852
  fun removePeer(data: ReadableMap, callback: Promise?) {
751
853
  val requiredKeys =
752
- HMSHelper.getUnavailableRequiredKey(
753
- data,
754
- arrayOf(Pair("peerId", "String"), Pair("reason", "String"))
755
- )
854
+ HMSHelper.getUnavailableRequiredKey(
855
+ data,
856
+ arrayOf(Pair("peerId", "String"), Pair("reason", "String"))
857
+ )
756
858
  if (requiredKeys === null) {
757
859
  val peerId = data.getString("peerId")
758
860
  val peer = HMSHelper.getRemotePeerFromPeerId(peerId, hmsSDK?.getRoom())
759
861
 
760
862
  if (peer != null) {
761
863
  hmsSDK?.removePeerRequest(
762
- peer,
763
- data.getString("reason") as String,
764
- object : HMSActionResultListener {
765
- override fun onSuccess() {
766
- callback?.resolve(emitHMSSuccess())
767
- }
768
- override fun onError(error: HMSException) {
769
- self.emitHMSError(error)
770
- callback?.reject(error.code.toString(), error.message)
771
- }
864
+ peer,
865
+ data.getString("reason") as String,
866
+ object : HMSActionResultListener {
867
+ override fun onSuccess() {
868
+ callback?.resolve(emitHMSSuccess())
772
869
  }
870
+ override fun onError(error: HMSException) {
871
+ self.emitHMSError(error)
872
+ callback?.reject(error.code.toString(), error.message)
873
+ }
874
+ }
773
875
  )
774
876
  } else {
775
877
  self.emitCustomError("PEER_NOT_FOUND")
@@ -784,23 +886,23 @@ class HMSRNSDK(
784
886
 
785
887
  fun endRoom(data: ReadableMap, callback: Promise?) {
786
888
  val requiredKeys =
787
- HMSHelper.getUnavailableRequiredKey(
788
- data,
789
- arrayOf(Pair("lock", "Boolean"), Pair("reason", "String"))
790
- )
889
+ HMSHelper.getUnavailableRequiredKey(
890
+ data,
891
+ arrayOf(Pair("lock", "Boolean"), Pair("reason", "String"))
892
+ )
791
893
  if (requiredKeys === null) {
792
894
  hmsSDK?.endRoom(
793
- data.getString("reason") as String,
794
- data.getBoolean("lock"),
795
- object : HMSActionResultListener {
796
- override fun onSuccess() {
797
- callback?.resolve(emitHMSSuccess())
798
- }
799
- override fun onError(error: HMSException) {
800
- self.emitHMSError(error)
801
- callback?.reject(error.code.toString(), error.message)
802
- }
895
+ data.getString("reason") as String,
896
+ data.getBoolean("lock"),
897
+ object : HMSActionResultListener {
898
+ override fun onSuccess() {
899
+ callback?.resolve(emitHMSSuccess())
900
+ }
901
+ override fun onError(error: HMSException) {
902
+ self.emitHMSError(error)
903
+ callback?.reject(error.code.toString(), error.message)
803
904
  }
905
+ }
804
906
  )
805
907
  } else {
806
908
  val errorMessage = "endRoom: $requiredKeys"
@@ -812,16 +914,16 @@ class HMSRNSDK(
812
914
  fun acceptRoleChange(callback: Promise?) {
813
915
  if (recentRoleChangeRequest !== null) {
814
916
  hmsSDK?.acceptChangeRole(
815
- recentRoleChangeRequest!!,
816
- object : HMSActionResultListener {
817
- override fun onSuccess() {
818
- callback?.resolve(emitHMSSuccess())
819
- }
820
- override fun onError(error: HMSException) {
821
- self.emitHMSError(error)
822
- callback?.reject(error.code.toString(), error.message)
823
- }
917
+ recentRoleChangeRequest!!,
918
+ object : HMSActionResultListener {
919
+ override fun onSuccess() {
920
+ callback?.resolve(emitHMSSuccess())
921
+ }
922
+ override fun onError(error: HMSException) {
923
+ self.emitHMSError(error)
924
+ callback?.reject(error.code.toString(), error.message)
824
925
  }
926
+ }
825
927
  )
826
928
  recentRoleChangeRequest = null
827
929
  } else {
@@ -837,14 +939,14 @@ class HMSRNSDK(
837
939
  var customError: HMSException? = null
838
940
  for (audioTrack in allAudioTracks) {
839
941
  hmsSDK?.changeTrackState(
840
- audioTrack,
841
- true,
842
- object : HMSActionResultListener {
843
- override fun onSuccess() {}
844
- override fun onError(error: HMSException) {
845
- customError = error
846
- }
942
+ audioTrack,
943
+ true,
944
+ object : HMSActionResultListener {
945
+ override fun onSuccess() {}
946
+ override fun onError(error: HMSException) {
947
+ customError = error
847
948
  }
949
+ }
848
950
  )
849
951
  }
850
952
  if (customError === null) {
@@ -885,10 +987,10 @@ class HMSRNSDK(
885
987
 
886
988
  fun setPlaybackAllowed(data: ReadableMap) {
887
989
  val requiredKeys =
888
- HMSHelper.getUnavailableRequiredKey(
889
- data,
890
- arrayOf(Pair("trackId", "String"), Pair("playbackAllowed", "Boolean"))
891
- )
990
+ HMSHelper.getUnavailableRequiredKey(
991
+ data,
992
+ arrayOf(Pair("trackId", "String"), Pair("playbackAllowed", "Boolean"))
993
+ )
892
994
  if (requiredKeys === null) {
893
995
  val trackId = data.getString("trackId")
894
996
  val playbackAllowed = data.getBoolean("playbackAllowed")
@@ -953,10 +1055,10 @@ class HMSRNSDK(
953
1055
 
954
1056
  fun setVolume(data: ReadableMap) {
955
1057
  val requiredKeys =
956
- HMSHelper.getUnavailableRequiredKey(
957
- data,
958
- arrayOf(Pair("trackId", "String"), Pair("volume", "Float"))
959
- )
1058
+ HMSHelper.getUnavailableRequiredKey(
1059
+ data,
1060
+ arrayOf(Pair("trackId", "String"), Pair("volume", "Float"))
1061
+ )
960
1062
 
961
1063
  if (requiredKeys === null) {
962
1064
  val trackId = data.getString("trackId")
@@ -1016,22 +1118,22 @@ class HMSRNSDK(
1016
1118
 
1017
1119
  fun changeMetadata(data: ReadableMap, callback: Promise?) {
1018
1120
  val requiredKeys =
1019
- HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("metadata", "String")))
1121
+ HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("metadata", "String")))
1020
1122
  if (requiredKeys === null) {
1021
1123
  val metadata = data.getString("metadata")
1022
1124
 
1023
1125
  if (metadata != null) {
1024
1126
  hmsSDK?.changeMetadata(
1025
- metadata,
1026
- object : HMSActionResultListener {
1027
- override fun onSuccess() {
1028
- callback?.resolve(emitHMSSuccess())
1029
- }
1030
- override fun onError(error: HMSException) {
1031
- callback?.reject(error.code.toString(), error.message)
1032
- self.emitHMSError(error)
1033
- }
1127
+ metadata,
1128
+ object : HMSActionResultListener {
1129
+ override fun onSuccess() {
1130
+ callback?.resolve(emitHMSSuccess())
1034
1131
  }
1132
+ override fun onError(error: HMSException) {
1133
+ callback?.reject(error.code.toString(), error.message)
1134
+ self.emitHMSError(error)
1135
+ }
1136
+ }
1035
1137
  )
1036
1138
  }
1037
1139
  } else {
@@ -1043,10 +1145,10 @@ class HMSRNSDK(
1043
1145
 
1044
1146
  fun startRTMPOrRecording(data: ReadableMap, callback: Promise?) {
1045
1147
  val requiredKeys =
1046
- HMSHelper.getUnavailableRequiredKey(
1047
- data,
1048
- arrayOf(Pair("record", "Boolean"), Pair("meetingURL", "String"))
1049
- )
1148
+ HMSHelper.getUnavailableRequiredKey(
1149
+ data,
1150
+ arrayOf(Pair("record", "Boolean"), Pair("meetingURL", "String"))
1151
+ )
1050
1152
  if (requiredKeys === null) {
1051
1153
  val config = HMSHelper.getRtmpConfig(data)
1052
1154
  if (config === null) {
@@ -1055,16 +1157,16 @@ class HMSRNSDK(
1055
1157
  rejectCallback(callback, errorMessage)
1056
1158
  } else {
1057
1159
  hmsSDK?.startRtmpOrRecording(
1058
- config,
1059
- object : HMSActionResultListener {
1060
- override fun onSuccess() {
1061
- callback?.resolve(emitHMSSuccess())
1062
- }
1063
- override fun onError(error: HMSException) {
1064
- callback?.reject(error.code.toString(), error.message)
1065
- self.emitHMSError(error)
1066
- }
1160
+ config,
1161
+ object : HMSActionResultListener {
1162
+ override fun onSuccess() {
1163
+ callback?.resolve(emitHMSSuccess())
1164
+ }
1165
+ override fun onError(error: HMSException) {
1166
+ callback?.reject(error.code.toString(), error.message)
1167
+ self.emitHMSError(error)
1067
1168
  }
1169
+ }
1068
1170
  )
1069
1171
  }
1070
1172
  } else {
@@ -1076,15 +1178,15 @@ class HMSRNSDK(
1076
1178
 
1077
1179
  fun stopRtmpAndRecording(callback: Promise?) {
1078
1180
  hmsSDK?.stopRtmpAndRecording(
1079
- object : HMSActionResultListener {
1080
- override fun onSuccess() {
1081
- callback?.resolve(emitHMSSuccess())
1082
- }
1083
- override fun onError(error: HMSException) {
1084
- callback?.reject(error.code.toString(), error.message)
1085
- self.emitHMSError(error)
1086
- }
1181
+ object : HMSActionResultListener {
1182
+ override fun onSuccess() {
1183
+ callback?.resolve(emitHMSSuccess())
1087
1184
  }
1185
+ override fun onError(error: HMSException) {
1186
+ callback?.reject(error.code.toString(), error.message)
1187
+ self.emitHMSError(error)
1188
+ }
1189
+ }
1088
1190
  )
1089
1191
  }
1090
1192
 
@@ -1104,48 +1206,48 @@ class HMSRNSDK(
1104
1206
 
1105
1207
  fun stopScreenshare(callback: Promise?) {
1106
1208
  hmsSDK?.stopScreenshare(
1107
- object : HMSActionResultListener {
1108
- override fun onError(error: HMSException) {
1109
- screenshareCallback = null
1110
- callback?.reject(error.code.toString(), error.message)
1111
- self.emitHMSError(error)
1112
- }
1113
- override fun onSuccess() {
1114
- screenshareCallback = null
1115
- callback?.resolve(emitHMSSuccess())
1116
- }
1209
+ object : HMSActionResultListener {
1210
+ override fun onError(error: HMSException) {
1211
+ screenshareCallback = null
1212
+ callback?.reject(error.code.toString(), error.message)
1213
+ self.emitHMSError(error)
1117
1214
  }
1215
+ override fun onSuccess() {
1216
+ screenshareCallback = null
1217
+ callback?.resolve(emitHMSSuccess())
1218
+ }
1219
+ }
1118
1220
  )
1119
1221
  }
1120
1222
 
1121
1223
  fun startHLSStreaming(data: ReadableMap, callback: Promise?) {
1122
1224
  val hlsConfig = HMSHelper.getHLSConfig(data)
1123
1225
  hmsSDK?.startHLSStreaming(
1124
- hlsConfig,
1125
- object : HMSActionResultListener {
1126
- override fun onSuccess() {
1127
- callback?.resolve(emitHMSSuccess())
1128
- }
1129
- override fun onError(error: HMSException) {
1130
- callback?.reject(error.code.toString(), error.message)
1131
- self.emitHMSError(error)
1132
- }
1226
+ hlsConfig,
1227
+ object : HMSActionResultListener {
1228
+ override fun onSuccess() {
1229
+ callback?.resolve(emitHMSSuccess())
1133
1230
  }
1231
+ override fun onError(error: HMSException) {
1232
+ callback?.reject(error.code.toString(), error.message)
1233
+ self.emitHMSError(error)
1234
+ }
1235
+ }
1134
1236
  )
1135
1237
  }
1136
1238
 
1137
1239
  fun stopHLSStreaming(callback: Promise?) {
1138
1240
  hmsSDK?.stopHLSStreaming(
1139
- null,
1140
- object : HMSActionResultListener {
1141
- override fun onSuccess() {
1142
- callback?.resolve(emitHMSSuccess())
1143
- }
1144
- override fun onError(error: HMSException) {
1145
- callback?.reject(error.code.toString(), error.message)
1146
- self.emitHMSError(error)
1147
- }
1241
+ null,
1242
+ object : HMSActionResultListener {
1243
+ override fun onSuccess() {
1244
+ callback?.resolve(emitHMSSuccess())
1148
1245
  }
1246
+ override fun onError(error: HMSException) {
1247
+ callback?.reject(error.code.toString(), error.message)
1248
+ self.emitHMSError(error)
1249
+ }
1250
+ }
1149
1251
  )
1150
1252
  }
1151
1253
 
@@ -1162,7 +1264,6 @@ class HMSRNSDK(
1162
1264
 
1163
1265
  for (track in auxTracks) {
1164
1266
  if (track.type === HMSTrackType.AUDIO) {
1165
-
1166
1267
  (track as? HMSRemoteAudioTrack)?.setVolume(10.0)
1167
1268
  }
1168
1269
  }
@@ -1176,17 +1277,17 @@ class HMSRNSDK(
1176
1277
  val name = data.getString("name")
1177
1278
  if (name != null && name != "") {
1178
1279
  hmsSDK?.changeName(
1179
- name,
1180
- object : HMSActionResultListener {
1181
- override fun onSuccess() {
1182
- callback?.resolve(emitHMSSuccess())
1183
- }
1280
+ name,
1281
+ object : HMSActionResultListener {
1282
+ override fun onSuccess() {
1283
+ callback?.resolve(emitHMSSuccess())
1284
+ }
1184
1285
 
1185
- override fun onError(error: HMSException) {
1186
- callback?.reject(error.code.toString(), error.message)
1187
- self.emitHMSError(error)
1188
- }
1286
+ override fun onError(error: HMSException) {
1287
+ callback?.reject(error.code.toString(), error.message)
1288
+ self.emitHMSError(error)
1189
1289
  }
1290
+ }
1190
1291
  )
1191
1292
  } else {
1192
1293
  self.emitCustomError("NAME_UNDEFINED")
@@ -1225,7 +1326,7 @@ class HMSRNSDK(
1225
1326
 
1226
1327
  fun switchAudioOutput(data: ReadableMap) {
1227
1328
  val requiredKeys =
1228
- HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("audioDevice", "String")))
1329
+ HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("audioDevice", "String")))
1229
1330
  if (requiredKeys === null) {
1230
1331
  val audioDevice = data.getString("audioDevice")
1231
1332
  hmsSDK?.switchAudioOutput(HMSHelper.getAudioDevice(audioDevice))
@@ -1248,28 +1349,28 @@ class HMSRNSDK(
1248
1349
 
1249
1350
  fun setAudioDeviceChangeListener() {
1250
1351
  hmsSDK?.setAudioDeviceChangeListener(
1251
- object : HMSAudioManager.AudioManagerDeviceChangeListener {
1252
- override fun onAudioDeviceChanged(
1253
- device: HMSAudioManager.AudioDevice?,
1254
- audioDevicesList: Set<HMSAudioManager.AudioDevice>?
1255
- ) {
1256
- val data: WritableMap = Arguments.createMap()
1257
- data.putString("device", device?.name)
1258
- data.putArray("audioDevicesList", HMSHelper.getAudioDevicesSet(audioDevicesList))
1259
- data.putString("id", id)
1260
- delegate.emitEvent("ON_AUDIO_DEVICE_CHANGED", data)
1261
- }
1352
+ object : HMSAudioManager.AudioManagerDeviceChangeListener {
1353
+ override fun onAudioDeviceChanged(
1354
+ device: HMSAudioManager.AudioDevice?,
1355
+ audioDevicesList: Set<HMSAudioManager.AudioDevice>?
1356
+ ) {
1357
+ val data: WritableMap = Arguments.createMap()
1358
+ data.putString("device", device?.name)
1359
+ data.putArray("audioDevicesList", HMSHelper.getAudioDevicesSet(audioDevicesList))
1360
+ data.putString("id", id)
1361
+ delegate.emitEvent("ON_AUDIO_DEVICE_CHANGED", data)
1362
+ }
1262
1363
 
1263
- override fun onError(error: HMSException) {
1264
- self.emitHMSError(error)
1265
- }
1364
+ override fun onError(error: HMSException) {
1365
+ self.emitHMSError(error)
1266
1366
  }
1367
+ }
1267
1368
  )
1268
1369
  }
1269
1370
 
1270
1371
  fun startAudioshare(data: ReadableMap, callback: Promise?) {
1271
1372
  val requiredKeys =
1272
- HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("audioMixingMode", "String")))
1373
+ HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("audioMixingMode", "String")))
1273
1374
  if (requiredKeys === null) {
1274
1375
  audioshareCallback = callback
1275
1376
  runOnUiThread {
@@ -1292,18 +1393,18 @@ class HMSRNSDK(
1292
1393
 
1293
1394
  fun stopAudioshare(callback: Promise?) {
1294
1395
  hmsSDK?.stopAudioshare(
1295
- object : HMSActionResultListener {
1296
- override fun onError(error: HMSException) {
1297
- audioshareCallback = null
1298
- callback?.reject(error.code.toString(), error.message)
1299
- self.emitHMSError(error)
1300
- }
1301
- override fun onSuccess() {
1302
- isAudioSharing = false
1303
- audioshareCallback = null
1304
- callback?.resolve(emitHMSSuccess())
1305
- }
1396
+ object : HMSActionResultListener {
1397
+ override fun onError(error: HMSException) {
1398
+ audioshareCallback = null
1399
+ callback?.reject(error.code.toString(), error.message)
1400
+ self.emitHMSError(error)
1306
1401
  }
1402
+ override fun onSuccess() {
1403
+ isAudioSharing = false
1404
+ audioshareCallback = null
1405
+ callback?.resolve(emitHMSSuccess())
1406
+ }
1407
+ }
1307
1408
  )
1308
1409
  }
1309
1410
 
@@ -1313,7 +1414,7 @@ class HMSRNSDK(
1313
1414
 
1314
1415
  fun setAudioMixingMode(data: ReadableMap, callback: Promise?) {
1315
1416
  val requiredKeys =
1316
- HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("audioMixingMode", "String")))
1417
+ HMSHelper.getUnavailableRequiredKey(data, arrayOf(Pair("audioMixingMode", "String")))
1317
1418
  if (requiredKeys === null) {
1318
1419
  val mode = HMSHelper.getAudioMixingMode(data.getString("audioMixingMode"))
1319
1420
  audioMixingMode = mode
@@ -1330,17 +1431,17 @@ class HMSRNSDK(
1330
1431
  if (data.hasKey("sessionMetaData")) {
1331
1432
  val sessionMetaData = data.getString("sessionMetaData")
1332
1433
  hmsSDK?.setSessionMetaData(
1333
- sessionMetaData,
1334
- object : HMSActionResultListener {
1335
- override fun onSuccess() {
1336
- callback?.resolve(emitHMSSuccess())
1337
- }
1434
+ sessionMetaData,
1435
+ object : HMSActionResultListener {
1436
+ override fun onSuccess() {
1437
+ callback?.resolve(emitHMSSuccess())
1438
+ }
1338
1439
 
1339
- override fun onError(error: HMSException) {
1340
- callback?.reject(error.code.toString(), error.message)
1341
- self.emitHMSError(error)
1342
- }
1440
+ override fun onError(error: HMSException) {
1441
+ callback?.reject(error.code.toString(), error.message)
1442
+ self.emitHMSError(error)
1343
1443
  }
1444
+ }
1344
1445
  )
1345
1446
  } else {
1346
1447
  val errorMessage = "setSessionMetaData: sessionMetaData_Is_Required"
@@ -1351,16 +1452,16 @@ class HMSRNSDK(
1351
1452
 
1352
1453
  fun getSessionMetaData(callback: Promise?) {
1353
1454
  hmsSDK?.getSessionMetaData(
1354
- object : HMSSessionMetadataListener {
1355
- override fun onSuccess(sessionMetadata: String?) {
1356
- callback?.resolve(sessionMetadata)
1357
- }
1455
+ object : HMSSessionMetadataListener {
1456
+ override fun onSuccess(sessionMetadata: String?) {
1457
+ callback?.resolve(sessionMetadata)
1458
+ }
1358
1459
 
1359
- override fun onError(error: HMSException) {
1360
- callback?.reject(error.code.toString(), error.message)
1361
- self.emitHMSError(error)
1362
- }
1460
+ override fun onError(error: HMSException) {
1461
+ callback?.reject(error.code.toString(), error.message)
1462
+ self.emitHMSError(error)
1363
1463
  }
1464
+ }
1364
1465
  )
1365
1466
  }
1366
1467
  }