@100mslive/roomkit-react 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (459) hide show
  1. package/README.md +1 -0
  2. package/dist/Accordion/Accordion.d.ts +964 -0
  3. package/dist/Accordion/index.d.ts +979 -0
  4. package/dist/ActiveSpeakerView-H3VYXANB.js +39 -0
  5. package/dist/ActiveSpeakerView-H3VYXANB.js.map +7 -0
  6. package/dist/ActiveSpeakerView-REZLWPPI.css +11 -0
  7. package/dist/ActiveSpeakerView-REZLWPPI.css.map +7 -0
  8. package/dist/AudioLevel/AudioLevel.d.ts +8 -0
  9. package/dist/AudioLevel/index.d.ts +1 -0
  10. package/dist/Avatar/Avatar.d.ts +487 -0
  11. package/dist/Avatar/getAvatarBg.d.ts +7 -0
  12. package/dist/Avatar/index.d.ts +1 -0
  13. package/dist/Button/Button.d.ts +488 -0
  14. package/dist/Button/index.d.ts +1 -0
  15. package/dist/Checkbox/Checkbox.d.ts +958 -0
  16. package/dist/Checkbox/index.d.ts +1 -0
  17. package/dist/Collapsible/Collapsible.d.ts +1434 -0
  18. package/dist/Collapsible/index.d.ts +1 -0
  19. package/dist/Divider/Divider.d.ts +958 -0
  20. package/dist/Divider/index.d.ts +1 -0
  21. package/dist/Dropdown/Dropdown.d.ts +5728 -0
  22. package/dist/Dropdown/index.d.ts +1 -0
  23. package/dist/Fieldset/Fieldset.d.ts +477 -0
  24. package/dist/Fieldset/index.d.ts +1 -0
  25. package/dist/Footer/Footer.d.ts +3834 -0
  26. package/dist/Footer/index.d.ts +1 -0
  27. package/dist/HLSView-3RDXRV7Y.js +689 -0
  28. package/dist/HLSView-3RDXRV7Y.js.map +7 -0
  29. package/dist/HLSView-6BVBCQM7.css +11 -0
  30. package/dist/HLSView-6BVBCQM7.css.map +7 -0
  31. package/dist/IconButton/IconButton.d.ts +479 -0
  32. package/dist/IconButton/index.d.ts +1 -0
  33. package/dist/Input/Input.d.ts +2917 -0
  34. package/dist/Input/index.d.ts +1 -0
  35. package/dist/Label/Label.d.ts +479 -0
  36. package/dist/Label/index.d.ts +1 -0
  37. package/dist/Layout/Box.d.ts +477 -0
  38. package/dist/Layout/Flex.d.ts +482 -0
  39. package/dist/Layout/index.d.ts +2 -0
  40. package/dist/Link/Link.d.ts +489 -0
  41. package/dist/Link/index.d.ts +2 -0
  42. package/dist/Loading/Loading.d.ts +14 -0
  43. package/dist/Loading/index.d.ts +1 -0
  44. package/dist/Modal/Dialog.d.ts +3826 -0
  45. package/dist/Modal/DialogContent.d.ts +3343 -0
  46. package/dist/Modal/index.d.ts +1 -0
  47. package/dist/Pagination/StyledPagination.d.ts +1918 -0
  48. package/dist/Pagination/index.d.ts +1 -0
  49. package/dist/PinnedTrackView-453PELNU.js +70 -0
  50. package/dist/PinnedTrackView-453PELNU.js.map +7 -0
  51. package/dist/PinnedTrackView-QQ5FDXJX.css +11 -0
  52. package/dist/PinnedTrackView-QQ5FDXJX.css.map +7 -0
  53. package/dist/Popover/index.d.ts +1436 -0
  54. package/dist/Progress/index.d.ts +957 -0
  55. package/dist/QRCode/QRCode.d.ts +3 -0
  56. package/dist/QRCode/index.d.ts +1 -0
  57. package/dist/RadioGroup/RadioGroup.d.ts +1435 -0
  58. package/dist/RadioGroup/index.d.ts +1 -0
  59. package/dist/ReactSelect/ReactSelect.d.ts +4778 -0
  60. package/dist/ReactSelect/index.d.ts +1 -0
  61. package/dist/Select/Select.d.ts +1437 -0
  62. package/dist/Select/index.d.ts +1 -0
  63. package/dist/Slider/Slider.d.ts +488 -0
  64. package/dist/Slider/index.d.ts +1 -0
  65. package/dist/Stats/Stats.d.ts +19 -0
  66. package/dist/Stats/StyledStats.d.ts +2872 -0
  67. package/dist/Stats/formatBytes.d.ts +1 -0
  68. package/dist/Stats/index.d.ts +1 -0
  69. package/dist/Switch/Switch.d.ts +482 -0
  70. package/dist/Switch/index.d.ts +1 -0
  71. package/dist/Tabs/Tabs.d.ts +1912 -0
  72. package/dist/Tabs/index.d.ts +1 -0
  73. package/dist/Text/Text.d.ts +605 -0
  74. package/dist/Text/index.d.ts +1 -0
  75. package/dist/Theme/ThemeProvider.d.ts +397 -0
  76. package/dist/Theme/base.config.d.ts +417 -0
  77. package/dist/Theme/index.d.ts +3 -0
  78. package/dist/Theme/stitches.config.d.ts +4702 -0
  79. package/dist/Theme/themes.d.ts +64 -0
  80. package/dist/Theme/useSSR.d.ts +6 -0
  81. package/dist/TileMenu/StyledMenuTile.d.ts +3351 -0
  82. package/dist/TileMenu/TileMenu.d.ts +6 -0
  83. package/dist/TileMenu/index.d.ts +1 -0
  84. package/dist/Toast/Toast.d.ts +2881 -0
  85. package/dist/Toast/index.d.ts +1 -0
  86. package/dist/Tooltip/Tooltip.d.ts +14 -0
  87. package/dist/Tooltip/index.d.ts +1 -0
  88. package/dist/Video/Video.d.ts +499 -0
  89. package/dist/Video/index.d.ts +1 -0
  90. package/dist/VideoList/StyledVideoList.d.ts +1438 -0
  91. package/dist/VideoList/index.d.ts +2 -0
  92. package/dist/VideoList/videoListUtils.d.ts +1 -0
  93. package/dist/VideoTile/StyledVideoTile.d.ts +4309 -0
  94. package/dist/VideoTile/index.d.ts +1 -0
  95. package/dist/VirtualBackground-LHYBWUT5.js +158 -0
  96. package/dist/VirtualBackground-LHYBWUT5.js.map +7 -0
  97. package/dist/chunk-7YUYZ64D.js +6843 -0
  98. package/dist/chunk-7YUYZ64D.js.map +7 -0
  99. package/dist/chunk-HCAGFNXW.js +8270 -0
  100. package/dist/chunk-HCAGFNXW.js.map +7 -0
  101. package/dist/chunk-KYYP6ZVK.js +907 -0
  102. package/dist/chunk-KYYP6ZVK.js.map +7 -0
  103. package/dist/chunk-ULXGBUSC.js +65 -0
  104. package/dist/chunk-ULXGBUSC.js.map +7 -0
  105. package/dist/chunk-XRJXE6UO.js +243 -0
  106. package/dist/chunk-XRJXE6UO.js.map +7 -0
  107. package/dist/conference-IDNRO4WK.js +3812 -0
  108. package/dist/conference-IDNRO4WK.js.map +7 -0
  109. package/dist/conference-KN6OKGDU.css +11 -0
  110. package/dist/conference-KN6OKGDU.css.map +7 -0
  111. package/dist/fixtures/chats.d.ts +4 -0
  112. package/dist/fixtures/peers.d.ts +3 -0
  113. package/dist/fixtures/tracks.d.ts +2 -0
  114. package/dist/index.cjs.css +11 -0
  115. package/dist/index.cjs.css.map +7 -0
  116. package/dist/index.cjs.js +22987 -0
  117. package/dist/index.cjs.js.map +7 -0
  118. package/dist/index.css +11 -0
  119. package/dist/index.css.map +7 -0
  120. package/dist/index.d.ts +38 -0
  121. package/dist/index.js +133 -0
  122. package/dist/index.js.map +7 -0
  123. package/dist/meta.cjs.json +13085 -0
  124. package/dist/meta.esbuild.json +13693 -0
  125. package/dist/transcription-BTSB7FZH.js +356 -0
  126. package/dist/transcription-BTSB7FZH.js.map +7 -0
  127. package/dist/utils/animations.d.ts +92 -0
  128. package/dist/utils/index.d.ts +2 -0
  129. package/dist/utils/styles.d.ts +21 -0
  130. package/package.json +116 -0
  131. package/src/Accordion/Accordion.stories.tsx +50 -0
  132. package/src/Accordion/Accordion.tsx +88 -0
  133. package/src/Accordion/index.ts +8 -0
  134. package/src/AudioLevel/AudioLevel.tsx +34 -0
  135. package/src/AudioLevel/index.ts +1 -0
  136. package/src/Avatar/Avatar.stories.tsx +33 -0
  137. package/src/Avatar/Avatar.tsx +55 -0
  138. package/src/Avatar/getAvatarBg.ts +46 -0
  139. package/src/Avatar/index.ts +1 -0
  140. package/src/Button/Button.mdx +43 -0
  141. package/src/Button/Button.stories.tsx +52 -0
  142. package/src/Button/Button.tsx +144 -0
  143. package/src/Button/index.tsx +1 -0
  144. package/src/Chat/Chat.mdx +39 -0
  145. package/src/Chat/Chat.stories.tsx +39 -0
  146. package/src/Checkbox/Checkbox.stories.tsx +61 -0
  147. package/src/Checkbox/Checkbox.tsx +33 -0
  148. package/src/Checkbox/index.tsx +1 -0
  149. package/src/Collapsible/Collapsible.tsx +34 -0
  150. package/src/Collapsible/index.tsx +1 -0
  151. package/src/Divider/Divider.tsx +45 -0
  152. package/src/Divider/HorizontalDivider.stories.tsx +34 -0
  153. package/src/Divider/VerticalDivider.stories.tsx +40 -0
  154. package/src/Divider/index.ts +1 -0
  155. package/src/Dropdown/Dropdown.stories.tsx +94 -0
  156. package/src/Dropdown/Dropdown.tsx +142 -0
  157. package/src/Dropdown/index.tsx +1 -0
  158. package/src/Fieldset/Fieldset.stories.tsx +29 -0
  159. package/src/Fieldset/Fieldset.tsx +11 -0
  160. package/src/Fieldset/index.tsx +1 -0
  161. package/src/Footer/Footer.stories.tsx +61 -0
  162. package/src/Footer/Footer.tsx +47 -0
  163. package/src/Footer/index.tsx +1 -0
  164. package/src/IconButton/IconButton.tsx +45 -0
  165. package/src/IconButton/index.tsx +1 -0
  166. package/src/Icons/Icons.stories.mdx +10 -0
  167. package/src/Icons/IconsList.jsx +17 -0
  168. package/src/Input/Input.stories.tsx +25 -0
  169. package/src/Input/Input.tsx +105 -0
  170. package/src/Input/PasswordInput.stories.tsx +53 -0
  171. package/src/Input/index.tsx +1 -0
  172. package/src/Introduction/Integrating.stories.mdx +100 -0
  173. package/src/Introduction/Introduction.stories.mdx +9 -0
  174. package/src/Label/Label.tsx +8 -0
  175. package/src/Label/index.ts +1 -0
  176. package/src/Layout/Box.tsx +3 -0
  177. package/src/Layout/Flex.tsx +76 -0
  178. package/src/Layout/index.tsx +2 -0
  179. package/src/Link/Link.stories.tsx +18 -0
  180. package/src/Link/Link.tsx +54 -0
  181. package/src/Link/index.tsx +2 -0
  182. package/src/Loading/Loading.mdx +15 -0
  183. package/src/Loading/Loading.stories.tsx +37 -0
  184. package/src/Loading/Loading.tsx +33 -0
  185. package/src/Loading/index.ts +1 -0
  186. package/src/Modal/Dialog.mdx +19 -0
  187. package/src/Modal/Dialog.stories.tsx +68 -0
  188. package/src/Modal/Dialog.tsx +26 -0
  189. package/src/Modal/DialogContent.tsx +63 -0
  190. package/src/Modal/index.ts +1 -0
  191. package/src/Pagination/StyledPagination.stories.tsx +80 -0
  192. package/src/Pagination/StyledPagination.tsx +68 -0
  193. package/src/Pagination/index.tsx +1 -0
  194. package/src/Popover/Popover.mdx +9 -0
  195. package/src/Popover/Popover.stories.tsx +95 -0
  196. package/src/Popover/index.tsx +26 -0
  197. package/src/Prebuilt/App.jsx +273 -0
  198. package/src/Prebuilt/AppContext.jsx +21 -0
  199. package/src/Prebuilt/IconButton.jsx +19 -0
  200. package/src/Prebuilt/Prebuilt.stories.tsx +20 -0
  201. package/src/Prebuilt/common/PeersSorter.js +89 -0
  202. package/src/Prebuilt/common/constants.js +208 -0
  203. package/src/Prebuilt/common/hooks.js +47 -0
  204. package/src/Prebuilt/common/roles.js +4 -0
  205. package/src/Prebuilt/common/useSortedPeers.js +28 -0
  206. package/src/Prebuilt/common/utils.js +91 -0
  207. package/src/Prebuilt/components/AppData/AppData.jsx +189 -0
  208. package/src/Prebuilt/components/AppData/useAppConfig.js +7 -0
  209. package/src/Prebuilt/components/AppData/useAppLayout.js +6 -0
  210. package/src/Prebuilt/components/AppData/useChatState.js +18 -0
  211. package/src/Prebuilt/components/AppData/useSidepane.js +49 -0
  212. package/src/Prebuilt/components/AppData/useUISettings.js +164 -0
  213. package/src/Prebuilt/components/AudioLevel/BeamSpeakerLabelsLogging.jsx +16 -0
  214. package/src/Prebuilt/components/AudioVideoToggle.jsx +67 -0
  215. package/src/Prebuilt/components/AuthToken.jsx +133 -0
  216. package/src/Prebuilt/components/BottomActionSheet/BottomActionSheet.jsx +96 -0
  217. package/src/Prebuilt/components/BottomActionSheet/BottomActionSheet.stories.tsx +46 -0
  218. package/src/Prebuilt/components/Chat/Chat.jsx +155 -0
  219. package/src/Prebuilt/components/Chat/ChatBody.jsx +370 -0
  220. package/src/Prebuilt/components/Chat/ChatFooter.jsx +150 -0
  221. package/src/Prebuilt/components/Chat/ChatHeader.jsx +67 -0
  222. package/src/Prebuilt/components/Chat/ChatSelector.jsx +162 -0
  223. package/src/Prebuilt/components/Chat/useEmojiPickerStyles.js +30 -0
  224. package/src/Prebuilt/components/Chat/useUnreadCount.js +17 -0
  225. package/src/Prebuilt/components/Connection/ConnectionIndicator.jsx +80 -0
  226. package/src/Prebuilt/components/Connection/TileConnection.jsx +40 -0
  227. package/src/Prebuilt/components/Connection/connectionQualityUtils.js +39 -0
  228. package/src/Prebuilt/components/EmojiReaction.jsx +138 -0
  229. package/src/Prebuilt/components/ErrorBoundary.jsx +105 -0
  230. package/src/Prebuilt/components/FirstPersonDisplay.jsx +50 -0
  231. package/src/Prebuilt/components/Footer/ChatToggle.jsx +27 -0
  232. package/src/Prebuilt/components/Footer/ConferencingFooter.jsx +104 -0
  233. package/src/Prebuilt/components/Footer/StreamingFooter.jsx +71 -0
  234. package/src/Prebuilt/components/Footer.jsx +8 -0
  235. package/src/Prebuilt/components/FullPageProgress.jsx +11 -0
  236. package/src/Prebuilt/components/GoLiveButton.jsx +45 -0
  237. package/src/Prebuilt/components/HMSVideo/Controls.jsx +21 -0
  238. package/src/Prebuilt/components/HMSVideo/FullscreenButton.jsx +18 -0
  239. package/src/Prebuilt/components/HMSVideo/HLSAutoplayBlockedPrompt.jsx +35 -0
  240. package/src/Prebuilt/components/HMSVideo/HLSQualitySelector.jsx +82 -0
  241. package/src/Prebuilt/components/HMSVideo/HMSVIdeoUtils.js +27 -0
  242. package/src/Prebuilt/components/HMSVideo/HMSVideo.jsx +11 -0
  243. package/src/Prebuilt/components/HMSVideo/PlayButton.jsx +13 -0
  244. package/src/Prebuilt/components/HMSVideo/VideoProgress.jsx +77 -0
  245. package/src/Prebuilt/components/HMSVideo/VideoTime.jsx +31 -0
  246. package/src/Prebuilt/components/HMSVideo/VolumeControl.jsx +39 -0
  247. package/src/Prebuilt/components/HMSVideo/index.js +19 -0
  248. package/src/Prebuilt/components/Header/AdditionalRoomState.jsx +217 -0
  249. package/src/Prebuilt/components/Header/AmbientMusic.jsx +88 -0
  250. package/src/Prebuilt/components/Header/ConferencingHeader.jsx +29 -0
  251. package/src/Prebuilt/components/Header/Header.jsx +8 -0
  252. package/src/Prebuilt/components/Header/HeaderComponents.jsx +41 -0
  253. package/src/Prebuilt/components/Header/ParticipantFilter.jsx +91 -0
  254. package/src/Prebuilt/components/Header/ParticipantList.jsx +337 -0
  255. package/src/Prebuilt/components/Header/StreamActions.jsx +225 -0
  256. package/src/Prebuilt/components/Header/StreamingHeader.jsx +55 -0
  257. package/src/Prebuilt/components/Header/index.jsx +1 -0
  258. package/src/Prebuilt/components/HlsStatsOverlay.jsx +101 -0
  259. package/src/Prebuilt/components/Image.jsx +7 -0
  260. package/src/Prebuilt/components/Input/KeyboardInputManager.js +107 -0
  261. package/src/Prebuilt/components/LeaveRoom.jsx +202 -0
  262. package/src/Prebuilt/components/MetaActions.jsx +45 -0
  263. package/src/Prebuilt/components/MoreSettings/BulkRoleChangeModal.jsx +139 -0
  264. package/src/Prebuilt/components/MoreSettings/ChangeNameModal.jsx +92 -0
  265. package/src/Prebuilt/components/MoreSettings/ChangeSelfRole.jsx +67 -0
  266. package/src/Prebuilt/components/MoreSettings/EmbedUrl.jsx +106 -0
  267. package/src/Prebuilt/components/MoreSettings/FullScreenItem.jsx +29 -0
  268. package/src/Prebuilt/components/MoreSettings/MoreSettings.jsx +225 -0
  269. package/src/Prebuilt/components/MoreSettings/MuteAllModal.jsx +90 -0
  270. package/src/Prebuilt/components/Notifications/AutoplayBlockedModal.jsx +38 -0
  271. package/src/Prebuilt/components/Notifications/InitErrorModal.jsx +39 -0
  272. package/src/Prebuilt/components/Notifications/MessageNotifications.jsx +25 -0
  273. package/src/Prebuilt/components/Notifications/Notifications.jsx +151 -0
  274. package/src/Prebuilt/components/Notifications/PeerNotifications.jsx +45 -0
  275. package/src/Prebuilt/components/Notifications/PermissionErrorModal.jsx +67 -0
  276. package/src/Prebuilt/components/Notifications/ReconnectNotifications.jsx +69 -0
  277. package/src/Prebuilt/components/Notifications/TrackBulkUnmuteModal.jsx +51 -0
  278. package/src/Prebuilt/components/Notifications/TrackNotifications.jsx +19 -0
  279. package/src/Prebuilt/components/Notifications/TrackUnmuteModal.jsx +49 -0
  280. package/src/Prebuilt/components/Notifications/index.jsx +1 -0
  281. package/src/Prebuilt/components/PIP/PIPComponent.jsx +82 -0
  282. package/src/Prebuilt/components/PIP/PIPManager.js +296 -0
  283. package/src/Prebuilt/components/PIP/SetupMediaSession.js +60 -0
  284. package/src/Prebuilt/components/PIP/index.jsx +11 -0
  285. package/src/Prebuilt/components/PIP/pip.test.js +72 -0
  286. package/src/Prebuilt/components/PIP/pipUtils.js +183 -0
  287. package/src/Prebuilt/components/Pagination.jsx +29 -0
  288. package/src/Prebuilt/components/Playlist/Playlist.jsx +129 -0
  289. package/src/Prebuilt/components/Playlist/PlaylistControls.jsx +172 -0
  290. package/src/Prebuilt/components/Playlist/PlaylistItem.jsx +51 -0
  291. package/src/Prebuilt/components/Playlist/VideoPlayer.jsx +95 -0
  292. package/src/Prebuilt/components/PostLeave.jsx +76 -0
  293. package/src/Prebuilt/components/Preview/PreviewContainer.jsx +51 -0
  294. package/src/Prebuilt/components/Preview/PreviewJoin.jsx +196 -0
  295. package/src/Prebuilt/components/Preview/PreviewName.jsx +37 -0
  296. package/src/Prebuilt/components/RoleChangeModal.jsx +185 -0
  297. package/src/Prebuilt/components/RoleChangeRequestModal.jsx +26 -0
  298. package/src/Prebuilt/components/ScreenShare.jsx +45 -0
  299. package/src/Prebuilt/components/ScreenshareDisplay.jsx +45 -0
  300. package/src/Prebuilt/components/ScreenshareHintModal.jsx +37 -0
  301. package/src/Prebuilt/components/ScreenshareTile.jsx +91 -0
  302. package/src/Prebuilt/components/Settings/DeviceSettings.jsx +220 -0
  303. package/src/Prebuilt/components/Settings/LayoutSettings.jsx +91 -0
  304. package/src/Prebuilt/components/Settings/NotificationSettings.jsx +61 -0
  305. package/src/Prebuilt/components/Settings/SettingsModal.jsx +171 -0
  306. package/src/Prebuilt/components/Settings/StartRecording.jsx +130 -0
  307. package/src/Prebuilt/components/Settings/SwitchWithLabel.jsx +40 -0
  308. package/src/Prebuilt/components/Settings/common.js +15 -0
  309. package/src/Prebuilt/components/ShareMenuIcon.jsx +26 -0
  310. package/src/Prebuilt/components/StatsForNerds.jsx +250 -0
  311. package/src/Prebuilt/components/Streaming/Common.jsx +132 -0
  312. package/src/Prebuilt/components/Streaming/HLSStreaming.jsx +226 -0
  313. package/src/Prebuilt/components/Streaming/RTMPIcon.jsx +24 -0
  314. package/src/Prebuilt/components/Streaming/RTMPStreaming.jsx +336 -0
  315. package/src/Prebuilt/components/Streaming/ResolutionInput.jsx +88 -0
  316. package/src/Prebuilt/components/Streaming/StreamingLanding.jsx +76 -0
  317. package/src/Prebuilt/components/TileMenu.jsx +275 -0
  318. package/src/Prebuilt/components/Toast/Toast.jsx +17 -0
  319. package/src/Prebuilt/components/Toast/ToastBatcher.js +57 -0
  320. package/src/Prebuilt/components/Toast/ToastConfig.jsx +134 -0
  321. package/src/Prebuilt/components/Toast/ToastContainer.jsx +30 -0
  322. package/src/Prebuilt/components/Toast/ToastManager.js +44 -0
  323. package/src/Prebuilt/components/VideoList.jsx +101 -0
  324. package/src/Prebuilt/components/VideoTile.jsx +177 -0
  325. package/src/Prebuilt/components/conference.jsx +164 -0
  326. package/src/Prebuilt/components/gridView.jsx +85 -0
  327. package/src/Prebuilt/components/hooks/useDropdownList.jsx +23 -0
  328. package/src/Prebuilt/components/hooks/useDropdownSelection.jsx +6 -0
  329. package/src/Prebuilt/components/hooks/useFeatures.js +22 -0
  330. package/src/Prebuilt/components/hooks/useFullscreen.js +43 -0
  331. package/src/Prebuilt/components/hooks/useMetadata.jsx +52 -0
  332. package/src/Prebuilt/components/hooks/useNavigation.js +19 -0
  333. package/src/Prebuilt/components/hooks/usePlaylist.js +25 -0
  334. package/src/Prebuilt/components/hooks/usePlaylistMusic.js +35 -0
  335. package/src/Prebuilt/components/hooks/useScreenshareAudio.js +28 -0
  336. package/src/Prebuilt/components/hooks/useSetPinnedMessage.js +38 -0
  337. package/src/Prebuilt/components/hooks/useSkipPreview.jsx +20 -0
  338. package/src/Prebuilt/components/hooks/useUserPreferences.jsx +25 -0
  339. package/src/Prebuilt/components/init/Init.jsx +58 -0
  340. package/src/Prebuilt/components/init/initUtils.js +90 -0
  341. package/src/Prebuilt/components/pdfAnnotator/pdfErrorView.jsx +29 -0
  342. package/src/Prebuilt/components/pdfAnnotator/pdfFileOptions.jsx +108 -0
  343. package/src/Prebuilt/components/pdfAnnotator/pdfHeader.jsx +31 -0
  344. package/src/Prebuilt/components/pdfAnnotator/pdfInfo.jsx +32 -0
  345. package/src/Prebuilt/components/pdfAnnotator/shareScreenOptions.jsx +233 -0
  346. package/src/Prebuilt/components/pdfAnnotator/submitPdf.jsx +89 -0
  347. package/src/Prebuilt/components/pdfAnnotator/uploadedFile.jsx +85 -0
  348. package/src/Prebuilt/components/peerTileUtils.jsx +27 -0
  349. package/src/Prebuilt/hms.js +7 -0
  350. package/src/Prebuilt/images/first_person.png +0 -0
  351. package/src/Prebuilt/index.d.ts +15 -0
  352. package/src/Prebuilt/index.js +2 -0
  353. package/src/Prebuilt/layouts/ActiveSpeakerView.jsx +34 -0
  354. package/src/Prebuilt/layouts/EmbedView.jsx +141 -0
  355. package/src/Prebuilt/layouts/HLSView.jsx +290 -0
  356. package/src/Prebuilt/layouts/InsetView.jsx +222 -0
  357. package/src/Prebuilt/layouts/NonPublisherView.jsx +51 -0
  358. package/src/Prebuilt/layouts/PDFView.jsx +122 -0
  359. package/src/Prebuilt/layouts/PinnedTrackView.jsx +59 -0
  360. package/src/Prebuilt/layouts/SidePane.jsx +51 -0
  361. package/src/Prebuilt/layouts/WaitingView.jsx +51 -0
  362. package/src/Prebuilt/layouts/WhiteboardView.jsx +66 -0
  363. package/src/Prebuilt/layouts/mainGridView.jsx +98 -0
  364. package/src/Prebuilt/layouts/mainView.jsx +113 -0
  365. package/src/Prebuilt/layouts/screenShareView.jsx +185 -0
  366. package/src/Prebuilt/plugins/FlyingEmoji.jsx +132 -0
  367. package/src/Prebuilt/plugins/RemoteStopScreenshare.jsx +18 -0
  368. package/src/Prebuilt/plugins/VirtualBackground/VirtualBackground.jsx +90 -0
  369. package/src/Prebuilt/plugins/VirtualBackground/vbutils.js +66 -0
  370. package/src/Prebuilt/plugins/confetti.jsx +60 -0
  371. package/src/Prebuilt/plugins/transcription/Transcriber.js +216 -0
  372. package/src/Prebuilt/plugins/transcription/TranscriptionButton.jsx +138 -0
  373. package/src/Prebuilt/plugins/transcription/index.jsx +1 -0
  374. package/src/Prebuilt/plugins/whiteboard/PusherCommunicationProvider.js +110 -0
  375. package/src/Prebuilt/plugins/whiteboard/README.md +29 -0
  376. package/src/Prebuilt/plugins/whiteboard/ToggleWhiteboard.jsx +43 -0
  377. package/src/Prebuilt/plugins/whiteboard/Whiteboard.css +12 -0
  378. package/src/Prebuilt/plugins/whiteboard/Whiteboard.jsx +11 -0
  379. package/src/Prebuilt/plugins/whiteboard/WhiteboardEvents.js +8 -0
  380. package/src/Prebuilt/plugins/whiteboard/index.js +3 -0
  381. package/src/Prebuilt/plugins/whiteboard/useMultiplayerState.js +212 -0
  382. package/src/Prebuilt/plugins/whiteboard/useWhiteboardMetadata.js +47 -0
  383. package/src/Prebuilt/primitives/DialogContent.jsx +280 -0
  384. package/src/Prebuilt/primitives/DropdownTrigger.jsx +46 -0
  385. package/src/Prebuilt/services/FeatureFlags.jsx +47 -0
  386. package/src/Prebuilt/services/tokenService.js +49 -0
  387. package/src/Progress/index.tsx +17 -0
  388. package/src/QRCode/QRCode.mdx +9 -0
  389. package/src/QRCode/QRCode.stories.tsx +29 -0
  390. package/src/QRCode/QRCode.tsx +6 -0
  391. package/src/QRCode/index.tsx +1 -0
  392. package/src/RadioGroup/RadioGroup.stories.tsx +32 -0
  393. package/src/RadioGroup/RadioGroup.tsx +33 -0
  394. package/src/RadioGroup/index.tsx +1 -0
  395. package/src/ReactSelect/ReactSelect.stories.tsx +83 -0
  396. package/src/ReactSelect/ReactSelect.tsx +97 -0
  397. package/src/ReactSelect/index.ts +1 -0
  398. package/src/Select/Select.stories.tsx +33 -0
  399. package/src/Select/Select.tsx +63 -0
  400. package/src/Select/index.ts +1 -0
  401. package/src/Slider/Slider.stories.tsx +21 -0
  402. package/src/Slider/Slider.tsx +70 -0
  403. package/src/Slider/index.ts +1 -0
  404. package/src/Stats/Stats.tsx +211 -0
  405. package/src/Stats/StyledStats.tsx +57 -0
  406. package/src/Stats/formatBytes.ts +19 -0
  407. package/src/Stats/index.tsx +1 -0
  408. package/src/Switch/Switch.mdx +11 -0
  409. package/src/Switch/Switch.stories.tsx +46 -0
  410. package/src/Switch/Switch.tsx +52 -0
  411. package/src/Switch/index.ts +1 -0
  412. package/src/Tabs/Tabs.stories.tsx +77 -0
  413. package/src/Tabs/Tabs.tsx +41 -0
  414. package/src/Tabs/index.tsx +1 -0
  415. package/src/Text/Text.stories.tsx +21 -0
  416. package/src/Text/Text.tsx +149 -0
  417. package/src/Text/index.tsx +1 -0
  418. package/src/Theme/Theme.stories.mdx +8 -0
  419. package/src/Theme/ThemeProvider.tsx +104 -0
  420. package/src/Theme/ThemeStory.jsx +58 -0
  421. package/src/Theme/base.config.ts +264 -0
  422. package/src/Theme/index.tsx +3 -0
  423. package/src/Theme/stitches.config.ts +100 -0
  424. package/src/Theme/themes.ts +70 -0
  425. package/src/Theme/useSSR.tsx +24 -0
  426. package/src/TileMenu/StyledMenuTile.tsx +101 -0
  427. package/src/TileMenu/TileMenu.tsx +96 -0
  428. package/src/TileMenu/index.tsx +1 -0
  429. package/src/Toast/AppToast.stories.tsx +56 -0
  430. package/src/Toast/Toast.mdx +19 -0
  431. package/src/Toast/Toast.stories.tsx +57 -0
  432. package/src/Toast/Toast.tsx +168 -0
  433. package/src/Toast/index.tsx +1 -0
  434. package/src/Tooltip/Tooltip.stories.tsx +62 -0
  435. package/src/Tooltip/Tooltip.tsx +79 -0
  436. package/src/Tooltip/index.ts +1 -0
  437. package/src/Video/UseVideo.mdx +22 -0
  438. package/src/Video/UseVideo.stories.tsx +26 -0
  439. package/src/Video/Video.mdx +24 -0
  440. package/src/Video/Video.stories.tsx +27 -0
  441. package/src/Video/Video.tsx +61 -0
  442. package/src/Video/index.tsx +1 -0
  443. package/src/VideoList/StyledVideoList.tsx +39 -0
  444. package/src/VideoList/VideoList.stories.tsx +92 -0
  445. package/src/VideoList/index.tsx +2 -0
  446. package/src/VideoList/videoListUtils.tsx +20 -0
  447. package/src/VideoTile/StyledVideoTile.tsx +148 -0
  448. package/src/VideoTile/VideoTile.mdx +28 -0
  449. package/src/VideoTile/VideoTile.stories.tsx +32 -0
  450. package/src/VideoTile/index.tsx +1 -0
  451. package/src/fixtures/chats.ts +25 -0
  452. package/src/fixtures/peers.ts +24 -0
  453. package/src/fixtures/tracks.ts +11 -0
  454. package/src/index.ts +38 -0
  455. package/src/store/SetupFakeStore.ts +33 -0
  456. package/src/store/StorybookSDK.ts +229 -0
  457. package/src/utils/animations.ts +90 -0
  458. package/src/utils/index.ts +2 -0
  459. package/src/utils/styles.ts +22 -0
@@ -0,0 +1,138 @@
1
+ import React, { useCallback, useEffect, useRef } from 'react';
2
+ import {
3
+ selectIsAllowedToPublish,
4
+ selectSessionStore,
5
+ useHMSActions,
6
+ useHMSStore,
7
+ useHMSVanillaStore,
8
+ } from '@100mslive/react-sdk';
9
+ import { ClosedCaptionIcon } from '@100mslive/react-icons';
10
+ import { Box } from '../../../Layout';
11
+ import { Text } from '../../../Text';
12
+ import { Tooltip } from '../../../Tooltip';
13
+ import IconButton from '../../IconButton';
14
+ import { Transcriber } from './Transcriber';
15
+ import { SESSION_STORE_KEY } from '../../common/constants';
16
+
17
+ export function TranscriptionButton() {
18
+ const transcriptionState = useHMSStore(selectSessionStore(SESSION_STORE_KEY.TRANSCRIPTION_STATE));
19
+ const rawStore = useHMSVanillaStore();
20
+ const isTranscriptionEnabled = !!transcriptionState?.enabled;
21
+ let transcript = '',
22
+ speakingPeer = '';
23
+ if (isTranscriptionEnabled) {
24
+ transcript = transcriptionState.transcript || '';
25
+ speakingPeer = transcriptionState.speakingPeer || '';
26
+ }
27
+
28
+ const transcriber = useRef(null);
29
+ const hmsActions = useHMSActions();
30
+ const isAllowedToPublish = useHMSStore(selectIsAllowedToPublish);
31
+
32
+ useEffect(() => {
33
+ hmsActions.sessionStore.observe(SESSION_STORE_KEY.TRANSCRIPTION_STATE);
34
+ }, [hmsActions]);
35
+
36
+ useEffect(() => {
37
+ if (!transcriber.current) {
38
+ // create transcriber with the current room state for transcription
39
+ transcriber.current = new Transcriber({
40
+ hmsStore: rawStore,
41
+ setTranscriptAndSpeakingPeer: async (transcript, peerName) => {
42
+ const transcriptionCurrentEnabledState = !!rawStore.getState(
43
+ selectSessionStore(SESSION_STORE_KEY.TRANSCRIPTION_STATE),
44
+ )?.enabled;
45
+ await hmsActions.sessionStore.set(SESSION_STORE_KEY.TRANSCRIPTION_STATE, {
46
+ enabled: transcriptionCurrentEnabledState,
47
+ transcript,
48
+ speakingPeer: peerName,
49
+ });
50
+ },
51
+ setIsTranscriptionEnabled: async newEnabledState => {
52
+ await hmsActions.sessionStore.set(SESSION_STORE_KEY.TRANSCRIPTION_STATE, {
53
+ enabled: newEnabledState,
54
+ });
55
+ },
56
+ });
57
+ }
58
+ return () => {
59
+ if (transcriber.current) {
60
+ transcriber.current.cleanup();
61
+ }
62
+ };
63
+ }, [hmsActions, rawStore]);
64
+
65
+ useEffect(() => {
66
+ // remote enabled transcript
67
+ if (isTranscriptionEnabled) {
68
+ transcriber.current.enableTranscription(true);
69
+ }
70
+ }, [isTranscriptionEnabled]);
71
+
72
+ const toggleTranscriptionState = useCallback(() => {
73
+ transcriber.current.toggleTranscriptionState();
74
+ }, []);
75
+
76
+ return (
77
+ <>
78
+ <Box
79
+ css={{
80
+ textAlign: 'left',
81
+ fontWeight: '$medium',
82
+ bottom: '120px',
83
+ position: 'fixed',
84
+ width: '100%',
85
+ fontSize: '$20px',
86
+ zIndex: '1000000',
87
+ color: 'white',
88
+ textShadow: '0px 0px 6px #000',
89
+ whiteSpace: 'pre-line',
90
+ paddingLeft: '40px',
91
+ }}
92
+ />
93
+ <Box
94
+ css={{
95
+ textAlign: 'center',
96
+ fontWeight: '$medium',
97
+ bottom: '90px',
98
+ position: 'fixed',
99
+ width: '100%',
100
+ fontSize: '$20px',
101
+ zIndex: '1000000',
102
+ color: 'white',
103
+ textShadow: '0px 0px 6px #000',
104
+ whiteSpace: 'pre-line',
105
+ }}
106
+ >
107
+ <Text
108
+ css={{
109
+ color: 'white',
110
+ textShadow: '0px 0px 6px #000',
111
+ }}
112
+ >
113
+ {transcript}
114
+ </Text>
115
+ <Text
116
+ css={{
117
+ color: '#c0bbbb',
118
+ textShadow: '0px 0px 6px #000',
119
+ textTransform: 'capitalize',
120
+ }}
121
+ >
122
+ {speakingPeer}
123
+ </Text>
124
+ </Box>
125
+ {isAllowedToPublish.audio && (
126
+ <Tooltip title={`Turn ${!isTranscriptionEnabled ? 'on' : 'off'} transcription`}>
127
+ <IconButton
128
+ active={!isTranscriptionEnabled}
129
+ onClick={toggleTranscriptionState}
130
+ data-testid="transcription_btn"
131
+ >
132
+ <ClosedCaptionIcon />
133
+ </IconButton>
134
+ </Tooltip>
135
+ )}
136
+ </>
137
+ );
138
+ }
@@ -0,0 +1 @@
1
+ export { TranscriptionButton as default } from './TranscriptionButton';
@@ -0,0 +1,110 @@
1
+ // @ts-check
2
+ import Pusher from 'pusher-js';
3
+
4
+ const stringifyWithNull = obj => JSON.stringify(obj, (k, v) => (v === undefined ? null : v));
5
+
6
+ /**
7
+ * On whiteboard close, owner sends current state to remote peers.
8
+ * Remote peers tear down too quickly(unsubscribing listeners) and are unable to store the last state.
9
+ *
10
+ * Hack: To overcome this, attach 2 listeners:
11
+ * one for storing the message(won't be unsubscribed),
12
+ * one for calling the actual whiteboard callback(will be unsubscribed on whiteboard close)
13
+ *
14
+ * This way the last state is always received and stored
15
+ */
16
+
17
+ /**
18
+ * Base class which can be extended to use various realtime communication services.
19
+ * Methods to broadcast and subscribe to events.
20
+ *
21
+ * Stores the last message received/broadcasted to resend when required(when board is ready)
22
+ */
23
+
24
+ class PusherCommunicationProvider {
25
+ constructor() {
26
+ /** @private */
27
+ this.initialized = false;
28
+ /** @private */
29
+ this.lastMessage = {};
30
+ }
31
+
32
+ init = (roomId = '') => {
33
+ if (this.initialized) {
34
+ return;
35
+ }
36
+
37
+ /** @private */
38
+ this.pusher = new Pusher(process.env.REACT_APP_PUSHER_APP_KEY, {
39
+ cluster: 'ap2',
40
+ authEndpoint: process.env.REACT_APP_PUSHER_AUTHENDPOINT,
41
+ });
42
+
43
+ // Pusher.default.logToConsole = true;
44
+
45
+ /** @private */
46
+ this.channel = this.pusher.subscribe(`private-${roomId}`);
47
+
48
+ /**
49
+ * When events(peer-join) are sent too early before subscribing to a channel,
50
+ * resend last event after subscription has succeeded.
51
+ */
52
+ this.channel.bind('pusher:subscription_succeeded', this.resendLastEvents);
53
+
54
+ console.log('Whiteboard initialized communication through Pusher');
55
+ this.initialized = true;
56
+ };
57
+
58
+ /**
59
+ * @param {string} eventName
60
+ * @param {any} message
61
+ */
62
+ storeEvent = (eventName, message) => {
63
+ this.lastMessage[eventName] = { eventName, ...message };
64
+ };
65
+
66
+ /**
67
+ * @param {string} eventName
68
+ * @returns {any}
69
+ */
70
+ getStoredEvent = eventName => {
71
+ return this.lastMessage[eventName];
72
+ };
73
+
74
+ /**
75
+ * @param {string} eventName
76
+ * @param {Object} arg
77
+ */
78
+ broadcastEvent = (eventName, arg = {}) => {
79
+ this.storeEvent(eventName, arg);
80
+
81
+ this.channel?.trigger(`client-${eventName}`, stringifyWithNull({ eventName, ...arg }));
82
+ };
83
+
84
+ /**
85
+ *
86
+ * @param {string} eventName
87
+ * @param {Function} cb
88
+ */
89
+ subscribe = (eventName, cb) => {
90
+ this.channel?.bind(`client-${eventName}`, message => this.storeEvent(eventName, message));
91
+ this.channel?.bind(`client-${eventName}`, cb);
92
+ return () => {
93
+ this.channel?.unbind(`client-${eventName}`, cb);
94
+ };
95
+ };
96
+
97
+ /** @private */
98
+ resendLastEvents = () => {
99
+ for (const eventName in this.lastMessage) {
100
+ if (this.lastMessage[eventName]) {
101
+ this.channel?.trigger(`client-${eventName}`, this.lastMessage[eventName]);
102
+ }
103
+ }
104
+ };
105
+ }
106
+
107
+ /**
108
+ * @type {PusherCommunicationProvider}
109
+ */
110
+ export const provider = new PusherCommunicationProvider();
@@ -0,0 +1,29 @@
1
+ # Collaborative Whiteboard setup
2
+
3
+ ## Pusher Account
4
+
5
+ - Create an Pusher account at https://pusher.com/.
6
+ - Create a new channels app.
7
+ - Go to the “App Keys” page for that app(apps list view at https://dashboard.pusher.com/apps), and make a note of your app_id, key, secret and cluster.
8
+ - Go to the "App Settings" page and enable client events.
9
+
10
+ ## Whiteboard Server
11
+
12
+ - Fork the whiteboard pusher server from https://github.com/100mslive/whiteboard-server and deploy it using your preferred hosting provider.
13
+ - Add the pusher keys noted earlier to environment variables.
14
+
15
+ ```
16
+ APP_CLUSTER="cluster"
17
+ APP_SECRET="secret"
18
+ APP_KEY="key"
19
+ APP_ID="app_id"
20
+ ```
21
+
22
+ - The API path is `api/pusher/auth`, say your deployment URL is `whiteboard-server.vercel.app`, the Pusher Auth Endpoint is `https://whiteboard-server.vercel.app/api/pusher/auth`
23
+
24
+ ## Whiteboard Client
25
+
26
+ - Copy the whole folder at `/src/plugins/whiteboard` into your live video conferencing apps using 100ms' SDKs.
27
+ - Add the pusher app key and pusher auth endpoint to `REACT_APP_PUSHER_APP_KEY` and `REACT_APP_PUSHER_AUTHENDPOINT` environment variables.
28
+ - The `useWhiteboardMetadata` hook returns state such as the whiteboard owner(`whiteboardOwner`) and action to toggle the whiteboard(`toggleWhiteboard`). Refer usage in `ToggleWhiteboard.jsx` - an icon button to toggle the whiteboard based on the active state.
29
+ - When the whiteboard is active(`whiteboardOwner` from `useWhiteboardMetadata` is not null), render the `Whiteboard` component on your UI to let your users draw on the whiteboard. Refer `mainView.jsx` and `WhiteboardView.jsx`.
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { selectLocalPeerRoleName, useHMSStore } from '@100mslive/react-sdk';
3
+ import { PencilDrawIcon } from '@100mslive/react-icons';
4
+ import { Tooltip } from '../../../Tooltip';
5
+ import IconButton from '../../IconButton';
6
+ import { useHLSViewerRole } from '../../components/AppData/useUISettings';
7
+ import { useIsFeatureEnabled } from '../../components/hooks/useFeatures';
8
+ import { useWhiteboardMetadata } from './useWhiteboardMetadata';
9
+ import { FEATURE_LIST } from '../../common/constants';
10
+
11
+ export const ToggleWhiteboard = () => {
12
+ const {
13
+ whiteboardEnabled,
14
+ whiteboardOwner: whiteboardActive,
15
+ amIWhiteboardOwner,
16
+ toggleWhiteboard,
17
+ } = useWhiteboardMetadata();
18
+ const hlsViewerRole = useHLSViewerRole();
19
+ const localPeerRole = useHMSStore(selectLocalPeerRoleName);
20
+ const isFeatureEnabled = useIsFeatureEnabled(FEATURE_LIST.WHITEBOARD);
21
+
22
+ if (!whiteboardEnabled || localPeerRole === hlsViewerRole || !isFeatureEnabled) {
23
+ return null;
24
+ }
25
+
26
+ return (
27
+ <Tooltip
28
+ title={`${
29
+ whiteboardActive ? (amIWhiteboardOwner ? `Stop whiteboard` : `Can't stop whiteboard`) : 'Start whiteboard'
30
+ }`}
31
+ key="whiteboard"
32
+ >
33
+ <IconButton
34
+ onClick={toggleWhiteboard}
35
+ active={!whiteboardActive}
36
+ disabled={whiteboardActive && !amIWhiteboardOwner}
37
+ data-testid="white_board_btn"
38
+ >
39
+ <PencilDrawIcon />
40
+ </IconButton>
41
+ </Tooltip>
42
+ );
43
+ };
@@ -0,0 +1,12 @@
1
+ /* Hide undo and redo buttons */
2
+ .c-bUEyht-jvfJsl-side-right > button:nth-child(1) {
3
+ display: none;
4
+ }
5
+
6
+ .c-bUEyht-jvfJsl-side-right > button:nth-child(2) {
7
+ display: none;
8
+ }
9
+
10
+ #TD-PrimaryTools-Image {
11
+ display: none;
12
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Tldraw } from '@tldraw/tldraw';
3
+ import { useMultiplayerState } from './useMultiplayerState';
4
+ import './Whiteboard.css';
5
+
6
+ export const Whiteboard = React.memo(({ roomId }) => {
7
+ const events = useMultiplayerState(roomId);
8
+ return (
9
+ <Tldraw autofocus disableAssets={true} showSponsorLink={false} showPages={false} showMenu={false} {...events} />
10
+ );
11
+ });
@@ -0,0 +1,8 @@
1
+ export const WhiteboardEvents = {
2
+ // To broadcast new changes made in whiteboard
3
+ STATE_CHANGE: 'state-change',
4
+ // To broadcast the current whole state of the board by the owner
5
+ CURRENT_STATE: 'current-state',
6
+ // For newly joined peers to request current state from owner
7
+ REQUEST_STATE: 'request-state',
8
+ };
@@ -0,0 +1,3 @@
1
+ export { Whiteboard } from './Whiteboard';
2
+ export { ToggleWhiteboard } from './ToggleWhiteboard';
3
+ export { useWhiteboardMetadata } from './useWhiteboardMetadata';
@@ -0,0 +1,212 @@
1
+ // @ts-check
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { selectDidIJoinWithin, useHMSStore } from '@100mslive/react-sdk';
4
+ import { provider as room } from './PusherCommunicationProvider';
5
+ import { WhiteboardEvents as Events } from './WhiteboardEvents';
6
+ import { useWhiteboardMetadata } from './useWhiteboardMetadata';
7
+
8
+ const useWhiteboardState = () => {
9
+ const { amIWhiteboardOwner } = useWhiteboardMetadata();
10
+ /*
11
+ * LIVE-1470 state need to have some delay after join.
12
+ * It will initialize pusher room and send request state.
13
+ */
14
+ const shouldRequestState = useHMSStore(selectDidIJoinWithin(2000));
15
+
16
+ return { shouldRequestState, amIWhiteboardOwner };
17
+ };
18
+
19
+ /**
20
+ * Ref: https://github.com/tldraw/tldraw/blob/main/apps/www/hooks/useMultiplayerState.ts
21
+ */
22
+ export function useMultiplayerState(roomId) {
23
+ const [app, setApp] = useState(null);
24
+ const [isReady, setIsReady] = useState(false);
25
+ const { amIWhiteboardOwner, shouldRequestState } = useWhiteboardState();
26
+
27
+ /**
28
+ * Stores current state(shapes, bindings, [assets]) of the whiteboard
29
+ */
30
+ const rLiveShapes = useRef(new Map());
31
+ const rLiveBindings = useRef(new Map());
32
+
33
+ const getCurrentState = useCallback(() => {
34
+ return {
35
+ shapes: rLiveShapes.current ? Object.fromEntries(rLiveShapes.current) : {},
36
+ bindings: rLiveBindings.current ? Object.fromEntries(rLiveBindings.current) : {},
37
+ };
38
+ }, []);
39
+
40
+ const sendCurrentState = useCallback(() => {
41
+ if (amIWhiteboardOwner && isReady) {
42
+ room.broadcastEvent(Events.CURRENT_STATE, getCurrentState());
43
+ }
44
+ }, [amIWhiteboardOwner, isReady, getCurrentState]);
45
+
46
+ const updateLocalState = useCallback(({ shapes, bindings, merge = true }) => {
47
+ if (!(shapes && bindings)) {
48
+ return;
49
+ }
50
+
51
+ if (merge) {
52
+ const lShapes = rLiveShapes.current;
53
+ const lBindings = rLiveBindings.current;
54
+
55
+ if (!(lShapes && lBindings)) {
56
+ return;
57
+ }
58
+ Object.entries(shapes).forEach(([id, shape]) => {
59
+ if (!shape) {
60
+ lShapes.delete(id);
61
+ } else {
62
+ lShapes.set(shape.id, shape);
63
+ }
64
+ });
65
+
66
+ Object.entries(bindings).forEach(([id, binding]) => {
67
+ if (!binding) {
68
+ lBindings.delete(id);
69
+ } else {
70
+ lBindings.set(binding.id, binding);
71
+ }
72
+ });
73
+ } else {
74
+ rLiveShapes.current = new Map(Object.entries(shapes));
75
+ rLiveBindings.current = new Map(Object.entries(bindings));
76
+ }
77
+ }, []);
78
+
79
+ const applyStateToBoard = useCallback(
80
+ state => {
81
+ app === null || app === void 0
82
+ ? void 0
83
+ : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
84
+ // @ts-ignore
85
+ app.replacePageContent(
86
+ state.shapes,
87
+ state.bindings,
88
+ {}, // Object.fromEntries(lAssets.entries())
89
+ );
90
+ },
91
+ [app],
92
+ );
93
+
94
+ const handleChanges = useCallback(
95
+ state => {
96
+ if (!state) {
97
+ return;
98
+ }
99
+
100
+ const { shapes, bindings, eventName } = state;
101
+ updateLocalState({
102
+ shapes,
103
+ bindings,
104
+ merge: eventName === Events.STATE_CHANGE,
105
+ });
106
+ applyStateToBoard(getCurrentState());
107
+ },
108
+ [applyStateToBoard, getCurrentState, updateLocalState],
109
+ );
110
+
111
+ const setupInitialState = useCallback(() => {
112
+ if (!isReady) {
113
+ return;
114
+ }
115
+
116
+ if (amIWhiteboardOwner) {
117
+ // On board open, update the document with initial/stored content
118
+ handleChanges(room.getStoredEvent(Events.CURRENT_STATE));
119
+ // Send current state to other peers in the room currently
120
+ sendCurrentState();
121
+ } else if (shouldRequestState) {
122
+ /**
123
+ * Newly joined peers request the owner for current state
124
+ * and update their boards when they receive it
125
+ */
126
+ room.broadcastEvent(Events.REQUEST_STATE);
127
+ }
128
+ }, [isReady, amIWhiteboardOwner, shouldRequestState, handleChanges, sendCurrentState]);
129
+
130
+ // Callbacks --------------
131
+ // Put the state into the window, for debugging.
132
+ const onMount = useCallback(
133
+ app => {
134
+ app.loadRoom(roomId);
135
+ app.pause(); // Turn off the app's own undo / redo stack
136
+ // window.app = app;
137
+ setApp(app);
138
+ },
139
+ [roomId],
140
+ );
141
+
142
+ // Update the live shapes when the app's shapes change.
143
+ const onChangePage = useCallback(
144
+ (_app, shapes, bindings) => {
145
+ updateLocalState({ shapes, bindings });
146
+ room.broadcastEvent(Events.STATE_CHANGE, { shapes, bindings });
147
+
148
+ /**
149
+ * Tldraw thinks that the next update passed to replacePageContent after onChangePage is the own update triggered by onChangePage
150
+ * and the replacePageContent doesn't have any effect if it is a valid update from remote.
151
+ *
152
+ * To overcome this replacePageContent locally onChangePage(not costly - returns from first line).
153
+ *
154
+ * Refer: https://github.com/tldraw/tldraw/blob/main/packages/tldraw/src/state/TldrawApp.ts#L684
155
+ */
156
+ applyStateToBoard(getCurrentState());
157
+ },
158
+ [updateLocalState, applyStateToBoard, getCurrentState],
159
+ );
160
+
161
+ // Handle presence updates when the user's pointer / selection changes
162
+ // const onChangePresence = useCallback((app, user) => {
163
+ // updateMyPresence({ id: app.room?.userId, user });
164
+ // }, [][updateMyPresence]);
165
+
166
+ // Subscriptions and initial setup
167
+ useEffect(() => {
168
+ if (!app) {
169
+ return;
170
+ }
171
+ const unsubs = [];
172
+
173
+ let stillAlive = true;
174
+
175
+ // Setup the document's storage and subscriptions
176
+ function setupDocument() {
177
+ // Subscribe to changes
178
+ if (stillAlive) {
179
+ unsubs.push(room.subscribe(Events.STATE_CHANGE, handleChanges));
180
+ unsubs.push(room.subscribe(Events.CURRENT_STATE, handleChanges));
181
+
182
+ // On request state(peer join), send whole current state to update the new peer's whiteboard
183
+ unsubs.push(room.subscribe(Events.REQUEST_STATE, sendCurrentState));
184
+
185
+ setIsReady(true);
186
+ }
187
+ }
188
+
189
+ room.init(roomId);
190
+ setupDocument();
191
+ setupInitialState();
192
+
193
+ return () => {
194
+ stillAlive = false;
195
+ unsubs.forEach(unsub => unsub());
196
+ };
197
+ }, [app, roomId, setupInitialState, sendCurrentState, handleChanges]);
198
+
199
+ useEffect(() => {
200
+ // Store last state on closing whitboard so that when the board is reopened the state could be fetched and reapplied
201
+ const handleUnmount = () => {
202
+ if (isReady && !shouldRequestState) {
203
+ console.log('Whiteboard unmount storing', getCurrentState());
204
+ room.storeEvent(Events.CURRENT_STATE, getCurrentState());
205
+ }
206
+ };
207
+
208
+ return handleUnmount;
209
+ }, [isReady, shouldRequestState, getCurrentState]);
210
+
211
+ return { onMount, onChangePage };
212
+ }
@@ -0,0 +1,47 @@
1
+ import { useCallback, useEffect, useMemo } from 'react';
2
+ import { selectLocalPeerID, selectPeerByCondition, useHMSStore } from '@100mslive/react-sdk';
3
+ import { useMyMetadata } from '../../components/hooks/useMetadata';
4
+ import { getMetadata } from '../../common/utils';
5
+ import { FeatureFlags } from '../../services/FeatureFlags';
6
+
7
+ const isWhiteboardOwner = peer => {
8
+ return !!getMetadata(peer?.metadata).whiteboardOwner;
9
+ };
10
+
11
+ export const useWhiteboardMetadata = () => {
12
+ const localPeerID = useHMSStore(selectLocalPeerID);
13
+ const { updateMetaData } = useMyMetadata();
14
+ const whiteboardOwner = useHMSStore(selectPeerByCondition(isWhiteboardOwner));
15
+ const amIWhiteboardOwner = useMemo(() => localPeerID === whiteboardOwner?.id, [localPeerID, whiteboardOwner]);
16
+
17
+ /**
18
+ * @param enabled {boolean}
19
+ */
20
+ const toggleWhiteboard = useCallback(async () => {
21
+ if (!process.env.REACT_APP_PUSHER_APP_KEY) {
22
+ console.error('Cannot start whiteboard - Pusher Key unavailable');
23
+ }
24
+ try {
25
+ if (!whiteboardOwner || amIWhiteboardOwner) {
26
+ await updateMetaData({ whiteboardOwner: !whiteboardOwner });
27
+ } else {
28
+ console.warn('Cannot toggle whiteboard as it was shared by another peer');
29
+ }
30
+ } catch (error) {
31
+ console.error('failed to toggle whiteboard to ', !whiteboardOwner, error);
32
+ }
33
+ }, [whiteboardOwner, updateMetaData, amIWhiteboardOwner]);
34
+
35
+ useEffect(() => {
36
+ window.toggleWhiteboard = toggleWhiteboard;
37
+ }, [toggleWhiteboard]);
38
+
39
+ return {
40
+ /** is whiteboard enabled for the room */
41
+ whiteboardEnabled: FeatureFlags.enableWhiteboard,
42
+ /** owner of the active whiteboard, can also be used to check if whiteboard is active */
43
+ whiteboardOwner,
44
+ amIWhiteboardOwner,
45
+ toggleWhiteboard,
46
+ };
47
+ };