@100mslive/react-native-hms 1.4.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 (144) hide show
  1. package/android/build.gradle +3 -2
  2. package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +189 -55
  3. package/android/src/main/java/com/reactnativehmssdk/HMSHelper.kt +1 -0
  4. package/android/src/main/java/com/reactnativehmssdk/HMSManager.kt +42 -14
  5. package/android/src/main/java/com/reactnativehmssdk/HMSRNSDK.kt +202 -46
  6. package/android/src/main/java/com/reactnativehmssdk/HMSSDKViewManager.kt +5 -0
  7. package/android/src/main/java/com/reactnativehmssdk/HMSView.kt +29 -21
  8. package/android/src/main/res/layout/hms_view.xml +2 -2
  9. package/ios/HMSConstants.swift +31 -0
  10. package/ios/HMSDecoder.swift +371 -156
  11. package/ios/HMSManager.m +9 -2
  12. package/ios/HMSManager.swift +142 -74
  13. package/ios/HMSRNSDK.swift +393 -181
  14. package/ios/HMSView.m +1 -0
  15. package/ios/HMSView.swift +21 -19
  16. package/lib/commonjs/classes/HMSCameraControl.js +28 -0
  17. package/lib/commonjs/classes/HMSCameraControl.js.map +1 -0
  18. package/lib/commonjs/classes/HMSEncoder.js +95 -13
  19. package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
  20. package/lib/commonjs/classes/HMSLayer.js +14 -0
  21. package/lib/commonjs/classes/HMSLayer.js.map +1 -0
  22. package/lib/commonjs/classes/HMSLocalVideoStats.js +11 -0
  23. package/lib/commonjs/classes/HMSLocalVideoStats.js.map +1 -1
  24. package/lib/commonjs/classes/HMSPeer.js +1 -1
  25. package/lib/commonjs/classes/HMSPeer.js.map +1 -1
  26. package/lib/commonjs/classes/HMSPublishSettings.js +2 -0
  27. package/lib/commonjs/classes/HMSPublishSettings.js.map +1 -1
  28. package/lib/commonjs/classes/HMSQualityLimitationReason.js +16 -0
  29. package/lib/commonjs/classes/HMSQualityLimitationReason.js.map +1 -0
  30. package/lib/commonjs/classes/HMSQualityLimitationReasons.js +27 -0
  31. package/lib/commonjs/classes/HMSQualityLimitationReasons.js.map +1 -0
  32. package/lib/commonjs/classes/HMSRemotePeer.js.map +1 -1
  33. package/lib/commonjs/classes/HMSRemoteVideoTrack.js +39 -3
  34. package/lib/commonjs/classes/HMSRemoteVideoTrack.js.map +1 -1
  35. package/lib/commonjs/classes/HMSRoom.js +4 -0
  36. package/lib/commonjs/classes/HMSRoom.js.map +1 -1
  37. package/lib/commonjs/classes/HMSRoomUpdate.js +1 -0
  38. package/lib/commonjs/classes/HMSRoomUpdate.js.map +1 -1
  39. package/lib/commonjs/classes/HMSSDK.js +32 -45
  40. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  41. package/lib/commonjs/classes/HMSSimulcastLayerDefinition.js +19 -0
  42. package/lib/commonjs/classes/HMSSimulcastLayerDefinition.js.map +1 -0
  43. package/lib/commonjs/classes/HMSSimulcastLayerSettingsPolicy.js +23 -0
  44. package/lib/commonjs/classes/HMSSimulcastLayerSettingsPolicy.js.map +1 -0
  45. package/lib/commonjs/classes/HMSSimulcastSettings.js +5 -4
  46. package/lib/commonjs/classes/HMSSimulcastSettings.js.map +1 -1
  47. package/lib/commonjs/classes/HMSSimulcastSettingsPolicy.js +17 -0
  48. package/lib/commonjs/classes/HMSSimulcastSettingsPolicy.js.map +1 -0
  49. package/lib/commonjs/classes/HMSSubscribeDegradationPolicy.js +21 -0
  50. package/lib/commonjs/classes/HMSSubscribeDegradationPolicy.js.map +1 -0
  51. package/lib/commonjs/classes/HMSSubscribeSettings.js +2 -0
  52. package/lib/commonjs/classes/HMSSubscribeSettings.js.map +1 -1
  53. package/lib/commonjs/classes/HMSVideoResolution.js.map +1 -1
  54. package/lib/commonjs/classes/HmsView.js +2 -0
  55. package/lib/commonjs/classes/HmsView.js.map +1 -1
  56. package/lib/commonjs/index.js +60 -0
  57. package/lib/commonjs/index.js.map +1 -1
  58. package/lib/module/classes/HMSCameraControl.js +21 -0
  59. package/lib/module/classes/HMSCameraControl.js.map +1 -0
  60. package/lib/module/classes/HMSEncoder.js +95 -13
  61. package/lib/module/classes/HMSEncoder.js.map +1 -1
  62. package/lib/module/classes/HMSLayer.js +7 -0
  63. package/lib/module/classes/HMSLayer.js.map +1 -0
  64. package/lib/module/classes/HMSLocalVideoStats.js +11 -0
  65. package/lib/module/classes/HMSLocalVideoStats.js.map +1 -1
  66. package/lib/module/classes/HMSPeer.js +1 -1
  67. package/lib/module/classes/HMSPeer.js.map +1 -1
  68. package/lib/module/classes/HMSPublishSettings.js +2 -0
  69. package/lib/module/classes/HMSPublishSettings.js.map +1 -1
  70. package/lib/module/classes/HMSQualityLimitationReason.js +9 -0
  71. package/lib/module/classes/HMSQualityLimitationReason.js.map +1 -0
  72. package/lib/module/classes/HMSQualityLimitationReasons.js +20 -0
  73. package/lib/module/classes/HMSQualityLimitationReasons.js.map +1 -0
  74. package/lib/module/classes/HMSRemotePeer.js.map +1 -1
  75. package/lib/module/classes/HMSRemoteVideoTrack.js +39 -3
  76. package/lib/module/classes/HMSRemoteVideoTrack.js.map +1 -1
  77. package/lib/module/classes/HMSRoom.js +4 -0
  78. package/lib/module/classes/HMSRoom.js.map +1 -1
  79. package/lib/module/classes/HMSRoomUpdate.js +1 -0
  80. package/lib/module/classes/HMSRoomUpdate.js.map +1 -1
  81. package/lib/module/classes/HMSSDK.js +33 -45
  82. package/lib/module/classes/HMSSDK.js.map +1 -1
  83. package/lib/module/classes/HMSSimulcastLayerDefinition.js +12 -0
  84. package/lib/module/classes/HMSSimulcastLayerDefinition.js.map +1 -0
  85. package/lib/module/classes/HMSSimulcastLayerSettingsPolicy.js +16 -0
  86. package/lib/module/classes/HMSSimulcastLayerSettingsPolicy.js.map +1 -0
  87. package/lib/module/classes/HMSSimulcastSettings.js +5 -4
  88. package/lib/module/classes/HMSSimulcastSettings.js.map +1 -1
  89. package/lib/module/classes/HMSSimulcastSettingsPolicy.js +10 -0
  90. package/lib/module/classes/HMSSimulcastSettingsPolicy.js.map +1 -0
  91. package/lib/module/classes/HMSSubscribeDegradationPolicy.js +14 -0
  92. package/lib/module/classes/HMSSubscribeDegradationPolicy.js.map +1 -0
  93. package/lib/module/classes/HMSSubscribeSettings.js +2 -0
  94. package/lib/module/classes/HMSSubscribeSettings.js.map +1 -1
  95. package/lib/module/classes/HMSVideoResolution.js.map +1 -1
  96. package/lib/module/classes/HmsView.js +2 -0
  97. package/lib/module/classes/HmsView.js.map +1 -1
  98. package/lib/module/index.js +5 -0
  99. package/lib/module/index.js.map +1 -1
  100. package/lib/typescript/classes/HMSCameraControl.d.ts +9 -0
  101. package/lib/typescript/classes/HMSEncoder.d.ts +13 -1
  102. package/lib/typescript/classes/HMSLayer.d.ts +5 -0
  103. package/lib/typescript/classes/HMSLocalVideoStats.d.ts +6 -0
  104. package/lib/typescript/classes/HMSPeer.d.ts +1 -1
  105. package/lib/typescript/classes/HMSPublishSettings.d.ts +3 -0
  106. package/lib/typescript/classes/HMSQualityLimitationReason.d.ts +7 -0
  107. package/lib/typescript/classes/HMSQualityLimitationReasons.d.ts +17 -0
  108. package/lib/typescript/classes/HMSRemotePeer.d.ts +0 -1
  109. package/lib/typescript/classes/HMSRemoteVideoTrack.d.ts +6 -2
  110. package/lib/typescript/classes/HMSRoomUpdate.d.ts +2 -1
  111. package/lib/typescript/classes/HMSSDK.d.ts +5 -31
  112. package/lib/typescript/classes/HMSSimulcastLayerDefinition.d.ts +10 -0
  113. package/lib/typescript/classes/HMSSimulcastLayerSettingsPolicy.d.ts +12 -0
  114. package/lib/typescript/classes/HMSSimulcastSettings.d.ts +7 -3
  115. package/lib/typescript/classes/HMSSimulcastSettingsPolicy.d.ts +7 -0
  116. package/lib/typescript/classes/HMSSubscribeDegradationPolicy.d.ts +10 -0
  117. package/lib/typescript/classes/HMSSubscribeSettings.d.ts +5 -2
  118. package/lib/typescript/classes/HMSVideoResolution.d.ts +2 -2
  119. package/lib/typescript/classes/HmsView.d.ts +2 -2
  120. package/lib/typescript/index.d.ts +5 -0
  121. package/package.json +1 -1
  122. package/sdk-versions.json +3 -3
  123. package/src/classes/HMSCameraControl.ts +21 -0
  124. package/src/classes/HMSEncoder.ts +125 -11
  125. package/src/classes/HMSLayer.ts +5 -0
  126. package/src/classes/HMSLocalVideoStats.ts +21 -0
  127. package/src/classes/HMSPeer.ts +1 -1
  128. package/src/classes/HMSPublishSettings.ts +4 -0
  129. package/src/classes/HMSQualityLimitationReason.ts +7 -0
  130. package/src/classes/HMSQualityLimitationReasons.ts +27 -0
  131. package/src/classes/HMSRemotePeer.ts +0 -1
  132. package/src/classes/HMSRemoteVideoTrack.ts +52 -4
  133. package/src/classes/HMSRoom.ts +2 -0
  134. package/src/classes/HMSRoomUpdate.ts +1 -0
  135. package/src/classes/HMSSDK.tsx +54 -48
  136. package/src/classes/HMSSimulcastLayerDefinition.ts +12 -0
  137. package/src/classes/HMSSimulcastLayerSettingsPolicy.ts +18 -0
  138. package/src/classes/HMSSimulcastSettings.ts +12 -3
  139. package/src/classes/HMSSimulcastSettingsPolicy.ts +9 -0
  140. package/src/classes/HMSSubscribeDegradationPolicy.ts +15 -0
  141. package/src/classes/HMSSubscribeSettings.ts +10 -2
  142. package/src/classes/HMSVideoResolution.ts +1 -1
  143. package/src/classes/HmsView.tsx +5 -1
  144. package/src/index.ts +5 -0
@@ -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)
@@ -884,6 +870,48 @@ class HMSManager(reactContext: ReactApplicationContext) :
884
870
  }
885
871
  }
886
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
+
887
915
  fun emitEvent(event: String, data: WritableMap) {
888
916
  reactApplicationContext
889
917
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)