@@ -14,7 +14,7 @@ import Icon from 'react-native-vector-icons/Ionicons';
14
14
import { DeviceEventEmitter } from 'react-native' ;
15
15
import InCallManager from 'react-native-incall-manager' ;
16
16
17
- var publishStreamId :string ;
17
+ var publishStreamId : string ;
18
18
19
19
export default function Conference ( ) {
20
20
var defaultRoomName = 'room1' ;
@@ -28,7 +28,7 @@ export default function Conference() {
28
28
const [ remoteTracks , setremoteTracks ] = useState < any > ( [ ] ) ;
29
29
const [ isMuted , setIsMuted ] = useState ( false ) ;
30
30
const [ isCameraOpen , setIsCameraOpen ] = useState ( true ) ;
31
-
31
+ const [ isWaitingWebsocketInit , setIsWaitingWebsocketInit ] = useState ( false ) ;
32
32
33
33
const adaptor = useAntMedia ( {
34
34
url : webSocketUrl ,
@@ -43,6 +43,9 @@ export default function Conference() {
43
43
} ,
44
44
callback ( command : any , data : any ) {
45
45
switch ( command ) {
46
+ case 'initiated' :
47
+ console . log ( 'initiated' ) ;
48
+ break ;
46
49
case 'pong' :
47
50
break ;
48
51
case 'publish_started' :
@@ -52,6 +55,19 @@ export default function Conference() {
52
55
break ;
53
56
case 'publish_finished' :
54
57
setIsPublishing ( false ) ;
58
+ adaptor . closeWebSocket ( ) ;
59
+ break ;
60
+ case 'local_stream_updated' :
61
+ console . log ( 'local_stream_updated' ) ;
62
+ verify ( ) ;
63
+ break ;
64
+ case 'websocket_not_initialized' :
65
+ setIsWaitingWebsocketInit ( true ) ;
66
+ adaptor . initialiseWebSocket ( ) ;
67
+ break ;
68
+ case 'websocket_closed' :
69
+ console . log ( 'websocket_closed' ) ;
70
+ adaptor . stopLocalStream ( ) ;
55
71
break ;
56
72
case 'play_finished' :
57
73
console . log ( 'play_finished' ) ;
@@ -77,6 +93,10 @@ export default function Conference() {
77
93
}
78
94
}
79
95
break ;
96
+ case "data_received" :
97
+ console . log ( 'data_received' , data ) ;
98
+ handleNotificationEvent ( data ) ;
99
+ break ;
80
100
case "available_devices" :
81
101
console . log ( 'available_devices' , data ) ;
82
102
break ;
@@ -92,16 +112,42 @@ export default function Conference() {
92
112
console . error ( 'callbackError' , err , data ) ;
93
113
}
94
114
} ,
95
- peer_connection_config : {
96
- iceServers : [
97
- {
98
- url : 'stun:stun.l.google.com:19302' ,
99
- } ,
100
- ] ,
101
- } ,
102
115
debug : true ,
103
116
} ) ;
104
117
118
+ const verify = ( ) => {
119
+ console . log ( 'in verify' ) ;
120
+ if ( adaptor . localStream . current && adaptor . localStream . current . toURL ( ) ) {
121
+ console . log ( 'in verify if adaptor local stream' , adaptor . localStream ) ;
122
+ if ( isWaitingWebsocketInit ) {
123
+ setIsWaitingWebsocketInit ( false ) ;
124
+ publishStreamId = generateRandomString ( 12 ) ;
125
+ adaptor . publish ( publishStreamId , undefined , undefined , undefined , undefined , roomId , "" ) ;
126
+ }
127
+ return setLocalMedia ( adaptor . localStream . current . toURL ( ) ) ;
128
+ }
129
+ setTimeout ( verify , 5000 ) ;
130
+ } ;
131
+
132
+ const handleNotificationEvent = ( notificationEvent : any ) => {
133
+ //var notificationEvent = JSON.parse(data);
134
+ if ( notificationEvent != null && typeof notificationEvent == "object" ) {
135
+ var eventStreamId = notificationEvent . streamId ;
136
+ var eventType = notificationEvent . eventType ;
137
+
138
+ if ( eventType == "VIDEO_TRACK_ASSIGNMENT_LIST" ) {
139
+ var videoTrackAssignmentList = notificationEvent . payload ;
140
+ console . log ( "VIDEO_TRACK_ASSIGNMENT_LIST" , videoTrackAssignmentList ) ;
141
+ } else if ( eventType == "AUDIO_TRACK_ASSIGNMENT" ) {
142
+ console . log ( "AUDIO_TRACK_ASSIGNMENT" , notificationEvent . payload ) ;
143
+ } else if ( eventType == "TRACK_LIST_UPDATED" ) {
144
+ console . log ( "TRACK_LIST_UPDATED" , notificationEvent . payload ) ;
145
+ adaptor . requestVideoTrackAssignments ( roomId ) ;
146
+ }
147
+
148
+ }
149
+ } ;
150
+
105
151
const handleMic = useCallback ( ( ) => {
106
152
if ( adaptor ) {
107
153
( isMuted ) ? adaptor . unmuteLocalMic ( ) : adaptor . muteLocalMic ( ) ;
@@ -133,14 +179,14 @@ export default function Conference() {
133
179
}
134
180
} , [ adaptor , roomId ] ) ;
135
181
136
- /*
137
- const handleRemoteAudio = useCallback((streamId: string) => {
138
- if (adaptor) {
139
- adaptor?.muteRemoteAudio(streamId, roomId);
140
- //adaptor?.unmuteRemoteAudio(streamId, roomId);
141
- }
142
- }, [adaptor]);
143
- */
182
+ /*
183
+ const handleRemoteAudio = useCallback((streamId: string) => {
184
+ if (adaptor) {
185
+ adaptor?.muteRemoteAudio(streamId, roomId);
186
+ //adaptor?.unmuteRemoteAudio(streamId, roomId);
187
+ }
188
+ }, [adaptor]);
189
+ */
144
190
145
191
const removeRemoteVideo = ( streamId ?: string ) => {
146
192
if ( streamId != null || streamId != undefined ) {
@@ -160,18 +206,6 @@ export default function Conference() {
160
206
setremoteTracks ( [ ] ) ;
161
207
} ;
162
208
163
- useEffect ( ( ) => {
164
- const verify = ( ) => {
165
- if ( adaptor . localStream . current && adaptor . localStream . current . toURL ( ) ) {
166
- let videoTrack = adaptor . localStream . current . getVideoTracks ( ) [ 0 ] ;
167
- // @ts -ignore
168
- return setLocalMedia ( videoTrack ) ;
169
- }
170
- setTimeout ( verify , 5000 ) ;
171
- } ;
172
- verify ( ) ;
173
- } , [ adaptor . localStream ] ) ;
174
-
175
209
useEffect ( ( ) => {
176
210
if ( localMedia && remoteTracks ) {
177
211
InCallManager . start ( { media : 'video' } ) ;
@@ -207,14 +241,14 @@ export default function Conference() {
207
241
</ >
208
242
) : (
209
243
< >
210
- < View style = { { flexDirection : 'row' , justifyContent : 'center' } } >
211
- < TouchableOpacity onPress = { handleMic } style = { styles . roundButton } >
212
- < Icon name = { isMuted ? 'mic-off-outline' : 'mic-outline' } size = { 15 } color = "#000" />
213
- </ TouchableOpacity >
214
- < TouchableOpacity onPress = { handleCamera } style = { styles . roundButton } >
215
- < Icon name = { isCameraOpen ? 'videocam-outline' : 'videocam-off-outline' } size = { 15 } color = "#000" />
216
- </ TouchableOpacity >
217
- </ View >
244
+ < View style = { { flexDirection : 'row' , justifyContent : 'center' } } >
245
+ < TouchableOpacity onPress = { handleMic } style = { styles . roundButton } >
246
+ < Icon name = { isMuted ? 'mic-off-outline' : 'mic-outline' } size = { 15 } color = "#000" />
247
+ </ TouchableOpacity >
248
+ < TouchableOpacity onPress = { handleCamera } style = { styles . roundButton } >
249
+ < Icon name = { isCameraOpen ? 'videocam-outline' : 'videocam-off-outline' } size = { 15 } color = "#000" />
250
+ </ TouchableOpacity >
251
+ </ View >
218
252
< Text style = { styles . heading1 } > Remote Streams</ Text >
219
253
{
220
254
< ScrollView
@@ -236,7 +270,7 @@ export default function Conference() {
236
270
< View key = { index } style = { trackObj . track . kind === 'audio' ? { display : 'none' } : { } } >
237
271
< > {
238
272
// @ts -ignore
239
- rtc_view ( trackObj . track , styles . players )
273
+ rtc_view ( trackObj . track , styles . players )
240
274
} </ >
241
275
{ /*
242
276
<View style={{ flexDirection: 'row', justifyContent: 'center' }}>
@@ -313,14 +347,14 @@ const styles = StyleSheet.create({
313
347
marginTop : 20 ,
314
348
} ,
315
349
roundButton : {
316
- alignItems : 'center' ,
317
- justifyContent : 'center' ,
318
- backgroundColor : '#DDDDDD' ,
319
- padding : 5 ,
320
- borderRadius : 25 , // This will make the button round
321
- width : 30 , // Diameter of the button
322
- height : 30 , // Diameter of the button
323
- marginTop : 10 ,
324
- marginHorizontal : 10 ,
325
- } ,
350
+ alignItems : 'center' ,
351
+ justifyContent : 'center' ,
352
+ backgroundColor : '#DDDDDD' ,
353
+ padding : 5 ,
354
+ borderRadius : 25 , // This will make the button round
355
+ width : 30 , // Diameter of the button
356
+ height : 30 , // Diameter of the button
357
+ marginTop : 10 ,
358
+ marginHorizontal : 10 ,
359
+ } ,
326
360
} ) ;
0 commit comments