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.
- package/package.json +5 -2
- package/template/_package-lock.json +22850 -0
- package/template/agora-rn-uikit/.git/HEAD +1 -0
- package/template/agora-rn-uikit/.git/config +16 -0
- package/template/agora-rn-uikit/.git/description +1 -0
- package/template/agora-rn-uikit/.git/hooks/applypatch-msg.sample +15 -0
- package/template/agora-rn-uikit/.git/hooks/commit-msg.sample +24 -0
- package/template/agora-rn-uikit/.git/hooks/fsmonitor-watchman.sample +173 -0
- package/template/agora-rn-uikit/.git/hooks/post-update.sample +8 -0
- package/template/agora-rn-uikit/.git/hooks/pre-applypatch.sample +14 -0
- package/template/agora-rn-uikit/.git/hooks/pre-commit.sample +49 -0
- package/template/agora-rn-uikit/.git/hooks/pre-merge-commit.sample +13 -0
- package/template/agora-rn-uikit/.git/hooks/pre-push.sample +53 -0
- package/template/agora-rn-uikit/.git/hooks/pre-rebase.sample +169 -0
- package/template/agora-rn-uikit/.git/hooks/pre-receive.sample +24 -0
- package/template/agora-rn-uikit/.git/hooks/prepare-commit-msg.sample +42 -0
- package/template/agora-rn-uikit/.git/hooks/push-to-checkout.sample +78 -0
- package/template/agora-rn-uikit/.git/hooks/update.sample +128 -0
- package/template/agora-rn-uikit/.git/index +0 -0
- package/template/agora-rn-uikit/.git/info/exclude +6 -0
- package/template/agora-rn-uikit/.git/logs/HEAD +2 -0
- package/template/agora-rn-uikit/.git/logs/refs/heads/ab-dev-auto +1 -0
- package/template/agora-rn-uikit/.git/logs/refs/heads/master +1 -0
- package/template/agora-rn-uikit/.git/logs/refs/remotes/origin/HEAD +1 -0
- package/template/agora-rn-uikit/.git/objects/pack/pack-f379286d0537eb68377220b4929979324b8d5d1c.idx +0 -0
- package/template/agora-rn-uikit/.git/objects/pack/pack-f379286d0537eb68377220b4929979324b8d5d1c.pack +0 -0
- package/template/agora-rn-uikit/.git/packed-refs +12 -0
- package/template/agora-rn-uikit/.git/refs/heads/ab-dev-auto +1 -0
- package/template/agora-rn-uikit/.git/refs/heads/master +1 -0
- package/template/agora-rn-uikit/.git/refs/remotes/origin/HEAD +1 -0
- package/template/agora-rn-uikit/.gitignore +63 -0
- package/template/agora-rn-uikit/package-lock.json +7612 -0
- package/template/agora-rn-uikit/package.json +1 -0
- package/template/agora-rn-uikit/src/AgoraUIKit.tsx +8 -8
- package/template/agora-rn-uikit/src/{LocalUserContext.tsx → Contexts/LocalUserContext.tsx} +1 -1
- package/template/agora-rn-uikit/src/{MaxUidContext.tsx → Contexts/MaxUidContext.tsx} +0 -0
- package/template/agora-rn-uikit/src/{MinUidContext.tsx → Contexts/MinUidContext.tsx} +0 -0
- package/template/agora-rn-uikit/src/{PropsContext.tsx → Contexts/PropsContext.tsx} +34 -16
- package/template/agora-rn-uikit/src/{RtcContext.tsx → Contexts/RtcContext.tsx} +12 -21
- package/template/agora-rn-uikit/src/Controls/BtnTemplate.tsx +25 -15
- package/template/agora-rn-uikit/src/Controls/Icons.ts +53 -3
- package/template/agora-rn-uikit/src/Controls/ImageIcon.tsx +53 -0
- package/template/agora-rn-uikit/src/Controls/Local/EndCall.tsx +4 -3
- package/template/agora-rn-uikit/src/Controls/Local/FullScreen.tsx +3 -3
- package/template/agora-rn-uikit/src/Controls/Local/LocalAudioMute.tsx +58 -14
- package/template/agora-rn-uikit/src/Controls/Local/LocalVideoMute.tsx +60 -14
- package/template/agora-rn-uikit/src/Controls/Local/Recording.tsx +2 -2
- package/template/agora-rn-uikit/src/Controls/Local/Screenshare.tsx +2 -2
- package/template/agora-rn-uikit/src/Controls/Local/SwitchCamera.tsx +9 -9
- package/template/agora-rn-uikit/src/Controls/LocalControls.tsx +20 -17
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteAudioMute.tsx +8 -8
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteSwap.tsx +3 -3
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteVideoMute.tsx +13 -8
- package/template/agora-rn-uikit/src/Controls/RemoteControls.tsx +1 -2
- package/template/agora-rn-uikit/src/Reducer/LocalMuteAudio.ts +20 -0
- package/template/agora-rn-uikit/src/Reducer/LocalMuteVideo.ts +20 -0
- package/template/agora-rn-uikit/src/Reducer/RemoteAudioStateChanged.ts +26 -0
- package/template/agora-rn-uikit/src/Reducer/RemoteVideoStateChanged.ts +26 -0
- package/template/agora-rn-uikit/src/Reducer/UpdateDualStreamMode.ts +46 -0
- package/template/agora-rn-uikit/src/Reducer/UserJoined.ts +47 -0
- package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteAudio.ts +20 -0
- package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteVideo.ts +20 -0
- package/template/agora-rn-uikit/src/Reducer/UserOffline.ts +21 -0
- package/template/agora-rn-uikit/src/Reducer/index.ts +9 -0
- package/template/agora-rn-uikit/src/Rtc/Create.tsx +138 -0
- package/template/agora-rn-uikit/src/Rtc/Join.tsx +100 -0
- package/template/agora-rn-uikit/src/RtcConfigure.tsx +197 -0
- package/template/agora-rn-uikit/src/Style.ts +3 -3
- package/template/agora-rn-uikit/src/Utils/actionTypeGuard.tsx +9 -0
- package/template/agora-rn-uikit/src/{events.ts → Utils/events.ts} +0 -0
- package/template/agora-rn-uikit/src/{permission.ts → Utils/permission.ts} +0 -0
- package/template/agora-rn-uikit/src/{quality.tsx → Utils/quality.tsx} +0 -0
- package/template/agora-rn-uikit/src/{MaxVideoView.native.tsx → Views/MaxVideoView.native.tsx} +3 -4
- package/template/agora-rn-uikit/src/{MaxVideoView.tsx → Views/MaxVideoView.tsx} +3 -4
- package/template/agora-rn-uikit/src/Views/MinVideoView.tsx +86 -0
- package/template/agora-rn-uikit/src/index.ts +67 -0
- package/template/bridge/rtc/webNg/RtcEngine.ts +23 -6
- package/template/package-lock.json +22850 -0
- package/template/package.json +6 -4
- package/template/react-native-toast-message/.gitignore +5 -0
- package/template/react-native-toast-message/.npmignore +5 -0
- package/template/react-native-toast-message/package-lock.json +10553 -0
- package/template/src/.DS_Store +0 -0
- package/template/src/assets/icons.ts +35 -6
- package/template/src/atoms/SecondaryButton.tsx +6 -5
- package/template/src/atoms/TextInput.tsx +6 -1
- package/template/src/components/Chat.tsx +50 -21
- package/template/src/components/ChatContext.ts +22 -1
- package/template/src/components/Controls.native.tsx +2 -2
- package/template/src/components/Controls.tsx +2 -2
- package/template/src/components/DeviceConfigure.tsx +1 -1
- package/template/src/components/GridVideo.tsx +69 -31
- package/template/src/components/Navbar.tsx +136 -113
- package/template/src/components/NetworkQualityContext.tsx +134 -0
- package/template/src/components/ParticipantsView.tsx +105 -49
- package/template/src/components/PinnedVideo.tsx +112 -71
- package/template/src/components/Precall.native.tsx +42 -23
- package/template/src/components/Precall.tsx +56 -51
- package/template/src/components/RTMConfigure.tsx +331 -181
- package/template/src/components/RTMEvents.tsx +84 -0
- package/template/src/components/Settings.tsx +19 -16
- package/template/src/components/Share.tsx +131 -62
- package/template/src/components/StorageContext.tsx +2 -0
- package/template/src/hooks/useImageDelay.tsx +28 -0
- package/template/src/pages/Authenticate.tsx +5 -4
- package/template/src/pages/Create.tsx +26 -16
- package/template/src/pages/Join.tsx +13 -30
- package/template/src/pages/VideoCall.tsx +181 -137
- package/template/src/subComponents/.DS_Store +0 -0
- package/template/src/subComponents/ChatContainer.tsx +40 -28
- package/template/src/subComponents/CopyJoinInfo.tsx +9 -12
- package/template/src/subComponents/LocalAudioMute.tsx +9 -9
- package/template/src/subComponents/LocalVideoMute.tsx +9 -9
- package/template/src/subComponents/LogoutButton.tsx +1 -1
- package/template/src/subComponents/NetworkQualityPill.tsx +161 -0
- package/template/src/subComponents/Recording.tsx +12 -16
- package/template/src/subComponents/RemoteAudioMute.tsx +23 -27
- package/template/src/subComponents/RemoteEndCall.tsx +7 -15
- package/template/src/subComponents/RemoteVideoMute.tsx +15 -28
- package/template/src/subComponents/ScreenShareNotice.tsx +61 -0
- package/template/src/subComponents/ScreenshareButton.tsx +76 -75
- package/template/src/subComponents/SelectOAuth.tsx +25 -12
- package/template/src/subComponents/SwitchCamera.tsx +5 -2
- package/template/src/subComponents/TextWithTooltip.native.tsx +128 -0
- package/template/src/subComponents/TextWithTooltip.tsx +44 -0
- package/template/src/subComponents/toastConfig.tsx +2 -2
- package/template/src/utils/hasBrandLogo.tsx +3 -0
- package/template/src/utils/isSafariBrowser.tsx +22 -0
- package/template/webpack.commons.js +1 -0
- package/template/agora-rn-uikit/Components.js +0 -35
- package/template/agora-rn-uikit/Contexts.js +0 -7
- package/template/agora-rn-uikit/index.js +0 -12
- package/template/agora-rn-uikit/src/MinVideoView.tsx +0 -87
- package/template/agora-rn-uikit/src/RTCConfigure.tsx +0 -516
|
@@ -11,43 +11,73 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import React, {useState, useContext, useEffect, useRef} from 'react';
|
|
13
13
|
import RtmEngine from 'agora-react-native-rtm';
|
|
14
|
-
import PropsContext from '../../agora-rn-uikit
|
|
14
|
+
import {PropsContext} from '../../agora-rn-uikit';
|
|
15
15
|
import ChatContext, {controlMessageEnum} from './ChatContext';
|
|
16
|
-
import RtcContext from '../../agora-rn-uikit
|
|
17
|
-
import {
|
|
16
|
+
import {RtcContext} from '../../agora-rn-uikit';
|
|
17
|
+
import {
|
|
18
|
+
messageStoreInterface,
|
|
19
|
+
messageChannelType,
|
|
20
|
+
messageSourceType,
|
|
21
|
+
messageActionType,
|
|
22
|
+
} from './ChatContext';
|
|
18
23
|
import {Platform} from 'react-native';
|
|
19
24
|
import {backOff} from 'exponential-backoff';
|
|
20
|
-
|
|
21
|
-
export enum mType {
|
|
22
|
-
Control = '0',
|
|
23
|
-
Normal = '1',
|
|
24
|
-
}
|
|
25
|
+
import events from './RTMEvents';
|
|
25
26
|
|
|
26
27
|
export enum UserType {
|
|
27
28
|
Normal,
|
|
28
29
|
ScreenShare,
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
const adjustUID = (number: number) => {
|
|
33
|
+
if (number < 0) {
|
|
34
|
+
number = 0xffffffff + number + 1;
|
|
35
|
+
}
|
|
36
|
+
return number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const stringifyPayload = (
|
|
40
|
+
source: messageSourceType,
|
|
41
|
+
type: messageActionType,
|
|
42
|
+
msg: string,
|
|
43
|
+
) => {
|
|
44
|
+
return JSON.stringify({
|
|
45
|
+
source,
|
|
46
|
+
type,
|
|
47
|
+
msg,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const parsePayload = (data: string) => {
|
|
52
|
+
return JSON.parse(data);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const timeNow = () => new Date().getTime();
|
|
56
|
+
|
|
31
57
|
const RtmConfigure = (props: any) => {
|
|
32
58
|
const {setRecordingActive, callActive, name} = props;
|
|
33
59
|
const {rtcProps} = useContext(PropsContext);
|
|
34
|
-
const {dispatch} = useContext(RtcContext);
|
|
60
|
+
const {RtcEngine, dispatch} = useContext(RtcContext);
|
|
35
61
|
const [messageStore, setMessageStore] = useState<messageStoreInterface[]>([]);
|
|
36
62
|
const [privateMessageStore, setPrivateMessageStore] = useState({});
|
|
37
63
|
const [login, setLogin] = useState<boolean>(false);
|
|
38
|
-
const [userList, setUserList] = useState({});
|
|
64
|
+
const [userList, setUserList] = useState<{[key: string]: any}>({});
|
|
39
65
|
let engine = useRef<RtmEngine>(null!);
|
|
40
66
|
let localUid = useRef<string>('');
|
|
41
|
-
const
|
|
67
|
+
const timerValueRef: any = useRef(5);
|
|
68
|
+
|
|
69
|
+
const addMessageToStore = (uid: string, msg: {body: string; ts: string}) => {
|
|
42
70
|
setMessageStore((m: messageStoreInterface[]) => {
|
|
43
|
-
return [...m, {ts: ts, uid: uid, msg:
|
|
71
|
+
return [...m, {ts: msg.ts, uid: uid, msg: msg.body}];
|
|
44
72
|
});
|
|
45
73
|
};
|
|
46
74
|
|
|
47
75
|
const addMessageToPrivateStore = (
|
|
48
76
|
uid: string,
|
|
49
|
-
|
|
50
|
-
|
|
77
|
+
msg: {
|
|
78
|
+
body: string;
|
|
79
|
+
ts: string;
|
|
80
|
+
},
|
|
51
81
|
local: boolean,
|
|
52
82
|
) => {
|
|
53
83
|
setPrivateMessageStore((state: any) => {
|
|
@@ -55,22 +85,130 @@ const RtmConfigure = (props: any) => {
|
|
|
55
85
|
newState[uid] !== undefined
|
|
56
86
|
? (newState[uid] = [
|
|
57
87
|
...newState[uid],
|
|
58
|
-
{ts: ts, uid: local ? localUid.current : uid, msg:
|
|
88
|
+
{ts: msg.ts, uid: local ? localUid.current : uid, msg: msg.body},
|
|
59
89
|
])
|
|
60
90
|
: (newState = {
|
|
61
91
|
...newState,
|
|
62
|
-
[uid]: [
|
|
92
|
+
[uid]: [
|
|
93
|
+
{ts: msg.ts, uid: local ? localUid.current : uid, msg: msg.body},
|
|
94
|
+
],
|
|
63
95
|
});
|
|
64
96
|
return {...newState};
|
|
65
97
|
});
|
|
66
|
-
// console.log(privateMessageStore);
|
|
67
98
|
};
|
|
99
|
+
|
|
100
|
+
const doLoginAndSetupRTM = async () => {
|
|
101
|
+
try {
|
|
102
|
+
await engine.current.login({
|
|
103
|
+
uid: localUid.current,
|
|
104
|
+
token: rtcProps.rtm,
|
|
105
|
+
});
|
|
106
|
+
timerValueRef.current = 5
|
|
107
|
+
setAttribute();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
setTimeout( async () => {
|
|
110
|
+
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
111
|
+
doLoginAndSetupRTM();
|
|
112
|
+
}, timerValueRef.current * 1000 );
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const setAttribute = async () => {
|
|
117
|
+
try {
|
|
118
|
+
await engine.current.setLocalUserAttributes([
|
|
119
|
+
{key: 'name', value: name || 'User'},
|
|
120
|
+
{key: 'screenUid', value: String(rtcProps.screenShareUid)},
|
|
121
|
+
]);
|
|
122
|
+
timerValueRef.current = 5
|
|
123
|
+
joinChannel()
|
|
124
|
+
} catch (error) {
|
|
125
|
+
setTimeout( async () => {
|
|
126
|
+
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
127
|
+
setAttribute();
|
|
128
|
+
}, timerValueRef.current * 1000 );
|
|
129
|
+
}
|
|
130
|
+
}
|
|
68
131
|
|
|
132
|
+
const joinChannel = async () => {
|
|
133
|
+
try {
|
|
134
|
+
await engine.current.joinChannel(rtcProps.channel);
|
|
135
|
+
timerValueRef.current = 5
|
|
136
|
+
getMembers()
|
|
137
|
+
} catch (error) {
|
|
138
|
+
setTimeout( async () => {
|
|
139
|
+
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
140
|
+
joinChannel();
|
|
141
|
+
}, timerValueRef.current * 1000 );
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const getMembers = async () => {
|
|
146
|
+
try {
|
|
147
|
+
await engine.current
|
|
148
|
+
.getChannelMembersBychannelId(rtcProps.channel)
|
|
149
|
+
.then((data) => {
|
|
150
|
+
data.members.map(async (member: any) => {
|
|
151
|
+
const backoffAttributes = backOff(
|
|
152
|
+
async () => {
|
|
153
|
+
const attr = await engine.current.getUserAttributesByUid(
|
|
154
|
+
member.uid,
|
|
155
|
+
);
|
|
156
|
+
if (attr?.attributes?.name && attr?.attributes?.screenUid) {
|
|
157
|
+
return attr;
|
|
158
|
+
} else {
|
|
159
|
+
throw attr;
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
retry: (e, idx) => {
|
|
164
|
+
console.log(
|
|
165
|
+
`[retrying] Attempt ${idx}. Fetching ${member.uid}'s name`,
|
|
166
|
+
e,
|
|
167
|
+
);
|
|
168
|
+
return true;
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
try {
|
|
173
|
+
const attr = await backoffAttributes;
|
|
174
|
+
console.log('[user attributes]:', {attr});
|
|
175
|
+
setUserList((prevState) => {
|
|
176
|
+
return {
|
|
177
|
+
...prevState,
|
|
178
|
+
[member.uid]: {
|
|
179
|
+
name: attr?.attributes?.name || 'User',
|
|
180
|
+
type: UserType.Normal,
|
|
181
|
+
screenUid: parseInt(attr?.attributes?.screenUid),
|
|
182
|
+
},
|
|
183
|
+
[parseInt(attr?.attributes?.screenUid)]: {
|
|
184
|
+
name: `${attr?.attributes?.name || 'User'}'s screenshare`,
|
|
185
|
+
type: UserType.ScreenShare,
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
} catch (e) {
|
|
190
|
+
console.error(`Could not retrieve name of ${member.uid}`, e);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
setLogin(true);
|
|
194
|
+
console.log('RTM init done');
|
|
195
|
+
});
|
|
196
|
+
timerValueRef.current = 5
|
|
197
|
+
} catch (error) {
|
|
198
|
+
setTimeout( async () => {
|
|
199
|
+
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
200
|
+
getMembers();
|
|
201
|
+
}, timerValueRef.current * 1000 );
|
|
202
|
+
}
|
|
203
|
+
}
|
|
69
204
|
const init = async () => {
|
|
70
205
|
engine.current = new RtmEngine();
|
|
71
206
|
rtcProps.uid
|
|
72
207
|
? (localUid.current = rtcProps.uid + '')
|
|
73
|
-
: (localUid.current = '' +
|
|
208
|
+
: (localUid.current = '' + timeNow());
|
|
209
|
+
engine.current.on('connectionStateChanged', (evt: any) => {
|
|
210
|
+
//console.log(evt);
|
|
211
|
+
});
|
|
74
212
|
engine.current.on('error', (evt: any) => {
|
|
75
213
|
// console.log(evt);
|
|
76
214
|
});
|
|
@@ -98,8 +236,6 @@ const RtmConfigure = (props: any) => {
|
|
|
98
236
|
try {
|
|
99
237
|
const attr = await backoffAttributes;
|
|
100
238
|
console.log('[user attributes]:', {attr});
|
|
101
|
-
// let arr = new Int32Array(1);
|
|
102
|
-
// arr[0] = parseInt(data.uid);
|
|
103
239
|
setUserList((prevState) => {
|
|
104
240
|
return {
|
|
105
241
|
...prevState,
|
|
@@ -123,204 +259,217 @@ const RtmConfigure = (props: any) => {
|
|
|
123
259
|
engine.current.on('channelMemberLeft', (data: any) => {
|
|
124
260
|
console.log('user left', data);
|
|
125
261
|
// Chat of left user becomes undefined. So don't cleanup
|
|
126
|
-
//
|
|
127
|
-
// let arr = new Int32Array(1);
|
|
128
|
-
// arr[0] = parseInt(data.uid);
|
|
129
|
-
// setUserList((prevState) => {
|
|
130
|
-
// const uid: number = Platform.OS === 'android' ? arr[0] : data.uid;
|
|
131
|
-
// const screenuid: number = prevState[uid].screenUid;
|
|
132
|
-
// const {[uid]: _user, [screenuid]: _screen, ...newState} = prevState;
|
|
133
|
-
// return newState;
|
|
134
|
-
// });
|
|
135
262
|
});
|
|
136
263
|
engine.current.on('messageReceived', (evt: any) => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
264
|
+
const {peerId, ts, text} = evt;
|
|
265
|
+
const textObj = parsePayload(text);
|
|
266
|
+
const {type, msg} = textObj;
|
|
267
|
+
|
|
268
|
+
let arr = new Int32Array(1);
|
|
269
|
+
arr[0] = parseInt(peerId);
|
|
270
|
+
|
|
271
|
+
const timestamp = timeNow();
|
|
272
|
+
|
|
273
|
+
const userUID = Platform.OS === 'android' ? arr[0] : peerId;
|
|
274
|
+
|
|
275
|
+
if (type === messageActionType.Control) {
|
|
276
|
+
try {
|
|
277
|
+
switch (msg) {
|
|
278
|
+
case controlMessageEnum.muteVideo:
|
|
279
|
+
RtcEngine.muteLocalVideoStream(true);
|
|
280
|
+
dispatch({
|
|
281
|
+
type: 'LocalMuteVideo',
|
|
282
|
+
value: [0],
|
|
283
|
+
});
|
|
284
|
+
break;
|
|
285
|
+
case controlMessageEnum.muteAudio:
|
|
286
|
+
RtcEngine.muteLocalAudioStream(true);
|
|
287
|
+
dispatch({
|
|
288
|
+
type: 'LocalMuteAudio',
|
|
289
|
+
value: [0],
|
|
290
|
+
});
|
|
291
|
+
break;
|
|
292
|
+
case controlMessageEnum.kickUser:
|
|
293
|
+
dispatch({
|
|
294
|
+
type: 'EndCall',
|
|
295
|
+
value: [],
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
default:
|
|
299
|
+
throw new Error('Unsupported message type');
|
|
300
|
+
}
|
|
301
|
+
} catch (e) {
|
|
302
|
+
events.emit(messageChannelType.Private, null, {
|
|
303
|
+
msg: `Error while dispatching ${messageChannelType.Private} control message`,
|
|
304
|
+
cause: e,
|
|
156
305
|
});
|
|
306
|
+
return;
|
|
157
307
|
}
|
|
158
|
-
} else if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
308
|
+
} else if (type === messageActionType.Normal) {
|
|
309
|
+
try {
|
|
310
|
+
addMessageToPrivateStore(
|
|
311
|
+
userUID,
|
|
312
|
+
{
|
|
313
|
+
body: `${type}${msg}`,
|
|
314
|
+
ts: timestamp,
|
|
315
|
+
},
|
|
316
|
+
false,
|
|
317
|
+
);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
events.emit(messageChannelType.Private, null, {
|
|
320
|
+
msg: `Error while adding ${messageChannelType.Private} message to store`,
|
|
321
|
+
cause: e,
|
|
322
|
+
});
|
|
323
|
+
return;
|
|
165
324
|
}
|
|
166
|
-
addMessageToPrivateStore(
|
|
167
|
-
Platform.OS === 'android' ? arr[0] : evt.peerId,
|
|
168
|
-
evt.text,
|
|
169
|
-
evt.ts,
|
|
170
|
-
false,
|
|
171
|
-
);
|
|
172
325
|
}
|
|
326
|
+
events.emit(messageChannelType.Private, {
|
|
327
|
+
uid: userUID,
|
|
328
|
+
ts: timestamp,
|
|
329
|
+
...textObj,
|
|
330
|
+
});
|
|
173
331
|
});
|
|
332
|
+
|
|
174
333
|
engine.current.on('channelMessageReceived', (evt) => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
334
|
+
const {uid, channelId, text, ts} = evt;
|
|
335
|
+
const textObj = parsePayload(text);
|
|
336
|
+
const {type, msg} = textObj;
|
|
337
|
+
|
|
179
338
|
let arr = new Int32Array(1);
|
|
180
339
|
arr[0] = parseInt(uid);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
340
|
+
|
|
341
|
+
const userUID = Platform.OS ? arr[0] : uid;
|
|
342
|
+
console.log('userId', userUID);
|
|
343
|
+
const timestamp = ts === 0 ? timeNow() : ts;
|
|
344
|
+
|
|
186
345
|
if (channelId === rtcProps.channel) {
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
346
|
+
if (type === messageActionType.Control) {
|
|
347
|
+
try {
|
|
348
|
+
switch (msg) {
|
|
349
|
+
case controlMessageEnum.muteVideo:
|
|
350
|
+
RtcEngine.muteLocalVideoStream(true);
|
|
351
|
+
dispatch({
|
|
352
|
+
type: 'LocalMuteVideo',
|
|
353
|
+
value: [0],
|
|
354
|
+
});
|
|
355
|
+
break;
|
|
356
|
+
case controlMessageEnum.muteAudio:
|
|
357
|
+
RtcEngine.muteLocalAudioStream(true);
|
|
358
|
+
dispatch({
|
|
359
|
+
type: 'LocalMuteAudio',
|
|
360
|
+
value: [0],
|
|
361
|
+
});
|
|
362
|
+
break;
|
|
363
|
+
case controlMessageEnum.cloudRecordingActive:
|
|
364
|
+
setRecordingActive(true);
|
|
365
|
+
break;
|
|
366
|
+
case controlMessageEnum.cloudRecordingUnactive:
|
|
367
|
+
setRecordingActive(false);
|
|
368
|
+
break;
|
|
369
|
+
default:
|
|
370
|
+
throw new Error('Unsupported message type');
|
|
371
|
+
}
|
|
372
|
+
} catch (e) {
|
|
373
|
+
events.emit(messageChannelType.Public, null, {
|
|
374
|
+
msg: `Error while dispatching ${messageChannelType.Public} control message`,
|
|
375
|
+
cause: e,
|
|
199
376
|
});
|
|
200
|
-
|
|
201
|
-
text.slice(1) === controlMessageEnum.cloudRecordingActive
|
|
202
|
-
) {
|
|
203
|
-
setRecordingActive(true);
|
|
204
|
-
} else if (
|
|
205
|
-
text.slice(1) === controlMessageEnum.cloudRecordingUnactive
|
|
206
|
-
) {
|
|
207
|
-
setRecordingActive(false);
|
|
377
|
+
return;
|
|
208
378
|
}
|
|
209
|
-
} else if (
|
|
210
|
-
addMessageToStore(uid, text, ts);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
engine.current.createClient(rtcProps.appId);
|
|
215
|
-
await engine.current.login({
|
|
216
|
-
uid: localUid.current,
|
|
217
|
-
token: rtcProps.rtm,
|
|
218
|
-
});
|
|
219
|
-
await engine.current.setLocalUserAttributes([
|
|
220
|
-
{key: 'name', value: name || 'User'},
|
|
221
|
-
{key: 'screenUid', value: String(rtcProps.screenShareUid)},
|
|
222
|
-
]);
|
|
223
|
-
await engine.current.joinChannel(rtcProps.channel);
|
|
224
|
-
engine.current
|
|
225
|
-
.getChannelMembersBychannelId(rtcProps.channel)
|
|
226
|
-
.then((data) => {
|
|
227
|
-
data.members.map(async (member: any) => {
|
|
228
|
-
const backoffAttributes = backOff(
|
|
229
|
-
async () => {
|
|
230
|
-
const attr = await engine.current.getUserAttributesByUid(
|
|
231
|
-
member.uid,
|
|
232
|
-
);
|
|
233
|
-
if (attr?.attributes?.name && attr?.attributes?.screenUid) {
|
|
234
|
-
return attr;
|
|
235
|
-
} else {
|
|
236
|
-
throw attr;
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
retry: (e, idx) => {
|
|
241
|
-
console.log(
|
|
242
|
-
`[retrying] Attempt ${idx}. Fetching ${member.uid}'s name`,
|
|
243
|
-
e,
|
|
244
|
-
);
|
|
245
|
-
return true;
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
);
|
|
379
|
+
} else if (type === messageActionType.Normal) {
|
|
249
380
|
try {
|
|
250
|
-
|
|
251
|
-
console.log('[user attributes]:', {attr});
|
|
252
|
-
// let arr = new Int32Array(1);
|
|
253
|
-
// arr[0] = parseInt(data.uid);
|
|
254
|
-
setUserList((prevState) => {
|
|
255
|
-
return {
|
|
256
|
-
...prevState,
|
|
257
|
-
[member.uid]: {
|
|
258
|
-
name: attr?.attributes?.name || 'User',
|
|
259
|
-
type: UserType.Normal,
|
|
260
|
-
screenUid: parseInt(attr?.attributes?.screenUid),
|
|
261
|
-
},
|
|
262
|
-
[parseInt(attr?.attributes?.screenUid)]: {
|
|
263
|
-
name: `${attr?.attributes?.name || 'User'}'s screenshare`,
|
|
264
|
-
type: UserType.ScreenShare,
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
});
|
|
381
|
+
addMessageToStore(userUID, {body: `${type}${msg}`, ts: timestamp});
|
|
268
382
|
} catch (e) {
|
|
269
|
-
|
|
383
|
+
events.emit(messageChannelType.Public, null, {
|
|
384
|
+
msg: `Error while adding ${messageChannelType.Public} message to store`,
|
|
385
|
+
cause: e,
|
|
386
|
+
});
|
|
387
|
+
return;
|
|
270
388
|
}
|
|
271
|
-
}
|
|
272
|
-
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
events.emit(messageChannelType.Public, {
|
|
392
|
+
uid: userUID,
|
|
393
|
+
ts: timestamp,
|
|
394
|
+
...textObj,
|
|
273
395
|
});
|
|
274
|
-
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
await engine.current.createClient(rtcProps.appId);
|
|
399
|
+
doLoginAndSetupRTM();
|
|
400
|
+
|
|
275
401
|
};
|
|
276
402
|
|
|
277
403
|
const sendMessage = async (msg: string) => {
|
|
278
|
-
if (msg
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
404
|
+
if (msg.trim() === '') return;
|
|
405
|
+
const text = stringifyPayload(
|
|
406
|
+
messageSourceType.Core,
|
|
407
|
+
messageActionType.Normal,
|
|
408
|
+
msg,
|
|
409
|
+
);
|
|
410
|
+
await (engine.current as RtmEngine).sendMessageByChannelId(
|
|
411
|
+
rtcProps.channel,
|
|
412
|
+
text,
|
|
413
|
+
);
|
|
414
|
+
addMessageToStore(localUid.current, {
|
|
415
|
+
body: messageActionType.Normal + msg,
|
|
416
|
+
ts: timeNow(),
|
|
417
|
+
});
|
|
288
418
|
};
|
|
289
419
|
const sendMessageToUid = async (msg: string, uid: number) => {
|
|
420
|
+
if (msg.trim() === '') return;
|
|
290
421
|
let adjustedUID = uid;
|
|
291
422
|
if (adjustedUID < 0) {
|
|
292
|
-
adjustedUID = uid
|
|
293
|
-
}
|
|
294
|
-
let ts = new Date().getTime();
|
|
295
|
-
if (msg !== '') {
|
|
296
|
-
await (engine.current as RtmEngine).sendMessageToPeer({
|
|
297
|
-
peerId: adjustedUID.toString(),
|
|
298
|
-
offline: false,
|
|
299
|
-
text: mType.Normal + '' + msg,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
// console.log(ts);
|
|
303
|
-
if (msg !== '') {
|
|
304
|
-
addMessageToPrivateStore(uid, mType.Normal + msg, ts, true);
|
|
423
|
+
adjustedUID = adjustUID(uid);
|
|
305
424
|
}
|
|
425
|
+
const text = stringifyPayload(
|
|
426
|
+
messageSourceType.Core,
|
|
427
|
+
messageActionType.Normal,
|
|
428
|
+
msg,
|
|
429
|
+
);
|
|
430
|
+
await (engine.current as RtmEngine).sendMessageToPeer({
|
|
431
|
+
peerId: adjustedUID.toString(),
|
|
432
|
+
offline: false,
|
|
433
|
+
text,
|
|
434
|
+
});
|
|
435
|
+
addMessageToPrivateStore(
|
|
436
|
+
uid,
|
|
437
|
+
{
|
|
438
|
+
body: messageActionType.Normal + msg,
|
|
439
|
+
ts: timeNow(),
|
|
440
|
+
},
|
|
441
|
+
true,
|
|
442
|
+
);
|
|
306
443
|
};
|
|
444
|
+
|
|
307
445
|
const sendControlMessage = async (msg: string) => {
|
|
446
|
+
const text = stringifyPayload(
|
|
447
|
+
messageSourceType.Core,
|
|
448
|
+
messageActionType.Control,
|
|
449
|
+
msg,
|
|
450
|
+
);
|
|
308
451
|
await (engine.current as RtmEngine).sendMessageByChannelId(
|
|
309
452
|
rtcProps.channel,
|
|
310
|
-
|
|
453
|
+
text,
|
|
311
454
|
);
|
|
312
455
|
};
|
|
456
|
+
|
|
313
457
|
const sendControlMessageToUid = async (msg: string, uid: number) => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
adjustedUID = uid + parseInt(0xffffffff) + 1;
|
|
458
|
+
if (uid < 0) {
|
|
459
|
+
uid = adjustUID(uid);
|
|
317
460
|
}
|
|
461
|
+
const text = stringifyPayload(
|
|
462
|
+
messageSourceType.Core,
|
|
463
|
+
messageActionType.Control,
|
|
464
|
+
msg,
|
|
465
|
+
);
|
|
318
466
|
await (engine.current as RtmEngine).sendMessageToPeer({
|
|
319
|
-
peerId:
|
|
467
|
+
peerId: uid.toString(),
|
|
320
468
|
offline: false,
|
|
321
|
-
text
|
|
469
|
+
text,
|
|
322
470
|
});
|
|
323
471
|
};
|
|
472
|
+
|
|
324
473
|
const end = async () => {
|
|
325
474
|
callActive
|
|
326
475
|
? (await (engine.current as RtmEngine).logout(),
|
|
@@ -350,6 +499,7 @@ const RtmConfigure = (props: any) => {
|
|
|
350
499
|
engine: engine.current,
|
|
351
500
|
localUid: localUid.current,
|
|
352
501
|
userList: userList,
|
|
502
|
+
events,
|
|
353
503
|
}}>
|
|
354
504
|
{login ? props.children : <></>}
|
|
355
505
|
</ChatContext.Provider>
|