agora-appbuilder-core 2.2.0 → 2.3.0-beta.0
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 +7 -1
- package/package.json +4 -3
- package/template/Gulpfile.js +306 -87
- package/template/_gitignore +4 -1
- package/template/_package-lock.json +2297 -2533
- package/template/agora-rn-uikit/.git/HEAD +1 -1
- package/template/agora-rn-uikit/.git/config +3 -3
- package/template/agora-rn-uikit/.git/index +0 -0
- package/template/agora-rn-uikit/.git/logs/HEAD +2 -2
- package/template/agora-rn-uikit/.git/logs/refs/heads/master +1 -1
- package/template/agora-rn-uikit/.git/logs/refs/heads/release/fpe-1.0.0 +1 -0
- package/template/agora-rn-uikit/.git/logs/refs/remotes/origin/HEAD +1 -1
- package/template/agora-rn-uikit/.git/objects/pack/pack-f274a85fccfc9b5112d154bb3b6d34cb4b8dedde.idx +0 -0
- package/template/agora-rn-uikit/.git/objects/pack/{pack-0061d00cd98162a329a32b537488a35d0abeb069.pack → pack-f274a85fccfc9b5112d154bb3b6d34cb4b8dedde.pack} +0 -0
- package/template/agora-rn-uikit/.git/packed-refs +5 -1
- package/template/agora-rn-uikit/.git/refs/heads/release/fpe-1.0.0 +1 -0
- package/template/agora-rn-uikit/src/AgoraUIKit.tsx +23 -20
- package/template/agora-rn-uikit/src/Contexts/LocalUserContext.tsx +13 -8
- package/template/agora-rn-uikit/src/Contexts/PropsContext.tsx +25 -9
- package/template/agora-rn-uikit/src/Contexts/RenderContext.tsx +10 -0
- package/template/agora-rn-uikit/src/Contexts/RtcContext.tsx +11 -5
- package/template/agora-rn-uikit/src/Controls/BtnTemplate.tsx +6 -2
- package/template/agora-rn-uikit/src/Controls/ImageIcon.tsx +1 -1
- package/template/agora-rn-uikit/src/Controls/Local/EndCall.tsx +6 -2
- package/template/agora-rn-uikit/src/Controls/Local/LocalAudioMute.tsx +2 -2
- package/template/agora-rn-uikit/src/Controls/Local/LocalVideoMute.tsx +2 -2
- package/template/agora-rn-uikit/src/Controls/Local/SwitchCamera.tsx +6 -2
- package/template/agora-rn-uikit/src/Controls/LocalControls.tsx +11 -6
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteAudioMute.tsx +10 -6
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteSwap.tsx +7 -6
- package/template/agora-rn-uikit/src/Controls/Remote/RemoteVideoMute.tsx +6 -5
- package/template/agora-rn-uikit/src/Controls/RemoteControls.tsx +3 -3
- package/template/agora-rn-uikit/src/Reducer/LocalMuteAudio.ts +16 -13
- package/template/agora-rn-uikit/src/Reducer/LocalMuteVideo.ts +16 -13
- package/template/agora-rn-uikit/src/Reducer/RemoteAudioStateChanged.ts +13 -13
- package/template/agora-rn-uikit/src/Reducer/RemoteVideoStateChanged.ts +16 -13
- package/template/agora-rn-uikit/src/Reducer/UpdateDualStreamMode.ts +28 -31
- package/template/agora-rn-uikit/src/Reducer/UserJoined.ts +48 -35
- package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteAudio.ts +11 -13
- package/template/agora-rn-uikit/src/Reducer/UserMuteRemoteVideo.ts +11 -13
- package/template/agora-rn-uikit/src/Reducer/UserOffline.ts +18 -15
- package/template/agora-rn-uikit/src/Rtc/Create.tsx +14 -2
- package/template/agora-rn-uikit/src/Rtc/Join.tsx +19 -3
- package/template/agora-rn-uikit/src/RtcConfigure.tsx +161 -44
- package/template/agora-rn-uikit/src/Utils/useLocalUid.ts +8 -0
- package/template/agora-rn-uikit/src/Views/MaxVideoView.native.tsx +8 -6
- package/template/agora-rn-uikit/src/Views/MaxVideoView.tsx +8 -6
- package/template/agora-rn-uikit/src/Views/MinVideoView.tsx +18 -9
- package/template/agora-rn-uikit/src/index.ts +12 -12
- package/template/babel.config.js +17 -1
- package/template/bridge/rtc/webNg/RtcEngine.ts +34 -28
- package/template/bridge/rtc/webNg/SurfaceView.tsx +3 -2
- package/template/bridge/rtc/webNg/Types.ts +14 -0
- package/template/bridge/rtc/webNg/index.ts +5 -2
- package/template/bridge/rtm/web/index.ts +13 -7
- package/template/electron-builder.js +3 -2
- package/template/esbuild.rsdk.go +226 -0
- package/template/{src/subComponents/LayoutEnum.tsx → esbuildConfigTransform.js} +1 -5
- package/template/fpe-api/components.ts +42 -0
- package/template/fpe-api/context.ts +45 -0
- package/template/fpe-api/fpeEvents.ts +9 -0
- package/template/fpe-api/index.ts +21 -0
- package/template/fpe-api/install.ts +128 -0
- package/template/fpe-api/typeDefinition.ts +143 -0
- package/template/fpe-api/useFpe.tsx +35 -0
- package/template/fpe-api/utils.ts +62 -0
- package/template/fpe-implementation/createHook.ts +33 -0
- package/template/fpe-implementation/dummyFpe.ts +17 -0
- package/template/fpe-implementation/index.ts +1 -0
- package/template/fpe-todo.txt +14 -0
- package/template/fpe.config.js +25 -0
- package/template/global.d.ts +4 -0
- package/template/index.rsdk.tsx +27 -0
- package/template/index.wsdk.tsx +27 -0
- package/template/package-lock.json +2297 -2533
- package/template/package.json +28 -12
- package/template/react-native-toast-message/src/index.js +9 -10
- package/template/react-native-toast-message/src/index.wsdk.js +419 -0
- package/template/src/App.tsx +97 -65
- package/template/src/AppWrapper.tsx +79 -0
- package/template/src/SDKAppWrapper.tsx +67 -0
- package/template/src/atoms/PrimaryButton.tsx +14 -8
- package/template/src/atoms/TextInput.tsx +13 -5
- package/template/src/components/Chat.tsx +171 -139
- package/template/src/components/ChatContext.ts +14 -22
- package/template/src/components/ColorConfigure.tsx +2 -2
- package/template/src/components/Controls.native.tsx +72 -62
- package/template/src/components/Controls.tsx +90 -69
- package/template/src/components/DeviceConfigure.tsx +1 -1
- package/template/src/components/DeviceContext.tsx +14 -7
- package/template/src/components/GraphQLProvider.tsx +9 -2
- package/template/src/components/GridVideo.tsx +20 -159
- package/template/src/components/HostControlView.tsx +54 -15
- package/template/src/components/Navbar.tsx +408 -157
- package/template/src/components/NetworkQualityContext.tsx +29 -22
- package/template/src/components/ParticipantsView.tsx +97 -119
- package/template/src/components/PinnedVideo.tsx +41 -188
- package/template/src/components/Precall.native.tsx +131 -97
- package/template/src/components/Precall.tsx +193 -158
- package/template/src/components/RTMConfigure.tsx +320 -398
- package/template/src/components/Router.sdk.ts +20 -0
- package/template/src/components/SessionContext.tsx +6 -3
- package/template/src/components/Settings.native.tsx +3 -0
- package/template/src/components/Settings.tsx +65 -31
- package/template/src/components/SettingsView.tsx +14 -8
- package/template/src/components/Share.tsx +188 -220
- package/template/src/components/StorageContext.tsx +5 -5
- package/template/src/components/StoreToken.tsx +5 -1
- package/template/src/components/chat-messages/useChatMessages.tsx +202 -0
- package/template/src/components/chat-notification/useChatNotification.tsx +78 -0
- package/template/src/components/chat-ui/useChatUIControl.tsx +66 -0
- package/template/src/components/common/Error.tsx +54 -0
- package/template/src/components/common/Logo.tsx +35 -0
- package/template/src/components/common/index.tsx +8 -0
- package/template/src/components/contexts/LiveStreamDataContext.tsx +79 -0
- package/template/src/components/contexts/ScreenShareContext.tsx +47 -0
- package/template/src/components/contexts/WhiteboardContext.tsx +59 -0
- package/template/src/components/dimension/DimensionContext.ts +27 -0
- package/template/src/components/dimension/DimensionProvider.tsx +34 -0
- package/template/src/components/livestream/LiveStreamContext.tsx +293 -272
- package/template/src/components/livestream/Types.ts +26 -7
- package/template/src/components/livestream/index.ts +13 -2
- package/template/src/components/livestream/views/LiveStreamControls.tsx +5 -1
- package/template/src/components/meeting-info/useMeetingInfo.tsx +63 -0
- package/template/src/components/meeting-info/useSetMeetingInfo.tsx +38 -0
- package/template/src/components/participants/AllAudienceParticipants.tsx +26 -21
- package/template/src/components/participants/AllHostParticipants.tsx +36 -53
- package/template/src/components/participants/MeParticipant.tsx +9 -10
- package/template/src/components/participants/ParticipantName.tsx +2 -1
- package/template/src/components/participants/RemoteParticipants.tsx +3 -3
- package/template/src/components/precall/LocalMute.native.tsx +91 -0
- package/template/src/components/precall/LocalMute.tsx +90 -0
- package/template/src/components/precall/VideoPreview.native.tsx +35 -0
- package/template/src/components/precall/VideoPreview.tsx +33 -0
- package/template/src/components/precall/index.tsx +28 -0
- package/template/src/components/precall/joinCallBtn.native.tsx +69 -0
- package/template/src/components/precall/joinCallBtn.tsx +91 -0
- package/template/src/components/precall/meetingTitle.tsx +26 -0
- package/template/src/components/precall/selectDevice.tsx +46 -0
- package/template/src/components/precall/textInput.tsx +43 -0
- package/template/src/components/precall/usePreCall.tsx +41 -0
- package/template/src/components/styles.ts +20 -3
- package/template/src/components/useShareLink.tsx +222 -0
- package/template/src/components/useWakeLock.tsx +3 -3
- package/template/src/custom-events/CustomEvents.ts +197 -0
- package/template/src/custom-events/index.tsx +4 -0
- package/template/src/custom-events/types.ts +51 -0
- package/template/src/language/default-labels/commonLabels.ts +21 -0
- package/template/src/language/default-labels/createScreenLabels.ts +22 -0
- package/template/src/language/default-labels/index.ts +38 -0
- package/template/src/language/default-labels/joinScreenLabels.ts +13 -0
- package/template/src/language/default-labels/precallScreenLabels.ts +33 -0
- package/template/src/language/default-labels/shareLinkScreenLabels.ts +44 -0
- package/template/src/language/default-labels/videoCallScreenLabels.ts +189 -0
- package/template/src/language/i18nTypes.ts +10 -0
- package/template/src/language/index.ts +18 -0
- package/template/src/language/useLanguage.tsx +92 -0
- package/template/src/pages/Authenticate.tsx +21 -15
- package/template/src/pages/Create.tsx +176 -159
- package/template/src/pages/Join.tsx +44 -32
- package/template/src/pages/VideoCall.tsx +134 -406
- package/template/src/pages/create/useCreate.tsx +37 -0
- package/template/src/pages/video-call/CustomLayout.ts +17 -0
- package/template/src/pages/video-call/CustomUserContextHolder.tsx +12 -0
- package/template/src/pages/video-call/DefaultLayouts.ts +65 -0
- package/template/src/pages/video-call/NameWithMicStatus.tsx +62 -0
- package/template/src/pages/video-call/RenderComponent.tsx +52 -0
- package/template/src/pages/video-call/VideoCallScreen.tsx +191 -0
- package/template/src/pages/video-call/VideoComponent.tsx +34 -0
- package/template/src/pages/video-call/VideoRenderer.tsx +86 -0
- package/template/src/pages/video-call/index.ts +20 -0
- package/template/src/rtm/RTMEngine.ts +58 -0
- package/template/src/rtm/utils.ts +28 -0
- package/template/src/rtm-events/EventUtils.ts +268 -0
- package/template/src/rtm-events/EventsQueue.ts +38 -0
- package/template/src/rtm-events/constants.ts +40 -0
- package/template/src/rtm-events/index.tsx +8 -0
- package/template/src/rtm-events/types.ts +7 -0
- package/template/src/subComponents/ChatBubble.tsx +18 -11
- package/template/src/subComponents/ChatContainer.tsx +78 -29
- package/template/src/subComponents/ChatInput.tsx +146 -70
- package/template/src/subComponents/CopyJoinInfo.tsx +52 -67
- package/template/src/subComponents/Error.tsx +35 -24
- package/template/src/subComponents/LanguageSelector.tsx +85 -0
- package/template/src/subComponents/LayoutIconDropdown.native.tsx +163 -0
- package/template/src/subComponents/LayoutIconDropdown.tsx +198 -0
- package/template/src/subComponents/LocalAudioMute.tsx +52 -30
- package/template/src/subComponents/LocalEndCall.tsx +52 -0
- package/template/src/subComponents/LocalSwitchCamera.tsx +61 -0
- package/template/src/subComponents/LocalVideoMute.tsx +48 -30
- package/template/src/subComponents/LogoutButton.tsx +20 -5
- package/template/src/subComponents/NetworkQualityPill.tsx +43 -13
- package/template/src/subComponents/OpenInNativeButton.tsx +3 -2
- package/template/src/subComponents/Recording.tsx +46 -138
- package/template/src/subComponents/RemoteAudioMute.tsx +30 -34
- package/template/src/subComponents/RemoteEndCall.tsx +18 -7
- package/template/src/subComponents/RemoteVideoMute.tsx +17 -9
- package/template/src/subComponents/ScreenShareNotice.tsx +40 -40
- package/template/src/subComponents/SelectDevice.tsx +88 -45
- package/template/src/subComponents/SelectOAuth.tsx +30 -6
- package/template/src/subComponents/SidePanelButtons.ts +39 -0
- package/template/src/subComponents/TextWithTooltip.native.tsx +2 -1
- package/template/src/subComponents/TextWithTooltip.tsx +15 -20
- package/template/src/subComponents/chat/ChatParticipants.tsx +31 -32
- package/template/src/subComponents/livestream/ApprovedLiveStreamControlsView.tsx +7 -3
- package/template/src/subComponents/livestream/CurrentLiveStreamRequestsView.tsx +32 -18
- package/template/src/subComponents/livestream/controls/LocalRaiseHand.tsx +22 -8
- package/template/src/subComponents/livestream/controls/RemoteLiveStreamApprovedRequestRecall.tsx +12 -7
- package/template/src/subComponents/livestream/controls/RemoteLiveStreamRequestApprove.tsx +24 -27
- package/template/src/subComponents/livestream/controls/RemoteLiveStreamRequestReject.tsx +23 -26
- package/template/src/subComponents/livestream/index.ts +10 -2
- package/template/src/subComponents/recording/useRecording.tsx +209 -0
- package/template/src/subComponents/recording/useRecordingLayoutQuery.tsx +64 -0
- package/template/src/subComponents/screenshare/ScreenshareButton.native.tsx +18 -0
- package/template/src/subComponents/screenshare/ScreenshareButton.tsx +59 -31
- package/template/src/subComponents/screenshare/ScreenshareConfigure.native.tsx +57 -52
- package/template/src/subComponents/screenshare/ScreenshareConfigure.tsx +97 -138
- package/template/src/subComponents/screenshare/useScreenshare.tsx +29 -0
- package/template/src/subComponents/toastConfig.tsx +25 -20
- package/template/src/utils/IsAttendeeUser.ts +34 -0
- package/template/src/utils/SdkEvents.ts +68 -0
- package/template/src/utils/common.tsx +40 -0
- package/template/src/utils/eventEmitter.ts +29 -0
- package/template/src/utils/getMeetingInvite.ts +30 -0
- package/template/src/utils/index.tsx +11 -2
- package/template/src/utils/isAudioEnabled.ts +29 -0
- package/template/src/utils/isHostUser.ts +33 -0
- package/template/src/utils/isMobileOrTablet.native.ts +5 -0
- package/template/src/utils/{mobileWebTest.tsx → isMobileOrTablet.ts} +5 -2
- package/template/src/utils/isPSTNUser.ts +30 -0
- package/template/src/utils/isSDK.sdk.ts +5 -0
- package/template/src/utils/isSDK.ts +5 -0
- package/template/src/utils/isScreenShareUser.ts +31 -0
- package/template/src/utils/isVideoEnabled.ts +29 -0
- package/template/src/utils/useButtonTemplate.tsx +43 -0
- package/template/src/utils/useCreateMeeting.ts +74 -0
- package/template/src/utils/useGetLiveStreamingRequests.ts +24 -0
- package/template/src/utils/useGetMeetingPhrase.ts +68 -0
- package/template/src/utils/useGetName.ts +20 -0
- package/template/src/{subComponents/screenshare/ScreenshareContext.tsx → utils/useGroupMessages.ts} +10 -7
- package/template/src/utils/useJoinMeeting.ts +120 -0
- package/template/src/utils/useLayout.tsx +40 -0
- package/template/src/utils/useLiveStreamingUids.ts +26 -0
- package/template/src/utils/useMutePSTN.ts +43 -0
- package/template/src/utils/useMuteToggleLocal.ts +109 -0
- package/template/src/utils/useNavParams.ts +6 -0
- package/template/src/utils/useNavigateTo.ts +8 -0
- package/template/src/utils/usePrivateMessages.ts +33 -0
- package/template/src/utils/useRemoteEndCall.ts +27 -0
- package/template/src/utils/useRemoteMute.ts +64 -0
- package/template/src/utils/useSendControlMessage.ts +51 -0
- package/template/src/utils/useSendMessage.ts +40 -0
- package/template/src/utils/useSetName.ts +20 -0
- package/template/src/utils/useSetUnreadMessageCount.ts +43 -0
- package/template/src/utils/useSidePanel.tsx +41 -0
- package/template/src/utils/useString.ts +61 -0
- package/template/src/utils/useUnreadMessageCount.ts +50 -0
- package/template/src/utils/useUserList.ts +26 -0
- package/template/tsconfig.json +4 -4
- package/template/tsconfig_fpeApi.json +103 -0
- package/template/tsconfig_rsdk_index.json +105 -0
- package/template/tsconfig_wsdk_index.json +104 -0
- package/template/webpack.commons.js +40 -16
- package/template/webpack.main.config.js +2 -1
- package/template/webpack.renderer.config.js +1 -1
- package/template/webpack.rsdk.config.js +33 -0
- package/template/webpack.ts.config.js +89 -0
- package/template/webpack.web.config.js +8 -1
- package/template/webpack.wsdk.config.js +34 -0
- package/template/agora-rn-uikit/.git/logs/refs/heads/ab-dev-auto +0 -1
- package/template/agora-rn-uikit/.git/objects/pack/pack-0061d00cd98162a329a32b537488a35d0abeb069.idx +0 -0
- package/template/agora-rn-uikit/.git/refs/heads/ab-dev-auto +0 -1
- package/template/agora-rn-uikit/src/Contexts/MaxUidContext.tsx +0 -7
- package/template/agora-rn-uikit/src/Contexts/MinUidContext.tsx +0 -8
- package/template/src/components/participants/context/ParticipantContext.tsx +0 -97
- package/template/src/subComponents/ScreenshareButton.tsx +0 -257
- package/template/src/subComponents/SwitchCamera.tsx +0 -35
- package/template/src/utils/hasBrandLogo.tsx +0 -3
- package/template/src/utils/mobileWebTest.native.tsx +0 -5
- package/template/src/utils/shouldAuthenticate.tsx +0 -7
|
@@ -9,34 +9,37 @@
|
|
|
9
9
|
information visit https://appbuilder.agora.io.
|
|
10
10
|
*********************************************
|
|
11
11
|
*/
|
|
12
|
+
// @ts-nocheck
|
|
12
13
|
import React, {useState, useContext, useEffect, useRef} from 'react';
|
|
13
|
-
import RtmEngine, {
|
|
14
|
-
|
|
15
|
-
RtmAttribute,
|
|
16
|
-
} from 'agora-react-native-rtm';
|
|
17
|
-
import {ClientRole, PropsContext} from '../../agora-rn-uikit';
|
|
14
|
+
import RtmEngine, {RtmAttribute} from 'agora-react-native-rtm';
|
|
15
|
+
import {PropsContext, useLocalUid} from '../../agora-rn-uikit';
|
|
18
16
|
import ChatContext, {controlMessageEnum} from './ChatContext';
|
|
19
17
|
import {RtcContext} from '../../agora-rn-uikit';
|
|
20
|
-
import {
|
|
21
|
-
messageStoreInterface,
|
|
22
|
-
messageChannelType,
|
|
23
|
-
messageSourceType,
|
|
24
|
-
messageActionType,
|
|
25
|
-
attrRequestTypes,
|
|
26
|
-
} from './ChatContext';
|
|
18
|
+
import {messageSourceType, messageActionType} from './ChatContext';
|
|
27
19
|
import {Platform} from 'react-native';
|
|
28
20
|
import {backOff} from 'exponential-backoff';
|
|
29
|
-
import
|
|
21
|
+
import {useString} from '../utils/useString';
|
|
22
|
+
import {isAndroid, isWeb} from '../utils/common';
|
|
23
|
+
import StorageContext from './StorageContext';
|
|
24
|
+
import {useRenderContext} from 'fpe-api';
|
|
25
|
+
import {safeJsonParse, timeNow, hasJsonStructure} from '../rtm/utils';
|
|
26
|
+
import {EventUtils, EventsQueue, eventMessageType} from '../rtm-events';
|
|
27
|
+
|
|
28
|
+
import RTMEngine from '../rtm/RTMEngine';
|
|
30
29
|
import {filterObject} from '../utils';
|
|
31
30
|
|
|
32
31
|
export enum UserType {
|
|
33
|
-
|
|
34
|
-
ScreenShare,
|
|
32
|
+
ScreenShare = 'screenshare',
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
const adjustUID = (
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const adjustUID = (uid: number | string) => {
|
|
36
|
+
let number: number | string;
|
|
37
|
+
if (typeof uid === 'string') number = uid;
|
|
38
|
+
else {
|
|
39
|
+
number = uid;
|
|
40
|
+
if (number < 0) {
|
|
41
|
+
number = 0xffffffff + number + 1;
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
return number;
|
|
42
45
|
};
|
|
@@ -57,45 +60,72 @@ const parsePayload = (data: string) => {
|
|
|
57
60
|
return JSON.parse(data);
|
|
58
61
|
};
|
|
59
62
|
|
|
60
|
-
function hasJsonStructure(str: string) {
|
|
61
|
-
if (typeof str !== 'string') return false;
|
|
62
|
-
try {
|
|
63
|
-
const result = JSON.parse(str);
|
|
64
|
-
const type = Object.prototype.toString.call(result);
|
|
65
|
-
return type === '[object Object]' || type === '[object Array]';
|
|
66
|
-
} catch (err) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function safeJsonParse(str: string) {
|
|
71
|
-
try {
|
|
72
|
-
return [null, JSON.parse(str)];
|
|
73
|
-
} catch (err) {
|
|
74
|
-
return [err];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const timeNow = () => new Date().getTime();
|
|
78
|
-
|
|
79
63
|
const RtmConfigure = (props: any) => {
|
|
80
|
-
const
|
|
64
|
+
const localUid = useLocalUid();
|
|
65
|
+
const {callActive} = props;
|
|
81
66
|
const {rtcProps} = useContext(PropsContext);
|
|
82
67
|
const {RtcEngine, dispatch} = useContext(RtcContext);
|
|
83
|
-
const
|
|
84
|
-
const
|
|
68
|
+
const {renderList, renderPosition} = useRenderContext();
|
|
69
|
+
const renderListRef = useRef({renderList: renderList});
|
|
70
|
+
const renderPositionRef = useRef({renderPosition: renderPosition});
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* inside event callback state won't have latest value.
|
|
74
|
+
* so creating ref to access the state
|
|
75
|
+
*/
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
renderPositionRef.current.renderPosition = renderPosition;
|
|
78
|
+
}, [renderPosition]);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
renderListRef.current.renderList = renderList;
|
|
82
|
+
}, [renderList]);
|
|
83
|
+
|
|
84
|
+
const {store, setStore} = useContext(StorageContext);
|
|
85
|
+
const getInitialUsername = () =>
|
|
86
|
+
store?.displayName ? store.displayName : '';
|
|
87
|
+
const [displayName, setDisplayName] = useState(getInitialUsername());
|
|
88
|
+
|
|
89
|
+
//Update the store displayName value if the state is changed
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
setStore((prevState) => {
|
|
92
|
+
return {
|
|
93
|
+
...prevState,
|
|
94
|
+
displayName,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}, [displayName]);
|
|
98
|
+
|
|
85
99
|
const [login, setLogin] = useState<boolean>(false);
|
|
86
|
-
|
|
100
|
+
|
|
101
|
+
const [hasUserJoinedRTM, setHasUserJoinedRTM] = useState<boolean>(false);
|
|
87
102
|
const [onlineUsersCount, setTotalOnlineUsers] = useState<number>(0);
|
|
88
103
|
|
|
104
|
+
//commented for v1 release
|
|
105
|
+
// const userText = useString('remoteUserDefaultLabel')();
|
|
106
|
+
const userText = 'User';
|
|
107
|
+
const pstnUserLabel = useString('pstnUserLabel')();
|
|
108
|
+
//commented for v1 release
|
|
109
|
+
//const getScreenShareName = useString('screenshareUserName');
|
|
110
|
+
const getScreenShareName = (name: string) => `${name}'s screenshare`;
|
|
111
|
+
|
|
89
112
|
let engine = useRef<RtmEngine>(null!);
|
|
90
|
-
let localUid = useRef<string>('');
|
|
91
113
|
const timerValueRef: any = useRef(5);
|
|
92
114
|
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
setTotalOnlineUsers(
|
|
117
|
+
Object.keys(
|
|
118
|
+
filterObject(renderList, ([k, v]) => v?.type === 'rtc' && !v.offline),
|
|
119
|
+
).length,
|
|
120
|
+
);
|
|
121
|
+
}, [renderList]);
|
|
122
|
+
|
|
93
123
|
React.useEffect(() => {
|
|
94
124
|
const handBrowserClose = () => {
|
|
95
125
|
engine.current.leaveChannel(rtcProps.channel);
|
|
96
126
|
};
|
|
97
127
|
|
|
98
|
-
if (
|
|
128
|
+
if (!isWeb) return;
|
|
99
129
|
window.addEventListener('beforeunload', handBrowserClose);
|
|
100
130
|
// cleanup this component
|
|
101
131
|
return () => {
|
|
@@ -103,52 +133,10 @@ const RtmConfigure = (props: any) => {
|
|
|
103
133
|
};
|
|
104
134
|
}, []);
|
|
105
135
|
|
|
106
|
-
React.useEffect(() => {
|
|
107
|
-
setTotalOnlineUsers(
|
|
108
|
-
Object.keys(
|
|
109
|
-
filterObject(
|
|
110
|
-
userList,
|
|
111
|
-
([k, v]) => v?.type === UserType.Normal && !v.offline,
|
|
112
|
-
),
|
|
113
|
-
).length,
|
|
114
|
-
);
|
|
115
|
-
}, [userList]);
|
|
116
|
-
|
|
117
|
-
const addMessageToStore = (uid: string, msg: {body: string; ts: string}) => {
|
|
118
|
-
setMessageStore((m: messageStoreInterface[]) => {
|
|
119
|
-
return [...m, {ts: msg.ts, uid: uid, msg: msg.body}];
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const addMessageToPrivateStore = (
|
|
124
|
-
uid: string,
|
|
125
|
-
msg: {
|
|
126
|
-
body: string;
|
|
127
|
-
ts: string;
|
|
128
|
-
},
|
|
129
|
-
local: boolean,
|
|
130
|
-
) => {
|
|
131
|
-
setPrivateMessageStore((state: any) => {
|
|
132
|
-
let newState = {...state};
|
|
133
|
-
newState[uid] !== undefined
|
|
134
|
-
? (newState[uid] = [
|
|
135
|
-
...newState[uid],
|
|
136
|
-
{ts: msg.ts, uid: local ? localUid.current : uid, msg: msg.body},
|
|
137
|
-
])
|
|
138
|
-
: (newState = {
|
|
139
|
-
...newState,
|
|
140
|
-
[uid]: [
|
|
141
|
-
{ts: msg.ts, uid: local ? localUid.current : uid, msg: msg.body},
|
|
142
|
-
],
|
|
143
|
-
});
|
|
144
|
-
return {...newState};
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
136
|
const doLoginAndSetupRTM = async () => {
|
|
149
137
|
try {
|
|
150
138
|
await engine.current.login({
|
|
151
|
-
uid: localUid.
|
|
139
|
+
uid: localUid.toString(),
|
|
152
140
|
token: rtcProps.rtm,
|
|
153
141
|
});
|
|
154
142
|
timerValueRef.current = 5;
|
|
@@ -162,13 +150,12 @@ const RtmConfigure = (props: any) => {
|
|
|
162
150
|
};
|
|
163
151
|
|
|
164
152
|
const setAttribute = async () => {
|
|
153
|
+
const rtmAttributes = [
|
|
154
|
+
{key: 'name', value: displayName || userText},
|
|
155
|
+
{key: 'screenUid', value: String(rtcProps.screenShareUid)},
|
|
156
|
+
];
|
|
165
157
|
try {
|
|
166
|
-
await engine.current.setLocalUserAttributes(
|
|
167
|
-
{key: 'name', value: name || 'User'},
|
|
168
|
-
{key: 'screenUid', value: String(rtcProps.screenShareUid)},
|
|
169
|
-
{key: 'role', value: String(rtcProps?.role)},
|
|
170
|
-
{key: 'requests', value: attrRequestTypes.none}, // stores Uid who have raised a request
|
|
171
|
-
]);
|
|
158
|
+
await engine.current.setLocalUserAttributes(rtmAttributes);
|
|
172
159
|
timerValueRef.current = 5;
|
|
173
160
|
joinChannel();
|
|
174
161
|
} catch (error) {
|
|
@@ -179,19 +166,13 @@ const RtmConfigure = (props: any) => {
|
|
|
179
166
|
}
|
|
180
167
|
};
|
|
181
168
|
|
|
182
|
-
const addOrUpdateLocalUserAttributes = async (attributes: RtmAttribute[]) => {
|
|
183
|
-
try {
|
|
184
|
-
await engine.current.addOrUpdateLocalUserAttributes(attributes);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.log('error while local user addOrUpdateAttributes: ', error);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
169
|
const joinChannel = async () => {
|
|
191
170
|
try {
|
|
192
171
|
await engine.current.joinChannel(rtcProps.channel);
|
|
193
172
|
timerValueRef.current = 5;
|
|
194
|
-
getMembers();
|
|
173
|
+
await getMembers();
|
|
174
|
+
setHasUserJoinedRTM(true);
|
|
175
|
+
await runQueuedCustomEvents();
|
|
195
176
|
} catch (error) {
|
|
196
177
|
setTimeout(async () => {
|
|
197
178
|
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
@@ -200,62 +181,102 @@ const RtmConfigure = (props: any) => {
|
|
|
200
181
|
}
|
|
201
182
|
};
|
|
202
183
|
|
|
184
|
+
const updateRenderListState = (
|
|
185
|
+
uid: number,
|
|
186
|
+
data: Partial<RenderInterface>,
|
|
187
|
+
) => {
|
|
188
|
+
dispatch({type: 'UpdateRenderList', value: [uid, data]});
|
|
189
|
+
};
|
|
190
|
+
|
|
203
191
|
const getMembers = async () => {
|
|
204
192
|
try {
|
|
205
193
|
await engine.current
|
|
206
194
|
.getChannelMembersBychannelId(rtcProps.channel)
|
|
207
|
-
.then((data) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
attr?.attributes?.name &&
|
|
216
|
-
attr?.attributes?.screenUid &&
|
|
217
|
-
attr?.attributes?.role &&
|
|
218
|
-
attr?.attributes?.requests
|
|
219
|
-
) {
|
|
220
|
-
return attr;
|
|
221
|
-
} else {
|
|
222
|
-
throw attr;
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
retry: (e, idx) => {
|
|
227
|
-
console.log(
|
|
228
|
-
`[retrying] Attempt ${idx}. Fetching ${member.uid}'s name`,
|
|
229
|
-
e,
|
|
195
|
+
.then(async (data) => {
|
|
196
|
+
await Promise.all(
|
|
197
|
+
data.members.map(async (member: any) => {
|
|
198
|
+
const backoffAttributes = backOff(
|
|
199
|
+
async () => {
|
|
200
|
+
const attr = await engine.current.getUserAttributesByUid(
|
|
201
|
+
member.uid,
|
|
230
202
|
);
|
|
231
|
-
|
|
203
|
+
for (const key in attr.attributes) {
|
|
204
|
+
if (
|
|
205
|
+
attr.attributes.hasOwnProperty(key) &&
|
|
206
|
+
attr.attributes[key]
|
|
207
|
+
) {
|
|
208
|
+
return attr;
|
|
209
|
+
} else {
|
|
210
|
+
throw attr;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
232
213
|
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
...prevState,
|
|
241
|
-
[member.uid]: {
|
|
242
|
-
name: attr?.attributes?.name || 'User',
|
|
243
|
-
type: UserType.Normal,
|
|
244
|
-
role: parseInt(attr?.attributes?.role),
|
|
245
|
-
screenUid: parseInt(attr?.attributes?.screenUid),
|
|
246
|
-
offline: false,
|
|
247
|
-
requests: attr?.attributes?.requests,
|
|
248
|
-
},
|
|
249
|
-
[parseInt(attr?.attributes?.screenUid)]: {
|
|
250
|
-
name: `${attr?.attributes?.name || 'User'}'s screenshare`,
|
|
251
|
-
type: UserType.ScreenShare,
|
|
214
|
+
{
|
|
215
|
+
retry: (e, idx) => {
|
|
216
|
+
console.log(
|
|
217
|
+
`[retrying] Attempt ${idx}. Fetching ${member.uid}'s name`,
|
|
218
|
+
e,
|
|
219
|
+
);
|
|
220
|
+
return true;
|
|
252
221
|
},
|
|
222
|
+
},
|
|
223
|
+
);
|
|
224
|
+
try {
|
|
225
|
+
const attr = await backoffAttributes;
|
|
226
|
+
console.log('[user attributes]:', {attr});
|
|
227
|
+
//RTC layer uid type is number. so doing the parseInt to convert to number
|
|
228
|
+
//todo hari check android uid comparsion
|
|
229
|
+
const uid = parseInt(member.uid);
|
|
230
|
+
const screenUid = parseInt(attr?.attributes?.screenUid);
|
|
231
|
+
//start - updating user data in rtc
|
|
232
|
+
const userData = {
|
|
233
|
+
name:
|
|
234
|
+
String(member.uid)[0] === '1'
|
|
235
|
+
? pstnUserLabel
|
|
236
|
+
: attr?.attributes?.name || userText,
|
|
237
|
+
screenUid: screenUid,
|
|
238
|
+
//below thing for livestreaming
|
|
239
|
+
type: 'rtc',
|
|
253
240
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
241
|
+
updateRenderListState(uid, userData);
|
|
242
|
+
//end- updating user data in rtc
|
|
243
|
+
|
|
244
|
+
//start - updating screenshare data in rtc
|
|
245
|
+
const screenShareUser = {
|
|
246
|
+
name: getScreenShareName(attr?.attributes?.name || userText),
|
|
247
|
+
type: UserType.ScreenShare,
|
|
248
|
+
};
|
|
249
|
+
updateRenderListState(screenUid, screenShareUser);
|
|
250
|
+
//end - updating screenshare data in rtc
|
|
251
|
+
// setting screenshare data
|
|
252
|
+
// name of the screenUid, isActive: false, (when the user starts screensharing it becomes true)
|
|
253
|
+
// isActive to identify all active screenshare users in the call
|
|
254
|
+
for (const [key, value] of Object.entries(attr?.attributes)) {
|
|
255
|
+
if (hasJsonStructure(value as string)) {
|
|
256
|
+
const [err, result] = safeJsonParse(value as string);
|
|
257
|
+
const payloadValue = result?.value || '';
|
|
258
|
+
const payloadAction = result?.action || '';
|
|
259
|
+
const data = {
|
|
260
|
+
evt: key,
|
|
261
|
+
payload: {
|
|
262
|
+
...result,
|
|
263
|
+
value: payloadValue,
|
|
264
|
+
action: payloadAction,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
// Todo:EVENTSUP Add the data to queue, dont add same mulitple events, use set so as to not repeat events
|
|
268
|
+
EventsQueue.enqueue({
|
|
269
|
+
data: data,
|
|
270
|
+
uid: member.uid,
|
|
271
|
+
ts: timeNow(),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} catch (e) {
|
|
276
|
+
console.error(`Could not retrieve name of ${member.uid}`, e);
|
|
277
|
+
}
|
|
278
|
+
}),
|
|
279
|
+
);
|
|
259
280
|
setLogin(true);
|
|
260
281
|
console.log('RTM init done');
|
|
261
282
|
});
|
|
@@ -263,15 +284,15 @@ const RtmConfigure = (props: any) => {
|
|
|
263
284
|
} catch (error) {
|
|
264
285
|
setTimeout(async () => {
|
|
265
286
|
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
266
|
-
getMembers();
|
|
287
|
+
await getMembers();
|
|
267
288
|
}, timerValueRef.current * 1000);
|
|
268
289
|
}
|
|
269
290
|
};
|
|
291
|
+
|
|
270
292
|
const init = async () => {
|
|
271
|
-
engine.current =
|
|
272
|
-
rtcProps.
|
|
273
|
-
|
|
274
|
-
: (localUid.current = '' + timeNow());
|
|
293
|
+
engine.current = RTMEngine.getInstance().engine;
|
|
294
|
+
RTMEngine.getInstance().setLoginInfo(localUid.toString(), rtcProps.channel);
|
|
295
|
+
|
|
275
296
|
engine.current.on('connectionStateChanged', (evt: any) => {
|
|
276
297
|
//console.log(evt);
|
|
277
298
|
});
|
|
@@ -282,15 +303,12 @@ const RtmConfigure = (props: any) => {
|
|
|
282
303
|
const backoffAttributes = backOff(
|
|
283
304
|
async () => {
|
|
284
305
|
const attr = await engine.current.getUserAttributesByUid(data.uid);
|
|
285
|
-
|
|
286
|
-
attr
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return attr;
|
|
292
|
-
} else {
|
|
293
|
-
throw attr;
|
|
306
|
+
for (const key in attr.attributes) {
|
|
307
|
+
if (attr.attributes.hasOwnProperty(key) && attr.attributes[key]) {
|
|
308
|
+
return attr;
|
|
309
|
+
} else {
|
|
310
|
+
throw attr;
|
|
311
|
+
}
|
|
294
312
|
}
|
|
295
313
|
},
|
|
296
314
|
{
|
|
@@ -307,23 +325,28 @@ const RtmConfigure = (props: any) => {
|
|
|
307
325
|
try {
|
|
308
326
|
const attr = await backoffAttributes;
|
|
309
327
|
console.log('[user attributes]:', {attr});
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
328
|
+
const uid = parseInt(data.uid);
|
|
329
|
+
const screenUid = parseInt(attr?.attributes?.screenUid);
|
|
330
|
+
//start - updating user data in rtc
|
|
331
|
+
const userData = {
|
|
332
|
+
name:
|
|
333
|
+
String(data.uid)[0] === '1'
|
|
334
|
+
? pstnUserLabel
|
|
335
|
+
: attr?.attributes?.name || userText,
|
|
336
|
+
screenUid: screenUid,
|
|
337
|
+
//below thing for livestreaming
|
|
338
|
+
type: 'rtc',
|
|
339
|
+
};
|
|
340
|
+
updateRenderListState(uid, userData);
|
|
341
|
+
//end- updating user data in rtc
|
|
342
|
+
|
|
343
|
+
//start - updating screenshare data in rtc
|
|
344
|
+
const screenShareUser = {
|
|
345
|
+
name: getScreenShareName(attr?.attributes?.name || userText),
|
|
346
|
+
type: UserType.ScreenShare,
|
|
347
|
+
};
|
|
348
|
+
updateRenderListState(screenUid, screenShareUser);
|
|
349
|
+
//end - updating screenshare data in rtc
|
|
327
350
|
} catch (e) {
|
|
328
351
|
console.error(`Could not retrieve name of ${data.uid}`, e);
|
|
329
352
|
}
|
|
@@ -334,17 +357,11 @@ const RtmConfigure = (props: any) => {
|
|
|
334
357
|
engine.current.on('channelMemberLeft', (data: any) => {
|
|
335
358
|
console.log('user left', data);
|
|
336
359
|
// Chat of left user becomes undefined. So don't cleanup
|
|
337
|
-
const
|
|
360
|
+
const uid = data?.uid ? parseInt(data?.uid) : undefined;
|
|
338
361
|
if (!uid) return;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
[uid]: {
|
|
343
|
-
...prevState[uid],
|
|
344
|
-
requests: attrRequestTypes.none,
|
|
345
|
-
offline: true,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
362
|
+
//updating the rtc data
|
|
363
|
+
updateRenderListState(uid, {
|
|
364
|
+
offline: true,
|
|
348
365
|
});
|
|
349
366
|
});
|
|
350
367
|
|
|
@@ -358,79 +375,59 @@ const RtmConfigure = (props: any) => {
|
|
|
358
375
|
|
|
359
376
|
const timestamp = timeNow();
|
|
360
377
|
|
|
361
|
-
const
|
|
378
|
+
const sender = isAndroid ? arr[0] : peerId;
|
|
362
379
|
|
|
363
380
|
if (type === messageActionType.Control) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
break;
|
|
388
|
-
// throw new Error('Unsupported message type');
|
|
389
|
-
}
|
|
390
|
-
} catch (e) {
|
|
391
|
-
events.emit(messageChannelType.Private, null, {
|
|
392
|
-
msg: `Error while dispatching ${messageChannelType.Private} control message`,
|
|
393
|
-
cause: e,
|
|
394
|
-
});
|
|
395
|
-
return;
|
|
381
|
+
switch (msg) {
|
|
382
|
+
case controlMessageEnum.muteVideo:
|
|
383
|
+
RtcEngine.muteLocalVideoStream(true);
|
|
384
|
+
dispatch({
|
|
385
|
+
type: 'LocalMuteVideo',
|
|
386
|
+
value: [0],
|
|
387
|
+
});
|
|
388
|
+
break;
|
|
389
|
+
case controlMessageEnum.muteAudio:
|
|
390
|
+
RtcEngine.muteLocalAudioStream(true);
|
|
391
|
+
dispatch({
|
|
392
|
+
type: 'LocalMuteAudio',
|
|
393
|
+
value: [0],
|
|
394
|
+
});
|
|
395
|
+
break;
|
|
396
|
+
case controlMessageEnum.kickUser:
|
|
397
|
+
dispatch({
|
|
398
|
+
type: 'EndCall',
|
|
399
|
+
value: [],
|
|
400
|
+
});
|
|
401
|
+
break;
|
|
402
|
+
default:
|
|
403
|
+
break;
|
|
396
404
|
}
|
|
397
|
-
} else if (type ===
|
|
405
|
+
} else if (type === eventMessageType.CUSTOM_EVENT) {
|
|
406
|
+
console.log('CUSTOM_EVENT_API: inside custom event type ', evt);
|
|
398
407
|
try {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
body: `${type}${msg}`,
|
|
403
|
-
ts: timestamp,
|
|
404
|
-
},
|
|
405
|
-
false,
|
|
406
|
-
);
|
|
407
|
-
} catch (e) {
|
|
408
|
-
events.emit(messageChannelType.Private, null, {
|
|
409
|
-
msg: `Error while adding ${messageChannelType.Private} message to store`,
|
|
410
|
-
cause: e,
|
|
411
|
-
});
|
|
412
|
-
return;
|
|
408
|
+
customEventDispatcher(msg, sender, timestamp);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
console.log('error while dispacthing', error);
|
|
413
411
|
}
|
|
414
412
|
}
|
|
415
|
-
events.emit(messageChannelType.Private, {
|
|
416
|
-
uid: userUID,
|
|
417
|
-
ts: timestamp,
|
|
418
|
-
...textObj,
|
|
419
|
-
});
|
|
420
413
|
});
|
|
421
414
|
|
|
422
415
|
engine.current.on('channelMessageReceived', (evt) => {
|
|
423
416
|
const {uid, channelId, text, ts} = evt;
|
|
424
417
|
const textObj = parsePayload(text);
|
|
418
|
+
const [err, result] = safeJsonParse(text);
|
|
425
419
|
const {type, msg} = textObj;
|
|
426
420
|
let arr = new Int32Array(1);
|
|
427
421
|
arr[0] = parseInt(uid);
|
|
428
422
|
|
|
429
|
-
const
|
|
430
|
-
const timestamp = ts === 0 ? timeNow() : ts;
|
|
423
|
+
const sender = Platform.OS ? arr[0] : uid;
|
|
424
|
+
const timestamp = ts ? (parseInt(ts) === 0 ? timeNow() : ts) : timeNow();
|
|
431
425
|
|
|
432
426
|
if (channelId === rtcProps.channel) {
|
|
433
|
-
if (
|
|
427
|
+
if (
|
|
428
|
+
type === eventMessageType.CONTROL_GROUP ||
|
|
429
|
+
type === messageActionType.Control
|
|
430
|
+
) {
|
|
434
431
|
let actionMsg = '';
|
|
435
432
|
if (hasJsonStructure(msg)) {
|
|
436
433
|
const [err, result] = safeJsonParse(msg);
|
|
@@ -441,91 +438,85 @@ const RtmConfigure = (props: any) => {
|
|
|
441
438
|
} else {
|
|
442
439
|
actionMsg = msg;
|
|
443
440
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
break;
|
|
463
|
-
case controlMessageEnum.cloudRecordingUnactive:
|
|
464
|
-
setRecordingActive(false);
|
|
465
|
-
break;
|
|
466
|
-
case controlMessageEnum.clientRoleChanged:
|
|
467
|
-
const {payload} = JSON.parse(msg);
|
|
468
|
-
if (payload && payload?.role) {
|
|
469
|
-
if (
|
|
470
|
-
payload.role.trim() !== '' &&
|
|
471
|
-
payload.role in ClientRole
|
|
472
|
-
) {
|
|
473
|
-
setUserList((prevState) => {
|
|
474
|
-
return {
|
|
475
|
-
...prevState,
|
|
476
|
-
[uid]: {
|
|
477
|
-
...prevState[uid],
|
|
478
|
-
role: parseInt(payload.role),
|
|
479
|
-
},
|
|
480
|
-
};
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
break;
|
|
485
|
-
default:
|
|
486
|
-
break;
|
|
487
|
-
// throw new Error('Unsupported message type');
|
|
488
|
-
}
|
|
489
|
-
} catch (e) {
|
|
490
|
-
events.emit(messageChannelType.Public, null, {
|
|
491
|
-
msg: `Error while dispatching ${messageChannelType.Public} control message`,
|
|
492
|
-
cause: e,
|
|
493
|
-
});
|
|
494
|
-
return;
|
|
441
|
+
switch (actionMsg) {
|
|
442
|
+
case controlMessageEnum.muteVideo:
|
|
443
|
+
RtcEngine.muteLocalVideoStream(true);
|
|
444
|
+
dispatch({
|
|
445
|
+
type: 'LocalMuteVideo',
|
|
446
|
+
value: [0],
|
|
447
|
+
});
|
|
448
|
+
break;
|
|
449
|
+
case controlMessageEnum.muteAudio:
|
|
450
|
+
RtcEngine.muteLocalAudioStream(true);
|
|
451
|
+
dispatch({
|
|
452
|
+
type: 'LocalMuteAudio',
|
|
453
|
+
value: [0],
|
|
454
|
+
});
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
break;
|
|
458
|
+
// throw new Error('Unsupported message type');
|
|
495
459
|
}
|
|
496
|
-
} else if (type ===
|
|
460
|
+
} else if (type === eventMessageType.CUSTOM_EVENT) {
|
|
461
|
+
console.log('CUSTOM_EVENT_API: inside custom event type ', evt);
|
|
497
462
|
try {
|
|
498
|
-
|
|
499
|
-
} catch (
|
|
500
|
-
|
|
501
|
-
msg: `Error while adding ${messageChannelType.Public} message to store`,
|
|
502
|
-
cause: e,
|
|
503
|
-
});
|
|
504
|
-
return;
|
|
463
|
+
customEventDispatcher(msg, sender, timestamp);
|
|
464
|
+
} catch (error) {
|
|
465
|
+
console.log('error while dispacthing', error);
|
|
505
466
|
}
|
|
506
467
|
}
|
|
507
468
|
}
|
|
508
|
-
events.emit(messageChannelType.Public, {
|
|
509
|
-
uid: userUID,
|
|
510
|
-
ts: timestamp,
|
|
511
|
-
...textObj,
|
|
512
|
-
});
|
|
513
469
|
});
|
|
470
|
+
doLoginAndSetupRTM();
|
|
471
|
+
};
|
|
514
472
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
473
|
+
const runQueuedCustomEvents = async () => {
|
|
474
|
+
try {
|
|
475
|
+
const eventsInQueue = EventsQueue.printQueue();
|
|
476
|
+
if (eventsInQueue.length !== 0) {
|
|
477
|
+
for (const queuedEvents of eventsInQueue) {
|
|
478
|
+
await customEventDispatcher(
|
|
479
|
+
queuedEvents.data,
|
|
480
|
+
queuedEvents.uid,
|
|
481
|
+
queuedEvents.ts,
|
|
482
|
+
);
|
|
483
|
+
EventsQueue.dequeue();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
} catch (error) {
|
|
487
|
+
throw Error(
|
|
488
|
+
'CUSTOM_EVENTS_API: error while running queued events ',
|
|
489
|
+
error,
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
526
493
|
|
|
527
|
-
|
|
528
|
-
|
|
494
|
+
const customEventDispatcher = async (
|
|
495
|
+
data: {
|
|
496
|
+
evt: string;
|
|
497
|
+
payload: {
|
|
498
|
+
level: 1 | 2 | 3;
|
|
499
|
+
action: string;
|
|
500
|
+
value: string;
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
sender: string,
|
|
504
|
+
ts: number,
|
|
505
|
+
) => {
|
|
506
|
+
console.log('CUSTOM_EVENT_API: inside customEventDispatcher ', data);
|
|
507
|
+
const {evt, payload} = data;
|
|
508
|
+
// Step 1: Set local attributes
|
|
509
|
+
if (payload?.level === 3) {
|
|
510
|
+
const rtmAttribute = {key: evt, value: JSON.stringify(data.payload)};
|
|
511
|
+
await engine.current.addOrUpdateLocalUserAttributes([rtmAttribute]);
|
|
512
|
+
}
|
|
513
|
+
// Step 2: Emit the event
|
|
514
|
+
try {
|
|
515
|
+
console.log('CUSTOM_EVENT_API: emiting event: ');
|
|
516
|
+
EventUtils.emitEvent(evt, {payload, sender, ts});
|
|
517
|
+
} catch (error) {
|
|
518
|
+
console.log('CUSTOM_EVENT_API: error while emiting event: ', error);
|
|
519
|
+
}
|
|
529
520
|
};
|
|
530
521
|
|
|
531
522
|
const sendMessage = async (msg: string) => {
|
|
@@ -539,13 +530,9 @@ const RtmConfigure = (props: any) => {
|
|
|
539
530
|
rtcProps.channel,
|
|
540
531
|
text,
|
|
541
532
|
);
|
|
542
|
-
addMessageToStore(localUid.current, {
|
|
543
|
-
body: messageActionType.Normal + msg,
|
|
544
|
-
ts: timeNow(),
|
|
545
|
-
});
|
|
546
533
|
};
|
|
547
534
|
|
|
548
|
-
const sendMessageToUid = async (msg: string, uid:
|
|
535
|
+
const sendMessageToUid = async (msg: string, uid: UidType) => {
|
|
549
536
|
if (msg.trim() === '') return;
|
|
550
537
|
let adjustedUID = uid;
|
|
551
538
|
if (adjustedUID < 0) {
|
|
@@ -561,14 +548,6 @@ const RtmConfigure = (props: any) => {
|
|
|
561
548
|
offline: false,
|
|
562
549
|
text,
|
|
563
550
|
});
|
|
564
|
-
addMessageToPrivateStore(
|
|
565
|
-
uid,
|
|
566
|
-
{
|
|
567
|
-
body: messageActionType.Normal + msg,
|
|
568
|
-
ts: timeNow(),
|
|
569
|
-
},
|
|
570
|
-
true,
|
|
571
|
-
);
|
|
572
551
|
};
|
|
573
552
|
|
|
574
553
|
const sendControlMessage = async (msg: string) => {
|
|
@@ -583,7 +562,7 @@ const RtmConfigure = (props: any) => {
|
|
|
583
562
|
);
|
|
584
563
|
};
|
|
585
564
|
|
|
586
|
-
const sendControlMessageToUid = async (msg: string, uid:
|
|
565
|
+
const sendControlMessageToUid = async (msg: string, uid: UidType) => {
|
|
587
566
|
if (uid < 0) {
|
|
588
567
|
uid = adjustUID(uid);
|
|
589
568
|
}
|
|
@@ -608,24 +587,6 @@ const RtmConfigure = (props: any) => {
|
|
|
608
587
|
: {};
|
|
609
588
|
};
|
|
610
589
|
|
|
611
|
-
const updateChannelAttributes = async (attributes: RtmChannelAttribute[]) => {
|
|
612
|
-
/**
|
|
613
|
-
* a) The following piece of code is commented for future reference.
|
|
614
|
-
* b) To be used in future implementations of channel attributes
|
|
615
|
-
* c) attributes should be an array of key value [{key:"keyTobeUsed", value; 'valueToBeUsed}]
|
|
616
|
-
* following the type RtmChannelAttribute
|
|
617
|
-
*/
|
|
618
|
-
// try {
|
|
619
|
-
// await (engine.current as RtmEngine).addOrUpdateChannelAttributes(
|
|
620
|
-
// rtcProps.channel,
|
|
621
|
-
// [...attributes],
|
|
622
|
-
// {enableNotificationToChannelMembers: true},
|
|
623
|
-
// );
|
|
624
|
-
// } catch (error) {
|
|
625
|
-
// console.log('AttributesUpdated error', error);
|
|
626
|
-
// }
|
|
627
|
-
};
|
|
628
|
-
|
|
629
590
|
useEffect(() => {
|
|
630
591
|
callActive ? init() : (console.log('waiting to init RTM'), setLogin(true));
|
|
631
592
|
return () => {
|
|
@@ -634,58 +595,19 @@ const RtmConfigure = (props: any) => {
|
|
|
634
595
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
635
596
|
}, [rtcProps.channel, rtcProps.appId, callActive]);
|
|
636
597
|
|
|
637
|
-
const broadcastUserAttributes = async (
|
|
638
|
-
attributes: RtmAttribute[],
|
|
639
|
-
ctrlMsg: controlMessageEnum,
|
|
640
|
-
) => {
|
|
641
|
-
// 1. Update my attributes in attribute-list
|
|
642
|
-
await addOrUpdateLocalUserAttributes(attributes);
|
|
643
|
-
|
|
644
|
-
let formattedAttributes: any = {};
|
|
645
|
-
// Transform the array into object of key value pair
|
|
646
|
-
attributes.map((attribute) => {
|
|
647
|
-
let key = Object.values(attribute)[0];
|
|
648
|
-
let value = Object.values(attribute)[1];
|
|
649
|
-
formattedAttributes[key] = value;
|
|
650
|
-
});
|
|
651
|
-
// 2. Update my attributes in user-list
|
|
652
|
-
setUserList((prevState) => {
|
|
653
|
-
return {
|
|
654
|
-
...prevState,
|
|
655
|
-
[localUid.current]: {
|
|
656
|
-
...prevState[localUid.current],
|
|
657
|
-
...formattedAttributes,
|
|
658
|
-
},
|
|
659
|
-
};
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* 3. Broadcast my updated attributes to everyone
|
|
664
|
-
* send payload and control message as string
|
|
665
|
-
*/
|
|
666
|
-
const msgAsString = JSON.stringify({
|
|
667
|
-
action: ctrlMsg,
|
|
668
|
-
payload: {...formattedAttributes},
|
|
669
|
-
});
|
|
670
|
-
sendControlMessage(msgAsString);
|
|
671
|
-
};
|
|
672
|
-
|
|
673
598
|
return (
|
|
674
599
|
<ChatContext.Provider
|
|
675
600
|
value={{
|
|
676
|
-
|
|
677
|
-
privateMessageStore,
|
|
601
|
+
hasUserJoinedRTM,
|
|
678
602
|
sendControlMessage,
|
|
679
603
|
sendControlMessageToUid,
|
|
680
604
|
sendMessage,
|
|
681
605
|
sendMessageToUid,
|
|
682
|
-
broadcastUserAttributes,
|
|
683
|
-
addOrUpdateLocalUserAttributes,
|
|
684
606
|
engine: engine.current,
|
|
685
|
-
localUid: localUid
|
|
686
|
-
userList: userList,
|
|
607
|
+
localUid: localUid,
|
|
687
608
|
onlineUsersCount,
|
|
688
|
-
|
|
609
|
+
setDisplayName,
|
|
610
|
+
displayName,
|
|
689
611
|
}}>
|
|
690
612
|
{login ? props.children : <></>}
|
|
691
613
|
</ChatContext.Provider>
|