agora-appbuilder-core 4.0.24 → 4.0.25-beta-2
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/package.json +1 -1
- package/template/agora-rn-uikit/.eslintrc.js +0 -5
- package/template/agora-rn-uikit/package-lock.json +6116 -23528
- package/template/agora-rn-uikit/package.json +14 -14
- package/template/agora-rn-uikit/src/AgoraUIKit.tsx +6 -6
- package/template/agora-rn-uikit/src/Contexts/LocalUserContext.tsx +6 -6
- package/template/agora-rn-uikit/src/Contexts/PropsContext.tsx +40 -79
- package/template/agora-rn-uikit/src/Contexts/RenderContext.tsx +10 -0
- package/template/agora-rn-uikit/src/Contexts/RtcContext.tsx +17 -26
- package/template/agora-rn-uikit/src/Controls/BtnTemplate.tsx +0 -1
- package/template/agora-rn-uikit/src/Controls/Icons.ts +0 -51
- package/template/agora-rn-uikit/src/Controls/Local/EndCall.tsx +4 -6
- package/template/agora-rn-uikit/src/Controls/Local/FullScreen.tsx +1 -3
- package/template/agora-rn-uikit/src/Controls/Local/LocalAudioMute.tsx +2 -5
- package/template/agora-rn-uikit/src/Controls/Local/LocalVideoMute.tsx +2 -5
- package/template/agora-rn-uikit/src/Controls/Local/Recording.tsx +2 -0
- package/template/agora-rn-uikit/src/Controls/Local/SwitchCamera.tsx +6 -7
- package/template/agora-rn-uikit/src/Controls/LocalControls.tsx +5 -5
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteAudioMute.tsx +4 -5
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteSwap.tsx +1 -3
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteVideoMute.tsx +4 -5
- package/template/agora-rn-uikit/src/Controls/RemoteControls.tsx +2 -2
- package/template/agora-rn-uikit/src/Reducer/ActiveSpeakerDetected.ts +11 -0
- package/template/agora-rn-uikit/src/Reducer/LocalMuteAudio.ts +7 -8
- package/template/agora-rn-uikit/src/Reducer/LocalMuteVideo.ts +7 -8
- package/template/agora-rn-uikit/src/Reducer/LocalPermissionState.ts +7 -6
- package/template/agora-rn-uikit/src/Reducer/RemoteAudioStateChanged.ts +8 -7
- package/template/agora-rn-uikit/src/Reducer/RemoteVideoStateChanged.ts +9 -9
- package/template/agora-rn-uikit/src/Reducer/UpdateDualStreamMode.ts +8 -7
- package/template/agora-rn-uikit/src/Reducer/UserJoined.ts +13 -14
- package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteAudio.ts +7 -6
- package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteVideo.ts +7 -6
- package/template/agora-rn-uikit/src/Reducer/UserOffline.ts +6 -5
- package/template/agora-rn-uikit/src/Reducer/UserPin.ts +3 -20
- package/template/agora-rn-uikit/src/Reducer/index.ts +1 -2
- package/template/agora-rn-uikit/src/Rtc/Create.tsx +125 -122
- package/template/agora-rn-uikit/src/Rtc/Join.tsx +27 -46
- package/template/agora-rn-uikit/src/RtcConfigure.tsx +77 -175
- package/template/agora-rn-uikit/src/Utils/quality.tsx +0 -8
- package/template/agora-rn-uikit/src/Views/MaxVideoView.native.tsx +12 -56
- package/template/agora-rn-uikit/src/Views/MaxVideoView.tsx +17 -47
- package/template/agora-rn-uikit/src/Views/MinVideoView.tsx +11 -19
- package/template/agora-rn-uikit/src/index.ts +9 -16
- package/template/customization-api/typeDefinition.ts +1 -4
- package/template/customization-api/utils.ts +1 -0
- package/template/defaultConfig.js +2 -0
- package/template/global.d.ts +2 -0
- package/template/src/AppRoutes.tsx +1 -7
- package/template/src/auth/AuthProvider.tsx +70 -24
- package/template/src/auth/useIDPAuth.electron.tsx +59 -2
- package/template/src/auth/useIDPAuth.native.tsx +59 -2
- package/template/src/auth/useIDPAuth.tsx +60 -2
- package/template/src/auth/useTokenAuth.tsx +66 -4
- package/template/src/components/DeviceConfigure.tsx +74 -68
- package/template/src/components/GraphQLProvider.tsx +0 -1
- package/template/src/components/contexts/WaitingRoomContext.tsx +11 -4
- package/template/src/components/recording-bot/RecordingBotRoute.tsx +1 -1
- package/template/src/components/useUserPreference.tsx +56 -9
- package/template/src/components/whiteboard/WhiteboardConfigure.tsx +4 -1
- package/template/src/components/whiteboard/WhiteboardToolBox.tsx +185 -24
- package/template/src/components/whiteboard/WhiteboardWidget.tsx +47 -6
- package/template/src/logger/AppBuilderLogger.tsx +94 -36
- package/template/src/logger/transports/customer-transport.ts +7 -3
- package/template/src/pages/VideoCall.tsx +3 -5
- package/template/src/subComponents/SelectDevice.tsx +14 -52
- package/template/src/subComponents/caption/useSTTAPI.tsx +39 -3
- package/template/src/subComponents/recording/useRecording.tsx +69 -20
- package/template/src/subComponents/waiting-rooms/useWaitingRoomAPI.ts +30 -8
- package/template/src/utils/common.tsx +6 -1
- package/template/src/utils/useCreateRoom.ts +21 -2
- package/template/src/utils/useFindActiveSpeaker.ts +12 -5
- package/template/src/utils/useGetMeetingPhrase.ts +44 -1
- package/template/src/utils/useJoinRoom.ts +29 -2
- package/template/src/utils/useMutePSTN.ts +29 -0
- package/template/agora-rn-uikit/src/Contexts/ContentContext.tsx +0 -10
- package/template/agora-rn-uikit/src/Contexts/DispatchContext.tsx +0 -22
- package/template/agora-rn-uikit/src/Reducer/ActiveSpeaker.ts +0 -30
- package/template/agora-rn-uikit/src/Reducer/UserSecondaryPin.ts +0 -23
- package/template/agora-rn-uikit/src/Utils/isBotUser.ts +0 -15
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import React, {useState, useEffect, useContext, useRef} from 'react';
|
|
2
|
-
import {
|
|
3
|
-
createAgoraRtcEngine,
|
|
1
|
+
import React, {useState, useEffect, useContext, useRef, FC} from 'react';
|
|
2
|
+
import RtcEngine, {
|
|
4
3
|
VideoEncoderConfiguration,
|
|
5
4
|
AreaCode,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
AudioScenarioType,
|
|
5
|
+
AudioProfile,
|
|
6
|
+
AudioScenario,
|
|
9
7
|
} from 'react-native-agora';
|
|
10
8
|
import {Platform} from 'react-native';
|
|
11
9
|
import requestCameraAndAudioPermission from '../Utils/permission';
|
|
12
|
-
import {DispatchType} from '../Contexts/
|
|
10
|
+
import {DispatchType} from '../Contexts/RtcContext';
|
|
13
11
|
import PropsContext, {
|
|
14
12
|
ToggleState,
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
ClientRole,
|
|
14
|
+
ChannelProfile,
|
|
17
15
|
PermissionState,
|
|
18
16
|
} from '../Contexts/PropsContext';
|
|
19
17
|
import quality from '../Utils/quality';
|
|
20
|
-
import {isBotUser} from '../Utils/isBotUser';
|
|
21
18
|
|
|
22
19
|
const Create = ({
|
|
23
20
|
dispatch,
|
|
@@ -25,9 +22,9 @@ const Create = ({
|
|
|
25
22
|
}: {
|
|
26
23
|
dispatch: DispatchType;
|
|
27
24
|
children: (
|
|
28
|
-
engine: React.MutableRefObject<
|
|
25
|
+
engine: React.MutableRefObject<RtcEngine>,
|
|
29
26
|
tracksReady: boolean,
|
|
30
|
-
) =>
|
|
27
|
+
) => JSX.Element;
|
|
31
28
|
}) => {
|
|
32
29
|
const mutexLock = useRef(false);
|
|
33
30
|
const [ready, setReady] = useState(false);
|
|
@@ -37,8 +34,10 @@ const Create = ({
|
|
|
37
34
|
geoFencing = true,
|
|
38
35
|
audioRoom = false,
|
|
39
36
|
activeSpeaker = false,
|
|
37
|
+
preferredCameraId = '',
|
|
38
|
+
preferredMicrophoneId = '',
|
|
40
39
|
} = rtcProps || {};
|
|
41
|
-
let engine = useRef<
|
|
40
|
+
let engine = useRef<RtcEngine>({} as RtcEngine);
|
|
42
41
|
// commented for v1 release
|
|
43
42
|
// const beforeCreate = rtcProps?.lifecycle?.useBeforeCreate
|
|
44
43
|
// ? rtcProps.lifecycle.useBeforeCreate()
|
|
@@ -87,7 +86,16 @@ const Create = ({
|
|
|
87
86
|
value: [ToggleState.disabled],
|
|
88
87
|
});
|
|
89
88
|
} else {
|
|
90
|
-
|
|
89
|
+
if (Platform.OS === 'web') {
|
|
90
|
+
await engine.current.enableVideo(
|
|
91
|
+
//@ts-ignore
|
|
92
|
+
preferredCameraId,
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
preferredMicrophoneId,
|
|
95
|
+
);
|
|
96
|
+
} else {
|
|
97
|
+
await engine.current.enableVideo();
|
|
98
|
+
}
|
|
91
99
|
dispatch({
|
|
92
100
|
type: 'LocalPermissionState',
|
|
93
101
|
value: [PermissionState.GRANTED_FOR_CAM_AND_MIC],
|
|
@@ -146,7 +154,17 @@ const Create = ({
|
|
|
146
154
|
value: [ToggleState.enabled],
|
|
147
155
|
});
|
|
148
156
|
} else {
|
|
149
|
-
|
|
157
|
+
if (Platform.OS === 'web') {
|
|
158
|
+
//@ts-ignore
|
|
159
|
+
await engine.current.enableVideo(
|
|
160
|
+
//@ts-ignore
|
|
161
|
+
preferredCameraId,
|
|
162
|
+
//@ts-ignore
|
|
163
|
+
preferredMicrophoneId,
|
|
164
|
+
);
|
|
165
|
+
} else {
|
|
166
|
+
await engine.current.enableVideo();
|
|
167
|
+
}
|
|
150
168
|
dispatch({
|
|
151
169
|
type: 'LocalPermissionState',
|
|
152
170
|
value: [PermissionState.GRANTED_FOR_CAM_AND_MIC],
|
|
@@ -191,12 +209,12 @@ const Create = ({
|
|
|
191
209
|
};
|
|
192
210
|
const enableVideoAndAudioWithInitialStates = async () => {
|
|
193
211
|
if (
|
|
194
|
-
mode
|
|
195
|
-
rtcProps?.role
|
|
212
|
+
mode == ChannelProfile.LiveBroadcasting &&
|
|
213
|
+
rtcProps?.role == ClientRole.Audience
|
|
196
214
|
) {
|
|
197
|
-
enableVideoAndAudioWithDisabledState();
|
|
215
|
+
await enableVideoAndAudioWithDisabledState();
|
|
198
216
|
} else {
|
|
199
|
-
enableVideoAndAudioWithEnabledState();
|
|
217
|
+
await enableVideoAndAudioWithEnabledState();
|
|
200
218
|
}
|
|
201
219
|
};
|
|
202
220
|
|
|
@@ -216,74 +234,62 @@ const Create = ({
|
|
|
216
234
|
// console.error('FPE:Error on executing useBeforeCreate', error);
|
|
217
235
|
// }
|
|
218
236
|
try {
|
|
219
|
-
engine.current = createAgoraRtcEngine();
|
|
220
237
|
if (
|
|
221
238
|
geoFencing === true &&
|
|
222
239
|
(Platform.OS === 'android' || Platform.OS === 'ios')
|
|
223
240
|
) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
}
|
|
241
|
+
engine.current = await RtcEngine.createWithAreaCode(
|
|
242
|
+
rtcProps.appId,
|
|
243
|
+
// eslint-disable-next-line no-bitwise
|
|
244
|
+
AreaCode.GLOB ^ AreaCode.CN,
|
|
245
|
+
);
|
|
231
246
|
} else {
|
|
232
|
-
|
|
233
|
-
engine.current.initialize({appId: rtcProps.appId});
|
|
234
|
-
}
|
|
247
|
+
engine.current = await RtcEngine.create(rtcProps.appId);
|
|
235
248
|
}
|
|
236
249
|
/* Live Streaming */
|
|
237
|
-
if (mode
|
|
250
|
+
if (mode == ChannelProfile.LiveBroadcasting) {
|
|
238
251
|
await engine.current.setChannelProfile(
|
|
239
|
-
|
|
252
|
+
ChannelProfile.LiveBroadcasting,
|
|
240
253
|
);
|
|
241
254
|
await engine.current.setClientRole(
|
|
242
|
-
rtcProps
|
|
243
|
-
?
|
|
244
|
-
:
|
|
255
|
+
rtcProps.role === ClientRole.Audience
|
|
256
|
+
? ClientRole.Audience
|
|
257
|
+
: ClientRole.Broadcaster,
|
|
245
258
|
);
|
|
246
259
|
} else {
|
|
247
|
-
await engine.current.setChannelProfile(
|
|
248
|
-
ChannelProfileType.ChannelProfileCommunication,
|
|
249
|
-
);
|
|
260
|
+
await engine.current.setChannelProfile(ChannelProfile.Communication);
|
|
250
261
|
}
|
|
251
262
|
if (activeSpeaker) {
|
|
252
|
-
await engine.current.enableAudioVolumeIndication(
|
|
263
|
+
await engine.current.enableAudioVolumeIndication(500, 3, true);
|
|
253
264
|
}
|
|
254
265
|
if (!audioRoom) {
|
|
255
|
-
if (rtcProps
|
|
266
|
+
if (rtcProps.profile) {
|
|
256
267
|
if (Platform.OS === 'web') {
|
|
257
268
|
// move this to bridge?
|
|
258
269
|
// @ts-ignore
|
|
259
270
|
await engine.current.setVideoProfile(rtcProps.profile);
|
|
260
271
|
} else {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
bitrate: 0,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
272
|
+
const config: VideoEncoderConfiguration =
|
|
273
|
+
quality[rtcProps.profile];
|
|
274
|
+
await engine.current.setVideoEncoderConfiguration({
|
|
275
|
+
...config,
|
|
276
|
+
bitrate: 0,
|
|
277
|
+
});
|
|
270
278
|
}
|
|
271
279
|
}
|
|
272
280
|
} else {
|
|
273
281
|
//web will work even without audio profile
|
|
274
282
|
//but native need to set audio profile otherwise user will experience low audio issue
|
|
275
283
|
if (Platform.OS === 'android' || Platform.OS === 'ios') {
|
|
276
|
-
//@ts-ignore
|
|
277
284
|
await engine.current.setAudioProfile(
|
|
278
|
-
|
|
279
|
-
|
|
285
|
+
AudioProfile.Default,
|
|
286
|
+
AudioScenario.Default,
|
|
280
287
|
);
|
|
281
288
|
//also audio route for voice-chat will work through earpiece not phonespeaker
|
|
282
289
|
//for audiolivecast it will work through phone speaker
|
|
283
290
|
//ref - https://docs.agora.io/en/help/integration-issues/profile_difference/#audio-route
|
|
284
291
|
//so setting into phone speaker manually as requested
|
|
285
|
-
if (mode
|
|
286
|
-
//@ts-ignore
|
|
292
|
+
if (mode == ChannelProfile.Communication) {
|
|
287
293
|
await engine.current.setEnableSpeakerphone(true);
|
|
288
294
|
}
|
|
289
295
|
}
|
|
@@ -299,84 +305,98 @@ const Create = ({
|
|
|
299
305
|
*/
|
|
300
306
|
if (
|
|
301
307
|
!(
|
|
302
|
-
mode ===
|
|
303
|
-
rtcProps
|
|
304
|
-
Platform.OS === 'web'
|
|
305
|
-
rtcProps?.recordingBot
|
|
308
|
+
mode === ChannelProfile.LiveBroadcasting &&
|
|
309
|
+
rtcProps.role == ClientRole.Audience &&
|
|
310
|
+
Platform.OS === 'web'
|
|
306
311
|
)
|
|
307
312
|
) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
} else {
|
|
313
|
-
enableVideoAndAudioWithInitialStates().then(() => {
|
|
314
|
-
setTracksReady(true);
|
|
315
|
-
isVideoEnabledRef.current = true;
|
|
316
|
-
});
|
|
317
|
-
}
|
|
313
|
+
enableVideoAndAudioWithInitialStates().then(() => {
|
|
314
|
+
setTracksReady(true);
|
|
315
|
+
isVideoEnabledRef.current = true;
|
|
316
|
+
});
|
|
318
317
|
}
|
|
319
318
|
|
|
320
319
|
engine.current.addListener(
|
|
321
|
-
'
|
|
322
|
-
async (
|
|
320
|
+
'JoinChannelSuccess',
|
|
321
|
+
async (channel, uid, elapsed) => {
|
|
323
322
|
//Invoke the callback
|
|
324
|
-
console.log('UIkit enabling dual stream', rtcProps
|
|
325
|
-
if (rtcProps
|
|
323
|
+
console.log('UIkit enabling dual stream', rtcProps.dual);
|
|
324
|
+
if (rtcProps.dual) {
|
|
326
325
|
console.log('UIkit enabled dual stream');
|
|
327
326
|
await engine.current!.enableDualStreamMode(rtcProps.dual);
|
|
328
327
|
// await engine.current.setRemoteSubscribeFallbackOption(1);
|
|
329
328
|
}
|
|
330
329
|
callbacks?.JoinChannelSuccess &&
|
|
331
|
-
callbacks.JoinChannelSuccess(
|
|
330
|
+
callbacks.JoinChannelSuccess(channel, uid, elapsed);
|
|
332
331
|
},
|
|
333
332
|
);
|
|
334
333
|
|
|
335
|
-
engine.current.addListener('
|
|
336
|
-
// exluding the connection obj being passed by native sdk
|
|
337
|
-
const [, ...remainingArgs] = args;
|
|
338
|
-
//@ts-ignore
|
|
339
|
-
// preventing bots(ex: STT, recording) in renderlist
|
|
340
|
-
if (isBotUser(remainingArgs)) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
334
|
+
engine.current.addListener('UserJoined', (...args) => {
|
|
343
335
|
//Get current peer IDs
|
|
344
336
|
dispatch({
|
|
345
337
|
type: 'UserJoined',
|
|
346
|
-
|
|
347
|
-
value: remainingArgs,
|
|
338
|
+
value: args,
|
|
348
339
|
});
|
|
349
340
|
});
|
|
350
341
|
|
|
351
|
-
engine.current.addListener('
|
|
352
|
-
const [, ...remainingArgs] = args;
|
|
342
|
+
engine.current.addListener('UserOffline', (...args) => {
|
|
353
343
|
//If user leaves
|
|
354
344
|
dispatch({
|
|
355
345
|
type: 'UserOffline',
|
|
356
|
-
|
|
357
|
-
value: remainingArgs,
|
|
346
|
+
value: args,
|
|
358
347
|
});
|
|
359
348
|
});
|
|
360
349
|
|
|
361
|
-
engine.current.addListener('
|
|
362
|
-
const [, ...remainingArgs] = args;
|
|
350
|
+
engine.current.addListener('RemoteAudioStateChanged', (...args) => {
|
|
363
351
|
dispatch({
|
|
364
352
|
type: 'RemoteAudioStateChanged',
|
|
365
|
-
|
|
366
|
-
value: remainingArgs,
|
|
353
|
+
value: args,
|
|
367
354
|
});
|
|
368
355
|
});
|
|
369
356
|
|
|
370
|
-
engine.current.addListener('
|
|
357
|
+
engine.current.addListener('Error', (e) => {
|
|
371
358
|
console.log('Error: ', e);
|
|
372
359
|
});
|
|
373
360
|
|
|
374
|
-
engine.current.addListener('
|
|
375
|
-
const [, ...remainingArgs] = args;
|
|
361
|
+
engine.current.addListener('RemoteVideoStateChanged', (...args) => {
|
|
376
362
|
dispatch({
|
|
377
363
|
type: 'RemoteVideoStateChanged',
|
|
378
|
-
|
|
379
|
-
|
|
364
|
+
value: args,
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
engine.current.addListener('AudioVolumeIndication', (...args) => {
|
|
369
|
+
// console.log('-- AudioVolumeCallback', args);
|
|
370
|
+
const [speakers, totalVolume] = args;
|
|
371
|
+
if (speakers[0]?.uid === 0) {
|
|
372
|
+
//callback for local user
|
|
373
|
+
const isLocalUserSpeaking = speakers[0].vad; //1-speaking , 0-not speaking
|
|
374
|
+
const localUserVolumeLevel = speakers[0].volume;
|
|
375
|
+
// vad value is not consistent while speaking so using volume level
|
|
376
|
+
if (localUserVolumeLevel > 0) {
|
|
377
|
+
dispatch({
|
|
378
|
+
type: 'ActiveSpeakerDetected',
|
|
379
|
+
value: [rtcProps.uid],
|
|
380
|
+
});
|
|
381
|
+
} else {
|
|
382
|
+
dispatch({
|
|
383
|
+
type: 'ActiveSpeakerDetected',
|
|
384
|
+
value: [undefined],
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
// remote users callback, this will be handeled in ActiveSpeaker callback(367)
|
|
389
|
+
// const highestvolumeObj = speakers.reduce(function (prev, current) {
|
|
390
|
+
// return prev.volume > current.volume ? prev : current;
|
|
391
|
+
// }, null);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
engine.current.addListener('ActiveSpeaker', (...args) => {
|
|
396
|
+
// used as a callback from the web bridge as well remote users
|
|
397
|
+
dispatch({
|
|
398
|
+
type: 'ActiveSpeakerDetected',
|
|
399
|
+
value: args,
|
|
380
400
|
});
|
|
381
401
|
});
|
|
382
402
|
|
|
@@ -390,39 +410,25 @@ const Create = ({
|
|
|
390
410
|
init();
|
|
391
411
|
}
|
|
392
412
|
return () => {
|
|
393
|
-
if (Platform.OS !== 'web') {
|
|
394
|
-
// for web, events are cleared in release method
|
|
395
|
-
engine.current.removeAllListeners('onJoinChannelSuccess');
|
|
396
|
-
engine.current.removeAllListeners('onLeaveChannel');
|
|
397
|
-
engine.current.removeAllListeners('onUserJoined');
|
|
398
|
-
engine.current.removeAllListeners('onUserOffline');
|
|
399
|
-
engine.current.removeAllListeners('onRemoteVideoStateChanged');
|
|
400
|
-
engine.current.removeAllListeners('onRemoteAudioStateChanged');
|
|
401
|
-
engine.current.removeAllListeners('onError');
|
|
402
|
-
}
|
|
403
|
-
|
|
404
413
|
/**
|
|
405
414
|
* if condition add for websdk issue
|
|
406
415
|
* For some reason even if engine.current is defined somehow destroy gets undefined and
|
|
407
416
|
* causes a crash so thats why this check is needed before we call the method
|
|
408
417
|
*/
|
|
409
|
-
if (
|
|
410
|
-
engine.current
|
|
418
|
+
if (engine.current.destroy) {
|
|
419
|
+
engine.current!.destroy();
|
|
411
420
|
}
|
|
412
421
|
};
|
|
413
|
-
|
|
414
|
-
}, [rtcProps?.appId, rtcProps?.uid]);
|
|
422
|
+
}, [rtcProps.appId, rtcProps.uid]);
|
|
415
423
|
|
|
416
424
|
useEffect(() => {
|
|
417
425
|
const toggleRole = async () => {
|
|
418
426
|
if (
|
|
419
|
-
mode
|
|
427
|
+
mode == ChannelProfile.LiveBroadcasting &&
|
|
420
428
|
engine.current.setClientRole // Check if engine initialized
|
|
421
429
|
) {
|
|
422
|
-
if (rtcProps
|
|
423
|
-
await engine.current?.setClientRole(
|
|
424
|
-
ClientRoleType.ClientRoleBroadcaster,
|
|
425
|
-
);
|
|
430
|
+
if (rtcProps.role == ClientRole.Broadcaster) {
|
|
431
|
+
await engine.current?.setClientRole(ClientRole.Broadcaster);
|
|
426
432
|
// isVideoEnabledRef checks if the permission is already taken once
|
|
427
433
|
if (!isVideoEnabledRef.current) {
|
|
428
434
|
await enableVideoAndAudioWithDisabledState();
|
|
@@ -447,7 +453,7 @@ const Create = ({
|
|
|
447
453
|
}
|
|
448
454
|
}
|
|
449
455
|
}
|
|
450
|
-
if (rtcProps
|
|
456
|
+
if (rtcProps.role == ClientRole.Audience) {
|
|
451
457
|
/**
|
|
452
458
|
* To switch the user role back to "audience", call unpublish first
|
|
453
459
|
* Otherwise the setClientRole method call fails and throws an exception.
|
|
@@ -466,9 +472,7 @@ const Create = ({
|
|
|
466
472
|
value: [ToggleState.disabled],
|
|
467
473
|
});
|
|
468
474
|
}
|
|
469
|
-
await engine.current?.setClientRole(
|
|
470
|
-
ClientRoleType.ClientRoleAudience,
|
|
471
|
-
);
|
|
475
|
+
await engine.current?.setClientRole(ClientRole.Audience);
|
|
472
476
|
}
|
|
473
477
|
}
|
|
474
478
|
};
|
|
@@ -478,8 +482,7 @@ const Create = ({
|
|
|
478
482
|
return;
|
|
479
483
|
}
|
|
480
484
|
toggleRole();
|
|
481
|
-
|
|
482
|
-
}, [rtcProps?.role]);
|
|
485
|
+
}, [rtcProps.role]);
|
|
483
486
|
|
|
484
487
|
return (
|
|
485
488
|
<>
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import React, {useEffect, useContext, useRef} from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {DispatchType} from '../Contexts/DispatchContext';
|
|
2
|
+
import RtcEngine from 'react-native-agora';
|
|
3
|
+
import {RenderStateInterface, DispatchType} from '../Contexts/RtcContext';
|
|
5
4
|
import PropsContext, {ToggleState} from '../Contexts/PropsContext';
|
|
6
5
|
import {Platform} from 'react-native';
|
|
7
6
|
|
|
8
7
|
const Join: React.FC<{
|
|
9
8
|
children: React.ReactNode;
|
|
10
9
|
precall: boolean;
|
|
11
|
-
engineRef: React.MutableRefObject<
|
|
12
|
-
uidState:
|
|
10
|
+
engineRef: React.MutableRefObject<RtcEngine>;
|
|
11
|
+
uidState: RenderStateInterface;
|
|
13
12
|
dispatch: DispatchType;
|
|
14
13
|
tracksReady: boolean;
|
|
15
|
-
preventJoin?: boolean;
|
|
16
14
|
}> = ({children, precall, engineRef, uidState, dispatch, tracksReady}) => {
|
|
17
15
|
let joinState = useRef(false);
|
|
18
16
|
const {rtcProps} = useContext(PropsContext);
|
|
19
|
-
|
|
20
|
-
const audioRoom = rtcProps?.audioRoom || false;
|
|
17
|
+
const {audioRoom = false} = rtcProps;
|
|
21
18
|
//commented for v1 release
|
|
22
19
|
// const beforeJoin = rtcProps?.lifecycle?.useBeforeJoin
|
|
23
20
|
// ? rtcProps.lifecycle.useBeforeJoin()
|
|
@@ -28,14 +25,9 @@ const Join: React.FC<{
|
|
|
28
25
|
//@ts-ignore
|
|
29
26
|
engineRef.current.publish();
|
|
30
27
|
}
|
|
31
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
28
|
}, [tracksReady]);
|
|
33
29
|
|
|
34
30
|
useEffect(() => {
|
|
35
|
-
if (rtcProps?.preventJoin) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
31
|
const engine = engineRef.current;
|
|
40
32
|
async function leave() {
|
|
41
33
|
try {
|
|
@@ -46,26 +38,20 @@ const Join: React.FC<{
|
|
|
46
38
|
console.error('Cannot leave the channel:', err);
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
|
-
const {
|
|
41
|
+
const {renderList, activeUids} = uidState;
|
|
50
42
|
const [maxUid] = activeUids;
|
|
51
|
-
const videoState =
|
|
43
|
+
const videoState = renderList[maxUid].video;
|
|
52
44
|
async function join() {
|
|
53
45
|
if (
|
|
54
|
-
rtcProps
|
|
55
|
-
rtcProps
|
|
56
|
-
rtcProps.encryption.mode
|
|
57
|
-
rtcProps.encryption.salt
|
|
46
|
+
rtcProps.encryption &&
|
|
47
|
+
rtcProps.encryption.key &&
|
|
48
|
+
rtcProps.encryption.mode
|
|
58
49
|
) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
datastreamEncryptionEnabled: true,
|
|
65
|
-
});
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.warn('encryption error', error);
|
|
68
|
-
}
|
|
50
|
+
console.log('using channel encryption', rtcProps.encryption);
|
|
51
|
+
await engine.enableEncryption(true, {
|
|
52
|
+
encryptionKey: rtcProps.encryption.key,
|
|
53
|
+
encryptionMode: rtcProps.encryption.mode,
|
|
54
|
+
});
|
|
69
55
|
}
|
|
70
56
|
if (
|
|
71
57
|
!audioRoom &&
|
|
@@ -90,16 +76,13 @@ const Join: React.FC<{
|
|
|
90
76
|
// } catch (error) {
|
|
91
77
|
// console.error('FPE:Error on executing useBeforeJoin', error);
|
|
92
78
|
// }
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error('RTC joinChannel error', error);
|
|
102
|
-
}
|
|
79
|
+
|
|
80
|
+
await engine.joinChannel(
|
|
81
|
+
rtcProps.token || null,
|
|
82
|
+
rtcProps.channel,
|
|
83
|
+
null,
|
|
84
|
+
rtcProps.uid || 0,
|
|
85
|
+
);
|
|
103
86
|
if (
|
|
104
87
|
!audioRoom &&
|
|
105
88
|
videoState === ToggleState.enabled &&
|
|
@@ -125,7 +108,7 @@ const Join: React.FC<{
|
|
|
125
108
|
await leave();
|
|
126
109
|
await join();
|
|
127
110
|
}
|
|
128
|
-
console.log('Attempted join: ', rtcProps
|
|
111
|
+
console.log('Attempted join: ', rtcProps.channel);
|
|
129
112
|
} else {
|
|
130
113
|
console.log('In precall - waiting to join');
|
|
131
114
|
}
|
|
@@ -136,14 +119,12 @@ const Join: React.FC<{
|
|
|
136
119
|
leave();
|
|
137
120
|
}
|
|
138
121
|
};
|
|
139
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
140
122
|
}, [
|
|
141
|
-
rtcProps
|
|
142
|
-
rtcProps
|
|
143
|
-
rtcProps
|
|
123
|
+
rtcProps.channel,
|
|
124
|
+
rtcProps.uid,
|
|
125
|
+
rtcProps.token,
|
|
144
126
|
precall,
|
|
145
|
-
rtcProps
|
|
146
|
-
rtcProps?.preventJoin,
|
|
127
|
+
rtcProps.encryption,
|
|
147
128
|
]);
|
|
148
129
|
|
|
149
130
|
return <>{children}</>;
|