@100mslive/react-native-hms 0.8.0 → 0.8.1
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.
- package/README.md +37 -39
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativehmssdk/HmsDecoder.kt +91 -17
- package/android/src/main/java/com/reactnativehmssdk/HmsHelper.kt +106 -0
- package/android/src/main/java/com/reactnativehmssdk/HmsModule.kt +38 -3
- package/android/src/main/java/com/reactnativehmssdk/HmsSDK.kt +342 -183
- package/android/src/main/java/com/reactnativehmssdk/HmsView.kt +4 -1
- package/ios/HmsDecoder.swift +105 -18
- package/ios/HmsHelper.swift +92 -0
- package/ios/HmsManager.m +5 -1
- package/ios/HmsManager.swift +41 -6
- package/ios/HmsSDK.swift +199 -60
- package/ios/HmsView.swift +1 -1
- package/lib/commonjs/classes/HMSAudioTrackSettings.js +3 -0
- package/lib/commonjs/classes/HMSAudioTrackSettings.js.map +1 -1
- package/lib/commonjs/classes/HMSBrowserRecordingState.js +23 -0
- package/lib/commonjs/classes/HMSBrowserRecordingState.js.map +1 -0
- package/lib/commonjs/classes/HMSCameraFacing.js +14 -0
- package/lib/commonjs/classes/HMSCameraFacing.js.map +1 -0
- package/lib/commonjs/classes/HMSConfig.js +3 -1
- package/lib/commonjs/classes/HMSConfig.js.map +1 -1
- package/lib/commonjs/classes/HMSEncoder.js +20 -3
- package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
- package/lib/commonjs/classes/HMSException.js +30 -0
- package/lib/commonjs/classes/HMSException.js.map +1 -0
- package/lib/commonjs/classes/HMSHelper.js +2 -2
- package/lib/commonjs/classes/HMSHelper.js.map +1 -1
- package/lib/commonjs/classes/HMSLocalAudioTrack.js +12 -0
- package/lib/commonjs/classes/HMSLocalAudioTrack.js.map +1 -1
- package/lib/commonjs/classes/HMSLocalPeer.js.map +1 -1
- package/lib/commonjs/classes/HMSPeer.js +3 -0
- package/lib/commonjs/classes/HMSPeer.js.map +1 -1
- package/lib/commonjs/classes/HMSPeerUpdate.js +1 -0
- package/lib/commonjs/classes/HMSPeerUpdate.js.map +1 -1
- package/lib/commonjs/classes/HMSPermissions.js +6 -0
- package/lib/commonjs/classes/HMSPermissions.js.map +1 -1
- package/lib/commonjs/classes/HMSRTMPConfig.js +26 -0
- package/lib/commonjs/classes/HMSRTMPConfig.js.map +1 -0
- package/lib/commonjs/classes/HMSRemotePeer.js.map +1 -1
- package/lib/commonjs/classes/HMSRoom.js +9 -0
- package/lib/commonjs/classes/HMSRoom.js.map +1 -1
- package/lib/commonjs/classes/HMSRtmpStreamingState.js +23 -0
- package/lib/commonjs/classes/HMSRtmpStreamingState.js.map +1 -0
- package/lib/commonjs/classes/HMSSDK.js +129 -70
- package/lib/commonjs/classes/HMSSDK.js.map +1 -1
- package/lib/commonjs/classes/HMSServerRecordingState.js +23 -0
- package/lib/commonjs/classes/HMSServerRecordingState.js.map +1 -0
- package/lib/commonjs/classes/HMSTrack.js +2 -19
- package/lib/commonjs/classes/HMSTrack.js.map +1 -1
- package/lib/commonjs/classes/HMSVideoResolution.js +23 -0
- package/lib/commonjs/classes/HMSVideoResolution.js.map +1 -0
- package/lib/commonjs/classes/HMSVideoSettings.js.map +1 -1
- package/lib/commonjs/classes/HMSVideoTrackSettings.js +0 -3
- package/lib/commonjs/classes/HMSVideoTrackSettings.js.map +1 -1
- package/lib/commonjs/index.js +84 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/classes/HMSAudioTrackSettings.js +3 -0
- package/lib/module/classes/HMSAudioTrackSettings.js.map +1 -1
- package/lib/module/classes/HMSBrowserRecordingState.js +14 -0
- package/lib/module/classes/HMSBrowserRecordingState.js.map +1 -0
- package/lib/module/classes/HMSCameraFacing.js +7 -0
- package/lib/module/classes/HMSCameraFacing.js.map +1 -0
- package/lib/module/classes/HMSConfig.js +3 -1
- package/lib/module/classes/HMSConfig.js.map +1 -1
- package/lib/module/classes/HMSEncoder.js +19 -3
- package/lib/module/classes/HMSEncoder.js.map +1 -1
- package/lib/module/classes/HMSException.js +21 -0
- package/lib/module/classes/HMSException.js.map +1 -0
- package/lib/module/classes/HMSHelper.js +2 -2
- package/lib/module/classes/HMSHelper.js.map +1 -1
- package/lib/module/classes/HMSLocalAudioTrack.js +13 -1
- package/lib/module/classes/HMSLocalAudioTrack.js.map +1 -1
- package/lib/module/classes/HMSLocalPeer.js.map +1 -1
- package/lib/module/classes/HMSPeer.js +3 -0
- package/lib/module/classes/HMSPeer.js.map +1 -1
- package/lib/module/classes/HMSPeerUpdate.js +1 -0
- package/lib/module/classes/HMSPeerUpdate.js.map +1 -1
- package/lib/module/classes/HMSPermissions.js +6 -0
- package/lib/module/classes/HMSPermissions.js.map +1 -1
- package/lib/module/classes/HMSRTMPConfig.js +17 -0
- package/lib/module/classes/HMSRTMPConfig.js.map +1 -0
- package/lib/module/classes/HMSRemotePeer.js.map +1 -1
- package/lib/module/classes/HMSRoom.js +9 -0
- package/lib/module/classes/HMSRoom.js.map +1 -1
- package/lib/module/classes/HMSRtmpStreamingState.js +14 -0
- package/lib/module/classes/HMSRtmpStreamingState.js.map +1 -0
- package/lib/module/classes/HMSSDK.js +130 -70
- package/lib/module/classes/HMSSDK.js.map +1 -1
- package/lib/module/classes/HMSServerRecordingState.js +14 -0
- package/lib/module/classes/HMSServerRecordingState.js.map +1 -0
- package/lib/module/classes/HMSTrack.js +2 -17
- package/lib/module/classes/HMSTrack.js.map +1 -1
- package/lib/module/classes/HMSVideoResolution.js +14 -0
- package/lib/module/classes/HMSVideoResolution.js.map +1 -0
- package/lib/module/classes/HMSVideoSettings.js.map +1 -1
- package/lib/module/classes/HMSVideoTrackSettings.js +0 -3
- package/lib/module/classes/HMSVideoTrackSettings.js.map +1 -1
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/classes/HMSAudioTrackSettings.d.ts +3 -0
- package/lib/typescript/classes/HMSBrowserRecordingState.d.ts +9 -0
- package/lib/typescript/classes/HMSCameraFacing.d.ts +4 -0
- package/lib/typescript/classes/HMSConfig.d.ts +2 -0
- package/lib/typescript/classes/HMSEncoder.d.ts +3 -1
- package/lib/typescript/classes/HMSException.d.ts +22 -0
- package/lib/typescript/classes/HMSLocalAudioTrack.d.ts +1 -0
- package/lib/typescript/classes/HMSLocalPeer.d.ts +1 -0
- package/lib/typescript/classes/HMSPeer.d.ts +2 -0
- package/lib/typescript/classes/HMSPeerUpdate.d.ts +1 -0
- package/lib/typescript/classes/HMSPermissions.d.ts +4 -0
- package/lib/typescript/classes/HMSRTMPConfig.d.ts +10 -0
- package/lib/typescript/classes/HMSRemotePeer.d.ts +1 -0
- package/lib/typescript/classes/HMSRoom.d.ts +9 -0
- package/lib/typescript/classes/HMSRtmpStreamingState.d.ts +9 -0
- package/lib/typescript/classes/HMSSDK.d.ts +10 -1
- package/lib/typescript/classes/HMSServerRecordingState.d.ts +9 -0
- package/lib/typescript/classes/HMSTrack.d.ts +1 -1
- package/lib/typescript/classes/HMSVideoResolution.d.ts +8 -0
- package/lib/typescript/classes/HMSVideoSettings.d.ts +3 -3
- package/lib/typescript/classes/HMSVideoTrackSettings.d.ts +13 -10
- package/lib/typescript/index.d.ts +6 -0
- package/package.json +1 -1
- package/src/classes/HMSAudioTrackSettings.ts +9 -1
- package/src/classes/HMSBrowserRecordingState.ts +11 -0
- package/src/classes/HMSCameraFacing.ts +4 -0
- package/src/classes/HMSConfig.ts +3 -1
- package/src/classes/HMSEncoder.ts +19 -2
- package/src/classes/HMSException.ts +33 -0
- package/src/classes/HMSHelper.ts +2 -2
- package/src/classes/HMSLocalAudioTrack.ts +13 -1
- package/src/classes/HMSLocalPeer.ts +1 -0
- package/src/classes/HMSPeer.ts +3 -0
- package/src/classes/HMSPeerUpdate.ts +1 -0
- package/src/classes/HMSPermissions.ts +6 -0
- package/src/classes/HMSRTMPConfig.ts +15 -0
- package/src/classes/HMSRemotePeer.ts +1 -0
- package/src/classes/HMSRoom.ts +12 -0
- package/src/classes/HMSRtmpStreamingState.ts +11 -0
- package/src/classes/HMSSDK.tsx +40 -2
- package/src/classes/HMSServerRecordingState.ts +11 -0
- package/src/classes/HMSTrack.ts +2 -15
- package/src/classes/HMSVideoResolution.ts +9 -0
- package/src/classes/HMSVideoSettings.ts +3 -3
- package/src/classes/HMSVideoTrackSettings.ts +13 -10
- package/src/index.ts +6 -0
package/README.md
CHANGED
|
@@ -61,18 +61,18 @@ We suggest using [react-native-permission](https://www.npmjs.com/package/react-n
|
|
|
61
61
|
|
|
62
62
|
## QuickStart
|
|
63
63
|
|
|
64
|
-
The package exports
|
|
64
|
+
The package exports all the classes and a HMSSDK class that manages everything.
|
|
65
65
|
|
|
66
66
|
# Setting up the HMS Instance:
|
|
67
67
|
|
|
68
|
-
first we'll have to call build method, that method returns an instance of
|
|
68
|
+
first we'll have to call build method, that method returns an instance of HMSSDK class and the same is used to perform all the operations
|
|
69
69
|
|
|
70
70
|
```js
|
|
71
|
-
import
|
|
71
|
+
import { HMSSDK } from '@100mslive/react-native-hms';
|
|
72
72
|
...
|
|
73
73
|
|
|
74
|
-
const hmsInstance = await
|
|
75
|
-
//save this instance, will be used for all the operations that we'll perform
|
|
74
|
+
const hmsInstance = await HMSSDK.build();
|
|
75
|
+
// save this instance, it will be used for all the operations that we'll perform
|
|
76
76
|
|
|
77
77
|
...
|
|
78
78
|
```
|
|
@@ -82,9 +82,7 @@ const hmsInstance = await HmsManager.build();
|
|
|
82
82
|
add event listeners for all the events such as onPreview, onJoin, onPeerUpdate etc. the actions can be found in HMSUpdateListenerActions class
|
|
83
83
|
|
|
84
84
|
```js
|
|
85
|
-
import
|
|
86
|
-
HMSUpdateListenerActions,
|
|
87
|
-
} from 'react-native-hms';
|
|
85
|
+
import { HMSUpdateListenerActions } from '@100mslive/react-native-hms';
|
|
88
86
|
...
|
|
89
87
|
|
|
90
88
|
// instance acquired from build() method
|
|
@@ -103,17 +101,15 @@ The event handlers are the way of handling any update happening in hms all event
|
|
|
103
101
|
Joining the room connects you to the remote peer and broadcasts your stream to other peers, we need instance of HMSConfig in order to pass the details of room and user to join function
|
|
104
102
|
|
|
105
103
|
```js
|
|
106
|
-
import
|
|
107
|
-
HMSUpdateListenerActions,
|
|
108
|
-
HMSConfig,
|
|
109
|
-
} from 'react-native-hms';
|
|
104
|
+
import { HMSUpdateListenerActions, HMSConfig } from '@100mslive/react-native-hms';
|
|
110
105
|
...
|
|
111
106
|
|
|
112
|
-
// instance acquired from build() method
|
|
113
107
|
const HmsConfig = new HMSConfig({authToken, userID, roomID});
|
|
114
|
-
|
|
108
|
+
|
|
109
|
+
// instance acquired from build() method
|
|
110
|
+
hmsInstance.preview(HmsConfig); // to start preview
|
|
115
111
|
// or
|
|
116
|
-
|
|
112
|
+
hmsInstance.join(HmsConfig); // to join a room
|
|
117
113
|
|
|
118
114
|
...
|
|
119
115
|
```
|
|
@@ -126,16 +122,17 @@ To display a video on screen the package provide a UI component named HmsView th
|
|
|
126
122
|
|
|
127
123
|
```js
|
|
128
124
|
...
|
|
125
|
+
import { HMSRemotePeer } from '@100mslive/react-native-hms';
|
|
129
126
|
|
|
130
|
-
//getting local track ID
|
|
131
|
-
const localTrackId =
|
|
127
|
+
// getting local track ID
|
|
128
|
+
const localTrackId: string = hmsInstance?.localPeer?.videoTrack?.trackId;
|
|
132
129
|
|
|
133
130
|
// getting remote track IDs
|
|
134
|
-
const remotePeers =
|
|
131
|
+
const remotePeers: HMSRemotePeer[] = hmsInstance?.remotePeers
|
|
135
132
|
const remoteVideoIds: string[] = [];
|
|
136
133
|
|
|
137
|
-
remotePeers.map((remotePeer:
|
|
138
|
-
const remoteTrackId = remotePeer?.videoTrack?.trackId;
|
|
134
|
+
remotePeers.map((remotePeer: HMSRemotePeer) => {
|
|
135
|
+
const remoteTrackId: string = remotePeer?.videoTrack?.trackId;
|
|
139
136
|
|
|
140
137
|
if (remoteTrackId) {
|
|
141
138
|
remoteVideoIds.push(remoteTrackId);
|
|
@@ -148,8 +145,10 @@ remotePeers.map((remotePeer: any) => {
|
|
|
148
145
|
# Display a video in HmsView
|
|
149
146
|
|
|
150
147
|
```js
|
|
151
|
-
import {
|
|
148
|
+
import { HMSVideoViewMode } from '@100mslive/react-native-hms';
|
|
152
149
|
|
|
150
|
+
// instance acquired from build() method
|
|
151
|
+
const HmsView = hmsInstance?.HmsView;
|
|
153
152
|
...
|
|
154
153
|
const styles = StyleSheet.create({
|
|
155
154
|
hmsView: {
|
|
@@ -162,7 +161,7 @@ const styles = StyleSheet.create({
|
|
|
162
161
|
// sink is passed false video would be removed. It is a ios only prop, for android it is handled by the package itself.
|
|
163
162
|
// scaleType can be selected from HMSVideoViewMode as required
|
|
164
163
|
// mirror can be passed as true to flip videos horizontally
|
|
165
|
-
<HmsView sink={true} style={styles.hmsView} trackId={trackId} mirror={true} scaleType={HMSVideoViewMode.
|
|
164
|
+
<HmsView sink={true} style={styles.hmsView} trackId={trackId} mirror={true} scaleType={HMSVideoViewMode.ASPECT_FIT} />
|
|
166
165
|
|
|
167
166
|
...
|
|
168
167
|
```
|
|
@@ -171,40 +170,39 @@ const styles = StyleSheet.create({
|
|
|
171
170
|
|
|
172
171
|
```js
|
|
173
172
|
// Mute Audio
|
|
174
|
-
|
|
173
|
+
hmsInstance?.localPeer?.localAudioTrack()?.setMute(true);
|
|
175
174
|
|
|
176
175
|
// Stop Video
|
|
177
|
-
|
|
176
|
+
hmsInstance?.localPeer?.localVideoTrack()?.setMute(true);
|
|
178
177
|
|
|
179
178
|
// Switch Camera
|
|
180
|
-
|
|
179
|
+
hmsInstance?.localPeer?.localVideoTrack()?.switchCamera();
|
|
181
180
|
|
|
182
|
-
// Leave the call
|
|
183
|
-
|
|
181
|
+
// Leave the call (async function)
|
|
182
|
+
await hmsInstance?.leave();
|
|
184
183
|
```
|
|
185
184
|
|
|
186
185
|
# Sending messages
|
|
187
186
|
|
|
188
187
|
```js
|
|
189
|
-
import {
|
|
188
|
+
import { HMSRole } from '@100mslive/react-native-hms';
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
message: value,
|
|
196
|
-
});
|
|
190
|
+
const message = 'hello'
|
|
191
|
+
const roles: HMSRole[] = hmsInstance?.knownRoles
|
|
192
|
+
// can any remote peer's peerID
|
|
193
|
+
const peerId: string = hmsInstance?.localPeer?.peerID
|
|
197
194
|
|
|
198
|
-
// send a
|
|
199
|
-
|
|
195
|
+
// send a different type of messages
|
|
196
|
+
hmsInstance?.sendBroadcastMessage(message);
|
|
197
|
+
hmsInstance?.sendGroupMessage(message, [role[0]);
|
|
198
|
+
hmsInstance?.sendDirectMessage(message, peerId);
|
|
200
199
|
```
|
|
201
200
|
|
|
202
201
|
# Error handling
|
|
203
202
|
|
|
204
203
|
```js
|
|
205
|
-
// import actions
|
|
206
204
|
import { HMSUpdateListenerActions } from '@100mslive/react-native-hms';
|
|
207
205
|
|
|
208
|
-
// add
|
|
209
|
-
|
|
206
|
+
// add an error event listener
|
|
207
|
+
hmsInstance.addEventListener(HMSUpdateListenerActions.ON_ERROR, onError);
|
|
210
208
|
```
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/build.gradle
CHANGED
|
@@ -64,6 +64,6 @@ dependencies {
|
|
|
64
64
|
//noinspection GradleDynamicVersion
|
|
65
65
|
implementation "com.facebook.react:react-native:+"
|
|
66
66
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // From node_modules
|
|
67
|
-
implementation 'com.github.100mslive:android-sdk:2.
|
|
67
|
+
implementation 'com.github.100mslive:android-sdk:2.2.3'
|
|
68
68
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
|
|
69
69
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
package com.reactnativehmssdk
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.*
|
|
4
|
-
import live.hms.video.error.HMSException
|
|
5
4
|
import java.util.*
|
|
5
|
+
import live.hms.video.error.HMSException
|
|
6
|
+
import live.hms.video.media.codec.HMSVideoCodec
|
|
6
7
|
import live.hms.video.media.settings.HMSAudioTrackSettings
|
|
7
8
|
import live.hms.video.media.settings.HMSVideoTrackSettings
|
|
8
9
|
import live.hms.video.media.tracks.*
|
|
@@ -18,6 +19,19 @@ object HmsDecoder {
|
|
|
18
19
|
room.putString("id", hmsRoom.roomId)
|
|
19
20
|
room.putString("name", hmsRoom.name)
|
|
20
21
|
room.putString("metaData", null)
|
|
22
|
+
room.putString("startedAt", hmsRoom.startedAt.toString())
|
|
23
|
+
room.putMap(
|
|
24
|
+
"browserRecordingState",
|
|
25
|
+
this.getHMSBrowserRecordingState(hmsRoom.browserRecordingState)
|
|
26
|
+
)
|
|
27
|
+
room.putMap(
|
|
28
|
+
"rtmpHMSRtmpStreamingState",
|
|
29
|
+
this.getHMSRtmpStreamingState(hmsRoom.rtmpHMSRtmpStreamingState)
|
|
30
|
+
)
|
|
31
|
+
room.putMap(
|
|
32
|
+
"serverRecordingState",
|
|
33
|
+
this.getHMSServerRecordingState(hmsRoom.serverRecordingState)
|
|
34
|
+
)
|
|
21
35
|
var peers: WritableArray = Arguments.createArray()
|
|
22
36
|
for (peer in hmsRoom.peerList) {
|
|
23
37
|
peers.pushMap(getHmsPeer(peer))
|
|
@@ -37,10 +51,7 @@ object HmsDecoder {
|
|
|
37
51
|
"customerUserID",
|
|
38
52
|
if (hmsPeer.customerUserID == null) hmsPeer.customerUserID else ""
|
|
39
53
|
)
|
|
40
|
-
peer.putString(
|
|
41
|
-
"customerDescription",
|
|
42
|
-
if (hmsPeer.customerDescription == null) hmsPeer.customerDescription else ""
|
|
43
|
-
)
|
|
54
|
+
peer.putString("metadata", if (hmsPeer.metadata == null) hmsPeer.metadata else "")
|
|
44
55
|
peer.putMap("audioTrack", getHmsAudioTrack(hmsPeer.audioTrack))
|
|
45
56
|
peer.putMap("videoTrack", getHmsVideoTrack(hmsPeer.videoTrack))
|
|
46
57
|
peer.putMap("role", getHmsRole(hmsPeer.hmsRole))
|
|
@@ -172,11 +183,25 @@ object HmsDecoder {
|
|
|
172
183
|
// getHmsSimulcastLayers(hmsPublishSettings.screenSimulcastLayers));
|
|
173
184
|
publishSettings.putMap("videoSimulcastLayers", null)
|
|
174
185
|
publishSettings.putMap("screenSimulcastLayers", null)
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
publishSettings.putArray(
|
|
187
|
+
"allowed",
|
|
188
|
+
if (hmsPublishSettings.allowed != null) getWriteableArray(hmsPublishSettings.allowed)
|
|
189
|
+
else emptyArray
|
|
190
|
+
)
|
|
177
191
|
}
|
|
178
192
|
return publishSettings
|
|
179
193
|
}
|
|
194
|
+
|
|
195
|
+
fun getWriteableArray(array: List<String>?): WritableArray {
|
|
196
|
+
val decodedArray: WritableArray = Arguments.createArray()
|
|
197
|
+
if (array != null) {
|
|
198
|
+
for (value in array) {
|
|
199
|
+
decodedArray.pushString(value)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return decodedArray
|
|
203
|
+
}
|
|
204
|
+
|
|
180
205
|
fun getHmsAudioSettings(hmsAudioSettings: AudioParams?): WritableMap {
|
|
181
206
|
val audioSettings: WritableMap = Arguments.createMap()
|
|
182
207
|
if (hmsAudioSettings != null) {
|
|
@@ -236,10 +261,7 @@ object HmsDecoder {
|
|
|
236
261
|
"customerUserID",
|
|
237
262
|
if (hmsLocalPeer.customerUserID != null) hmsLocalPeer.customerUserID else ""
|
|
238
263
|
)
|
|
239
|
-
peer.putString(
|
|
240
|
-
"customerDescription",
|
|
241
|
-
if (hmsLocalPeer.customerDescription != null) hmsLocalPeer.customerDescription else ""
|
|
242
|
-
)
|
|
264
|
+
peer.putString("metadata", if (hmsLocalPeer.metadata != null) hmsLocalPeer.metadata else "")
|
|
243
265
|
peer.putMap("audioTrack", getHmsAudioTrack(hmsLocalPeer.audioTrack))
|
|
244
266
|
peer.putMap("videoTrack", getHmsVideoTrack(hmsLocalPeer.videoTrack))
|
|
245
267
|
peer.putMap("role", getHmsRole(hmsLocalPeer.hmsRole))
|
|
@@ -288,7 +310,7 @@ object HmsDecoder {
|
|
|
288
310
|
fun getHmsVideoTrackSettings(hmsVideoTrackSettings: HMSVideoTrackSettings?): WritableMap {
|
|
289
311
|
val settings: WritableMap = Arguments.createMap()
|
|
290
312
|
if (hmsVideoTrackSettings != null) {
|
|
291
|
-
settings.
|
|
313
|
+
settings.putString("codec", getHmsVideoTrackCodec(hmsVideoTrackSettings.codec))
|
|
292
314
|
|
|
293
315
|
val resolution: WritableMap = Arguments.createMap()
|
|
294
316
|
resolution.putInt("height", hmsVideoTrackSettings.resolution.height)
|
|
@@ -297,7 +319,10 @@ object HmsDecoder {
|
|
|
297
319
|
|
|
298
320
|
settings.putInt("maxBitrate", hmsVideoTrackSettings.maxBitRate)
|
|
299
321
|
settings.putInt("maxFrameRate", hmsVideoTrackSettings.maxFrameRate)
|
|
300
|
-
settings.
|
|
322
|
+
settings.putString(
|
|
323
|
+
"cameraFacing",
|
|
324
|
+
getHmsVideoTrackCameraFacing(hmsVideoTrackSettings.cameraFacing)
|
|
325
|
+
)
|
|
301
326
|
// settings.putString("trackDescription",
|
|
302
327
|
// if(hmsVideoTrackSettings.trackDescription!==null)hmsVideoTrackSettings.trackDescription
|
|
303
328
|
// else "");
|
|
@@ -306,6 +331,31 @@ object HmsDecoder {
|
|
|
306
331
|
return settings
|
|
307
332
|
}
|
|
308
333
|
|
|
334
|
+
fun getHmsVideoTrackCodec(codec: HMSVideoCodec): String {
|
|
335
|
+
return when (codec) {
|
|
336
|
+
HMSVideoCodec.H264 -> {
|
|
337
|
+
"h264"
|
|
338
|
+
}
|
|
339
|
+
HMSVideoCodec.VP9 -> {
|
|
340
|
+
"vp9"
|
|
341
|
+
}
|
|
342
|
+
HMSVideoCodec.VP8 -> {
|
|
343
|
+
"vp8"
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
fun getHmsVideoTrackCameraFacing(cameraFacing: HMSVideoTrackSettings.CameraFacing): String {
|
|
349
|
+
return when (cameraFacing) {
|
|
350
|
+
HMSVideoTrackSettings.CameraFacing.FRONT -> {
|
|
351
|
+
"FRONT"
|
|
352
|
+
}
|
|
353
|
+
HMSVideoTrackSettings.CameraFacing.BACK -> {
|
|
354
|
+
"BACK"
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
309
359
|
fun getHmsRemotePeers(remotePeers: Array<HMSRemotePeer>?): WritableArray {
|
|
310
360
|
val peers: WritableArray = Arguments.createArray()
|
|
311
361
|
if (remotePeers != null) {
|
|
@@ -326,10 +376,7 @@ object HmsDecoder {
|
|
|
326
376
|
"customerUserID",
|
|
327
377
|
if (hmsRemotePeer.customerUserID != null) hmsRemotePeer.customerUserID else ""
|
|
328
378
|
)
|
|
329
|
-
peer.putString(
|
|
330
|
-
"customerDescription",
|
|
331
|
-
if (hmsRemotePeer.customerDescription != null) hmsRemotePeer.customerDescription else ""
|
|
332
|
-
)
|
|
379
|
+
peer.putString("metadata", if (hmsRemotePeer.metadata != null) hmsRemotePeer.metadata else "")
|
|
333
380
|
peer.putMap("audioTrack", getHmsAudioTrack(hmsRemotePeer.audioTrack))
|
|
334
381
|
peer.putMap("videoTrack", getHmsVideoTrack(hmsRemotePeer.videoTrack))
|
|
335
382
|
peer.putMap("role", getHmsRole(hmsRemotePeer.hmsRole))
|
|
@@ -427,4 +474,31 @@ object HmsDecoder {
|
|
|
427
474
|
|
|
428
475
|
return decodedError
|
|
429
476
|
}
|
|
477
|
+
|
|
478
|
+
fun getHMSBrowserRecordingState(data: HMSBrowserRecordingState?): ReadableMap {
|
|
479
|
+
val input = Arguments.createMap()
|
|
480
|
+
if (data !== null) {
|
|
481
|
+
input.putBoolean("running", data.running)
|
|
482
|
+
input.putMap("error", data.error?.let { this.getError(it) })
|
|
483
|
+
}
|
|
484
|
+
return input
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
fun getHMSRtmpStreamingState(data: HMSRtmpStreamingState?): ReadableMap {
|
|
488
|
+
val input = Arguments.createMap()
|
|
489
|
+
if (data !== null) {
|
|
490
|
+
input.putBoolean("running", data.running)
|
|
491
|
+
input.putMap("error", data.error?.let { this.getError(it) })
|
|
492
|
+
}
|
|
493
|
+
return input
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
fun getHMSServerRecordingState(data: HMSServerRecordingState?): ReadableMap {
|
|
497
|
+
val input = Arguments.createMap()
|
|
498
|
+
if (data !== null) {
|
|
499
|
+
input.putBoolean("running", data.running)
|
|
500
|
+
input.putMap("error", data.error?.let { this.getError(it) })
|
|
501
|
+
}
|
|
502
|
+
return input
|
|
503
|
+
}
|
|
430
504
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
package com.reactnativehmssdk
|
|
2
2
|
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
3
4
|
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import live.hms.video.media.codec.HMSAudioCodec
|
|
6
|
+
import live.hms.video.media.codec.HMSVideoCodec
|
|
7
|
+
import live.hms.video.media.settings.HMSAudioTrackSettings
|
|
8
|
+
import live.hms.video.media.settings.HMSVideoResolution
|
|
9
|
+
import live.hms.video.media.settings.HMSVideoTrackSettings
|
|
4
10
|
import live.hms.video.media.tracks.*
|
|
5
11
|
import live.hms.video.sdk.models.*
|
|
6
12
|
import live.hms.video.sdk.models.role.*
|
|
@@ -22,6 +28,11 @@ object HmsHelper {
|
|
|
22
28
|
return false
|
|
23
29
|
}
|
|
24
30
|
}
|
|
31
|
+
"Float" -> {
|
|
32
|
+
if (map.getDouble(key) == null) {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
25
36
|
"Boolean" -> {
|
|
26
37
|
if (map.getBoolean(key) == null) {
|
|
27
38
|
return false
|
|
@@ -163,6 +174,91 @@ object HmsHelper {
|
|
|
163
174
|
return null
|
|
164
175
|
}
|
|
165
176
|
|
|
177
|
+
fun getAudioTrackSettings(data: ReadableMap?): HMSAudioTrackSettings {
|
|
178
|
+
val builder = HMSAudioTrackSettings.Builder()
|
|
179
|
+
|
|
180
|
+
if (data != null) {
|
|
181
|
+
val maxBitrate = data.getInt("maxBitrate")
|
|
182
|
+
val codec = getAudioCodec(data.getString("codec"))
|
|
183
|
+
val trackDescription = data.getString("trackDescription")
|
|
184
|
+
|
|
185
|
+
builder.maxBitrate(maxBitrate)
|
|
186
|
+
builder.codec(codec)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return builder.build()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// TODO: find out a way to set settings required to create HMSVideTrackSettings
|
|
193
|
+
|
|
194
|
+
fun getVideoTrackSettings(data: ReadableMap?): HMSVideoTrackSettings {
|
|
195
|
+
val builder = HMSVideoTrackSettings.Builder()
|
|
196
|
+
if (data != null) {
|
|
197
|
+
val codec = getVideoCodec(data.getString("codec"))
|
|
198
|
+
val resolution = getVideoResolution(data.getMap("resolution"))
|
|
199
|
+
val maxBitrate = data.getInt("maxBitrate")
|
|
200
|
+
val maxFrameRate = data.getInt("maxFrameRate")
|
|
201
|
+
val cameraFacing = getCameraFacing(data.getString("cameraFacing"))
|
|
202
|
+
val trackDescription = data.getString("trackDescription")
|
|
203
|
+
|
|
204
|
+
builder.codec(codec)
|
|
205
|
+
builder.cameraFacing(cameraFacing)
|
|
206
|
+
if (resolution != null) {
|
|
207
|
+
builder.resolution(resolution)
|
|
208
|
+
}
|
|
209
|
+
builder.maxBitrate(maxBitrate)
|
|
210
|
+
builder.maxFrameRate(maxFrameRate)
|
|
211
|
+
}
|
|
212
|
+
return builder.build()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
fun getVideoResolution(map: ReadableMap?): HMSVideoResolution? {
|
|
216
|
+
val width = map?.getDouble("width")
|
|
217
|
+
val height = map?.getDouble("height")
|
|
218
|
+
|
|
219
|
+
return if (width != null && height != null) {
|
|
220
|
+
HMSVideoResolution(width = width.toInt(), height = height.toInt())
|
|
221
|
+
} else {
|
|
222
|
+
null
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fun getAudioCodec(codecString: String?): HMSAudioCodec {
|
|
227
|
+
when (codecString) {
|
|
228
|
+
"opus" -> {
|
|
229
|
+
return HMSAudioCodec.OPUS
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return HMSAudioCodec.OPUS
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fun getVideoCodec(codecString: String?): HMSVideoCodec {
|
|
236
|
+
when (codecString) {
|
|
237
|
+
"h264" -> {
|
|
238
|
+
return HMSVideoCodec.H264
|
|
239
|
+
}
|
|
240
|
+
"vp8" -> {
|
|
241
|
+
return HMSVideoCodec.VP8
|
|
242
|
+
}
|
|
243
|
+
"vp9" -> {
|
|
244
|
+
return HMSVideoCodec.VP9
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return HMSVideoCodec.H264
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
fun getCameraFacing(cameraFacing: String?): HMSVideoTrackSettings.CameraFacing {
|
|
251
|
+
when (cameraFacing) {
|
|
252
|
+
"FRONT" -> {
|
|
253
|
+
return HMSVideoTrackSettings.CameraFacing.FRONT
|
|
254
|
+
}
|
|
255
|
+
"BACK" -> {
|
|
256
|
+
return HMSVideoTrackSettings.CameraFacing.BACK
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return HMSVideoTrackSettings.CameraFacing.FRONT
|
|
260
|
+
}
|
|
261
|
+
|
|
166
262
|
fun getHms(credentials: ReadableMap, hmsCollection: MutableMap<String, HmsSDK>): HmsSDK? {
|
|
167
263
|
val id = credentials.getString("id")
|
|
168
264
|
|
|
@@ -172,4 +268,14 @@ object HmsHelper {
|
|
|
172
268
|
return null
|
|
173
269
|
}
|
|
174
270
|
}
|
|
271
|
+
|
|
272
|
+
fun getRtmpUrls(rtmpURLsList: ReadableArray?): List<String> {
|
|
273
|
+
val rtmpURLs = mutableListOf<String>()
|
|
274
|
+
if (rtmpURLsList !== null) {
|
|
275
|
+
for (rtmpURL in rtmpURLsList.toArrayList()) {
|
|
276
|
+
rtmpURLs.add(rtmpURL as String)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return rtmpURLs
|
|
280
|
+
}
|
|
175
281
|
}
|
|
@@ -23,19 +23,19 @@ class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
|
|
|
23
23
|
// Example method
|
|
24
24
|
// See https://reactnative.dev/docs/native-modules-android
|
|
25
25
|
@ReactMethod
|
|
26
|
-
fun build(callback: Promise?) {
|
|
26
|
+
fun build(data: ReadableMap?, callback: Promise?) {
|
|
27
27
|
val hasItem = hmsCollection.containsKey("12345")
|
|
28
28
|
if (hasItem) {
|
|
29
29
|
val uuid = UUID.randomUUID()
|
|
30
30
|
val randomUUIDString = uuid.toString()
|
|
31
|
-
val sdkInstance: HmsSDK = HmsSDK(this, randomUUIDString, reactApplicationContext)
|
|
31
|
+
val sdkInstance: HmsSDK = HmsSDK(data, this, randomUUIDString, reactApplicationContext)
|
|
32
32
|
|
|
33
33
|
hmsCollection[randomUUIDString] = sdkInstance
|
|
34
34
|
|
|
35
35
|
callback?.resolve(randomUUIDString)
|
|
36
36
|
} else {
|
|
37
37
|
val randomUUIDString = "12345"
|
|
38
|
-
val sdkInstance: HmsSDK = HmsSDK(this, randomUUIDString, reactApplicationContext)
|
|
38
|
+
val sdkInstance: HmsSDK = HmsSDK(data, this, randomUUIDString, reactApplicationContext)
|
|
39
39
|
|
|
40
40
|
hmsCollection[randomUUIDString] = sdkInstance
|
|
41
41
|
|
|
@@ -176,6 +176,20 @@ class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
|
|
|
176
176
|
hms?.acceptRoleChange()
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
@ReactMethod
|
|
180
|
+
fun setVolume(data: ReadableMap) {
|
|
181
|
+
val hms = HmsHelper.getHms(data, hmsCollection)
|
|
182
|
+
|
|
183
|
+
hms?.setVolume(data)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@ReactMethod
|
|
187
|
+
fun getVolume(data: ReadableMap, callback: Promise?) {
|
|
188
|
+
val hms = HmsHelper.getHms(data, hmsCollection)
|
|
189
|
+
|
|
190
|
+
hms?.getVolume(data, callback)
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
@ReactMethod
|
|
180
194
|
fun muteAllPeersAudio(data: ReadableMap) {
|
|
181
195
|
val hms = HmsHelper.getHms(data, hmsCollection)
|
|
@@ -183,6 +197,27 @@ class HmsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
|
|
|
183
197
|
hms?.muteAllPeersAudio(data)
|
|
184
198
|
}
|
|
185
199
|
|
|
200
|
+
@ReactMethod
|
|
201
|
+
fun changeMetadata(data: ReadableMap, callback: Promise?) {
|
|
202
|
+
val hms = HmsHelper.getHms(data, hmsCollection)
|
|
203
|
+
|
|
204
|
+
hms?.changeMetadata(data, callback)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@ReactMethod
|
|
208
|
+
fun startRTMPOrRecording(data: ReadableMap, callback: Promise?) {
|
|
209
|
+
val hms = HmsHelper.getHms(data, hmsCollection)
|
|
210
|
+
|
|
211
|
+
hms?.startRTMPOrRecording(data, callback)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@ReactMethod
|
|
215
|
+
fun stopRtmpAndRecording(data: ReadableMap, callback: Promise?) {
|
|
216
|
+
val hms = HmsHelper.getHms(data, hmsCollection)
|
|
217
|
+
|
|
218
|
+
hms?.stopRtmpAndRecording(callback)
|
|
219
|
+
}
|
|
220
|
+
|
|
186
221
|
fun emitEvent(event: String, data: WritableMap) {
|
|
187
222
|
reactApplicationContext
|
|
188
223
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|