@100mslive/react-native-hms 1.3.0 → 1.5.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 (165) hide show
  1. package/README.md +59 -5
  2. package/android/build.gradle +3 -2
  3. package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +189 -55
  4. package/android/src/main/java/com/reactnativehmssdk/HMSHelper.kt +1 -0
  5. package/android/src/main/java/com/reactnativehmssdk/HMSManager.kt +49 -14
  6. package/android/src/main/java/com/reactnativehmssdk/HMSRNSDK.kt +240 -46
  7. package/android/src/main/java/com/reactnativehmssdk/HMSSDKViewManager.kt +5 -0
  8. package/android/src/main/java/com/reactnativehmssdk/HMSView.kt +29 -21
  9. package/android/src/main/res/layout/hms_view.xml +2 -2
  10. package/ios/HMSConstants.swift +31 -0
  11. package/ios/HMSDecoder.swift +371 -156
  12. package/ios/HMSManager.m +10 -2
  13. package/ios/HMSManager.swift +149 -74
  14. package/ios/HMSRNSDK.swift +431 -181
  15. package/ios/HMSView.m +1 -0
  16. package/ios/HMSView.swift +21 -19
  17. package/lib/commonjs/classes/HMSAudioTrackSettings.js +1 -1
  18. package/lib/commonjs/classes/HMSAudioTrackSettings.js.map +1 -1
  19. package/lib/commonjs/classes/HMSCameraControl.js +28 -0
  20. package/lib/commonjs/classes/HMSCameraControl.js.map +1 -0
  21. package/lib/commonjs/classes/HMSEncoder.js +95 -13
  22. package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
  23. package/lib/commonjs/classes/HMSException.js +3 -4
  24. package/lib/commonjs/classes/HMSException.js.map +1 -1
  25. package/lib/commonjs/classes/HMSLayer.js +14 -0
  26. package/lib/commonjs/classes/HMSLayer.js.map +1 -0
  27. package/lib/commonjs/classes/HMSLocalVideoStats.js +11 -0
  28. package/lib/commonjs/classes/HMSLocalVideoStats.js.map +1 -1
  29. package/lib/commonjs/classes/HMSLocalVideoTrack.js +5 -6
  30. package/lib/commonjs/classes/HMSLocalVideoTrack.js.map +1 -1
  31. package/lib/commonjs/classes/HMSMessage.js +1 -2
  32. package/lib/commonjs/classes/HMSMessage.js.map +1 -1
  33. package/lib/commonjs/classes/HMSPeer.js +3 -4
  34. package/lib/commonjs/classes/HMSPeer.js.map +1 -1
  35. package/lib/commonjs/classes/HMSPublishSettings.js +2 -0
  36. package/lib/commonjs/classes/HMSPublishSettings.js.map +1 -1
  37. package/lib/commonjs/classes/HMSQualityLimitationReason.js +16 -0
  38. package/lib/commonjs/classes/HMSQualityLimitationReason.js.map +1 -0
  39. package/lib/commonjs/classes/HMSQualityLimitationReasons.js +27 -0
  40. package/lib/commonjs/classes/HMSQualityLimitationReasons.js.map +1 -0
  41. package/lib/commonjs/classes/HMSRemotePeer.js.map +1 -1
  42. package/lib/commonjs/classes/HMSRemoteVideoTrack.js +39 -4
  43. package/lib/commonjs/classes/HMSRemoteVideoTrack.js.map +1 -1
  44. package/lib/commonjs/classes/HMSRoom.js +4 -0
  45. package/lib/commonjs/classes/HMSRoom.js.map +1 -1
  46. package/lib/commonjs/classes/HMSRoomUpdate.js +1 -0
  47. package/lib/commonjs/classes/HMSRoomUpdate.js.map +1 -1
  48. package/lib/commonjs/classes/HMSSDK.js +70 -62
  49. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  50. package/lib/commonjs/classes/HMSSimulcastLayerDefinition.js +19 -0
  51. package/lib/commonjs/classes/HMSSimulcastLayerDefinition.js.map +1 -0
  52. package/lib/commonjs/classes/HMSSimulcastLayerSettingsPolicy.js +23 -0
  53. package/lib/commonjs/classes/HMSSimulcastLayerSettingsPolicy.js.map +1 -0
  54. package/lib/commonjs/classes/HMSSimulcastSettings.js +5 -4
  55. package/lib/commonjs/classes/HMSSimulcastSettings.js.map +1 -1
  56. package/lib/commonjs/classes/HMSSimulcastSettingsPolicy.js +17 -0
  57. package/lib/commonjs/classes/HMSSimulcastSettingsPolicy.js.map +1 -0
  58. package/lib/commonjs/classes/HMSSubscribeDegradationPolicy.js +21 -0
  59. package/lib/commonjs/classes/HMSSubscribeDegradationPolicy.js.map +1 -0
  60. package/lib/commonjs/classes/HMSSubscribeSettings.js +2 -0
  61. package/lib/commonjs/classes/HMSSubscribeSettings.js.map +1 -1
  62. package/lib/commonjs/classes/HMSVideoResolution.js.map +1 -1
  63. package/lib/commonjs/classes/HMSVideoTrackSettings.js +1 -1
  64. package/lib/commonjs/classes/HMSVideoTrackSettings.js.map +1 -1
  65. package/lib/commonjs/classes/HmsView.js +2 -0
  66. package/lib/commonjs/classes/HmsView.js.map +1 -1
  67. package/lib/commonjs/index.js +60 -0
  68. package/lib/commonjs/index.js.map +1 -1
  69. package/lib/module/classes/HMSAudioTrackSettings.js +1 -1
  70. package/lib/module/classes/HMSAudioTrackSettings.js.map +1 -1
  71. package/lib/module/classes/HMSCameraControl.js +21 -0
  72. package/lib/module/classes/HMSCameraControl.js.map +1 -0
  73. package/lib/module/classes/HMSEncoder.js +95 -13
  74. package/lib/module/classes/HMSEncoder.js.map +1 -1
  75. package/lib/module/classes/HMSException.js +3 -4
  76. package/lib/module/classes/HMSException.js.map +1 -1
  77. package/lib/module/classes/HMSLayer.js +7 -0
  78. package/lib/module/classes/HMSLayer.js.map +1 -0
  79. package/lib/module/classes/HMSLocalVideoStats.js +11 -0
  80. package/lib/module/classes/HMSLocalVideoStats.js.map +1 -1
  81. package/lib/module/classes/HMSLocalVideoTrack.js +5 -6
  82. package/lib/module/classes/HMSLocalVideoTrack.js.map +1 -1
  83. package/lib/module/classes/HMSMessage.js +1 -2
  84. package/lib/module/classes/HMSMessage.js.map +1 -1
  85. package/lib/module/classes/HMSPeer.js +3 -4
  86. package/lib/module/classes/HMSPeer.js.map +1 -1
  87. package/lib/module/classes/HMSPublishSettings.js +2 -0
  88. package/lib/module/classes/HMSPublishSettings.js.map +1 -1
  89. package/lib/module/classes/HMSQualityLimitationReason.js +9 -0
  90. package/lib/module/classes/HMSQualityLimitationReason.js.map +1 -0
  91. package/lib/module/classes/HMSQualityLimitationReasons.js +20 -0
  92. package/lib/module/classes/HMSQualityLimitationReasons.js.map +1 -0
  93. package/lib/module/classes/HMSRemotePeer.js.map +1 -1
  94. package/lib/module/classes/HMSRemoteVideoTrack.js +39 -4
  95. package/lib/module/classes/HMSRemoteVideoTrack.js.map +1 -1
  96. package/lib/module/classes/HMSRoom.js +4 -0
  97. package/lib/module/classes/HMSRoom.js.map +1 -1
  98. package/lib/module/classes/HMSRoomUpdate.js +1 -0
  99. package/lib/module/classes/HMSRoomUpdate.js.map +1 -1
  100. package/lib/module/classes/HMSSDK.js +71 -62
  101. package/lib/module/classes/HMSSDK.js.map +1 -1
  102. package/lib/module/classes/HMSSimulcastLayerDefinition.js +12 -0
  103. package/lib/module/classes/HMSSimulcastLayerDefinition.js.map +1 -0
  104. package/lib/module/classes/HMSSimulcastLayerSettingsPolicy.js +16 -0
  105. package/lib/module/classes/HMSSimulcastLayerSettingsPolicy.js.map +1 -0
  106. package/lib/module/classes/HMSSimulcastSettings.js +5 -4
  107. package/lib/module/classes/HMSSimulcastSettings.js.map +1 -1
  108. package/lib/module/classes/HMSSimulcastSettingsPolicy.js +10 -0
  109. package/lib/module/classes/HMSSimulcastSettingsPolicy.js.map +1 -0
  110. package/lib/module/classes/HMSSubscribeDegradationPolicy.js +14 -0
  111. package/lib/module/classes/HMSSubscribeDegradationPolicy.js.map +1 -0
  112. package/lib/module/classes/HMSSubscribeSettings.js +2 -0
  113. package/lib/module/classes/HMSSubscribeSettings.js.map +1 -1
  114. package/lib/module/classes/HMSVideoResolution.js.map +1 -1
  115. package/lib/module/classes/HMSVideoTrackSettings.js +1 -1
  116. package/lib/module/classes/HMSVideoTrackSettings.js.map +1 -1
  117. package/lib/module/classes/HmsView.js +2 -0
  118. package/lib/module/classes/HmsView.js.map +1 -1
  119. package/lib/module/index.js +5 -0
  120. package/lib/module/index.js.map +1 -1
  121. package/lib/typescript/classes/HMSCameraControl.d.ts +9 -0
  122. package/lib/typescript/classes/HMSEncoder.d.ts +13 -1
  123. package/lib/typescript/classes/HMSLayer.d.ts +5 -0
  124. package/lib/typescript/classes/HMSLocalVideoStats.d.ts +6 -0
  125. package/lib/typescript/classes/HMSPeer.d.ts +1 -1
  126. package/lib/typescript/classes/HMSPublishSettings.d.ts +3 -0
  127. package/lib/typescript/classes/HMSQualityLimitationReason.d.ts +7 -0
  128. package/lib/typescript/classes/HMSQualityLimitationReasons.d.ts +17 -0
  129. package/lib/typescript/classes/HMSRemotePeer.d.ts +0 -1
  130. package/lib/typescript/classes/HMSRemoteVideoTrack.d.ts +6 -2
  131. package/lib/typescript/classes/HMSRoomUpdate.d.ts +2 -1
  132. package/lib/typescript/classes/HMSSDK.d.ts +24 -42
  133. package/lib/typescript/classes/HMSSimulcastLayerDefinition.d.ts +10 -0
  134. package/lib/typescript/classes/HMSSimulcastLayerSettingsPolicy.d.ts +12 -0
  135. package/lib/typescript/classes/HMSSimulcastSettings.d.ts +7 -3
  136. package/lib/typescript/classes/HMSSimulcastSettingsPolicy.d.ts +7 -0
  137. package/lib/typescript/classes/HMSSubscribeDegradationPolicy.d.ts +10 -0
  138. package/lib/typescript/classes/HMSSubscribeSettings.d.ts +5 -2
  139. package/lib/typescript/classes/HMSVideoResolution.d.ts +2 -2
  140. package/lib/typescript/classes/HmsView.d.ts +2 -2
  141. package/lib/typescript/index.d.ts +5 -0
  142. package/package.json +2 -2
  143. package/sdk-versions.json +3 -3
  144. package/src/classes/HMSCameraControl.ts +21 -0
  145. package/src/classes/HMSEncoder.ts +125 -11
  146. package/src/classes/HMSLayer.ts +5 -0
  147. package/src/classes/HMSLocalVideoStats.ts +21 -0
  148. package/src/classes/HMSPeer.ts +1 -1
  149. package/src/classes/HMSPublishSettings.ts +4 -0
  150. package/src/classes/HMSQualityLimitationReason.ts +7 -0
  151. package/src/classes/HMSQualityLimitationReasons.ts +27 -0
  152. package/src/classes/HMSRemotePeer.ts +0 -1
  153. package/src/classes/HMSRemoteVideoTrack.ts +52 -4
  154. package/src/classes/HMSRoom.ts +2 -0
  155. package/src/classes/HMSRoomUpdate.ts +1 -0
  156. package/src/classes/HMSSDK.tsx +99 -67
  157. package/src/classes/HMSSimulcastLayerDefinition.ts +12 -0
  158. package/src/classes/HMSSimulcastLayerSettingsPolicy.ts +18 -0
  159. package/src/classes/HMSSimulcastSettings.ts +12 -3
  160. package/src/classes/HMSSimulcastSettingsPolicy.ts +9 -0
  161. package/src/classes/HMSSubscribeDegradationPolicy.ts +15 -0
  162. package/src/classes/HMSSubscribeSettings.ts +10 -2
  163. package/src/classes/HMSVideoResolution.ts +1 -1
  164. package/src/classes/HmsView.tsx +5 -1
  165. package/src/index.ts +5 -0
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  <a href="https://100ms.live/">
2
- <img src="https://github.com/100mslive/100ms-react-native/blob/main/100ms.gif" height=256/>
3
- <img src="https://github.com/100mslive/100ms-react-native/blob/main/100ms.svg" title="100ms logo" float=center height=256>
2
+ <img src="https://raw.githubusercontent.com/100mslive/react-native-hms/main/100ms.svg" title="100ms logo" float=center height=256>
4
3
  </a>
5
4
 
6
5
  [![npm](https://img.shields.io/npm/v/@100mslive/react-native-hms)](https://www.npmjs.com/package/@100mslive/react-native-hms)
@@ -17,6 +16,11 @@
17
16
 
18
17
  # 100ms React Native SDK
19
18
 
19
+ Integrate Real Time Audio and Video conferencing, Interactive Live Streaming, and Chat in your apps with 100ms React Native SDK.
20
+
21
+ With support for HLS and RTMP Live Streaming and Recording, Picture-in-Picture (PiP), one-to-one Video Call Modes, Audio Rooms, Video Player and much more, add immersive real-time communications to your apps.
22
+
23
+
20
24
  📖 Read the Complete Documentation here: https://www.100ms.live/docs/react-native/v2/foundation/basics
21
25
 
22
26
  ## 🏃 Example App
@@ -120,17 +124,65 @@ More information about Audio Video Permission on iOS & Android is [available her
120
124
 
121
125
  The package exports all the classes and a HMSSDK class that manages everything.
122
126
 
123
- ## Setting up the HMS Instance
127
+ ## [Setting up the HMS Instance](https://www.100ms.live/docs/react-native/v2/how--to-guides/install-the-sdk/hmssdk)
124
128
 
125
129
  First invoke the `build` method which returns an instance of `HMSSDK`. Save this instance to perform all actions related to 100ms.
126
130
 
127
131
  ```ts
128
132
  import { HMSSDK } from '@100mslive/react-native-hms';
129
133
 
130
- // create HMSSDK instance using the build method & save it for further usage
134
+ /**
135
+ * create HMSSDK instance using the build method & save it for further usage
136
+ *
137
+ * Important Note: Don't build new `HMSSDK` instance before destroying the previous one.
138
+ * for more info checkout {@link https://www.100ms.live/docs/react-native/v2/how--to-guides/install-the-sdk/hmssdk#what-does-destroy-method-do}
139
+ */
131
140
  const hmsInstance = await HMSSDK.build();
132
141
  ```
133
142
 
143
+ ## [Get Authentication Token](https://www.100ms.live/docs/react-native/v2/get-started/quickstart#fetch-token-to-join-the-room)
144
+
145
+ ### Fetch token using room-code method (Recommended)
146
+
147
+ We can get the authentication token using room-code from meeting URL.
148
+
149
+ Let's understand the subdomain and code from the sample URL
150
+
151
+ In this sample url: `http://100ms-rocks.app.100ms.live/meeting/abc-defg-hij`
152
+ - Subdomain is `100ms-rocks`
153
+ - Room code is `abc-defg-hij`
154
+
155
+ Now to get the room-code from meeting URL, we can write our own logic or use the `getCode` method from [here](https://github.com/100mslive/react-native-hms/blob/main/example/src/utils/getRoomLinkDetails.ts)
156
+
157
+ To generate token we will be using `getAuthTokenByRoomCode` method available on `HMSSDK` instance. This method has `roomCode` as a required
158
+ parameter and `userId` & `endpoint` as optional parameter.
159
+
160
+ Let's checkout the implementation:
161
+
162
+ ```js
163
+ /**
164
+ * `getAuthTokenByRoomCode` returns a promise which is resolved with "auth token"
165
+ * checkout {@link https://www.100ms.live/docs/react-native/v2/how--to-guides/install-the-sdk/hmssdk#what-does-destroy-method-do}
166
+ */
167
+ const token = await hmsInstance.getAuthTokenByRoomCode('YOUR_ROOM_CODE');
168
+
169
+ /**
170
+ * Create `HMSConfig` with the above auth token and username
171
+ */
172
+ const hmsConfig = new HMSConfig({ authToken: token, username: 'John Appleseed' });
173
+ ```
174
+
175
+ ### Get temporary token from dashboard
176
+
177
+ To test audio/video functionality, you need to connect to a 100ms Room. Please check the following steps for the same -
178
+
179
+ 1. Navigate to your [100ms dashboard](https://dashboard.100ms.live/dashboard) or [create an account](https://dashboard.100ms.live/register) if you don't have one.
180
+ 2. Use the `Video Conferencing Starter Kit` to create a room with a default template assigned to it to test this app quickly.
181
+ 3. Go to the [Rooms page](https://dashboard.100ms.live/rooms) in your dashboard, click on the `Room Id` of the room you created above, and click on the `Join Room` button on the top right.
182
+ 4. You will see 100ms demo URLs for the roles created when you deployed the starter kit; you can click on the 'key' icon to copy the token and update the `AUTH_TOKEN` variable in "App.js" file.
183
+ > Token from 100ms dashboard is for testing purposes only, For production applications you must generate tokens on your own server. Refer to the [Management Token section](/concepts/v2/concepts/security-and-tokens#management-token) in Authentication and Tokens guide for more information.
184
+
185
+
134
186
  ## [Add Event Listeners](https://www.100ms.live/docs/react-native/v2/features/event-listeners)
135
187
 
136
188
  Add Event Listeners to get notified about actions happening in the 100ms Room.
@@ -175,6 +227,8 @@ NOTE: `ON_JOIN` Event Listener must be **attached** before calling `join` functi
175
227
  // create HMSSDK instance using the build function
176
228
  const hmsInstance = await HMSSDK.build();
177
229
 
230
+ // Generate 100ms Auth Token by Room Code
231
+ const token = await hmsInstance.getAuthTokenByRoomCode('abc-defg-hij'); // Sample Room Code
178
232
 
179
233
  // You'll need to add Event Listeners for HMSUpdateListenerActions, which are invoked to notify about updates happening in the room like a peer joins/leaves, a track got muted/unmuted, any errors that occur, etc.
180
234
  hmsInstance.addEventListener(HMSUpdateListenerActions.ON_JOIN, onJoinSuccess);
@@ -185,7 +239,7 @@ hmsInstance.addEventListener(HMSUpdateListenerActions.ON_ERROR, onError);
185
239
 
186
240
  // Next, create an object of HMSConfig class using the available joining configurations.
187
241
  let config = new HMSConfig({
188
- authToken: 'eyJH5c...', // client-side token generated from your token service
242
+ authToken: token, // client-side token generated by `getAuthTokenByRoomCode` method
189
243
  username: 'John Appleseed',
190
244
  });
191
245
 
@@ -1,6 +1,6 @@
1
1
  import groovy.json.JsonSlurper
2
2
 
3
- def sdkVersionsJson = new JsonSlurper().parse file("../sdk-versions.json")
3
+ def sdkVersions = new JsonSlurper().parse file("../sdk-versions.json")
4
4
 
5
5
  buildscript {
6
6
  ext.kotlin_version = '1.5.30-RC'
@@ -69,7 +69,8 @@ dependencies {
69
69
  //noinspection GradleDynamicVersion
70
70
  implementation "com.facebook.react:react-native:+"
71
71
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // From node_modules
72
- implementation "live.100ms:android-sdk:${sdkVersionsJson["android"]}"
72
+ implementation "live.100ms:android-sdk:${sdkVersions["android"]}"
73
+ implementation "live.100ms:video-view:${sdkVersions["android"]}"
73
74
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
74
75
  implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
75
76
  implementation 'androidx.appcompat:appcompat:1.3.1'
@@ -1,12 +1,11 @@
1
1
  package com.reactnativehmssdk
2
2
 
3
3
  import com.facebook.react.bridge.*
4
+ import live.hms.video.connection.degredation.QualityLimitationReasons
4
5
  import live.hms.video.connection.stats.*
5
6
  import live.hms.video.connection.stats.quality.HMSNetworkQuality
6
7
  import live.hms.video.error.HMSException
7
- import live.hms.video.media.settings.HMSAudioTrackSettings
8
- import live.hms.video.media.settings.HMSVideoResolution
9
- import live.hms.video.media.settings.HMSVideoTrackSettings
8
+ import live.hms.video.media.settings.*
10
9
  import live.hms.video.media.tracks.*
11
10
  import live.hms.video.sdk.models.*
12
11
  import live.hms.video.sdk.models.enums.HMSPeerUpdate
@@ -77,12 +76,14 @@ object HMSDecoder {
77
76
  val room: WritableMap = Arguments.createMap()
78
77
  if (hmsRoom != null) {
79
78
  room.putString("id", hmsRoom.roomId)
80
- room.putString("sessionId", hmsRoom.sessionId)
79
+ hmsRoom.sessionId?.let {
80
+ room.putString("sessionId", it)
81
+ }
81
82
  room.putString("name", hmsRoom.name)
82
83
  room.putString("metaData", null)
83
- hmsRoom.startedAt?.let {
84
- room.putString("startedAt", it.toString())
85
- }
84
+ // hmsRoom.startedAt?.let {
85
+ // room.putString("startedAt", it.toString())
86
+ // }
86
87
 
87
88
  hmsRoom.browserRecordingState?.let {
88
89
  room.putMap(
@@ -113,7 +114,9 @@ object HMSDecoder {
113
114
  room.putMap("hlsRecordingState", this.getHMSHlsRecordingState(hmsRoom.hlsRecordingState))
114
115
  }
115
116
 
116
- room.putMap("localPeer", this.getHmsLocalPeer(hmsRoom.localPeer))
117
+ hmsRoom.localPeer?.let {
118
+ room.putMap("localPeer", this.getHmsLocalPeer(it))
119
+ }
117
120
 
118
121
  room.putArray("peers", this.getAllPeers(hmsRoom.peerList))
119
122
 
@@ -309,6 +312,10 @@ object HMSDecoder {
309
312
  publishSettings.putMap("screen", this.getHmsVideoSettings(it))
310
313
  }
311
314
 
315
+ hmsPublishSettings.simulcast?.let {
316
+ publishSettings.putMap("simulcast", this.getHmsSimulcastSettings(it))
317
+ }
318
+
312
319
  publishSettings.putArray("allowed", this.getWriteableArray(hmsPublishSettings.allowed))
313
320
  }
314
321
  return publishSettings
@@ -345,6 +352,50 @@ object HMSDecoder {
345
352
  return videoSettings
346
353
  }
347
354
 
355
+ private fun getHmsSimulcastSettings(hmsSimulcastSettings: Simulcast?): WritableMap {
356
+ val simulcastSettings: WritableMap = Arguments.createMap()
357
+ if (hmsSimulcastSettings != null) {
358
+ hmsSimulcastSettings.video?.let {
359
+ simulcastSettings.putMap("video", getHmsVideoSimulcastLayersParams(it))
360
+ }
361
+ hmsSimulcastSettings.screen?.let {
362
+ simulcastSettings.putMap("screen", getHmsVideoSimulcastLayersParams(it))
363
+ }
364
+ }
365
+ return simulcastSettings
366
+ }
367
+
368
+ private fun getHmsVideoSimulcastLayersParams(hmsVideoSimulcastLayersParams: VideoSimulcastLayersParams?): WritableMap {
369
+ val videoSimulcastLayersParams: WritableMap = Arguments.createMap()
370
+ if (hmsVideoSimulcastLayersParams != null) {
371
+ hmsVideoSimulcastLayersParams.layers?.let {
372
+ val layersParams = Arguments.createArray()
373
+ it.forEach { layer -> layersParams.pushMap(getHmsLayerParams(layer)) }
374
+ videoSimulcastLayersParams.putArray("layers", layersParams)
375
+ }
376
+ }
377
+ return videoSimulcastLayersParams
378
+ }
379
+
380
+ private fun getHmsLayerParams(hmsLayerParams: LayerParams?): WritableMap {
381
+ val layerParams: WritableMap = Arguments.createMap()
382
+ if (hmsLayerParams != null) {
383
+ hmsLayerParams.rid?.let {
384
+ layerParams.putString("rid", it)
385
+ }
386
+ hmsLayerParams.maxBitrate?.let {
387
+ layerParams.putInt("maxBitrate", it)
388
+ }
389
+ hmsLayerParams.scaleResolutionDownBy?.let {
390
+ layerParams.putDouble("scaleResolutionDownBy", it.toDouble())
391
+ }
392
+ hmsLayerParams.maxFramerate?.let {
393
+ layerParams.putInt("maxFramerate", it)
394
+ }
395
+ }
396
+ return layerParams
397
+ }
398
+
348
399
  fun getHmsLocalPeer(hmsLocalPeer: HMSLocalPeer?): WritableMap {
349
400
  val peer: WritableMap = Arguments.createMap()
350
401
  if (hmsLocalPeer != null) {
@@ -412,10 +463,11 @@ object HMSDecoder {
412
463
  return settings
413
464
  }
414
465
 
415
- private fun getHmsVideoTrackResolution(hmsResolution: HMSVideoResolution): WritableMap {
416
- val resolution: WritableMap = Arguments.createMap()
417
- resolution.putInt("height", hmsResolution.height)
418
- resolution.putInt("width", hmsResolution.width)
466
+ private fun getHmsVideoTrackResolution(hmsResolution: HMSVideoResolution): WritableArray {
467
+ val resolution: WritableArray = Arguments.createArray() // [width, height]
468
+ resolution.pushInt(hmsResolution.width)
469
+ resolution.pushInt(hmsResolution.height)
470
+
419
471
  return resolution
420
472
  }
421
473
 
@@ -630,6 +682,11 @@ object HMSDecoder {
630
682
  val subscribeSettings: WritableMap = Arguments.createMap()
631
683
  if (hmsSubscribeSettings != null) {
632
684
  subscribeSettings.putInt("maxSubsBitRate", hmsSubscribeSettings.maxSubsBitRate)
685
+
686
+ hmsSubscribeSettings.subscribeDegradationParam?.let {
687
+ subscribeSettings.putMap("subscribeDegradation", this.getHmsSubscribeDegradationSettings(it))
688
+ }
689
+
633
690
  subscribeSettings.putArray(
634
691
  "subscribeTo",
635
692
  this.getWriteableArray(hmsSubscribeSettings.subscribeTo)
@@ -702,26 +759,32 @@ object HMSDecoder {
702
759
  return hmsNetworkQuality
703
760
  }
704
761
 
705
- fun getHMSRTCStats(hmsRtcStats: HMSRTCStats?): WritableMap {
706
- val rtcStats: WritableMap = Arguments.createMap()
762
+ fun getHMSRTCStats(hmsRtcStats: HMSRTCStats?): WritableArray {
763
+ val rtcStats: WritableArray = Arguments.createArray() // [bitrateReceived, bitrateSent, bytesReceived, bytesSent, packetsLost, packetsReceived, roundTripTime]
707
764
  if (hmsRtcStats != null) {
708
- rtcStats.putDouble("bitrateReceived", hmsRtcStats.bitrateReceived)
709
- rtcStats.putDouble("bitrateSent", hmsRtcStats.bitrateSent)
710
- rtcStats.putString("bytesSent", hmsRtcStats.bytesSent.toString())
711
- rtcStats.putString("bytesReceived", hmsRtcStats.bytesReceived.toString())
712
- rtcStats.putString("packetsLost", hmsRtcStats.packetsLost.toString())
713
- rtcStats.putString("packetsReceived", hmsRtcStats.packetsReceived.toString())
714
- rtcStats.putDouble("roundTripTime", hmsRtcStats.roundTripTime)
765
+ rtcStats.pushDouble(hmsRtcStats.bitrateReceived)
766
+ rtcStats.pushDouble(hmsRtcStats.bitrateSent)
767
+ rtcStats.pushString(hmsRtcStats.bytesReceived.toString())
768
+ rtcStats.pushString(hmsRtcStats.bytesSent.toString())
769
+ rtcStats.pushString(hmsRtcStats.packetsLost.toString())
770
+ rtcStats.pushString(hmsRtcStats.packetsReceived.toString())
771
+ rtcStats.pushDouble(hmsRtcStats.roundTripTime)
715
772
  }
716
773
  return rtcStats
717
774
  }
718
775
 
719
- fun getLocalAudioStats(hmsLocalAudioStats: HMSLocalAudioStats?): WritableMap {
720
- val localAudioStats: WritableMap = Arguments.createMap()
776
+ fun getLocalAudioStats(hmsLocalAudioStats: HMSLocalAudioStats?): WritableArray {
777
+ val localAudioStats: WritableArray = Arguments.createArray()
778
+
721
779
  if (hmsLocalAudioStats != null) {
722
- hmsLocalAudioStats.bitrate?.let { localAudioStats.putDouble("bitrate", it) }
723
- localAudioStats.putString("bytesSent", hmsLocalAudioStats.bytesSent.toString())
724
- hmsLocalAudioStats.roundTripTime?.let { localAudioStats.putDouble("roundTripTime", it) }
780
+ val bitrate = hmsLocalAudioStats.bitrate ?: -1.0
781
+ localAudioStats.pushDouble(bitrate)
782
+
783
+ val bytesSent = hmsLocalAudioStats.bytesSent.let { if (it === null) "" else it.toString() }
784
+ localAudioStats.pushString(bytesSent)
785
+
786
+ val roundTripTime = hmsLocalAudioStats.roundTripTime ?: -1.0
787
+ localAudioStats.pushDouble(roundTripTime)
725
788
  }
726
789
  return localAudioStats
727
790
  }
@@ -730,48 +793,119 @@ object HMSDecoder {
730
793
  val stats: WritableArray = Arguments.createArray()
731
794
 
732
795
  for (stat in hmsLocalVideoStats) {
733
- val localVideoStats: WritableMap = Arguments.createMap()
796
+ val localVideoStats: WritableArray = Arguments.createArray() // [bitrate, bytesSent, roundTripTime, frameRate, resolution, layer, qualityLimitationReasons]
734
797
 
735
- localVideoStats.putString("bytesSent", stat.bytesSent.toString())
736
- localVideoStats.putMap(
737
- "resolution",
738
- stat.resolution?.let { this.getHmsVideoTrackResolution(it) }
739
- )
740
- stat.bitrate?.let { localVideoStats.putDouble("bitrate", it) }
741
- stat.roundTripTime?.let { localVideoStats.putDouble("roundTripTime", it) }
742
- stat.frameRate?.let { localVideoStats.putDouble("frameRate", it) }
743
- stats.pushMap(localVideoStats)
798
+ val bitrate = stat.bitrate ?: -1.0
799
+ localVideoStats.pushDouble(bitrate)
800
+
801
+ val bytesSent = stat.bytesSent.let { if (it === null) "" else it.toString() }
802
+ localVideoStats.pushString(bytesSent)
803
+
804
+ val roundTripTime = stat.roundTripTime ?: -1.0
805
+ localVideoStats.pushDouble(roundTripTime)
806
+
807
+ val frameRate = stat.frameRate ?: -1.0
808
+ localVideoStats.pushDouble(frameRate)
809
+
810
+ stat.resolution.let {
811
+ if (it === null) {
812
+ localVideoStats.pushNull()
813
+ } else {
814
+ localVideoStats.pushArray(getHmsVideoTrackResolution(it)) // [width, height]
815
+ }
816
+ }
817
+
818
+ val layer = stat.hmsLayer.let { if (it === null) HMSLayer.HIGH.name else it.name }
819
+ localVideoStats.pushString(layer)
820
+
821
+ val qualityLimitationReasons = getHmsQualityLimitationReasons(stat.qualityLimitationReason)
822
+ localVideoStats.pushMap(qualityLimitationReasons)
823
+
824
+ stats.pushArray(localVideoStats)
744
825
  }
745
826
 
746
827
  return stats
747
828
  }
748
829
 
749
- fun getRemoteAudioStats(hmsRemoteAudioStats: HMSRemoteAudioStats?): WritableMap {
750
- val remoteAudioStats: WritableMap = Arguments.createMap()
830
+ private fun getHmsQualityLimitationReasons(hmsQualityLimitationReasons: QualityLimitationReasons?): WritableMap {
831
+ val qualityLimitationReasons: WritableMap = Arguments.createMap()
832
+
833
+ if (hmsQualityLimitationReasons != null) {
834
+ hmsQualityLimitationReasons.bandWidth?.let { qualityLimitationReasons.putDouble("bandwidth", it) }
835
+ hmsQualityLimitationReasons.cpu?.let { qualityLimitationReasons.putDouble("cpu", it) }
836
+ hmsQualityLimitationReasons.none?.let { qualityLimitationReasons.putDouble("none", it) }
837
+ hmsQualityLimitationReasons.other?.let { qualityLimitationReasons.putDouble("other", it) }
838
+ hmsQualityLimitationReasons.qualityLimitationResolutionChanges?.let { qualityLimitationReasons.putInt("qualityLimitationResolutionChanges", it.toInt()) }
839
+ qualityLimitationReasons.putString("reason", hmsQualityLimitationReasons.reason.name)
840
+ }
841
+ return qualityLimitationReasons
842
+ }
843
+
844
+ fun getRemoteAudioStats(hmsRemoteAudioStats: HMSRemoteAudioStats?): WritableArray {
845
+ val remoteAudioStats: WritableArray = Arguments.createArray()
846
+
751
847
  if (hmsRemoteAudioStats != null) {
752
- hmsRemoteAudioStats.bitrate?.let { remoteAudioStats.putDouble("bitrate", it) }
753
- remoteAudioStats.putString("bytesReceived", hmsRemoteAudioStats.bytesReceived.toString())
754
- hmsRemoteAudioStats.jitter?.let { remoteAudioStats.putDouble("jitter", it) }
755
- hmsRemoteAudioStats.packetsLost?.let { remoteAudioStats.putInt("packetsLost", it) }
756
- remoteAudioStats.putString("packetsReceived", hmsRemoteAudioStats.packetsReceived.toString())
848
+ val bitrate = hmsRemoteAudioStats.bitrate ?: -1.0
849
+ remoteAudioStats.pushDouble(bitrate)
850
+
851
+ val bytesReceived = hmsRemoteAudioStats.bytesReceived.let { if (it === null) "" else it.toString() }
852
+ remoteAudioStats.pushString(bytesReceived)
853
+
854
+ val jitter = hmsRemoteAudioStats.jitter ?: -1.0
855
+ remoteAudioStats.pushDouble(jitter)
856
+
857
+ val packetsLost = hmsRemoteAudioStats.packetsLost ?: -1
858
+ remoteAudioStats.pushInt(packetsLost)
859
+
860
+ val packetsReceived = hmsRemoteAudioStats.packetsReceived.let { if (it === null) "" else it.toString() }
861
+ remoteAudioStats.pushString(packetsReceived)
757
862
  }
758
863
  return remoteAudioStats
759
864
  }
760
865
 
761
- fun getRemoteVideoStats(hmsRemoteVideoStats: HMSRemoteVideoStats?): WritableMap {
762
- val remoteVideoStats: WritableMap = Arguments.createMap()
866
+ fun getRemoteVideoStats(hmsRemoteVideoStats: HMSRemoteVideoStats?): WritableArray {
867
+ val remoteVideoStats: WritableArray = Arguments.createArray() // [bitrate, bytesReceived, frameRate, jitter, packetsLost, packetsReceived, resolution]
868
+
763
869
  if (hmsRemoteVideoStats != null) {
764
- remoteVideoStats.putString("bytesReceived", hmsRemoteVideoStats.bytesReceived.toString())
765
- remoteVideoStats.putString("packetsReceived", hmsRemoteVideoStats.packetsReceived.toString())
766
- hmsRemoteVideoStats.bitrate?.let { remoteVideoStats.putDouble("bitrate", it) }
767
- remoteVideoStats.putMap(
768
- "resolution",
769
- hmsRemoteVideoStats.resolution?.let { this.getHmsVideoTrackResolution(it) }
770
- )
771
- hmsRemoteVideoStats.frameRate?.let { remoteVideoStats.putDouble("frameRate", it) }
772
- hmsRemoteVideoStats.jitter?.let { remoteVideoStats.putDouble("jitter", it) }
773
- hmsRemoteVideoStats.packetsLost?.let { remoteVideoStats.putInt("packetsLost", it) }
870
+ val bitrate = hmsRemoteVideoStats.bitrate ?: -1.0
871
+ remoteVideoStats.pushDouble(bitrate)
872
+
873
+ val bytesReceived = hmsRemoteVideoStats.bytesReceived.let { if (it === null) "" else it.toString() }
874
+ remoteVideoStats.pushString(bytesReceived)
875
+
876
+ val frameRate = hmsRemoteVideoStats.frameRate ?: -1.0
877
+ remoteVideoStats.pushDouble(frameRate)
878
+
879
+ val jitter = hmsRemoteVideoStats.jitter ?: -1.0
880
+ remoteVideoStats.pushDouble(jitter)
881
+
882
+ val packetsLost = hmsRemoteVideoStats.packetsLost ?: -1
883
+ remoteVideoStats.pushInt(packetsLost)
884
+
885
+ val packetsReceived = hmsRemoteVideoStats.packetsReceived.let { if (it === null) "" else it.toString() }
886
+ remoteVideoStats.pushString(packetsReceived)
887
+
888
+ hmsRemoteVideoStats.resolution.let {
889
+ if (it === null) {
890
+ remoteVideoStats.pushNull()
891
+ } else {
892
+ remoteVideoStats.pushArray(getHmsVideoTrackResolution(it)) // [width, height]
893
+ }
894
+ }
774
895
  }
775
896
  return remoteVideoStats
776
897
  }
898
+
899
+ private fun getSimulcastLayerDefinition(hmsSimulcastLayerDefinition: HMSSimulcastLayerDefinition): WritableMap {
900
+ val simulcastLayerDefinition: WritableMap = Arguments.createMap()
901
+ simulcastLayerDefinition.putString("layer", hmsSimulcastLayerDefinition.layer.name)
902
+ simulcastLayerDefinition.putArray("resolution", getHmsVideoTrackResolution(hmsSimulcastLayerDefinition.resolution)) // [width, height]
903
+ return simulcastLayerDefinition
904
+ }
905
+
906
+ fun getSimulcastLayerDefinitions(hmsSimulcastLayerDefinitions: List<HMSSimulcastLayerDefinition>): WritableArray {
907
+ val simulcastLayerDefinitions: WritableArray = Arguments.createArray()
908
+ hmsSimulcastLayerDefinitions.forEach { simulcastLayerDefinitions.pushMap(getSimulcastLayerDefinition(it)) }
909
+ return simulcastLayerDefinitions
910
+ }
777
911
  }
@@ -545,6 +545,7 @@ object HMSHelper {
545
545
  return config
546
546
  }
547
547
 
548
+ // TODO: replace surfaceView with hmsVideoView
548
549
  @RequiresApi(Build.VERSION_CODES.N)
549
550
  fun captureSurfaceView(
550
551
  surfaceView: SurfaceViewRenderer,
@@ -370,20 +370,6 @@ class HMSManager(reactContext: ReactApplicationContext) :
370
370
  callback?.resolve(result)
371
371
  }
372
372
 
373
- @ReactMethod
374
- fun enableRTCStats(data: ReadableMap) {
375
- val hms = HMSHelper.getHms(data, hmsCollection)
376
-
377
- hms?.enableRTCStats()
378
- }
379
-
380
- @ReactMethod
381
- fun disableRTCStats(data: ReadableMap) {
382
- val hms = HMSHelper.getHms(data, hmsCollection)
383
-
384
- hms?.disableRTCStats()
385
- }
386
-
387
373
  @ReactMethod
388
374
  fun enableNetworkQualityUpdates(data: ReadableMap) {
389
375
  val hms = HMSHelper.getHms(data, hmsCollection)
@@ -482,6 +468,13 @@ class HMSManager(reactContext: ReactApplicationContext) :
482
468
  hms?.restrictData(data, promise)
483
469
  }
484
470
 
471
+ @ReactMethod()
472
+ fun getAuthTokenByRoomCode(data: ReadableMap, promise: Promise) {
473
+ val hms = HMSHelper.getHms(data, hmsCollection)
474
+
475
+ hms?.getAuthTokenByRoomCode(data, promise)
476
+ }
477
+
485
478
  // region Person-In-Person Mode Action handing
486
479
  private val pipReceiver by lazy {
487
480
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -877,6 +870,48 @@ class HMSManager(reactContext: ReactApplicationContext) :
877
870
  }
878
871
  }
879
872
 
873
+ @ReactMethod
874
+ fun getRemoteVideoTrackFromTrackId(data: ReadableMap, promise: Promise) {
875
+ val hms = HMSHelper.getHms(data, hmsCollection)
876
+
877
+ hms?.getRemoteVideoTrackFromTrackId(data, promise)
878
+ }
879
+
880
+ @ReactMethod
881
+ fun getRemoteAudioTrackFromTrackId(data: ReadableMap, promise: Promise) {
882
+ val hms = HMSHelper.getHms(data, hmsCollection)
883
+
884
+ hms?.getRemoteAudioTrackFromTrackId(data, promise)
885
+ }
886
+
887
+ @ReactMethod
888
+ fun getVideoTrackLayer(data: ReadableMap, promise: Promise) {
889
+ val hms = HMSHelper.getHms(data, hmsCollection)
890
+
891
+ hms?.getVideoTrackLayer(data, promise)
892
+ }
893
+
894
+ @ReactMethod
895
+ fun getVideoTrackLayerDefinition(data: ReadableMap, promise: Promise) {
896
+ val hms = HMSHelper.getHms(data, hmsCollection)
897
+
898
+ hms?.getVideoTrackLayerDefinition(data, promise)
899
+ }
900
+
901
+ @ReactMethod
902
+ fun setVideoTrackLayer(data: ReadableMap, promise: Promise?) {
903
+ val hms = HMSHelper.getHms(data, hmsCollection)
904
+
905
+ hms?.setVideoTrackLayer(data, promise)
906
+ }
907
+
908
+ @ReactMethod
909
+ fun captureImageAtMaxSupportedResolution(data: ReadableMap, promise: Promise?) {
910
+ val hms = HMSHelper.getHms(data, hmsCollection)
911
+
912
+ hms?.captureImageAtMaxSupportedResolution(data, promise)
913
+ }
914
+
880
915
  fun emitEvent(event: String, data: WritableMap) {
881
916
  reactApplicationContext
882
917
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)