agora-appbuilder-core 1.0.8 → 2.0.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.
Files changed (134) hide show
  1. package/package.json +5 -2
  2. package/template/_package-lock.json +22850 -0
  3. package/template/agora-rn-uikit/.git/HEAD +1 -0
  4. package/template/agora-rn-uikit/.git/config +16 -0
  5. package/template/agora-rn-uikit/.git/description +1 -0
  6. package/template/agora-rn-uikit/.git/hooks/applypatch-msg.sample +15 -0
  7. package/template/agora-rn-uikit/.git/hooks/commit-msg.sample +24 -0
  8. package/template/agora-rn-uikit/.git/hooks/fsmonitor-watchman.sample +173 -0
  9. package/template/agora-rn-uikit/.git/hooks/post-update.sample +8 -0
  10. package/template/agora-rn-uikit/.git/hooks/pre-applypatch.sample +14 -0
  11. package/template/agora-rn-uikit/.git/hooks/pre-commit.sample +49 -0
  12. package/template/agora-rn-uikit/.git/hooks/pre-merge-commit.sample +13 -0
  13. package/template/agora-rn-uikit/.git/hooks/pre-push.sample +53 -0
  14. package/template/agora-rn-uikit/.git/hooks/pre-rebase.sample +169 -0
  15. package/template/agora-rn-uikit/.git/hooks/pre-receive.sample +24 -0
  16. package/template/agora-rn-uikit/.git/hooks/prepare-commit-msg.sample +42 -0
  17. package/template/agora-rn-uikit/.git/hooks/push-to-checkout.sample +78 -0
  18. package/template/agora-rn-uikit/.git/hooks/update.sample +128 -0
  19. package/template/agora-rn-uikit/.git/index +0 -0
  20. package/template/agora-rn-uikit/.git/info/exclude +6 -0
  21. package/template/agora-rn-uikit/.git/logs/HEAD +2 -0
  22. package/template/agora-rn-uikit/.git/logs/refs/heads/ab-dev-auto +1 -0
  23. package/template/agora-rn-uikit/.git/logs/refs/heads/master +1 -0
  24. package/template/agora-rn-uikit/.git/logs/refs/remotes/origin/HEAD +1 -0
  25. package/template/agora-rn-uikit/.git/objects/pack/pack-f379286d0537eb68377220b4929979324b8d5d1c.idx +0 -0
  26. package/template/agora-rn-uikit/.git/objects/pack/pack-f379286d0537eb68377220b4929979324b8d5d1c.pack +0 -0
  27. package/template/agora-rn-uikit/.git/packed-refs +12 -0
  28. package/template/agora-rn-uikit/.git/refs/heads/ab-dev-auto +1 -0
  29. package/template/agora-rn-uikit/.git/refs/heads/master +1 -0
  30. package/template/agora-rn-uikit/.git/refs/remotes/origin/HEAD +1 -0
  31. package/template/agora-rn-uikit/.gitignore +63 -0
  32. package/template/agora-rn-uikit/package-lock.json +7612 -0
  33. package/template/agora-rn-uikit/package.json +1 -0
  34. package/template/agora-rn-uikit/src/AgoraUIKit.tsx +8 -8
  35. package/template/agora-rn-uikit/src/{LocalUserContext.tsx → Contexts/LocalUserContext.tsx} +1 -1
  36. package/template/agora-rn-uikit/src/{MaxUidContext.tsx → Contexts/MaxUidContext.tsx} +0 -0
  37. package/template/agora-rn-uikit/src/{MinUidContext.tsx → Contexts/MinUidContext.tsx} +0 -0
  38. package/template/agora-rn-uikit/src/{PropsContext.tsx → Contexts/PropsContext.tsx} +34 -16
  39. package/template/agora-rn-uikit/src/{RtcContext.tsx → Contexts/RtcContext.tsx} +12 -21
  40. package/template/agora-rn-uikit/src/Controls/BtnTemplate.tsx +25 -15
  41. package/template/agora-rn-uikit/src/Controls/Icons.ts +53 -3
  42. package/template/agora-rn-uikit/src/Controls/ImageIcon.tsx +53 -0
  43. package/template/agora-rn-uikit/src/Controls/Local/EndCall.tsx +4 -3
  44. package/template/agora-rn-uikit/src/Controls/Local/FullScreen.tsx +3 -3
  45. package/template/agora-rn-uikit/src/Controls/Local/LocalAudioMute.tsx +58 -14
  46. package/template/agora-rn-uikit/src/Controls/Local/LocalVideoMute.tsx +60 -14
  47. package/template/agora-rn-uikit/src/Controls/Local/Recording.tsx +2 -2
  48. package/template/agora-rn-uikit/src/Controls/Local/Screenshare.tsx +2 -2
  49. package/template/agora-rn-uikit/src/Controls/Local/SwitchCamera.tsx +9 -9
  50. package/template/agora-rn-uikit/src/Controls/LocalControls.tsx +20 -17
  51. package/template/agora-rn-uikit/src/Controls/Remote/RemoteAudioMute.tsx +8 -8
  52. package/template/agora-rn-uikit/src/Controls/Remote/RemoteSwap.tsx +3 -3
  53. package/template/agora-rn-uikit/src/Controls/Remote/RemoteVideoMute.tsx +13 -8
  54. package/template/agora-rn-uikit/src/Controls/RemoteControls.tsx +1 -2
  55. package/template/agora-rn-uikit/src/Reducer/LocalMuteAudio.ts +20 -0
  56. package/template/agora-rn-uikit/src/Reducer/LocalMuteVideo.ts +20 -0
  57. package/template/agora-rn-uikit/src/Reducer/RemoteAudioStateChanged.ts +26 -0
  58. package/template/agora-rn-uikit/src/Reducer/RemoteVideoStateChanged.ts +26 -0
  59. package/template/agora-rn-uikit/src/Reducer/UpdateDualStreamMode.ts +46 -0
  60. package/template/agora-rn-uikit/src/Reducer/UserJoined.ts +47 -0
  61. package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteAudio.ts +20 -0
  62. package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteVideo.ts +20 -0
  63. package/template/agora-rn-uikit/src/Reducer/UserOffline.ts +21 -0
  64. package/template/agora-rn-uikit/src/Reducer/index.ts +9 -0
  65. package/template/agora-rn-uikit/src/Rtc/Create.tsx +138 -0
  66. package/template/agora-rn-uikit/src/Rtc/Join.tsx +100 -0
  67. package/template/agora-rn-uikit/src/RtcConfigure.tsx +197 -0
  68. package/template/agora-rn-uikit/src/Style.ts +3 -3
  69. package/template/agora-rn-uikit/src/Utils/actionTypeGuard.tsx +9 -0
  70. package/template/agora-rn-uikit/src/{events.ts → Utils/events.ts} +0 -0
  71. package/template/agora-rn-uikit/src/{permission.ts → Utils/permission.ts} +0 -0
  72. package/template/agora-rn-uikit/src/{quality.tsx → Utils/quality.tsx} +0 -0
  73. package/template/agora-rn-uikit/src/{MaxVideoView.native.tsx → Views/MaxVideoView.native.tsx} +3 -4
  74. package/template/agora-rn-uikit/src/{MaxVideoView.tsx → Views/MaxVideoView.tsx} +3 -4
  75. package/template/agora-rn-uikit/src/Views/MinVideoView.tsx +86 -0
  76. package/template/agora-rn-uikit/src/index.ts +67 -0
  77. package/template/bridge/rtc/webNg/RtcEngine.ts +23 -6
  78. package/template/package-lock.json +22850 -0
  79. package/template/package.json +6 -4
  80. package/template/react-native-toast-message/.gitignore +5 -0
  81. package/template/react-native-toast-message/.npmignore +5 -0
  82. package/template/react-native-toast-message/package-lock.json +10553 -0
  83. package/template/src/.DS_Store +0 -0
  84. package/template/src/assets/icons.ts +35 -6
  85. package/template/src/atoms/SecondaryButton.tsx +6 -5
  86. package/template/src/atoms/TextInput.tsx +6 -1
  87. package/template/src/components/Chat.tsx +50 -21
  88. package/template/src/components/ChatContext.ts +22 -1
  89. package/template/src/components/Controls.native.tsx +2 -2
  90. package/template/src/components/Controls.tsx +2 -2
  91. package/template/src/components/DeviceConfigure.tsx +1 -1
  92. package/template/src/components/GridVideo.tsx +69 -31
  93. package/template/src/components/Navbar.tsx +136 -113
  94. package/template/src/components/NetworkQualityContext.tsx +134 -0
  95. package/template/src/components/ParticipantsView.tsx +105 -49
  96. package/template/src/components/PinnedVideo.tsx +112 -71
  97. package/template/src/components/Precall.native.tsx +42 -23
  98. package/template/src/components/Precall.tsx +56 -51
  99. package/template/src/components/RTMConfigure.tsx +331 -181
  100. package/template/src/components/RTMEvents.tsx +84 -0
  101. package/template/src/components/Settings.tsx +19 -16
  102. package/template/src/components/Share.tsx +131 -62
  103. package/template/src/components/StorageContext.tsx +2 -0
  104. package/template/src/hooks/useImageDelay.tsx +28 -0
  105. package/template/src/pages/Authenticate.tsx +5 -4
  106. package/template/src/pages/Create.tsx +26 -16
  107. package/template/src/pages/Join.tsx +13 -30
  108. package/template/src/pages/VideoCall.tsx +181 -137
  109. package/template/src/subComponents/.DS_Store +0 -0
  110. package/template/src/subComponents/ChatContainer.tsx +40 -28
  111. package/template/src/subComponents/CopyJoinInfo.tsx +9 -12
  112. package/template/src/subComponents/LocalAudioMute.tsx +9 -9
  113. package/template/src/subComponents/LocalVideoMute.tsx +9 -9
  114. package/template/src/subComponents/LogoutButton.tsx +1 -1
  115. package/template/src/subComponents/NetworkQualityPill.tsx +161 -0
  116. package/template/src/subComponents/Recording.tsx +12 -16
  117. package/template/src/subComponents/RemoteAudioMute.tsx +23 -27
  118. package/template/src/subComponents/RemoteEndCall.tsx +7 -15
  119. package/template/src/subComponents/RemoteVideoMute.tsx +15 -28
  120. package/template/src/subComponents/ScreenShareNotice.tsx +61 -0
  121. package/template/src/subComponents/ScreenshareButton.tsx +76 -75
  122. package/template/src/subComponents/SelectOAuth.tsx +25 -12
  123. package/template/src/subComponents/SwitchCamera.tsx +5 -2
  124. package/template/src/subComponents/TextWithTooltip.native.tsx +128 -0
  125. package/template/src/subComponents/TextWithTooltip.tsx +44 -0
  126. package/template/src/subComponents/toastConfig.tsx +2 -2
  127. package/template/src/utils/hasBrandLogo.tsx +3 -0
  128. package/template/src/utils/isSafariBrowser.tsx +22 -0
  129. package/template/webpack.commons.js +1 -0
  130. package/template/agora-rn-uikit/Components.js +0 -35
  131. package/template/agora-rn-uikit/Contexts.js +0 -7
  132. package/template/agora-rn-uikit/index.js +0 -12
  133. package/template/agora-rn-uikit/src/MinVideoView.tsx +0 -87
  134. package/template/agora-rn-uikit/src/RTCConfigure.tsx +0 -516
@@ -1,87 +0,0 @@
1
- import React, { useState, useContext } from 'react';
2
- import { View, TouchableOpacity, Image } from 'react-native';
3
- import { RtcLocalView, RtcRemoteView, VideoRenderMode } from 'react-native-agora';
4
- import styles from './Style';
5
- import icons from './Controls/Icons';
6
- import RemoteControls from './Controls/RemoteControls';
7
- import PropsContext from './PropsContext';
8
- import {UidInterface} from './RtcContext';
9
-
10
- const LocalView = RtcLocalView.SurfaceView;
11
- const RemoteView = RtcRemoteView.SurfaceView;
12
-
13
- interface MinViewInterface {
14
- user: UidInterface;
15
- color?: string;
16
- showOverlay?: boolean;
17
- }
18
-
19
- const MinVideoView: React.FC<MinViewInterface> = (props) => {
20
- const [overlay, setOverlay] = useState(false);
21
- const { styleProps } = useContext(PropsContext);
22
- const { minViewStyles, theme, remoteBtnStyles } = styleProps || {};
23
- const { minCloseBtnStyles } = remoteBtnStyles || {};
24
- const { showOverlay } = props || {};
25
-
26
- return (
27
- <View style={{ margin: 5 }}>
28
- {overlay && showOverlay ?
29
- <TouchableOpacity onPress={() => setOverlay(true)}>
30
- {props.user.uid === 'local' ? (
31
- props.user.video ? (
32
- <LocalView
33
- style={{ ...styles.minView, ...(minViewStyles as object) }}
34
- renderMode={VideoRenderMode.Hidden}
35
- zOrderMediaOverlay={true}
36
- />
37
- ) : (
38
- <View style={{flex: 1, backgroundColor: '#000'}} />
39
- )
40
- ) : (
41
- <RemoteView
42
- style={{ ...styles.minView, ...(minViewStyles as object) }}
43
- uid={props.user.uid as number}
44
- renderMode={VideoRenderMode.Hidden}
45
- zOrderMediaOverlay={true}
46
- />
47
- )}
48
- </TouchableOpacity>
49
- : props.user.uid === 'local' ? (
50
- <LocalView
51
- style={{ ...styles.minView, ...(minViewStyles as object) }}
52
- renderMode={VideoRenderMode.Hidden}
53
- zOrderMediaOverlay={true}
54
- />
55
- ) : (
56
- <RemoteView
57
- style={{ ...styles.minView, ...(minViewStyles as object) }}
58
- uid={props.user.uid as number}
59
- renderMode={VideoRenderMode.Hidden}
60
- zOrderMediaOverlay={true}
61
- />
62
- )}
63
-
64
- {overlay && showOverlay ? (
65
- <View style={styles.minOverlay}>
66
- <TouchableOpacity
67
- style={{ ...styles.minCloseBtn, ...(minCloseBtnStyles as object) }}
68
- onPress={() => setOverlay(!overlay)}>
69
- <Image
70
- style={{
71
- width: 25,
72
- height: 25,
73
- tintColor: theme || props.color || '#fff',
74
- }}
75
- source={{ uri: icons.close }}
76
- />
77
- </TouchableOpacity>
78
- <RemoteControls showRemoteSwap={true} user={props.user} />
79
- </View>
80
- ) : (
81
- <></>
82
- )}
83
- </View>
84
- );
85
- };
86
-
87
- export default MinVideoView;
@@ -1,516 +0,0 @@
1
- import React, {
2
- useState,
3
- useEffect,
4
- useReducer,
5
- useContext,
6
- useRef,
7
- useCallback,
8
- useDebugValue,
9
- } from 'react';
10
- import RtcEngine, {
11
- VideoEncoderConfiguration,
12
- AreaCode,
13
- } from 'react-native-agora';
14
- import {Platform} from 'react-native';
15
- import requestCameraAndAudioPermission from './permission';
16
- import {
17
- RtcProvider,
18
- UidInterface,
19
- UidStateInterface,
20
- DispatchType,
21
- ActionInterface,
22
- ActionType,
23
- } from './RtcContext';
24
- import PropsContext, {
25
- RtcPropsInterface,
26
- CallbacksInterface,
27
- DualStreamMode,
28
- } from './PropsContext';
29
- import {MinUidProvider} from './MinUidContext';
30
- import {MaxUidProvider} from './MaxUidContext';
31
- import quality from './quality';
32
-
33
- const initialState: UidStateInterface = {
34
- min: [],
35
- max: [
36
- {
37
- uid: 'local',
38
- audio: true,
39
- video: true,
40
- streamType: 'high',
41
- },
42
- ],
43
- };
44
-
45
- const RtcConfigure: React.FC<Partial<RtcPropsInterface>> = (props) => {
46
- const [ready, setReady] = useState<boolean>(false);
47
- useDebugValue(ready, (ready) => `ready to join ${String(ready)}`);
48
- let joinRes: ((arg0: boolean) => void) | null = null;
49
- let canJoin = useRef(new Promise<boolean | void>((res) => (joinRes = res)));
50
- const {callbacks, rtcProps} = useContext(PropsContext);
51
- let engine = useRef<RtcEngine | null>(null);
52
- let [dualStreamMode, setDualStreamMode] = useState<DualStreamMode>(
53
- rtcProps.initialDualStreamMode || DualStreamMode.DYNAMIC,
54
- );
55
- let {callActive} = props;
56
- callActive === undefined ? (callActive = true) : {};
57
-
58
- const reducer = (
59
- state: UidStateInterface,
60
- action: ActionInterface<keyof CallbacksInterface, CallbacksInterface>,
61
- ) => {
62
- let stateUpdate = {},
63
- uids = [...state.max, ...state.min].map((u: UidInterface) => u.uid);
64
-
65
- switch (action.type) {
66
- case 'UpdateDualStreamMode':
67
- const newMode = (action as ActionType<'UpdateDualStreamMode'>).value[0];
68
- if (newMode === DualStreamMode.HIGH) {
69
- const maxStateUpdate: UidInterface[] = state.max.map((user) => ({
70
- ...user,
71
- streamType: 'high',
72
- }));
73
- const minStateUpdate: UidInterface[] = state.min.map((user) => ({
74
- ...user,
75
- streamType: 'high',
76
- }));
77
- stateUpdate = {min: minStateUpdate, max: maxStateUpdate};
78
- }
79
- if (newMode === DualStreamMode.LOW) {
80
- const maxStateUpdate: UidInterface[] = state.max.map((user) => ({
81
- ...user,
82
- streamType: 'low',
83
- }));
84
- const minStateUpdate: UidInterface[] = state.min.map((user) => ({
85
- ...user,
86
- streamType: 'low',
87
- }));
88
- stateUpdate = {min: minStateUpdate, max: maxStateUpdate};
89
- }
90
- if (newMode === DualStreamMode.DYNAMIC) {
91
- const maxStateUpdate: UidInterface[] = state.max.map((user) => ({
92
- ...user,
93
- streamType: 'high',
94
- }));
95
- const minStateUpdate: UidInterface[] = state.min.map((user) => ({
96
- ...user,
97
- streamType: 'low',
98
- }));
99
- stateUpdate = {min: minStateUpdate, max: maxStateUpdate};
100
- }
101
- break;
102
- case 'UserJoined':
103
- if (
104
- uids.indexOf((action as ActionType<'UserJoined'>).value[0]) === -1
105
- ) {
106
- //If new user has joined
107
-
108
- let minUpdate = [
109
- ...state.min,
110
- {
111
- uid: (action as ActionType<'UserJoined'>).value[0],
112
- audio: false,
113
- video: false,
114
- streamType:
115
- dualStreamMode === DualStreamMode.HIGH ? 'high' : 'low', // Low if DualStreamMode is LOW or DYNAMIC by default
116
- },
117
- ]; //By default add to minimized
118
-
119
- if (minUpdate.length === 1 && state.max[0].uid === 'local') {
120
- //Only one remote and local is maximized
121
- //Change stream type to high if dualStreaMode is DYNAMIC
122
- if (dualStreamMode === DualStreamMode.DYNAMIC) {
123
- minUpdate[0].streamType = 'high';
124
- }
125
- //Swap max and min
126
- stateUpdate = {
127
- max: minUpdate,
128
- min: state.max,
129
- };
130
- } else {
131
- //More than one remote
132
- stateUpdate = {
133
- min: minUpdate,
134
- };
135
- }
136
-
137
- console.log('new user joined!\n', state, stateUpdate, {
138
- dualStreamMode,
139
- });
140
- }
141
- break;
142
- case 'UserOffline':
143
- if (
144
- state.max[0].uid === (action as ActionType<'UserOffline'>).value[0]
145
- ) {
146
- //If max has the remote video
147
- let minUpdate = [...state.min];
148
- stateUpdate = {
149
- max: [minUpdate.pop()],
150
- min: minUpdate,
151
- };
152
- } else {
153
- stateUpdate = {
154
- min: state.min.filter(
155
- (user) =>
156
- user.uid !== (action as ActionType<'UserOffline'>).value[0],
157
- ),
158
- };
159
- }
160
- break;
161
- case 'SwapVideo':
162
- stateUpdate = swapVideo(state, action.value[0] as UidInterface);
163
- break;
164
- case 'UserMuteRemoteAudio':
165
- const audioMute = (user: UidInterface) => {
166
- if (user.uid === (action.value[0] as UidInterface).uid) {
167
- user.audio = !action.value[1];
168
- }
169
- return user;
170
- };
171
- stateUpdate = {
172
- min: state.min.map(audioMute),
173
- max: state.max.map(audioMute),
174
- };
175
- break;
176
- case 'UserMuteRemoteVideo':
177
- const videoMute = (user: UidInterface) => {
178
- if (user.uid === (action.value[0] as UidInterface).uid) {
179
- user.video = !action.value[1];
180
- }
181
- return user;
182
- };
183
- stateUpdate = {
184
- min: state.min.map(videoMute),
185
- max: state.max.map(videoMute),
186
- };
187
- break;
188
- case 'LocalMuteAudio':
189
- (engine.current as RtcEngine).muteLocalAudioStream(
190
- (action as ActionType<'LocalMuteAudio'>).value[0],
191
- );
192
- const LocalAudioMute = (user: UidInterface) => {
193
- if (user.uid === 'local') {
194
- user.audio = !(action as ActionType<'LocalMuteAudio'>).value[0];
195
- }
196
- return user;
197
- };
198
- stateUpdate = {
199
- min: state.min.map(LocalAudioMute),
200
- max: state.max.map(LocalAudioMute),
201
- };
202
- break;
203
- case 'LocalMuteVideo':
204
- (engine.current as RtcEngine).muteLocalVideoStream(
205
- (action as ActionType<'LocalMuteAudio'>).value[0],
206
- );
207
- const LocalVideoMute = (user: UidInterface) => {
208
- if (user.uid === 'local') {
209
- user.video = !(action as ActionType<'LocalMuteVideo'>).value[0];
210
- }
211
- return user;
212
- };
213
- stateUpdate = {
214
- min: state.min.map(LocalVideoMute),
215
- max: state.max.map(LocalVideoMute),
216
- };
217
- break;
218
- case 'SwitchCamera':
219
- (engine.current as RtcEngine).switchCamera();
220
- break;
221
- case 'RemoteAudioStateChanged':
222
- let audioState;
223
- if (action.value[1] === 0) {
224
- audioState = false;
225
- } else if (action.value[1] === 2) {
226
- audioState = true;
227
- }
228
- const audioChange = (user: UidInterface) => {
229
- if (user.uid == action.value[0]) {
230
- user.audio = audioState;
231
- user.video = user.video;
232
- }
233
- return user;
234
- };
235
- stateUpdate = {
236
- min: state.min.map(audioChange),
237
- max: state.max.map(audioChange),
238
- };
239
- break;
240
- case 'RemoteVideoStateChanged':
241
- let videoState;
242
- let logx = action.value;
243
- if (action.value[1] === 0) {
244
- videoState = false;
245
- } else if (action.value[1] === 2) {
246
- videoState = true;
247
- }
248
- const videoChange = (user: UidInterface) => {
249
- if (user.uid == action.value[0]) {
250
- user.video = videoState;
251
- user.audio = user.audio;
252
- }
253
- return user;
254
- };
255
- stateUpdate = {
256
- min: state.min.map(videoChange),
257
- max: state.max.map(videoChange),
258
- };
259
- break;
260
- }
261
-
262
- // Handle event listeners
263
-
264
- if (callbacks && callbacks[action.type]) {
265
- // @ts-ignore
266
- callbacks[action.type].apply(null, action.value);
267
- console.log('callback executed');
268
- } else {
269
- // console.log('callback not found', action.type);
270
- }
271
-
272
- // console.log(state, action, stateUpdate);
273
-
274
- return {
275
- ...state,
276
- ...stateUpdate,
277
- };
278
- };
279
-
280
- const swapVideo = useCallback(
281
- (state: UidStateInterface, ele: UidInterface) => {
282
- let newState: UidStateInterface = {
283
- min: [],
284
- max: [],
285
- };
286
- // Remove the minimized element which is being swapped out
287
- newState.min = state.min.filter((e) => e !== ele);
288
-
289
- let maxEle = state.max[0]; // Element which is currently maximized
290
- let minEle = ele;
291
-
292
- if (dualStreamMode === DualStreamMode.DYNAMIC) {
293
- maxEle.streamType = 'low'; // set stream quality to low
294
- minEle.streamType = 'high'; // set stream quality to high
295
-
296
- // No need to modify the streamType if the mode is not dynamic
297
- }
298
-
299
- if (maxEle.uid === 'local') {
300
- newState.min.unshift(maxEle);
301
- } else {
302
- newState.min.push(maxEle);
303
- }
304
- newState.max = [minEle];
305
-
306
- return newState;
307
- },
308
- [dualStreamMode],
309
- );
310
- const [uidState, dispatch] = useReducer(reducer, initialState);
311
-
312
- // When mode is updated, reducer is triggered to update the individual states
313
- useEffect(() => {
314
- (dispatch as DispatchType<'UpdateDualStreamMode'>)({
315
- type: 'UpdateDualStreamMode',
316
- value: [dualStreamMode],
317
- });
318
- }, [dualStreamMode]);
319
-
320
- // useEffect(() => {
321
- // const setStreamType = (user: UidInterface) => {
322
- // if (user.uid !== 'local') {
323
- // engine.current?.setRemoteVideoStreamType(
324
- // user.uid as number,
325
- // user.streamType === 'high' ? 0 : 1,
326
- // );
327
- // }
328
- // };
329
- // uidState.max.map(setStreamType);
330
- // uidState.min.map(setStreamType);
331
- // }, [uidState.min, uidState.max]);
332
-
333
- useEffect(() => {
334
- async function init() {
335
- if (Platform.OS === 'android') {
336
- //Request required permissions from Android
337
- await requestCameraAndAudioPermission();
338
- }
339
- try {
340
- if (Platform.OS === 'android' || Platform.OS === 'ios') {
341
- engine.current = await RtcEngine.createWithAreaCode(
342
- rtcProps.appId,
343
- AreaCode.GLOB ^ AreaCode.CN,
344
- );
345
- } else {
346
- engine.current = await RtcEngine.create(rtcProps.appId);
347
- }
348
- console.log(engine.current);
349
- if (rtcProps.profile) {
350
- if (Platform.OS === 'web') {
351
- // @ts-ignore
352
- await engine.current.setVideoProfile(rtcProps.profile);
353
- } else {
354
- const config: VideoEncoderConfiguration = quality[rtcProps.profile];
355
- await engine.current.setVideoEncoderConfiguration({
356
- ...config,
357
- bitrate: 0,
358
- });
359
- }
360
- }
361
- try {
362
- await engine.current.enableVideo();
363
- } catch (e) {
364
- (dispatch as DispatchType<'LocalMuteAudio'>)({
365
- type: 'LocalMuteAudio',
366
- value: [true],
367
- });
368
- (dispatch as DispatchType<'LocalMuteVideo'>)({
369
- type: 'LocalMuteVideo',
370
- value: [true],
371
- });
372
- console.error('No devices', e);
373
- }
374
-
375
- engine.current.addListener('JoinChannelSuccess', async (...args) => {
376
- //Get current peer IDs
377
- (dispatch as DispatchType<'JoinChannelSuccess'>)({
378
- type: 'JoinChannelSuccess',
379
- value: args,
380
- });
381
-
382
- console.log('UIkit enabling dual stream', rtcProps.dual);
383
- if (rtcProps.dual) {
384
- console.log('UIkit enabled dual stream');
385
- await engine.current.enableDualStreamMode(rtcProps.dual);
386
- // await engine.current.setRemoteSubscribeFallbackOption(1);
387
- }
388
- });
389
-
390
- engine.current.addListener('UserJoined', (...args) => {
391
- //Get current peer IDs
392
- (dispatch as DispatchType<'UserJoined'>)({
393
- type: 'UserJoined',
394
- value: args,
395
- });
396
- });
397
-
398
- engine.current.addListener('UserOffline', (...args) => {
399
- //If user leaves
400
- (dispatch as DispatchType<'UserOffline'>)({
401
- type: 'UserOffline',
402
- value: args,
403
- });
404
- });
405
-
406
- engine.current.addListener('RemoteAudioStateChanged', (...args) => {
407
- console.log('RemoteAudioStateChanged', args);
408
-
409
- (dispatch as DispatchType<'RemoteAudioStateChanged'>)({
410
- type: 'RemoteAudioStateChanged',
411
- value: args,
412
- });
413
- });
414
-
415
- engine.current.addListener('Error', (e) => {
416
- console.log('Error: ', e);
417
- });
418
-
419
- engine.current.addListener('RemoteVideoStateChanged', (...args) => {
420
- console.log('RemoteVideoStateChanged', args);
421
-
422
- dispatch({
423
- type: 'RemoteVideoStateChanged',
424
- value: args,
425
- });
426
- });
427
-
428
- (joinRes as (arg0: boolean) => void)(true);
429
- setReady(true);
430
- } catch (e) {
431
- console.error(e);
432
- }
433
- }
434
-
435
- if (joinRes) {
436
- init();
437
- return () => {
438
- (engine.current as RtcEngine).destroy();
439
- };
440
- }
441
- // eslint-disable-next-line react-hooks/exhaustive-deps
442
- }, [rtcProps.appId]);
443
-
444
- // Dynamically switches channel when channel prop changes
445
- useEffect(() => {
446
- async function join() {
447
- await canJoin.current;
448
- if (
449
- engine.current &&
450
- rtcProps.encryption &&
451
- rtcProps.encryption.key &&
452
- rtcProps.encryption.mode
453
- ) {
454
- console.log('using channel encryption', rtcProps.encryption);
455
- // await engine.current.setEncryptionSecret(rtcProps.encryption.key);
456
- // await engine.current.setEncryptionMode(rtcProps.encryption.mode);
457
- await engine.current.enableEncryption(true, {
458
- encryptionKey: rtcProps.encryption.key,
459
- encryptionMode: rtcProps.encryption.mode,
460
- });
461
- }
462
- if (engine.current) {
463
- if(uidState.max[0].video){
464
- await engine.current.muteLocalVideoStream(true);
465
- }
466
-
467
- await engine.current.joinChannel(
468
- rtcProps.token || null,
469
- rtcProps.channel,
470
- null,
471
- rtcProps.uid || 0,
472
- );
473
- if(uidState.max[0].video){
474
- await engine.current.muteLocalVideoStream(false);
475
- }
476
-
477
- } else {
478
- console.error('trying to join before RTC Engine was initialized');
479
- }
480
- }
481
- if (callActive) {
482
- join();
483
- console.log('Attempted join: ', rtcProps.channel);
484
- } else {
485
- console.log('In precall - waiting to join');
486
- }
487
- return () => {
488
- if (callActive) {
489
- console.log('Leaving channel');
490
- canJoin.current = (engine.current as RtcEngine)
491
- .leaveChannel()
492
- .catch((err: any) => console.log(err));
493
- }
494
- };
495
- }, [rtcProps.channel, rtcProps.uid, rtcProps.token, callActive]);
496
-
497
- return (
498
- <RtcProvider
499
- value={{
500
- RtcEngine: engine.current as RtcEngine,
501
- dispatch,
502
- setDualStreamMode,
503
- }}>
504
- <MaxUidProvider value={uidState.max}>
505
- <MinUidProvider value={uidState.min}>
506
- {
507
- // Render children once RTCEngine has been initialized
508
- ready ? props.children : <></>
509
- }
510
- </MinUidProvider>
511
- </MaxUidProvider>
512
- </RtcProvider>
513
- );
514
- };
515
-
516
- export default RtcConfigure;