agora-appbuilder-core 2.2.0 → 2.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +32186 -3078
- 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 +29 -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.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 +91 -115
- 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 +328 -416
- 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 +208 -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 +41 -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 +239 -0
- package/template/src/components/useWakeLock.tsx +3 -3
- package/template/src/custom-events/CustomEvents.ts +221 -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 +44 -0
- package/template/src/rtm-events/EventUtils.ts +267 -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 +79 -30
- 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 +61 -31
- package/template/src/subComponents/screenshare/ScreenshareConfigure.native.tsx +57 -52
- package/template/src/subComponents/screenshare/ScreenshareConfigure.tsx +102 -143
- 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/HEAD +0 -1
- package/template/agora-rn-uikit/.git/config +0 -16
- package/template/agora-rn-uikit/.git/description +0 -1
- package/template/agora-rn-uikit/.git/hooks/applypatch-msg.sample +0 -15
- package/template/agora-rn-uikit/.git/hooks/commit-msg.sample +0 -24
- package/template/agora-rn-uikit/.git/hooks/fsmonitor-watchman.sample +0 -173
- package/template/agora-rn-uikit/.git/hooks/post-update.sample +0 -8
- package/template/agora-rn-uikit/.git/hooks/pre-applypatch.sample +0 -14
- package/template/agora-rn-uikit/.git/hooks/pre-commit.sample +0 -49
- package/template/agora-rn-uikit/.git/hooks/pre-merge-commit.sample +0 -13
- package/template/agora-rn-uikit/.git/hooks/pre-push.sample +0 -53
- package/template/agora-rn-uikit/.git/hooks/pre-rebase.sample +0 -169
- package/template/agora-rn-uikit/.git/hooks/pre-receive.sample +0 -24
- package/template/agora-rn-uikit/.git/hooks/prepare-commit-msg.sample +0 -42
- package/template/agora-rn-uikit/.git/hooks/push-to-checkout.sample +0 -78
- package/template/agora-rn-uikit/.git/hooks/update.sample +0 -128
- package/template/agora-rn-uikit/.git/index +0 -0
- package/template/agora-rn-uikit/.git/info/exclude +0 -6
- package/template/agora-rn-uikit/.git/logs/HEAD +0 -2
- package/template/agora-rn-uikit/.git/logs/refs/heads/ab-dev-auto +0 -1
- package/template/agora-rn-uikit/.git/logs/refs/heads/master +0 -1
- package/template/agora-rn-uikit/.git/logs/refs/remotes/origin/HEAD +0 -1
- package/template/agora-rn-uikit/.git/objects/pack/pack-0061d00cd98162a329a32b537488a35d0abeb069.idx +0 -0
- package/template/agora-rn-uikit/.git/objects/pack/pack-0061d00cd98162a329a32b537488a35d0abeb069.pack +0 -0
- package/template/agora-rn-uikit/.git/packed-refs +0 -24
- package/template/agora-rn-uikit/.git/refs/heads/ab-dev-auto +0 -1
- package/template/agora-rn-uikit/.git/refs/heads/master +0 -1
- package/template/agora-rn-uikit/.git/refs/remotes/origin/HEAD +0 -1
- package/template/agora-rn-uikit/.gitignore +0 -63
- package/template/agora-rn-uikit/package-lock.json +0 -7612
- package/template/agora-rn-uikit/src/Contexts/MaxUidContext.tsx +0 -7
- package/template/agora-rn-uikit/src/Contexts/MinUidContext.tsx +0 -8
- package/template/package-lock.json +0 -22923
- package/template/react-native-toast-message/.gitignore +0 -5
- package/template/react-native-toast-message/.npmignore +0 -5
- package/template/react-native-toast-message/package-lock.json +0 -10553
- package/template/src/.DS_Store +0 -0
- package/template/src/components/participants/context/ParticipantContext.tsx +0 -97
- package/template/src/subComponents/.DS_Store +0 -0
- 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,38 +9,35 @@
|
|
|
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 {
|
|
26
|
+
safeJsonParse,
|
|
27
|
+
timeNow,
|
|
28
|
+
hasJsonStructure,
|
|
29
|
+
getMessageTime,
|
|
30
|
+
get32BitUid,
|
|
31
|
+
adjustUID,
|
|
32
|
+
} from '../rtm/utils';
|
|
33
|
+
import {EventUtils, EventsQueue, eventMessageType} from '../rtm-events';
|
|
34
|
+
import RTMEngine from '../rtm/RTMEngine';
|
|
30
35
|
import {filterObject} from '../utils';
|
|
31
36
|
|
|
32
37
|
export enum UserType {
|
|
33
|
-
|
|
34
|
-
ScreenShare,
|
|
38
|
+
ScreenShare = 'screenshare',
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
const adjustUID = (number: number) => {
|
|
38
|
-
if (number < 0) {
|
|
39
|
-
number = 0xffffffff + number + 1;
|
|
40
|
-
}
|
|
41
|
-
return number;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
41
|
const stringifyPayload = (
|
|
45
42
|
source: messageSourceType,
|
|
46
43
|
type: messageActionType,
|
|
@@ -57,45 +54,72 @@ const parsePayload = (data: string) => {
|
|
|
57
54
|
return JSON.parse(data);
|
|
58
55
|
};
|
|
59
56
|
|
|
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
57
|
const RtmConfigure = (props: any) => {
|
|
80
|
-
const
|
|
58
|
+
const localUid = useLocalUid();
|
|
59
|
+
const {callActive} = props;
|
|
81
60
|
const {rtcProps} = useContext(PropsContext);
|
|
82
61
|
const {RtcEngine, dispatch} = useContext(RtcContext);
|
|
83
|
-
const
|
|
84
|
-
const
|
|
62
|
+
const {renderList, renderPosition} = useRenderContext();
|
|
63
|
+
const renderListRef = useRef({renderList: renderList});
|
|
64
|
+
const renderPositionRef = useRef({renderPosition: renderPosition});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* inside event callback state won't have latest value.
|
|
68
|
+
* so creating ref to access the state
|
|
69
|
+
*/
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
renderPositionRef.current.renderPosition = renderPosition;
|
|
72
|
+
}, [renderPosition]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
renderListRef.current.renderList = renderList;
|
|
76
|
+
}, [renderList]);
|
|
77
|
+
|
|
78
|
+
const {store, setStore} = useContext(StorageContext);
|
|
79
|
+
const getInitialUsername = () =>
|
|
80
|
+
store?.displayName ? store.displayName : '';
|
|
81
|
+
const [displayName, setDisplayName] = useState(getInitialUsername());
|
|
82
|
+
|
|
83
|
+
//Update the store displayName value if the state is changed
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setStore((prevState) => {
|
|
86
|
+
return {
|
|
87
|
+
...prevState,
|
|
88
|
+
displayName,
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}, [displayName]);
|
|
92
|
+
|
|
85
93
|
const [login, setLogin] = useState<boolean>(false);
|
|
86
|
-
|
|
94
|
+
|
|
95
|
+
const [hasUserJoinedRTM, setHasUserJoinedRTM] = useState<boolean>(false);
|
|
87
96
|
const [onlineUsersCount, setTotalOnlineUsers] = useState<number>(0);
|
|
88
97
|
|
|
98
|
+
//commented for v1 release
|
|
99
|
+
// const userText = useString('remoteUserDefaultLabel')();
|
|
100
|
+
const userText = 'User';
|
|
101
|
+
const pstnUserLabel = useString('pstnUserLabel')();
|
|
102
|
+
//commented for v1 release
|
|
103
|
+
//const getScreenShareName = useString('screenshareUserName');
|
|
104
|
+
const getScreenShareName = (name: string) => `${name}'s screenshare`;
|
|
105
|
+
|
|
89
106
|
let engine = useRef<RtmEngine>(null!);
|
|
90
|
-
let localUid = useRef<string>('');
|
|
91
107
|
const timerValueRef: any = useRef(5);
|
|
92
108
|
|
|
109
|
+
React.useEffect(() => {
|
|
110
|
+
setTotalOnlineUsers(
|
|
111
|
+
Object.keys(
|
|
112
|
+
filterObject(renderList, ([k, v]) => v?.type === 'rtc' && !v.offline),
|
|
113
|
+
).length,
|
|
114
|
+
);
|
|
115
|
+
}, [renderList]);
|
|
116
|
+
|
|
93
117
|
React.useEffect(() => {
|
|
94
118
|
const handBrowserClose = () => {
|
|
95
119
|
engine.current.leaveChannel(rtcProps.channel);
|
|
96
120
|
};
|
|
97
121
|
|
|
98
|
-
if (
|
|
122
|
+
if (!isWeb) return;
|
|
99
123
|
window.addEventListener('beforeunload', handBrowserClose);
|
|
100
124
|
// cleanup this component
|
|
101
125
|
return () => {
|
|
@@ -103,52 +127,10 @@ const RtmConfigure = (props: any) => {
|
|
|
103
127
|
};
|
|
104
128
|
}, []);
|
|
105
129
|
|
|
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
130
|
const doLoginAndSetupRTM = async () => {
|
|
149
131
|
try {
|
|
150
132
|
await engine.current.login({
|
|
151
|
-
uid: localUid.
|
|
133
|
+
uid: localUid.toString(),
|
|
152
134
|
token: rtcProps.rtm,
|
|
153
135
|
});
|
|
154
136
|
timerValueRef.current = 5;
|
|
@@ -162,13 +144,12 @@ const RtmConfigure = (props: any) => {
|
|
|
162
144
|
};
|
|
163
145
|
|
|
164
146
|
const setAttribute = async () => {
|
|
147
|
+
const rtmAttributes = [
|
|
148
|
+
{key: 'name', value: displayName || userText},
|
|
149
|
+
{key: 'screenUid', value: String(rtcProps.screenShareUid)},
|
|
150
|
+
];
|
|
165
151
|
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
|
-
]);
|
|
152
|
+
await engine.current.setLocalUserAttributes(rtmAttributes);
|
|
172
153
|
timerValueRef.current = 5;
|
|
173
154
|
joinChannel();
|
|
174
155
|
} catch (error) {
|
|
@@ -179,19 +160,13 @@ const RtmConfigure = (props: any) => {
|
|
|
179
160
|
}
|
|
180
161
|
};
|
|
181
162
|
|
|
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
163
|
const joinChannel = async () => {
|
|
191
164
|
try {
|
|
192
165
|
await engine.current.joinChannel(rtcProps.channel);
|
|
193
166
|
timerValueRef.current = 5;
|
|
194
|
-
getMembers();
|
|
167
|
+
await getMembers();
|
|
168
|
+
setHasUserJoinedRTM(true);
|
|
169
|
+
await runQueuedCustomEvents();
|
|
195
170
|
} catch (error) {
|
|
196
171
|
setTimeout(async () => {
|
|
197
172
|
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
@@ -200,62 +175,102 @@ const RtmConfigure = (props: any) => {
|
|
|
200
175
|
}
|
|
201
176
|
};
|
|
202
177
|
|
|
178
|
+
const updateRenderListState = (
|
|
179
|
+
uid: number,
|
|
180
|
+
data: Partial<RenderInterface>,
|
|
181
|
+
) => {
|
|
182
|
+
dispatch({type: 'UpdateRenderList', value: [uid, data]});
|
|
183
|
+
};
|
|
184
|
+
|
|
203
185
|
const getMembers = async () => {
|
|
204
186
|
try {
|
|
205
187
|
await engine.current
|
|
206
188
|
.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,
|
|
189
|
+
.then(async (data) => {
|
|
190
|
+
await Promise.all(
|
|
191
|
+
data.members.map(async (member: any) => {
|
|
192
|
+
const backoffAttributes = backOff(
|
|
193
|
+
async () => {
|
|
194
|
+
const attr = await engine.current.getUserAttributesByUid(
|
|
195
|
+
member.uid,
|
|
230
196
|
);
|
|
231
|
-
|
|
197
|
+
for (const key in attr.attributes) {
|
|
198
|
+
if (
|
|
199
|
+
attr.attributes.hasOwnProperty(key) &&
|
|
200
|
+
attr.attributes[key]
|
|
201
|
+
) {
|
|
202
|
+
return attr;
|
|
203
|
+
} else {
|
|
204
|
+
throw attr;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
232
207
|
},
|
|
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,
|
|
208
|
+
{
|
|
209
|
+
retry: (e, idx) => {
|
|
210
|
+
console.log(
|
|
211
|
+
`[retrying] Attempt ${idx}. Fetching ${member.uid}'s name`,
|
|
212
|
+
e,
|
|
213
|
+
);
|
|
214
|
+
return true;
|
|
252
215
|
},
|
|
216
|
+
},
|
|
217
|
+
);
|
|
218
|
+
try {
|
|
219
|
+
const attr = await backoffAttributes;
|
|
220
|
+
console.log('[user attributes]:', {attr});
|
|
221
|
+
//RTC layer uid type is number. so doing the parseInt to convert to number
|
|
222
|
+
//todo hari check android uid comparsion
|
|
223
|
+
const uid = parseInt(member.uid);
|
|
224
|
+
const screenUid = parseInt(attr?.attributes?.screenUid);
|
|
225
|
+
//start - updating user data in rtc
|
|
226
|
+
const userData = {
|
|
227
|
+
name:
|
|
228
|
+
String(member.uid)[0] === '1'
|
|
229
|
+
? pstnUserLabel
|
|
230
|
+
: attr?.attributes?.name || userText,
|
|
231
|
+
screenUid: screenUid,
|
|
232
|
+
//below thing for livestreaming
|
|
233
|
+
type: 'rtc',
|
|
253
234
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
235
|
+
updateRenderListState(uid, userData);
|
|
236
|
+
//end- updating user data in rtc
|
|
237
|
+
|
|
238
|
+
//start - updating screenshare data in rtc
|
|
239
|
+
const screenShareUser = {
|
|
240
|
+
name: getScreenShareName(attr?.attributes?.name || userText),
|
|
241
|
+
type: UserType.ScreenShare,
|
|
242
|
+
};
|
|
243
|
+
updateRenderListState(screenUid, screenShareUser);
|
|
244
|
+
//end - updating screenshare data in rtc
|
|
245
|
+
// setting screenshare data
|
|
246
|
+
// name of the screenUid, isActive: false, (when the user starts screensharing it becomes true)
|
|
247
|
+
// isActive to identify all active screenshare users in the call
|
|
248
|
+
for (const [key, value] of Object.entries(attr?.attributes)) {
|
|
249
|
+
if (hasJsonStructure(value as string)) {
|
|
250
|
+
const [err, result] = safeJsonParse(value as string);
|
|
251
|
+
const payloadValue = result?.value || '';
|
|
252
|
+
const payloadAction = result?.action || '';
|
|
253
|
+
const data = {
|
|
254
|
+
evt: key,
|
|
255
|
+
payload: {
|
|
256
|
+
...result,
|
|
257
|
+
value: payloadValue,
|
|
258
|
+
action: payloadAction,
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
// Todo:EVENTSUP Add the data to queue, dont add same mulitple events, use set so as to not repeat events
|
|
262
|
+
EventsQueue.enqueue({
|
|
263
|
+
data: data,
|
|
264
|
+
uid: member.uid,
|
|
265
|
+
ts: timeNow(),
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
} catch (e) {
|
|
270
|
+
console.error(`Could not retrieve name of ${member.uid}`, e);
|
|
271
|
+
}
|
|
272
|
+
}),
|
|
273
|
+
);
|
|
259
274
|
setLogin(true);
|
|
260
275
|
console.log('RTM init done');
|
|
261
276
|
});
|
|
@@ -263,15 +278,15 @@ const RtmConfigure = (props: any) => {
|
|
|
263
278
|
} catch (error) {
|
|
264
279
|
setTimeout(async () => {
|
|
265
280
|
timerValueRef.current = timerValueRef.current + timerValueRef.current;
|
|
266
|
-
getMembers();
|
|
281
|
+
await getMembers();
|
|
267
282
|
}, timerValueRef.current * 1000);
|
|
268
283
|
}
|
|
269
284
|
};
|
|
285
|
+
|
|
270
286
|
const init = async () => {
|
|
271
|
-
engine.current =
|
|
272
|
-
rtcProps.
|
|
273
|
-
|
|
274
|
-
: (localUid.current = '' + timeNow());
|
|
287
|
+
engine.current = RTMEngine.getInstance().engine;
|
|
288
|
+
RTMEngine.getInstance().setLoginInfo(localUid.toString(), rtcProps.channel);
|
|
289
|
+
|
|
275
290
|
engine.current.on('connectionStateChanged', (evt: any) => {
|
|
276
291
|
//console.log(evt);
|
|
277
292
|
});
|
|
@@ -282,15 +297,12 @@ const RtmConfigure = (props: any) => {
|
|
|
282
297
|
const backoffAttributes = backOff(
|
|
283
298
|
async () => {
|
|
284
299
|
const attr = await engine.current.getUserAttributesByUid(data.uid);
|
|
285
|
-
|
|
286
|
-
attr
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return attr;
|
|
292
|
-
} else {
|
|
293
|
-
throw attr;
|
|
300
|
+
for (const key in attr.attributes) {
|
|
301
|
+
if (attr.attributes.hasOwnProperty(key) && attr.attributes[key]) {
|
|
302
|
+
return attr;
|
|
303
|
+
} else {
|
|
304
|
+
throw attr;
|
|
305
|
+
}
|
|
294
306
|
}
|
|
295
307
|
},
|
|
296
308
|
{
|
|
@@ -307,23 +319,28 @@ const RtmConfigure = (props: any) => {
|
|
|
307
319
|
try {
|
|
308
320
|
const attr = await backoffAttributes;
|
|
309
321
|
console.log('[user attributes]:', {attr});
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
322
|
+
const uid = parseInt(data.uid);
|
|
323
|
+
const screenUid = parseInt(attr?.attributes?.screenUid);
|
|
324
|
+
//start - updating user data in rtc
|
|
325
|
+
const userData = {
|
|
326
|
+
name:
|
|
327
|
+
String(data.uid)[0] === '1'
|
|
328
|
+
? pstnUserLabel
|
|
329
|
+
: attr?.attributes?.name || userText,
|
|
330
|
+
screenUid: screenUid,
|
|
331
|
+
//below thing for livestreaming
|
|
332
|
+
type: 'rtc',
|
|
333
|
+
};
|
|
334
|
+
updateRenderListState(uid, userData);
|
|
335
|
+
//end- updating user data in rtc
|
|
336
|
+
|
|
337
|
+
//start - updating screenshare data in rtc
|
|
338
|
+
const screenShareUser = {
|
|
339
|
+
name: getScreenShareName(attr?.attributes?.name || userText),
|
|
340
|
+
type: UserType.ScreenShare,
|
|
341
|
+
};
|
|
342
|
+
updateRenderListState(screenUid, screenShareUser);
|
|
343
|
+
//end - updating screenshare data in rtc
|
|
327
344
|
} catch (e) {
|
|
328
345
|
console.error(`Could not retrieve name of ${data.uid}`, e);
|
|
329
346
|
}
|
|
@@ -334,17 +351,11 @@ const RtmConfigure = (props: any) => {
|
|
|
334
351
|
engine.current.on('channelMemberLeft', (data: any) => {
|
|
335
352
|
console.log('user left', data);
|
|
336
353
|
// Chat of left user becomes undefined. So don't cleanup
|
|
337
|
-
const
|
|
354
|
+
const uid = data?.uid ? parseInt(data?.uid) : undefined;
|
|
338
355
|
if (!uid) return;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
[uid]: {
|
|
343
|
-
...prevState[uid],
|
|
344
|
-
requests: attrRequestTypes.none,
|
|
345
|
-
offline: true,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
356
|
+
//updating the rtc data
|
|
357
|
+
updateRenderListState(uid, {
|
|
358
|
+
offline: true,
|
|
348
359
|
});
|
|
349
360
|
});
|
|
350
361
|
|
|
@@ -353,84 +364,60 @@ const RtmConfigure = (props: any) => {
|
|
|
353
364
|
const textObj = parsePayload(text);
|
|
354
365
|
const {type, msg} = textObj;
|
|
355
366
|
|
|
356
|
-
|
|
357
|
-
arr[0] = parseInt(peerId);
|
|
358
|
-
|
|
359
|
-
const timestamp = timeNow();
|
|
367
|
+
const timestamp = getMessageTime(ts);
|
|
360
368
|
|
|
361
|
-
const
|
|
369
|
+
const sender = isAndroid ? get32BitUid(peerId) : peerId;
|
|
362
370
|
|
|
363
371
|
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;
|
|
372
|
+
switch (msg) {
|
|
373
|
+
case controlMessageEnum.muteVideo:
|
|
374
|
+
RtcEngine.muteLocalVideoStream(true);
|
|
375
|
+
dispatch({
|
|
376
|
+
type: 'LocalMuteVideo',
|
|
377
|
+
value: [0],
|
|
378
|
+
});
|
|
379
|
+
break;
|
|
380
|
+
case controlMessageEnum.muteAudio:
|
|
381
|
+
RtcEngine.muteLocalAudioStream(true);
|
|
382
|
+
dispatch({
|
|
383
|
+
type: 'LocalMuteAudio',
|
|
384
|
+
value: [0],
|
|
385
|
+
});
|
|
386
|
+
break;
|
|
387
|
+
case controlMessageEnum.kickUser:
|
|
388
|
+
dispatch({
|
|
389
|
+
type: 'EndCall',
|
|
390
|
+
value: [],
|
|
391
|
+
});
|
|
392
|
+
break;
|
|
393
|
+
default:
|
|
394
|
+
break;
|
|
396
395
|
}
|
|
397
|
-
} else if (type ===
|
|
396
|
+
} else if (type === eventMessageType.CUSTOM_EVENT) {
|
|
397
|
+
console.log('CUSTOM_EVENT_API: inside custom event type ', evt);
|
|
398
398
|
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;
|
|
399
|
+
customEventDispatcher(msg, sender, timestamp);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
console.log('error while dispacthing', error);
|
|
413
402
|
}
|
|
414
403
|
}
|
|
415
|
-
events.emit(messageChannelType.Private, {
|
|
416
|
-
uid: userUID,
|
|
417
|
-
ts: timestamp,
|
|
418
|
-
...textObj,
|
|
419
|
-
});
|
|
420
404
|
});
|
|
421
405
|
|
|
422
406
|
engine.current.on('channelMessageReceived', (evt) => {
|
|
423
407
|
const {uid, channelId, text, ts} = evt;
|
|
424
408
|
const textObj = parsePayload(text);
|
|
409
|
+
const [err, result] = safeJsonParse(text);
|
|
425
410
|
const {type, msg} = textObj;
|
|
426
|
-
let arr = new Int32Array(1);
|
|
427
|
-
arr[0] = parseInt(uid);
|
|
428
411
|
|
|
429
|
-
const
|
|
430
|
-
|
|
412
|
+
const timestamp = getMessageTime(ts);
|
|
413
|
+
|
|
414
|
+
const sender = Platform.OS ? get32BitUid(uid) : uid;
|
|
431
415
|
|
|
432
416
|
if (channelId === rtcProps.channel) {
|
|
433
|
-
if (
|
|
417
|
+
if (
|
|
418
|
+
type === eventMessageType.CONTROL_GROUP ||
|
|
419
|
+
type === messageActionType.Control
|
|
420
|
+
) {
|
|
434
421
|
let actionMsg = '';
|
|
435
422
|
if (hasJsonStructure(msg)) {
|
|
436
423
|
const [err, result] = safeJsonParse(msg);
|
|
@@ -441,91 +428,85 @@ const RtmConfigure = (props: any) => {
|
|
|
441
428
|
} else {
|
|
442
429
|
actionMsg = msg;
|
|
443
430
|
}
|
|
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;
|
|
431
|
+
switch (actionMsg) {
|
|
432
|
+
case controlMessageEnum.muteVideo:
|
|
433
|
+
RtcEngine.muteLocalVideoStream(true);
|
|
434
|
+
dispatch({
|
|
435
|
+
type: 'LocalMuteVideo',
|
|
436
|
+
value: [0],
|
|
437
|
+
});
|
|
438
|
+
break;
|
|
439
|
+
case controlMessageEnum.muteAudio:
|
|
440
|
+
RtcEngine.muteLocalAudioStream(true);
|
|
441
|
+
dispatch({
|
|
442
|
+
type: 'LocalMuteAudio',
|
|
443
|
+
value: [0],
|
|
444
|
+
});
|
|
445
|
+
break;
|
|
446
|
+
default:
|
|
447
|
+
break;
|
|
448
|
+
// throw new Error('Unsupported message type');
|
|
495
449
|
}
|
|
496
|
-
} else if (type ===
|
|
450
|
+
} else if (type === eventMessageType.CUSTOM_EVENT) {
|
|
451
|
+
console.log('CUSTOM_EVENT_API: inside custom event type ', evt);
|
|
497
452
|
try {
|
|
498
|
-
|
|
499
|
-
} catch (
|
|
500
|
-
|
|
501
|
-
msg: `Error while adding ${messageChannelType.Public} message to store`,
|
|
502
|
-
cause: e,
|
|
503
|
-
});
|
|
504
|
-
return;
|
|
453
|
+
customEventDispatcher(msg, sender, timestamp);
|
|
454
|
+
} catch (error) {
|
|
455
|
+
console.log('error while dispacthing', error);
|
|
505
456
|
}
|
|
506
457
|
}
|
|
507
458
|
}
|
|
508
|
-
events.emit(messageChannelType.Public, {
|
|
509
|
-
uid: userUID,
|
|
510
|
-
ts: timestamp,
|
|
511
|
-
...textObj,
|
|
512
|
-
});
|
|
513
459
|
});
|
|
460
|
+
doLoginAndSetupRTM();
|
|
461
|
+
};
|
|
514
462
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
463
|
+
const runQueuedCustomEvents = async () => {
|
|
464
|
+
try {
|
|
465
|
+
const eventsInQueue = EventsQueue.printQueue();
|
|
466
|
+
if (eventsInQueue.length !== 0) {
|
|
467
|
+
for (const queuedEvents of eventsInQueue) {
|
|
468
|
+
await customEventDispatcher(
|
|
469
|
+
queuedEvents.data,
|
|
470
|
+
queuedEvents.uid,
|
|
471
|
+
queuedEvents.ts,
|
|
472
|
+
);
|
|
473
|
+
EventsQueue.dequeue();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
} catch (error) {
|
|
477
|
+
throw Error(
|
|
478
|
+
'CUSTOM_EVENTS_API: error while running queued events ',
|
|
479
|
+
error,
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
526
483
|
|
|
527
|
-
|
|
528
|
-
|
|
484
|
+
const customEventDispatcher = async (
|
|
485
|
+
data: {
|
|
486
|
+
evt: string;
|
|
487
|
+
payload: {
|
|
488
|
+
level: 1 | 2 | 3;
|
|
489
|
+
action: string;
|
|
490
|
+
value: string;
|
|
491
|
+
};
|
|
492
|
+
},
|
|
493
|
+
sender: string,
|
|
494
|
+
ts: number,
|
|
495
|
+
) => {
|
|
496
|
+
console.log('CUSTOM_EVENT_API: inside customEventDispatcher ', data);
|
|
497
|
+
const {evt, payload} = data;
|
|
498
|
+
// Step 1: Set local attributes
|
|
499
|
+
if (payload?.level === 3) {
|
|
500
|
+
const rtmAttribute = {key: evt, value: JSON.stringify(data.payload)};
|
|
501
|
+
await engine.current.addOrUpdateLocalUserAttributes([rtmAttribute]);
|
|
502
|
+
}
|
|
503
|
+
// Step 2: Emit the event
|
|
504
|
+
try {
|
|
505
|
+
console.log('CUSTOM_EVENT_API: emiting event: ');
|
|
506
|
+
EventUtils.emitEvent(evt, {payload, sender, ts});
|
|
507
|
+
} catch (error) {
|
|
508
|
+
console.log('CUSTOM_EVENT_API: error while emiting event: ', error);
|
|
509
|
+
}
|
|
529
510
|
};
|
|
530
511
|
|
|
531
512
|
const sendMessage = async (msg: string) => {
|
|
@@ -539,18 +520,13 @@ const RtmConfigure = (props: any) => {
|
|
|
539
520
|
rtcProps.channel,
|
|
540
521
|
text,
|
|
541
522
|
);
|
|
542
|
-
addMessageToStore(localUid.current, {
|
|
543
|
-
body: messageActionType.Normal + msg,
|
|
544
|
-
ts: timeNow(),
|
|
545
|
-
});
|
|
546
523
|
};
|
|
547
524
|
|
|
548
|
-
const sendMessageToUid = async (msg: string, uid:
|
|
525
|
+
const sendMessageToUid = async (msg: string, uid: UidType) => {
|
|
549
526
|
if (msg.trim() === '') return;
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
527
|
+
|
|
528
|
+
const adjustedUID = adjustUID(uid);
|
|
529
|
+
|
|
554
530
|
const text = stringifyPayload(
|
|
555
531
|
messageSourceType.Core,
|
|
556
532
|
messageActionType.Normal,
|
|
@@ -561,14 +537,6 @@ const RtmConfigure = (props: any) => {
|
|
|
561
537
|
offline: false,
|
|
562
538
|
text,
|
|
563
539
|
});
|
|
564
|
-
addMessageToPrivateStore(
|
|
565
|
-
uid,
|
|
566
|
-
{
|
|
567
|
-
body: messageActionType.Normal + msg,
|
|
568
|
-
ts: timeNow(),
|
|
569
|
-
},
|
|
570
|
-
true,
|
|
571
|
-
);
|
|
572
540
|
};
|
|
573
541
|
|
|
574
542
|
const sendControlMessage = async (msg: string) => {
|
|
@@ -583,17 +551,18 @@ const RtmConfigure = (props: any) => {
|
|
|
583
551
|
);
|
|
584
552
|
};
|
|
585
553
|
|
|
586
|
-
const sendControlMessageToUid = async (msg: string, uid:
|
|
587
|
-
if (
|
|
588
|
-
|
|
589
|
-
|
|
554
|
+
const sendControlMessageToUid = async (msg: string, uid: UidType) => {
|
|
555
|
+
if (msg.trim() === '') return;
|
|
556
|
+
|
|
557
|
+
const adjustedUID = adjustUID(uid);
|
|
558
|
+
|
|
590
559
|
const text = stringifyPayload(
|
|
591
560
|
messageSourceType.Core,
|
|
592
561
|
messageActionType.Control,
|
|
593
562
|
msg,
|
|
594
563
|
);
|
|
595
564
|
await (engine.current as RtmEngine).sendMessageToPeer({
|
|
596
|
-
peerId:
|
|
565
|
+
peerId: adjustedUID.toString(),
|
|
597
566
|
offline: false,
|
|
598
567
|
text,
|
|
599
568
|
});
|
|
@@ -608,24 +577,6 @@ const RtmConfigure = (props: any) => {
|
|
|
608
577
|
: {};
|
|
609
578
|
};
|
|
610
579
|
|
|
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
580
|
useEffect(() => {
|
|
630
581
|
callActive ? init() : (console.log('waiting to init RTM'), setLogin(true));
|
|
631
582
|
return () => {
|
|
@@ -634,58 +585,19 @@ const RtmConfigure = (props: any) => {
|
|
|
634
585
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
635
586
|
}, [rtcProps.channel, rtcProps.appId, callActive]);
|
|
636
587
|
|
|
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
588
|
return (
|
|
674
589
|
<ChatContext.Provider
|
|
675
590
|
value={{
|
|
676
|
-
|
|
677
|
-
privateMessageStore,
|
|
591
|
+
hasUserJoinedRTM,
|
|
678
592
|
sendControlMessage,
|
|
679
593
|
sendControlMessageToUid,
|
|
680
594
|
sendMessage,
|
|
681
595
|
sendMessageToUid,
|
|
682
|
-
broadcastUserAttributes,
|
|
683
|
-
addOrUpdateLocalUserAttributes,
|
|
684
596
|
engine: engine.current,
|
|
685
|
-
localUid: localUid
|
|
686
|
-
userList: userList,
|
|
597
|
+
localUid: localUid,
|
|
687
598
|
onlineUsersCount,
|
|
688
|
-
|
|
599
|
+
setDisplayName,
|
|
600
|
+
displayName,
|
|
689
601
|
}}>
|
|
690
602
|
{login ? props.children : <></>}
|
|
691
603
|
</ChatContext.Provider>
|