@100mslive/react-native-hms 0.8.4 → 0.9.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 (82) hide show
  1. package/README.md +6 -6
  2. package/android/build.gradle +3 -1
  3. package/android/src/main/java/com/reactnativehmssdk/HmsDecoder.kt +27 -2
  4. package/android/src/main/java/com/reactnativehmssdk/HmsHelper.kt +25 -0
  5. package/android/src/main/java/com/reactnativehmssdk/HmsModule.kt +81 -4
  6. package/android/src/main/java/com/reactnativehmssdk/HmsSDK.kt +174 -84
  7. package/android/src/main/java/com/reactnativehmssdk/HmsScreenshareActivity.kt +66 -0
  8. package/android/src/main/java/com/reactnativehmssdk/HmsView.kt +28 -3
  9. package/android/src/main/java/com/reactnativehmssdk/HmssdkViewManager.kt +10 -1
  10. package/android/src/main/res/layout/hms_view.xml +19 -0
  11. package/ios/HmsDecoder.swift +58 -2
  12. package/ios/HmsHelper.swift +21 -0
  13. package/ios/HmsManager.m +4 -2
  14. package/ios/HmsManager.swift +16 -2
  15. package/ios/HmsSDK.swift +63 -11
  16. package/ios/HmsView.swift +22 -54
  17. package/lib/commonjs/classes/HMSEncoder.js +2 -1
  18. package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
  19. package/lib/commonjs/classes/HMSHLSConfig.js +20 -0
  20. package/lib/commonjs/classes/HMSHLSConfig.js.map +1 -0
  21. package/lib/commonjs/classes/HMSHLSMeetingURLVariant.js +23 -0
  22. package/lib/commonjs/classes/HMSHLSMeetingURLVariant.js.map +1 -0
  23. package/lib/commonjs/classes/HMSHLSStreamingState.js +23 -0
  24. package/lib/commonjs/classes/HMSHLSStreamingState.js.map +1 -0
  25. package/lib/commonjs/classes/HMSHLSVariant.js +29 -0
  26. package/lib/commonjs/classes/HMSHLSVariant.js.map +1 -0
  27. package/lib/commonjs/classes/HMSLogger.js +27 -0
  28. package/lib/commonjs/classes/HMSLogger.js.map +1 -1
  29. package/lib/commonjs/classes/HMSRoom.js +3 -0
  30. package/lib/commonjs/classes/HMSRoom.js.map +1 -1
  31. package/lib/commonjs/classes/HMSRoomUpdate.js +6 -0
  32. package/lib/commonjs/classes/HMSRoomUpdate.js.map +1 -1
  33. package/lib/commonjs/classes/HMSSDK.js +203 -96
  34. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  35. package/lib/commonjs/classes/HmsView.js +26 -4
  36. package/lib/commonjs/classes/HmsView.js.map +1 -1
  37. package/lib/commonjs/index.js +56 -0
  38. package/lib/commonjs/index.js.map +1 -1
  39. package/lib/module/classes/HMSEncoder.js +2 -1
  40. package/lib/module/classes/HMSEncoder.js.map +1 -1
  41. package/lib/module/classes/HMSHLSConfig.js +11 -0
  42. package/lib/module/classes/HMSHLSConfig.js.map +1 -0
  43. package/lib/module/classes/HMSHLSMeetingURLVariant.js +14 -0
  44. package/lib/module/classes/HMSHLSMeetingURLVariant.js.map +1 -0
  45. package/lib/module/classes/HMSHLSStreamingState.js +14 -0
  46. package/lib/module/classes/HMSHLSStreamingState.js.map +1 -0
  47. package/lib/module/classes/HMSHLSVariant.js +20 -0
  48. package/lib/module/classes/HMSHLSVariant.js.map +1 -0
  49. package/lib/module/classes/HMSLogger.js +27 -0
  50. package/lib/module/classes/HMSLogger.js.map +1 -1
  51. package/lib/module/classes/HMSRoom.js +3 -0
  52. package/lib/module/classes/HMSRoom.js.map +1 -1
  53. package/lib/module/classes/HMSRoomUpdate.js +6 -0
  54. package/lib/module/classes/HMSRoomUpdate.js.map +1 -1
  55. package/lib/module/classes/HMSSDK.js +204 -97
  56. package/lib/module/classes/HMSSDK.js.map +1 -1
  57. package/lib/module/classes/HmsView.js +23 -4
  58. package/lib/module/classes/HmsView.js.map +1 -1
  59. package/lib/module/index.js +4 -0
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/typescript/classes/HMSHLSConfig.d.ts +7 -0
  62. package/lib/typescript/classes/HMSHLSMeetingURLVariant.d.ts +8 -0
  63. package/lib/typescript/classes/HMSHLSStreamingState.d.ts +9 -0
  64. package/lib/typescript/classes/HMSHLSVariant.d.ts +12 -0
  65. package/lib/typescript/classes/HMSLogger.d.ts +2 -0
  66. package/lib/typescript/classes/HMSRoom.d.ts +3 -0
  67. package/lib/typescript/classes/HMSRoomUpdate.d.ts +7 -1
  68. package/lib/typescript/classes/HMSSDK.d.ts +16 -7
  69. package/lib/typescript/index.d.ts +4 -0
  70. package/package.json +1 -2
  71. package/react-native-hms.podspec +1 -1
  72. package/src/classes/HMSEncoder.ts +1 -0
  73. package/src/classes/HMSHLSConfig.ts +9 -0
  74. package/src/classes/HMSHLSMeetingURLVariant.ts +9 -0
  75. package/src/classes/HMSHLSStreamingState.ts +11 -0
  76. package/src/classes/HMSHLSVariant.ts +18 -0
  77. package/src/classes/HMSLogger.ts +14 -0
  78. package/src/classes/HMSRoom.ts +4 -0
  79. package/src/classes/HMSRoomUpdate.ts +6 -0
  80. package/src/classes/HMSSDK.tsx +95 -19
  81. package/src/classes/HmsView.tsx +32 -4
  82. package/src/index.ts +4 -0
package/README.md CHANGED
@@ -124,7 +124,7 @@ To display a video on screen the package provide a UI component named HmsView th
124
124
  ...
125
125
  import { HMSRemotePeer } from '@100mslive/react-native-hms';
126
126
 
127
- // getting local track ID
127
+ // getting local track ID
128
128
  const localTrackId: string = hmsInstance?.localPeer?.videoTrack?.trackId;
129
129
 
130
130
  // getting remote track IDs
@@ -185,17 +185,17 @@ await hmsInstance?.leave();
185
185
  # Sending messages
186
186
 
187
187
  ```js
188
- import { HMSRole } from '@100mslive/react-native-hms';
188
+ import { HMSRole, HMSPeer } from '@100mslive/react-native-hms';
189
189
 
190
190
  const message = 'hello'
191
191
  const roles: HMSRole[] = hmsInstance?.knownRoles
192
- // can any remote peer's peerID
193
- const peerId: string = hmsInstance?.localPeer?.peerID
192
+ // any remote peer
193
+ const peer: HMSPeer = hmsInstance?.remotePeers[0]
194
194
 
195
195
  // send a different type of messages
196
196
  hmsInstance?.sendBroadcastMessage(message);
197
197
  hmsInstance?.sendGroupMessage(message, [role[0]);
198
- hmsInstance?.sendDirectMessage(message, peerId);
198
+ hmsInstance?.sendDirectMessage(message, peer);
199
199
  ```
200
200
 
201
201
  # Error handling
@@ -203,6 +203,6 @@ hmsInstance?.sendDirectMessage(message, peerId);
203
203
  ```js
204
204
  import { HMSUpdateListenerActions } from '@100mslive/react-native-hms';
205
205
 
206
- // add an error event listener
206
+ // add an error event listener
207
207
  hmsInstance.addEventListener(HMSUpdateListenerActions.ON_ERROR, onError);
208
208
  ```
@@ -63,6 +63,8 @@ dependencies {
63
63
  //noinspection GradleDynamicVersion
64
64
  implementation "com.facebook.react:react-native:+"
65
65
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // From node_modules
66
- implementation 'com.github.100mslive:android-sdk:2.2.5'
66
+ implementation 'com.github.100mslive.android-sdk:lib:2.2.8'
67
67
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
68
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
69
+ implementation 'androidx.appcompat:appcompat:1.3.1'
68
70
  }
@@ -31,6 +31,7 @@ object HmsDecoder {
31
31
  "serverRecordingState",
32
32
  this.getHMSServerRecordingState(hmsRoom.serverRecordingState)
33
33
  )
34
+ room.putMap("hlsStreamingState", this.getHMSHlsStreamingState(hmsRoom.hlsStreamingState))
34
35
  room.putMap("localPeer", this.getHmsLocalPeer(hmsRoom.localPeer))
35
36
  room.putArray("peers", this.getAllPeers(hmsRoom.peerList))
36
37
  }
@@ -153,7 +154,7 @@ object HmsDecoder {
153
154
 
154
155
  private fun getHmsAudioSettings(hmsAudioSettings: AudioParams?): WritableMap {
155
156
  val audioSettings: WritableMap = Arguments.createMap()
156
- if (hmsAudioSettings != null) {
157
+ if (hmsAudioSettings != null && hmsAudioSettings.codec != null) {
157
158
  audioSettings.putInt("bitRate", hmsAudioSettings.bitRate)
158
159
  audioSettings.putString("codec", hmsAudioSettings.codec.name)
159
160
  }
@@ -162,7 +163,7 @@ object HmsDecoder {
162
163
 
163
164
  private fun getHmsVideoSettings(hmsVideoSettings: VideoParams?): WritableMap {
164
165
  val videoSettings: WritableMap = Arguments.createMap()
165
- if (hmsVideoSettings != null) {
166
+ if (hmsVideoSettings != null && hmsVideoSettings.codec != null) {
166
167
  videoSettings.putInt("bitRate", hmsVideoSettings.bitRate)
167
168
  videoSettings.putInt("frameRate", hmsVideoSettings.frameRate)
168
169
  videoSettings.putInt("width", hmsVideoSettings.width)
@@ -388,6 +389,30 @@ object HmsDecoder {
388
389
  return input
389
390
  }
390
391
 
392
+ private fun getHMSHlsStreamingState(data: HMSHLSStreamingState?): ReadableMap {
393
+ val input = Arguments.createMap()
394
+ if (data !== null) {
395
+ input.putBoolean("running", data.running)
396
+ input.putArray("variants", this.getHMSHLSVariant(data.variants))
397
+ }
398
+ return input
399
+ }
400
+
401
+ private fun getHMSHLSVariant(data: ArrayList<HMSHLSVariant>?): ReadableArray {
402
+ val variants = Arguments.createArray()
403
+ if (data !== null) {
404
+ for (variant in data) {
405
+ val input = Arguments.createMap()
406
+ input.putString("hlsStreamUrl", variant.hlsStreamUrl)
407
+ input.putString("meetingUrl", variant.meetingUrl)
408
+ input.putString("metadata", variant.metadata)
409
+ variant.startedAt?.let { input.putInt("startedAt", it.toInt()) }
410
+ variants.pushMap(input)
411
+ }
412
+ }
413
+ return variants
414
+ }
415
+
391
416
  private fun getHmsSubscribeSettings(hmsSubscribeSettings: SubscribeParams?): WritableMap {
392
417
  val subscribeSettings: WritableMap = Arguments.createMap()
393
418
  if (hmsSubscribeSettings != null) {
@@ -304,4 +304,29 @@ object HmsHelper {
304
304
  }
305
305
  return rtmpURLs
306
306
  }
307
+
308
+ fun getHMSHLSMeetingURLVariants(
309
+ hmsMeetingURLVariants: ArrayList<HashMap<String, String>>?
310
+ ): List<HMSHLSMeetingURLVariant> {
311
+ val meetingURLVariants = mutableListOf<HMSHLSMeetingURLVariant>()
312
+ if (hmsMeetingURLVariants !== null) {
313
+ for (variant in hmsMeetingURLVariants) {
314
+ val meetingURLVariant = this.getHMSHLSMeetingURLVariant(variant)
315
+ meetingURLVariants.add(meetingURLVariant)
316
+ }
317
+ }
318
+ return meetingURLVariants
319
+ }
320
+
321
+ private fun getHMSHLSMeetingURLVariant(
322
+ hmsMeetingURLVariant: HashMap<String, String>?
323
+ ): HMSHLSMeetingURLVariant {
324
+ var meetingURLVariant = HMSHLSMeetingURLVariant("", "")
325
+ if (hmsMeetingURLVariant !== null) {
326
+ val meetingUrl = hmsMeetingURLVariant["meetingUrl"] as String
327
+ val metadata = hmsMeetingURLVariant["metadata"] as String
328
+ meetingURLVariant = HMSHLSMeetingURLVariant(meetingUrl, metadata)
329
+ }
330
+ return meetingURLVariant
331
+ }
307
332
  }
@@ -1,5 +1,8 @@
1
1
  package com.reactnativehmssdk
2
2
 
3
+ import android.app.Activity
4
+ import android.app.Application
5
+ import android.os.Bundle
3
6
  import com.facebook.react.bridge.*
4
7
  import com.facebook.react.module.annotations.ReactModule
5
8
  import com.facebook.react.modules.core.DeviceEventManagerModule
@@ -7,11 +10,12 @@ import com.reactnativehmssdk.HmsModule.Companion.REACT_CLASS
7
10
  import java.util.UUID
8
11
 
9
12
  @ReactModule(name = REACT_CLASS)
10
- class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
13
+ class HmsModule(reactContext: ReactApplicationContext) :
14
+ ReactContextBaseJavaModule(reactContext), Application.ActivityLifecycleCallbacks {
11
15
  companion object {
12
16
  const val REACT_CLASS = "HmsManager"
17
+ var hmsCollection = mutableMapOf<String, HmsSDK>()
13
18
  }
14
- private var hmsCollection = mutableMapOf<String, HmsSDK>()
15
19
  override fun getName(): String {
16
20
  return "HmsManager"
17
21
  }
@@ -121,10 +125,10 @@ class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
121
125
  }
122
126
 
123
127
  @ReactMethod
124
- fun changeTrackStateRoles(data: ReadableMap, callback: Promise?) {
128
+ fun changeTrackStateForRoles(data: ReadableMap, callback: Promise?) {
125
129
  val hms = HmsHelper.getHms(data, hmsCollection)
126
130
 
127
- hms?.changeTrackStateRoles(data, callback)
131
+ hms?.changeTrackStateForRoles(data, callback)
128
132
  }
129
133
 
130
134
  @ReactMethod
@@ -204,6 +208,29 @@ class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
204
208
  hms?.changeMetadata(data, callback)
205
209
  }
206
210
 
211
+ @ReactMethod
212
+ fun startScreenshare(data: ReadableMap) {
213
+ currentActivity?.application?.registerActivityLifecycleCallbacks(this)
214
+ val hms = HmsHelper.getHms(data, hmsCollection)
215
+
216
+ hms?.startScreenshare()
217
+ }
218
+
219
+ @ReactMethod
220
+ fun isScreenShared(data: ReadableMap, callback: Promise?) {
221
+ val hms = HmsHelper.getHms(data, hmsCollection)
222
+
223
+ hms?.isScreenShared(callback)
224
+ }
225
+
226
+ @ReactMethod
227
+ fun stopScreenshare(data: ReadableMap, callback: Promise?) {
228
+ val hms = HmsHelper.getHms(data, hmsCollection)
229
+
230
+ currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
231
+ hms?.stopScreenshare(callback)
232
+ }
233
+
207
234
  @ReactMethod
208
235
  fun startRTMPOrRecording(data: ReadableMap, callback: Promise?) {
209
236
  val hms = HmsHelper.getHms(data, hmsCollection)
@@ -218,9 +245,59 @@ class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
218
245
  hms?.stopRtmpAndRecording(callback)
219
246
  }
220
247
 
248
+ @ReactMethod
249
+ fun startHLSStreaming(data: ReadableMap, callback: Promise?) {
250
+ val hms = HmsHelper.getHms(data, hmsCollection)
251
+
252
+ hms?.startHLSStreaming(data, callback)
253
+ }
254
+
255
+ @ReactMethod
256
+ fun stopHLSStreaming(data: ReadableMap, callback: Promise?) {
257
+ val hms = HmsHelper.getHms(data, hmsCollection)
258
+
259
+ hms?.stopHLSStreaming(callback)
260
+ }
261
+
262
+ @ReactMethod
263
+ fun resetVolume(data: ReadableMap) {
264
+ val hms = HmsHelper.getHms(data, hmsCollection)
265
+
266
+ hms?.resetVolume()
267
+ }
268
+
221
269
  fun emitEvent(event: String, data: WritableMap) {
222
270
  reactApplicationContext
223
271
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
224
272
  .emit(event, data)
225
273
  }
274
+
275
+ override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
276
+
277
+ override fun onActivityStarted(activity: Activity) {}
278
+
279
+ override fun onActivityResumed(activity: Activity) {}
280
+
281
+ override fun onActivityPaused(activity: Activity) {}
282
+
283
+ override fun onActivityStopped(activity: Activity) {}
284
+
285
+ override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
286
+
287
+ override fun onActivityDestroyed(activity: Activity) {
288
+ try {
289
+ if (activity.componentName.shortClassName == ".MainActivity") {
290
+ for (key in hmsCollection.keys) {
291
+ val hmsLocalPeer = hmsCollection[key]?.hmsSDK?.getLocalPeer()
292
+ if (hmsLocalPeer != null) {
293
+ hmsCollection[key]?.leave(null)
294
+ }
295
+ }
296
+ currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
297
+ hmsCollection = mutableMapOf<String, HmsSDK>()
298
+ }
299
+ } catch (e: Exception) {
300
+ // Log.d("error", e.message)
301
+ }
302
+ }
226
303
  }
@@ -1,13 +1,17 @@
1
1
  package com.reactnativehmssdk
2
2
 
3
+ import android.content.Intent
4
+ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
3
5
  import com.facebook.react.bridge.*
6
+ import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
4
7
  import java.util.*
5
8
  import kotlinx.coroutines.launch
6
9
  import live.hms.video.error.HMSException
7
- import live.hms.video.media.tracks.*
10
+ import live.hms.video.media.tracks.HMSRemoteAudioTrack
11
+ import live.hms.video.media.tracks.HMSTrack
12
+ import live.hms.video.media.tracks.HMSTrackType
8
13
  import live.hms.video.sdk.*
9
14
  import live.hms.video.sdk.models.*
10
- import live.hms.video.sdk.models.HMSConfig
11
15
  import live.hms.video.sdk.models.enums.HMSPeerUpdate
12
16
  import live.hms.video.sdk.models.enums.HMSRoomUpdate
13
17
  import live.hms.video.sdk.models.enums.HMSTrackUpdate
@@ -22,8 +26,9 @@ class HmsSDK(
22
26
  ) {
23
27
  var hmsSDK: HMSSDK? = null
24
28
  private var recentRoleChangeRequest: HMSRoleChangeRequest? = null
29
+ var delegate: HmsModule = HmsDelegate
30
+ private var context: ReactApplicationContext = reactApplicationContext
25
31
  private var previewInProgress: Boolean = false
26
- private var delegate: HmsModule = HmsDelegate
27
32
  private var id: String = sdkId
28
33
  private var self = this
29
34
 
@@ -38,14 +43,7 @@ class HmsSDK(
38
43
 
39
44
  private fun emitCustomError(message: String) {
40
45
  val data: WritableMap = Arguments.createMap()
41
- val hmsError =
42
- HMSException(
43
- 102,
44
- message,
45
- message,
46
- message,
47
- message
48
- )
46
+ val hmsError = HMSException(102, message, message, message, message)
49
47
  data.putString("event", "ON_ERROR")
50
48
  data.putString("id", id)
51
49
  data.putMap("error", HmsDecoder.getError(hmsError))
@@ -86,7 +84,7 @@ class HmsSDK(
86
84
  }
87
85
 
88
86
  fun preview(credentials: ReadableMap) {
89
- if(previewInProgress){
87
+ if (previewInProgress) {
90
88
  self.emitCustomError("PREVIEW_ALREADY_IN_PROGRESS")
91
89
  return
92
90
  }
@@ -163,7 +161,7 @@ class HmsSDK(
163
161
  }
164
162
 
165
163
  fun join(credentials: ReadableMap) {
166
- if(previewInProgress){
164
+ if (previewInProgress) {
167
165
  self.emitCustomError("PREVIEW_IS_IN_PROGRESS")
168
166
  return
169
167
  }
@@ -426,15 +424,14 @@ class HmsSDK(
426
424
 
427
425
  fun sendBroadcastMessage(data: ReadableMap, callback: Promise?) {
428
426
  val requiredKeys =
429
- HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("message", "String")))
427
+ HmsHelper.areAllRequiredKeysAvailable(
428
+ data,
429
+ arrayOf(Pair("message", "String"), Pair("type", "String"))
430
+ )
430
431
  if (requiredKeys) {
431
- val type =
432
- if (HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("type", "String"))))
433
- data.getString("type")
434
- else "chat"
435
432
  hmsSDK?.sendBroadcastMessage(
436
433
  data.getString("message") as String,
437
- type as String,
434
+ data.getString("type") as String,
438
435
  object : HMSMessageResultListener {
439
436
  override fun onError(error: HMSException) {
440
437
  self.emitHMSError(error)
@@ -455,34 +452,27 @@ class HmsSDK(
455
452
  val requiredKeys =
456
453
  HmsHelper.areAllRequiredKeysAvailable(
457
454
  data,
458
- arrayOf(Pair("message", "String"), Pair("roles", "Array"))
455
+ arrayOf(Pair("message", "String"), Pair("roles", "Array"), Pair("type", "String"))
459
456
  )
460
457
  if (requiredKeys) {
461
- val type =
462
- if (HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("type", "String"))))
463
- data.getString("type")
464
- else "chat"
465
- val message = data.getString("message")
466
458
  val targetedRoles = data.getArray("roles")?.toArrayList() as? ArrayList<String>
467
459
  val roles = hmsSDK?.getRoles()
468
460
  val encodedTargetedRoles = HmsHelper.getRolesFromRoleNames(targetedRoles, roles)
469
461
 
470
- if (message != null) {
471
- hmsSDK?.sendGroupMessage(
472
- message,
473
- type as String,
474
- encodedTargetedRoles,
475
- object : HMSMessageResultListener {
476
- override fun onError(error: HMSException) {
477
- self.emitHMSError(error)
478
- callback?.reject(error.code.toString(), error.message)
479
- }
480
- override fun onSuccess(hmsMessage: HMSMessage) {
481
- callback?.resolve(emitHMSSuccess(hmsMessage))
482
- }
462
+ hmsSDK?.sendGroupMessage(
463
+ data.getString("message") as String,
464
+ data.getString("type") as String,
465
+ encodedTargetedRoles,
466
+ object : HMSMessageResultListener {
467
+ override fun onError(error: HMSException) {
468
+ self.emitHMSError(error)
469
+ callback?.reject(error.code.toString(), error.message)
483
470
  }
484
- )
485
- }
471
+ override fun onSuccess(hmsMessage: HMSMessage) {
472
+ callback?.resolve(emitHMSSuccess(hmsMessage))
473
+ }
474
+ }
475
+ )
486
476
  } else {
487
477
  self.emitRequiredKeysError()
488
478
  callback?.reject("101", "REQUIRED_KEYS_NOT_FOUND")
@@ -493,21 +483,16 @@ class HmsSDK(
493
483
  val requiredKeys =
494
484
  HmsHelper.areAllRequiredKeysAvailable(
495
485
  data,
496
- arrayOf(Pair("message", "String"), Pair("peerId", "String"))
486
+ arrayOf(Pair("message", "String"), Pair("peerId", "String"), Pair("type", "String"))
497
487
  )
498
488
  if (requiredKeys) {
499
- val type =
500
- if (HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("type", "String"))))
501
- data.getString("type")
502
- else "chat"
503
- val message = data.getString("message")
504
489
  val peerId = data.getString("peerId")
505
490
  val peers = hmsSDK?.getPeers()
506
491
  val peer = HmsHelper.getPeerFromPeerId(peerId, peers)
507
- if (message != null && peer != null) {
492
+ if (peer != null) {
508
493
  hmsSDK?.sendDirectMessage(
509
- message,
510
- type as String,
494
+ data.getString("message") as String,
495
+ data.getString("type") as String,
511
496
  peer,
512
497
  object : HMSMessageResultListener {
513
498
  override fun onError(error: HMSException) {
@@ -519,6 +504,9 @@ class HmsSDK(
519
504
  }
520
505
  }
521
506
  )
507
+ } else {
508
+ self.emitCustomError("PEER_NOT_FOUND")
509
+ callback?.reject("101", "PEER_NOT_FOUND")
522
510
  }
523
511
  } else {
524
512
  self.emitRequiredKeysError()
@@ -596,24 +584,35 @@ class HmsSDK(
596
584
  }
597
585
  }
598
586
 
599
- fun changeTrackStateRoles(data: ReadableMap, callback: Promise?) {
587
+ fun changeTrackStateForRoles(data: ReadableMap, callback: Promise?) {
600
588
  val requiredKeys =
601
589
  HmsHelper.areAllRequiredKeysAvailable(
602
590
  data,
603
591
  arrayOf(
604
- Pair("source", "String"),
605
592
  Pair("mute", "Boolean"),
606
- Pair("type", "String"),
607
- Pair("roles", "Array")
608
593
  )
609
594
  )
610
595
  if (requiredKeys) {
611
596
  val mute: Boolean = data.getBoolean("mute")
612
597
  val type =
613
- if (data.getString("type") == HMSTrackType.AUDIO.toString()) HMSTrackType.AUDIO
614
- else HMSTrackType.VIDEO
615
- val source = data.getString("source")
616
- val targetedRoles = data.getArray("roles")?.toArrayList() as? ArrayList<String>
598
+ if (HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("type", "String")))) {
599
+ if (data.getString("type") == HMSTrackType.AUDIO.toString()) HMSTrackType.AUDIO
600
+ else HMSTrackType.VIDEO
601
+ } else {
602
+ null
603
+ }
604
+ val source =
605
+ if (HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("source", "String")))) {
606
+ data.getString("source")
607
+ } else {
608
+ null
609
+ }
610
+ val targetedRoles =
611
+ if (HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("roles", "Array")))) {
612
+ data.getArray("roles")?.toArrayList() as? ArrayList<String>
613
+ } else {
614
+ null
615
+ }
617
616
  val roles = hmsSDK?.getRoles()
618
617
  val encodedTargetedRoles = HmsHelper.getRolesFromRoleNames(targetedRoles, roles)
619
618
  hmsSDK?.changeTrackState(
@@ -664,23 +663,19 @@ class HmsSDK(
664
663
 
665
664
  fun removePeer(data: ReadableMap, callback: Promise?) {
666
665
  val requiredKeys =
667
- HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("peerId", "String")))
666
+ HmsHelper.areAllRequiredKeysAvailable(
667
+ data,
668
+ arrayOf(Pair("peerId", "String"), Pair("reason", "String"))
669
+ )
668
670
  if (requiredKeys) {
669
671
  val peerId = data.getString("peerId")
670
- var reason = data.getString("reason")
671
-
672
- if (reason == null) {
673
- reason = ""
674
- }
675
-
676
672
  val peers = hmsSDK?.getRemotePeers()
677
-
678
673
  val peer = HmsHelper.getRemotePeerFromPeerId(peerId, peers)
679
674
 
680
675
  if (peer != null) {
681
676
  hmsSDK?.removePeerRequest(
682
677
  peer,
683
- reason,
678
+ data.getString("reason") as String,
684
679
  object : HMSActionResultListener {
685
680
  override fun onSuccess() {
686
681
  callback?.resolve(emitHMSSuccess())
@@ -692,6 +687,7 @@ class HmsSDK(
692
687
  }
693
688
  )
694
689
  } else {
690
+ self.emitCustomError("PEER_NOT_FOUND")
695
691
  callback?.reject("101", "PEER_NOT_FOUND")
696
692
  }
697
693
  } else {
@@ -701,25 +697,29 @@ class HmsSDK(
701
697
  }
702
698
 
703
699
  fun endRoom(data: ReadableMap, callback: Promise?) {
704
- val lock = data.getBoolean("lock")
705
- var reason = data.getString("reason")
706
- if (reason == null) {
707
- reason = ""
708
- }
709
-
710
- hmsSDK?.endRoom(
711
- reason,
712
- lock,
713
- object : HMSActionResultListener {
714
- override fun onSuccess() {
715
- callback?.resolve(emitHMSSuccess())
716
- }
717
- override fun onError(error: HMSException) {
718
- self.emitHMSError(error)
719
- callback?.reject(error.code.toString(), error.message)
700
+ val requiredKeys =
701
+ HmsHelper.areAllRequiredKeysAvailable(
702
+ data,
703
+ arrayOf(Pair("lock", "Boolean"), Pair("reason", "String"))
704
+ )
705
+ if (requiredKeys) {
706
+ hmsSDK?.endRoom(
707
+ data.getString("reason") as String,
708
+ data.getBoolean("lock"),
709
+ object : HMSActionResultListener {
710
+ override fun onSuccess() {
711
+ callback?.resolve(emitHMSSuccess())
712
+ }
713
+ override fun onError(error: HMSException) {
714
+ self.emitHMSError(error)
715
+ callback?.reject(error.code.toString(), error.message)
716
+ }
720
717
  }
721
- }
722
- )
718
+ )
719
+ } else {
720
+ self.emitRequiredKeysError()
721
+ callback?.reject("101", "REQUIRED_KEYS_NOT_FOUND")
722
+ }
723
723
  }
724
724
 
725
725
  fun acceptRoleChange(callback: Promise?) {
@@ -953,4 +953,94 @@ class HmsSDK(
953
953
  }
954
954
  )
955
955
  }
956
+
957
+ fun startScreenshare() {
958
+ runOnUiThread {
959
+ val intent = Intent(context, HmsScreenshareActivity::class.java)
960
+ intent.flags = FLAG_ACTIVITY_NEW_TASK
961
+ intent.putExtra("id", id)
962
+ context.startActivity(intent)
963
+ }
964
+ }
965
+
966
+ fun isScreenShared(callback: Promise?) {
967
+ callback?.resolve(hmsSDK?.isScreenShared())
968
+ }
969
+
970
+ fun stopScreenshare(callback: Promise?) {
971
+ hmsSDK?.stopScreenshare(
972
+ object : HMSActionResultListener {
973
+ override fun onError(error: HMSException) {
974
+ callback?.reject(error.code.toString(), error.message)
975
+ self.emitHMSError(error)
976
+ }
977
+ override fun onSuccess() {
978
+ callback?.resolve(emitHMSSuccess())
979
+ }
980
+ }
981
+ )
982
+ }
983
+
984
+ fun startHLSStreaming(data: ReadableMap, callback: Promise?) {
985
+ val requiredKeys =
986
+ HmsHelper.areAllRequiredKeysAvailable(data, arrayOf(Pair("meetingURLVariants", "Array")))
987
+ if (requiredKeys) {
988
+ val meetingURLVariants =
989
+ data.getArray("meetingURLVariants")?.toArrayList() as? ArrayList<HashMap<String, String>>
990
+ val hlsMeetingUrlVariant = HmsHelper.getHMSHLSMeetingURLVariants(meetingURLVariants)
991
+ val config = HMSHLSConfig(hlsMeetingUrlVariant)
992
+
993
+ hmsSDK?.startHLSStreaming(
994
+ config,
995
+ object : HMSActionResultListener {
996
+ override fun onSuccess() {
997
+ callback?.resolve(emitHMSSuccess())
998
+ }
999
+ override fun onError(error: HMSException) {
1000
+ callback?.reject(error.code.toString(), error.message)
1001
+ self.emitHMSError(error)
1002
+ }
1003
+ }
1004
+ )
1005
+ } else {
1006
+ callback?.reject("101", "REQUIRED_KEYS_NOT_FOUND")
1007
+ self.emitRequiredKeysError()
1008
+ }
1009
+ }
1010
+
1011
+ fun stopHLSStreaming(callback: Promise?) {
1012
+ hmsSDK?.stopHLSStreaming(
1013
+ null,
1014
+ object : HMSActionResultListener {
1015
+ override fun onSuccess() {
1016
+ callback?.resolve(emitHMSSuccess())
1017
+ }
1018
+ override fun onError(error: HMSException) {
1019
+ callback?.reject(error.code.toString(), error.message)
1020
+ self.emitHMSError(error)
1021
+ }
1022
+ }
1023
+ )
1024
+ }
1025
+
1026
+ fun resetVolume() {
1027
+ val remotePeers = hmsSDK?.getRemotePeers()
1028
+
1029
+ if (remotePeers != null) {
1030
+ for (peer in remotePeers) {
1031
+ val playbackAllowed = peer.audioTrack?.isPlaybackAllowed
1032
+ if (playbackAllowed !== null && playbackAllowed) {
1033
+ peer.audioTrack?.setVolume(10.0)
1034
+ }
1035
+ val auxTracks = peer.auxiliaryTracks
1036
+
1037
+ for (track in auxTracks) {
1038
+ if (track.type === HMSTrackType.AUDIO) {
1039
+
1040
+ (track as? HMSRemoteAudioTrack)?.setVolume(10.0)
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ }
956
1046
  }