agora-appbuilder-core 2.2.0 → 2.3.0-beta.10

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