@microsoft/live-share-react 2.0.0-internal.1 → 2.0.0-internal.11

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 (313) hide show
  1. package/LICENSE +64 -61
  2. package/README.md +169 -164
  3. package/bin/cjs/index.d.ts +7 -0
  4. package/bin/cjs/index.d.ts.map +1 -0
  5. package/bin/cjs/index.js +23 -0
  6. package/bin/cjs/index.js.map +1 -0
  7. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +26 -0
  8. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  9. package/bin/cjs/interfaces/LiveInterfaceExtensions.js +7 -0
  10. package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +1 -0
  11. package/bin/cjs/interfaces/index.d.ts +2 -0
  12. package/bin/cjs/interfaces/index.d.ts.map +1 -0
  13. package/bin/cjs/interfaces/index.js +18 -0
  14. package/bin/cjs/interfaces/index.js.map +1 -0
  15. package/bin/cjs/internal/errors.d.ts +41 -0
  16. package/bin/cjs/internal/errors.d.ts.map +1 -0
  17. package/bin/cjs/internal/errors.js +48 -0
  18. package/bin/cjs/internal/errors.js.map +1 -0
  19. package/bin/cjs/internal/index.d.ts +3 -0
  20. package/bin/cjs/internal/index.d.ts.map +1 -0
  21. package/bin/cjs/internal/index.js +19 -0
  22. package/bin/cjs/internal/index.js.map +1 -0
  23. package/bin/cjs/internal/type-guards.d.ts +11 -0
  24. package/bin/cjs/internal/type-guards.d.ts.map +1 -0
  25. package/bin/cjs/internal/type-guards.js +24 -0
  26. package/bin/cjs/internal/type-guards.js.map +1 -0
  27. package/bin/cjs/live-hooks/index.d.ts +8 -0
  28. package/bin/cjs/live-hooks/index.d.ts.map +1 -0
  29. package/bin/cjs/live-hooks/index.js +24 -0
  30. package/bin/cjs/live-hooks/index.js.map +1 -0
  31. package/bin/cjs/live-hooks/useLiveCanvas.d.ts +80 -0
  32. package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +1 -0
  33. package/bin/cjs/live-hooks/useLiveCanvas.js +244 -0
  34. package/bin/cjs/live-hooks/useLiveCanvas.js.map +1 -0
  35. package/bin/cjs/live-hooks/useLiveEvent.d.ts +59 -0
  36. package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +1 -0
  37. package/bin/cjs/live-hooks/useLiveEvent.js +150 -0
  38. package/bin/cjs/live-hooks/useLiveEvent.js.map +1 -0
  39. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +163 -0
  40. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  41. package/bin/cjs/live-hooks/useLiveFollowMode.js +360 -0
  42. package/bin/cjs/live-hooks/useLiveFollowMode.js.map +1 -0
  43. package/bin/cjs/live-hooks/useLivePresence.d.ts +76 -0
  44. package/bin/cjs/live-hooks/useLivePresence.d.ts.map +1 -0
  45. package/bin/cjs/live-hooks/useLivePresence.js +170 -0
  46. package/bin/cjs/live-hooks/useLivePresence.js.map +1 -0
  47. package/bin/cjs/live-hooks/useLiveState.d.ts +66 -0
  48. package/bin/cjs/live-hooks/useLiveState.d.ts.map +1 -0
  49. package/bin/cjs/live-hooks/useLiveState.js +134 -0
  50. package/bin/cjs/live-hooks/useLiveState.js.map +1 -0
  51. package/bin/cjs/live-hooks/useLiveTimer.d.ts +80 -0
  52. package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +1 -0
  53. package/bin/cjs/live-hooks/useLiveTimer.js +233 -0
  54. package/bin/cjs/live-hooks/useLiveTimer.js.map +1 -0
  55. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +86 -0
  56. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  57. package/bin/cjs/live-hooks/useMediaSynchronizer.js +301 -0
  58. package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +1 -0
  59. package/bin/cjs/package.json +1 -0
  60. package/bin/cjs/providers/AzureProvider.d.ts +113 -0
  61. package/bin/cjs/providers/AzureProvider.d.ts.map +1 -0
  62. package/bin/cjs/providers/AzureProvider.js +127 -0
  63. package/bin/cjs/providers/AzureProvider.js.map +1 -0
  64. package/bin/cjs/providers/LiveShareProvider.d.ts +193 -0
  65. package/bin/cjs/providers/LiveShareProvider.d.ts.map +1 -0
  66. package/bin/cjs/providers/LiveShareProvider.js +205 -0
  67. package/bin/cjs/providers/LiveShareProvider.js.map +1 -0
  68. package/bin/cjs/providers/index.d.ts +3 -0
  69. package/bin/cjs/providers/index.d.ts.map +1 -0
  70. package/bin/cjs/providers/index.js +19 -0
  71. package/bin/cjs/providers/index.js.map +1 -0
  72. package/bin/cjs/shared-hooks/index.d.ts +7 -0
  73. package/bin/cjs/shared-hooks/index.d.ts.map +1 -0
  74. package/bin/cjs/shared-hooks/index.js +23 -0
  75. package/bin/cjs/shared-hooks/index.js.map +1 -0
  76. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  77. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  78. package/bin/cjs/shared-hooks/internals/tree-node-constants.js +6 -0
  79. package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +1 -0
  80. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +10 -0
  81. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  82. package/bin/cjs/shared-hooks/internals/tree-node-types.js +23 -0
  83. package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +1 -0
  84. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  85. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  86. package/bin/cjs/shared-hooks/internals/tree-node-utils.js +193 -0
  87. package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +1 -0
  88. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +23 -0
  89. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  90. package/bin/cjs/shared-hooks/useDynamicDDS.js +87 -0
  91. package/bin/cjs/shared-hooks/useDynamicDDS.js.map +1 -0
  92. package/bin/cjs/shared-hooks/useSharedMap.d.ts +25 -0
  93. package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +1 -0
  94. package/bin/cjs/shared-hooks/useSharedMap.js +134 -0
  95. package/bin/cjs/shared-hooks/useSharedMap.js.map +1 -0
  96. package/bin/cjs/shared-hooks/useSharedState.d.ts +22 -0
  97. package/bin/cjs/shared-hooks/useSharedState.d.ts.map +1 -0
  98. package/bin/cjs/shared-hooks/useSharedState.js +80 -0
  99. package/bin/cjs/shared-hooks/useSharedState.js.map +1 -0
  100. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +37 -0
  101. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  102. package/bin/cjs/shared-hooks/useSharedStateRegistry.js +120 -0
  103. package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +1 -0
  104. package/bin/cjs/shared-hooks/useSharedTree.d.ts +57 -0
  105. package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +1 -0
  106. package/bin/cjs/shared-hooks/useSharedTree.js +123 -0
  107. package/bin/cjs/shared-hooks/useSharedTree.js.map +1 -0
  108. package/bin/cjs/shared-hooks/useTreeNode.d.ts +96 -0
  109. package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +1 -0
  110. package/bin/cjs/shared-hooks/useTreeNode.js +135 -0
  111. package/bin/cjs/shared-hooks/useTreeNode.js.map +1 -0
  112. package/bin/cjs/types/ActionTypes.d.ts +112 -0
  113. package/bin/cjs/types/ActionTypes.d.ts.map +1 -0
  114. package/bin/cjs/types/ActionTypes.js +7 -0
  115. package/bin/cjs/types/ActionTypes.js.map +1 -0
  116. package/bin/cjs/types/PropTypes.d.ts +56 -0
  117. package/bin/cjs/types/PropTypes.d.ts.map +1 -0
  118. package/bin/cjs/types/PropTypes.js +7 -0
  119. package/bin/cjs/types/PropTypes.js.map +1 -0
  120. package/bin/cjs/types/ResultTypes.d.ts +334 -0
  121. package/bin/cjs/types/ResultTypes.d.ts.map +1 -0
  122. package/bin/cjs/types/ResultTypes.js +7 -0
  123. package/bin/cjs/types/ResultTypes.js.map +1 -0
  124. package/bin/cjs/types/index.d.ts +4 -0
  125. package/bin/cjs/types/index.d.ts.map +1 -0
  126. package/bin/cjs/types/index.js +20 -0
  127. package/bin/cjs/types/index.js.map +1 -0
  128. package/bin/cjs/utils/index.d.ts +2 -0
  129. package/bin/cjs/utils/index.d.ts.map +1 -0
  130. package/bin/cjs/utils/index.js +18 -0
  131. package/bin/cjs/utils/index.js.map +1 -0
  132. package/bin/cjs/utils/type-check.d.ts +15 -0
  133. package/bin/cjs/utils/type-check.d.ts.map +1 -0
  134. package/bin/cjs/utils/type-check.js +62 -0
  135. package/bin/cjs/utils/type-check.js.map +1 -0
  136. package/bin/esm/index.d.ts +7 -0
  137. package/bin/esm/index.d.ts.map +1 -0
  138. package/bin/esm/index.js +7 -0
  139. package/bin/esm/index.js.map +1 -0
  140. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts +26 -0
  141. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  142. package/bin/esm/interfaces/LiveInterfaceExtensions.js +6 -0
  143. package/bin/esm/interfaces/LiveInterfaceExtensions.js.map +1 -0
  144. package/bin/esm/interfaces/index.d.ts +2 -0
  145. package/bin/esm/interfaces/index.d.ts.map +1 -0
  146. package/bin/esm/interfaces/index.js +2 -0
  147. package/bin/esm/interfaces/index.js.map +1 -0
  148. package/bin/esm/internal/errors.d.ts +41 -0
  149. package/bin/esm/internal/errors.d.ts.map +1 -0
  150. package/bin/esm/internal/errors.js +42 -0
  151. package/bin/esm/internal/errors.js.map +1 -0
  152. package/bin/esm/internal/index.d.ts +3 -0
  153. package/bin/esm/internal/index.d.ts.map +1 -0
  154. package/bin/esm/internal/index.js +3 -0
  155. package/bin/esm/internal/index.js.map +1 -0
  156. package/bin/esm/internal/type-guards.d.ts +11 -0
  157. package/bin/esm/internal/type-guards.d.ts.map +1 -0
  158. package/bin/esm/internal/type-guards.js +20 -0
  159. package/bin/esm/internal/type-guards.js.map +1 -0
  160. package/bin/esm/live-hooks/index.d.ts +8 -0
  161. package/bin/esm/live-hooks/index.d.ts.map +1 -0
  162. package/bin/esm/live-hooks/index.js +8 -0
  163. package/bin/esm/live-hooks/index.js.map +1 -0
  164. package/bin/esm/live-hooks/useLiveCanvas.d.ts +80 -0
  165. package/bin/esm/live-hooks/useLiveCanvas.d.ts.map +1 -0
  166. package/bin/esm/live-hooks/useLiveCanvas.js +238 -0
  167. package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
  168. package/bin/esm/live-hooks/useLiveEvent.d.ts +59 -0
  169. package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
  170. package/bin/esm/live-hooks/useLiveEvent.js +144 -0
  171. package/bin/esm/live-hooks/useLiveEvent.js.map +1 -0
  172. package/bin/esm/live-hooks/useLiveFollowMode.d.ts +163 -0
  173. package/bin/esm/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  174. package/bin/esm/live-hooks/useLiveFollowMode.js +354 -0
  175. package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -0
  176. package/bin/esm/live-hooks/useLivePresence.d.ts +76 -0
  177. package/bin/esm/live-hooks/useLivePresence.d.ts.map +1 -0
  178. package/bin/esm/live-hooks/useLivePresence.js +164 -0
  179. package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
  180. package/bin/esm/live-hooks/useLiveState.d.ts +66 -0
  181. package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
  182. package/bin/esm/live-hooks/useLiveState.js +128 -0
  183. package/bin/esm/live-hooks/useLiveState.js.map +1 -0
  184. package/bin/esm/live-hooks/useLiveTimer.d.ts +80 -0
  185. package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
  186. package/bin/esm/live-hooks/useLiveTimer.js +227 -0
  187. package/bin/esm/live-hooks/useLiveTimer.js.map +1 -0
  188. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts +86 -0
  189. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  190. package/bin/esm/live-hooks/useMediaSynchronizer.js +295 -0
  191. package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
  192. package/bin/esm/providers/AzureProvider.d.ts +113 -0
  193. package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
  194. package/bin/esm/providers/AzureProvider.js +119 -0
  195. package/bin/esm/providers/AzureProvider.js.map +1 -0
  196. package/bin/esm/providers/LiveShareProvider.d.ts +193 -0
  197. package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
  198. package/bin/esm/providers/LiveShareProvider.js +197 -0
  199. package/bin/esm/providers/LiveShareProvider.js.map +1 -0
  200. package/bin/esm/providers/index.d.ts +3 -0
  201. package/bin/esm/providers/index.d.ts.map +1 -0
  202. package/bin/esm/providers/index.js +3 -0
  203. package/bin/esm/providers/index.js.map +1 -0
  204. package/bin/esm/shared-hooks/index.d.ts +7 -0
  205. package/bin/esm/shared-hooks/index.d.ts.map +1 -0
  206. package/bin/esm/shared-hooks/index.js +7 -0
  207. package/bin/esm/shared-hooks/index.js.map +1 -0
  208. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  209. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  210. package/bin/esm/shared-hooks/internals/tree-node-constants.js +3 -0
  211. package/bin/esm/shared-hooks/internals/tree-node-constants.js.map +1 -0
  212. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts +10 -0
  213. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  214. package/bin/esm/shared-hooks/internals/tree-node-types.js +18 -0
  215. package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -0
  216. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  217. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  218. package/bin/esm/shared-hooks/internals/tree-node-utils.js +188 -0
  219. package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
  220. package/bin/esm/shared-hooks/useDynamicDDS.d.ts +23 -0
  221. package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  222. package/bin/esm/shared-hooks/useDynamicDDS.js +81 -0
  223. package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
  224. package/bin/esm/shared-hooks/useSharedMap.d.ts +25 -0
  225. package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
  226. package/bin/esm/shared-hooks/useSharedMap.js +128 -0
  227. package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
  228. package/bin/esm/shared-hooks/useSharedState.d.ts +22 -0
  229. package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
  230. package/bin/esm/shared-hooks/useSharedState.js +74 -0
  231. package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
  232. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts +37 -0
  233. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  234. package/bin/esm/shared-hooks/useSharedStateRegistry.js +113 -0
  235. package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -0
  236. package/bin/esm/shared-hooks/useSharedTree.d.ts +57 -0
  237. package/bin/esm/shared-hooks/useSharedTree.d.ts.map +1 -0
  238. package/bin/esm/shared-hooks/useSharedTree.js +117 -0
  239. package/bin/esm/shared-hooks/useSharedTree.js.map +1 -0
  240. package/bin/esm/shared-hooks/useTreeNode.d.ts +96 -0
  241. package/bin/esm/shared-hooks/useTreeNode.d.ts.map +1 -0
  242. package/bin/esm/shared-hooks/useTreeNode.js +132 -0
  243. package/bin/esm/shared-hooks/useTreeNode.js.map +1 -0
  244. package/bin/esm/types/ActionTypes.d.ts +112 -0
  245. package/bin/esm/types/ActionTypes.d.ts.map +1 -0
  246. package/bin/esm/types/ActionTypes.js +6 -0
  247. package/bin/esm/types/ActionTypes.js.map +1 -0
  248. package/bin/esm/types/PropTypes.d.ts +56 -0
  249. package/bin/esm/types/PropTypes.d.ts.map +1 -0
  250. package/bin/esm/types/PropTypes.js +6 -0
  251. package/bin/esm/types/PropTypes.js.map +1 -0
  252. package/bin/esm/types/ResultTypes.d.ts +334 -0
  253. package/bin/esm/types/ResultTypes.d.ts.map +1 -0
  254. package/bin/esm/types/ResultTypes.js +6 -0
  255. package/bin/esm/types/ResultTypes.js.map +1 -0
  256. package/bin/esm/types/index.d.ts +4 -0
  257. package/bin/esm/types/index.d.ts.map +1 -0
  258. package/bin/esm/types/index.js +4 -0
  259. package/bin/esm/types/index.js.map +1 -0
  260. package/bin/esm/utils/index.d.ts +2 -0
  261. package/bin/esm/utils/index.d.ts.map +1 -0
  262. package/bin/esm/utils/index.js +2 -0
  263. package/bin/esm/utils/index.js.map +1 -0
  264. package/bin/esm/utils/type-check.d.ts +15 -0
  265. package/bin/esm/utils/type-check.d.ts.map +1 -0
  266. package/bin/esm/utils/type-check.js +54 -0
  267. package/bin/esm/utils/type-check.js.map +1 -0
  268. package/bin/live-hooks/useLiveCanvas.js +1 -1
  269. package/bin/live-hooks/useLiveCanvas.js.map +1 -1
  270. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  271. package/bin/live-hooks/useLiveState.js +6 -2
  272. package/bin/live-hooks/useLiveState.js.map +1 -1
  273. package/bin/live-hooks/useMediaSynchronizer.js +1 -1
  274. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
  275. package/bin/providers/AzureProvider.js +2 -2
  276. package/bin/providers/AzureProvider.js.map +1 -1
  277. package/bin/providers/LiveShareProvider.js +3 -3
  278. package/bin/providers/LiveShareProvider.js.map +1 -1
  279. package/package.json +61 -47
  280. package/src/index.ts +6 -6
  281. package/src/interfaces/index.ts +1 -1
  282. package/src/internal/index.ts +2 -2
  283. package/src/internal/type-guards.ts +1 -1
  284. package/src/live-hooks/index.ts +7 -7
  285. package/src/live-hooks/useLiveCanvas.ts +154 -82
  286. package/src/live-hooks/useLiveEvent.ts +43 -7
  287. package/src/live-hooks/useLiveFollowMode.ts +149 -6
  288. package/src/live-hooks/useLivePresence.ts +80 -17
  289. package/src/live-hooks/useLiveState.ts +54 -6
  290. package/src/live-hooks/useLiveTimer.ts +59 -4
  291. package/src/live-hooks/useMediaSynchronizer.ts +71 -6
  292. package/src/providers/AzureProvider.tsx +21 -21
  293. package/src/providers/LiveShareProvider.tsx +115 -13
  294. package/src/providers/index.ts +2 -2
  295. package/src/shared-hooks/index.ts +6 -4
  296. package/src/shared-hooks/internals/tree-node-constants.ts +2 -0
  297. package/src/shared-hooks/internals/tree-node-types.ts +26 -0
  298. package/src/shared-hooks/internals/tree-node-utils.ts +269 -0
  299. package/src/shared-hooks/useDynamicDDS.ts +28 -17
  300. package/src/shared-hooks/useSharedMap.ts +42 -17
  301. package/src/shared-hooks/useSharedState.ts +6 -3
  302. package/src/shared-hooks/useSharedStateRegistry.ts +44 -22
  303. package/src/shared-hooks/useSharedTree.ts +144 -0
  304. package/src/shared-hooks/useTreeNode.ts +147 -0
  305. package/src/types/ActionTypes.ts +13 -9
  306. package/src/types/PropTypes.ts +57 -0
  307. package/src/types/ResultTypes.ts +71 -17
  308. package/src/types/index.ts +3 -3
  309. package/src/utils/index.ts +1 -1
  310. package/tsconfig.cjs.json +14 -0
  311. package/tsconfig.json +65 -70
  312. package/.nycrc.json +0 -10
  313. package/tsconfig.build.json +0 -6
@@ -0,0 +1,144 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import { LiveEventEvents, LiveEvent, LiveDataObjectInitializeState, } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks/index.js";
17
+ import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal/index.js";
18
+ import { useFluidObjectsContext } from "../providers/index.js";
19
+ /**
20
+ * React hook for using a Live Share `LiveEvent`.
21
+ *
22
+ * @remarks
23
+ * Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
24
+ * such as when sending push notifications or reactions.
25
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
26
+ *
27
+ * @template TEvent Optional typing for events sent & received. Default is `object` type.
28
+ * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
29
+ * will be created, otherwise it will use the existing one.
30
+ * @param allowedRoles Optional. The meeting roles eligible to send events through this object.
31
+ * @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
32
+ * @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
33
+ *
34
+ * @example
35
+ ```jsx
36
+ import { useLiveEvent } from "@microsoft/live-share-react";
37
+
38
+ const emojis = ["❤️", "😂", "👍", "👎"];
39
+
40
+ // Define a unique key that differentiates this usage of `useLiveEvent` from others in your app
41
+ const MY_UNIQUE_KEY = "event-key";
42
+
43
+ // Example component for using useLiveEvent
44
+ export const MyCustomEvent = () => {
45
+ const { latestEvent, liveEvent, sendEvent } = useLiveEvent(MY_UNIQUE_KEY);
46
+
47
+ // Render loading UI when creating LiveEvent instance for first time
48
+ if (!liveEvent) return <>Loading...</>;
49
+
50
+ // Render UI
51
+ return (
52
+ <div>
53
+ {`Latest event: ${latestEvent?.value}, from local user: ${latestEvent?.local}`}
54
+ {"Select a planet below:"}
55
+ {emojis.map((emoji) => (
56
+ <button
57
+ key={emoji}
58
+ onClick={() => {
59
+ sendEvent(emoji);
60
+ }}
61
+ >
62
+ {emoji}
63
+ </button>
64
+ ))}
65
+ </div>
66
+ );
67
+ };
68
+ ```
69
+ */
70
+ export function useLiveEvent(uniqueKey, allowedRoles, onReceivedEvent) {
71
+ /**
72
+ * Stateful latest event (user facing) and its non-user-facing setter method.
73
+ */
74
+ const [latestEvent, setLatestReceived] = React.useState();
75
+ /**
76
+ * Reference for all received/sent events. The current value of this is user-facing. Because
77
+ * this is always set at the same time as latestEvent, it is effectively a stateful value.
78
+ */
79
+ const allEventsRef = React.useRef([]);
80
+ /**
81
+ * User facing: dynamically load the DDS for the given unique key.
82
+ */
83
+ const { dds: liveEvent } = useDynamicDDS(uniqueKey, (LiveEvent));
84
+ const { container } = useFluidObjectsContext();
85
+ /**
86
+ * User facing: callback to send event through `LiveEvent`
87
+ */
88
+ const sendEvent = React.useCallback((event, targetClientId) => __awaiter(this, void 0, void 0, function* () {
89
+ if (!container) {
90
+ throw new ActionContainerNotJoinedError("liveEvent", "sendEvent");
91
+ }
92
+ if (liveEvent === undefined) {
93
+ throw new ActionLiveDataObjectUndefinedError("liveEvent", "sendEvent");
94
+ }
95
+ if (!liveEvent.isInitialized) {
96
+ throw new ActionLiveDataObjectInitializedError("liveEvent", "sendEvent");
97
+ }
98
+ return yield liveEvent.send(event, targetClientId);
99
+ }), [container, liveEvent]);
100
+ /**
101
+ * Setup change listeners and start `LiveEvent` if needed
102
+ */
103
+ React.useEffect(() => {
104
+ if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined)
105
+ return;
106
+ // Register event listener
107
+ const onEventReceived = (event, local, clientId, timestamp) => {
108
+ // If developer passed the optional onReceivedEvent callback, we
109
+ // call it.
110
+ onReceivedEvent === null || onReceivedEvent === void 0 ? void 0 : onReceivedEvent(event, local);
111
+ // Set the received event to our local state
112
+ const received = {
113
+ value: event,
114
+ local,
115
+ clientId,
116
+ timestamp,
117
+ };
118
+ allEventsRef.current = [...allEventsRef.current, received];
119
+ setLatestReceived(received);
120
+ };
121
+ // Reset the events list if it allEventRef.current is non-empty.
122
+ // This happens when the `id` a developer provides changes on the fly.
123
+ if (allEventsRef.current.length > 0) {
124
+ allEventsRef.current = [];
125
+ setLatestReceived(undefined);
126
+ }
127
+ liveEvent.on(LiveEventEvents.received, onEventReceived);
128
+ if (liveEvent.initializeState === LiveDataObjectInitializeState.needed) {
129
+ // Start live event
130
+ liveEvent.initialize(allowedRoles);
131
+ }
132
+ return () => {
133
+ // on unmount, remove event listeners
134
+ liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.off(LiveEventEvents.received, onEventReceived);
135
+ };
136
+ }, [liveEvent]);
137
+ return {
138
+ latestEvent,
139
+ allEvents: allEventsRef.current,
140
+ sendEvent,
141
+ liveEvent,
142
+ };
143
+ }
144
+ //# sourceMappingURL=useLiveEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,163 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { UserMeetingRole } from "@microsoft/live-share";
6
+ import { IUseLiveFollowModeResults } from "../types/index.js";
7
+ /**
8
+ * React hook for using a Live Share `LiveFollowMode`.
9
+ *
10
+ * @remarks
11
+ * Use this hook if you want to add the ability to follow specific users or let a user present to everyone in the session.
12
+ * Each user has their own `stateValue`, which is the value other users will reference when that user is presenting or being followed.
13
+ * The `state` response includes the user's `value` that the local user is "following", whether it be their own or someone else's.
14
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
15
+ *
16
+ * @template TData Optional typing for the custom user presence data object. Default is `object` type.
17
+ *
18
+ * @param uniqueKey The unique key for `LiveFollowMode`. If one does not yet exist, a new one will be created.
19
+ * @param initialData The initial value for the local user's `stateValue`.
20
+ * @param allowedRoles Optional. The user roles that are allowed to present to use `startPresenting()` or `stopPresenting()`.
21
+ * @returns `IUseLiveFollowModeResults` results, which contains React stateful objects and callbacks.
22
+ *
23
+ * @example
24
+ ```jsx
25
+ import { FollowModeType } from "@microsoft/live-share";
26
+ import { useLiveFollowMode } from "@microsoft/live-share-react";
27
+ // As an example, we will use a fake component to denote what a 3D viewer might look like in an app
28
+ import { Example3DModelViewer } from "./components";
29
+
30
+ // Define a unique key that differentiates this usage of `useLiveFollowMode` from others in your app
31
+ const MY_UNIQUE_KEY = "follow-mode-key";
32
+
33
+ // Define the initial stateValue for the local user (optional).
34
+ const startingCameraPosition = {
35
+ x: 0,
36
+ y: 0,
37
+ z: 0,
38
+ };
39
+
40
+ // Example component for using useLiveFollowMode
41
+ export function MyLiveFollowMode() {
42
+ const {
43
+ state,
44
+ localUser,
45
+ otherUsers,
46
+ allUsers,
47
+ liveFollowMode,
48
+ update,
49
+ startPresenting,
50
+ stopPresenting,
51
+ beginSuspension,
52
+ endSuspension,
53
+ followUser,
54
+ stopFollowing,
55
+ } = useLiveFollowMode(MY_UNIQUE_KEY, startingCameraPosition);
56
+
57
+ // Example of an event listener for a camera position changed event.
58
+ // For something like a camera change event, you should use a debounce function.
59
+ function onCameraPositionChanged(position, isUserAction) {
60
+ // Broadcast change to other users so that they have their latest camera position
61
+ update(position);
62
+ // If the local user changed the position while following another user, we want to suspend.
63
+ // Note: helps to distinguish changes initiated by the local user (e.g., drag mouse) separately from other change events.
64
+ if (!isUserAction) return;
65
+ switch (state.type) {
66
+ case FollowModeType.followPresenter:
67
+ case FollowModeType.followUser: {
68
+ // This will trigger a "stateChanged" event update for the local user only.
69
+ followMode.beginSuspension();
70
+ break;
71
+ }
72
+ default: {
73
+ // No need to suspend for other types
74
+ break;
75
+ }
76
+ }
77
+ }
78
+
79
+ // Can optionally get the relevant user's presence object
80
+ const followingUser = liveFollowMode?.getUser(state.followingUserId);
81
+
82
+ // Render loading UI when creating LiveFollowMode instance for first time
83
+ if (!liveFollowMode) return <>Loading...</>;
84
+
85
+ // Render UI
86
+ return (
87
+ <div>
88
+ {state.type === FollowModeType.local && (
89
+ <div>
90
+ <p>{""}</p>
91
+ <button onClick={startPresenting}>
92
+ {"Start presenting"}
93
+ </button>
94
+ </div>
95
+ )}
96
+ {state.type === FollowModeType.activeFollowers && (
97
+ <div>
98
+ <p>{`${state.otherUsersCount} users are following you`}</p>
99
+ <button onClick={startPresenting}>
100
+ {"Present to all"}
101
+ </button>
102
+ </div>
103
+ )}
104
+ {state.type === FollowModeType.activePresenter && (
105
+ <div>
106
+ <p>{`You are actively presenting to everyone`}</p>
107
+ <button onClick={stopPresenting}>
108
+ {"Stop presenting"}
109
+ </button>
110
+ </div>
111
+ )}
112
+ {state.type === FollowModeType.followPresenter && (
113
+ <div>
114
+ <p>{`${followingUser?.displayName} is presenting to everyone`}</p>
115
+ <button onClick={startPresenting}>{"Take control"}</button>
116
+ </div>
117
+ )}
118
+ {state.type === FollowModeType.suspendFollowPresenter && (
119
+ <div>
120
+ <p>{`${followingUser?.displayName} is presenting to everyone`}</p>
121
+ <button onClick={endSuspension}>
122
+ {"Sync to presenter"}
123
+ </button>
124
+ </div>
125
+ )}
126
+ {state.type === FollowModeType.followUser && (
127
+ <div>
128
+ <p>{`You are following ${followingUser?.displayName}`}</p>
129
+ <button onClick={stopFollowing}>{"Stop following"}</button>
130
+ </div>
131
+ )}
132
+ {state.type === FollowModeType.suspendFollowUser && (
133
+ <div>
134
+ <p>{`You were following ${followingUser?.displayName}`}</p>
135
+ <button onClick={stopFollowing}>
136
+ {"Resume following"}
137
+ </button>
138
+ </div>
139
+ )}
140
+ <div>
141
+ <p>{"Follow a specific user:"}</p>
142
+ {otherUsers.map((user) => (
143
+ <button
144
+ onClick={() => {
145
+ followUser(user.userId);
146
+ }}
147
+ key={user.userId}
148
+ >
149
+ {user.displayName}
150
+ </button>
151
+ ))}
152
+ </div>
153
+ <Example3DModelViewer
154
+ cameraPosition={state.value}
155
+ onCameraPositionChanged={onCameraPositionChanged}
156
+ />
157
+ </div>
158
+ );
159
+ };
160
+ ```
161
+ */
162
+ export declare function useLiveFollowMode<TData = any>(uniqueKey: string, initialData: TData | (() => TData), allowedRoles?: UserMeetingRole[]): IUseLiveFollowModeResults<TData>;
163
+ //# sourceMappingURL=useLiveFollowMode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveFollowMode.d.ts","sourceRoot":"","sources":["../../../src/live-hooks/useLiveFollowMode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAKlB,MAAM,uBAAuB,CAAC;AAS/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0JG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,GAAG,GAAG,EACzC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAClC,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,yBAAyB,CAAC,KAAK,CAAC,CA+QlC"}
@@ -0,0 +1,354 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import { LiveDataObjectInitializeState, LiveFollowMode, } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks/index.js";
17
+ import { useFluidObjectsContext } from "../providers/index.js";
18
+ import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal/index.js";
19
+ /**
20
+ * React hook for using a Live Share `LiveFollowMode`.
21
+ *
22
+ * @remarks
23
+ * Use this hook if you want to add the ability to follow specific users or let a user present to everyone in the session.
24
+ * Each user has their own `stateValue`, which is the value other users will reference when that user is presenting or being followed.
25
+ * The `state` response includes the user's `value` that the local user is "following", whether it be their own or someone else's.
26
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
27
+ *
28
+ * @template TData Optional typing for the custom user presence data object. Default is `object` type.
29
+ *
30
+ * @param uniqueKey The unique key for `LiveFollowMode`. If one does not yet exist, a new one will be created.
31
+ * @param initialData The initial value for the local user's `stateValue`.
32
+ * @param allowedRoles Optional. The user roles that are allowed to present to use `startPresenting()` or `stopPresenting()`.
33
+ * @returns `IUseLiveFollowModeResults` results, which contains React stateful objects and callbacks.
34
+ *
35
+ * @example
36
+ ```jsx
37
+ import { FollowModeType } from "@microsoft/live-share";
38
+ import { useLiveFollowMode } from "@microsoft/live-share-react";
39
+ // As an example, we will use a fake component to denote what a 3D viewer might look like in an app
40
+ import { Example3DModelViewer } from "./components";
41
+
42
+ // Define a unique key that differentiates this usage of `useLiveFollowMode` from others in your app
43
+ const MY_UNIQUE_KEY = "follow-mode-key";
44
+
45
+ // Define the initial stateValue for the local user (optional).
46
+ const startingCameraPosition = {
47
+ x: 0,
48
+ y: 0,
49
+ z: 0,
50
+ };
51
+
52
+ // Example component for using useLiveFollowMode
53
+ export function MyLiveFollowMode() {
54
+ const {
55
+ state,
56
+ localUser,
57
+ otherUsers,
58
+ allUsers,
59
+ liveFollowMode,
60
+ update,
61
+ startPresenting,
62
+ stopPresenting,
63
+ beginSuspension,
64
+ endSuspension,
65
+ followUser,
66
+ stopFollowing,
67
+ } = useLiveFollowMode(MY_UNIQUE_KEY, startingCameraPosition);
68
+
69
+ // Example of an event listener for a camera position changed event.
70
+ // For something like a camera change event, you should use a debounce function.
71
+ function onCameraPositionChanged(position, isUserAction) {
72
+ // Broadcast change to other users so that they have their latest camera position
73
+ update(position);
74
+ // If the local user changed the position while following another user, we want to suspend.
75
+ // Note: helps to distinguish changes initiated by the local user (e.g., drag mouse) separately from other change events.
76
+ if (!isUserAction) return;
77
+ switch (state.type) {
78
+ case FollowModeType.followPresenter:
79
+ case FollowModeType.followUser: {
80
+ // This will trigger a "stateChanged" event update for the local user only.
81
+ followMode.beginSuspension();
82
+ break;
83
+ }
84
+ default: {
85
+ // No need to suspend for other types
86
+ break;
87
+ }
88
+ }
89
+ }
90
+
91
+ // Can optionally get the relevant user's presence object
92
+ const followingUser = liveFollowMode?.getUser(state.followingUserId);
93
+
94
+ // Render loading UI when creating LiveFollowMode instance for first time
95
+ if (!liveFollowMode) return <>Loading...</>;
96
+
97
+ // Render UI
98
+ return (
99
+ <div>
100
+ {state.type === FollowModeType.local && (
101
+ <div>
102
+ <p>{""}</p>
103
+ <button onClick={startPresenting}>
104
+ {"Start presenting"}
105
+ </button>
106
+ </div>
107
+ )}
108
+ {state.type === FollowModeType.activeFollowers && (
109
+ <div>
110
+ <p>{`${state.otherUsersCount} users are following you`}</p>
111
+ <button onClick={startPresenting}>
112
+ {"Present to all"}
113
+ </button>
114
+ </div>
115
+ )}
116
+ {state.type === FollowModeType.activePresenter && (
117
+ <div>
118
+ <p>{`You are actively presenting to everyone`}</p>
119
+ <button onClick={stopPresenting}>
120
+ {"Stop presenting"}
121
+ </button>
122
+ </div>
123
+ )}
124
+ {state.type === FollowModeType.followPresenter && (
125
+ <div>
126
+ <p>{`${followingUser?.displayName} is presenting to everyone`}</p>
127
+ <button onClick={startPresenting}>{"Take control"}</button>
128
+ </div>
129
+ )}
130
+ {state.type === FollowModeType.suspendFollowPresenter && (
131
+ <div>
132
+ <p>{`${followingUser?.displayName} is presenting to everyone`}</p>
133
+ <button onClick={endSuspension}>
134
+ {"Sync to presenter"}
135
+ </button>
136
+ </div>
137
+ )}
138
+ {state.type === FollowModeType.followUser && (
139
+ <div>
140
+ <p>{`You are following ${followingUser?.displayName}`}</p>
141
+ <button onClick={stopFollowing}>{"Stop following"}</button>
142
+ </div>
143
+ )}
144
+ {state.type === FollowModeType.suspendFollowUser && (
145
+ <div>
146
+ <p>{`You were following ${followingUser?.displayName}`}</p>
147
+ <button onClick={stopFollowing}>
148
+ {"Resume following"}
149
+ </button>
150
+ </div>
151
+ )}
152
+ <div>
153
+ <p>{"Follow a specific user:"}</p>
154
+ {otherUsers.map((user) => (
155
+ <button
156
+ onClick={() => {
157
+ followUser(user.userId);
158
+ }}
159
+ key={user.userId}
160
+ >
161
+ {user.displayName}
162
+ </button>
163
+ ))}
164
+ </div>
165
+ <Example3DModelViewer
166
+ cameraPosition={state.value}
167
+ onCameraPositionChanged={onCameraPositionChanged}
168
+ />
169
+ </div>
170
+ );
171
+ };
172
+ ```
173
+ */
174
+ export function useLiveFollowMode(uniqueKey, initialData, allowedRoles) {
175
+ /**
176
+ * Stateful follow state.
177
+ */
178
+ const [state, setState] = React.useState();
179
+ /**
180
+ * Stateful all user presence list and its non-user-facing setter method.
181
+ */
182
+ const [allUsers, setAllUsers] = React.useState([]);
183
+ /**
184
+ * User facing: dynamically load the DDS for the given unique key.
185
+ */
186
+ const { dds: liveFollowMode } = useDynamicDDS(uniqueKey, (LiveFollowMode));
187
+ /**
188
+ * User facing: list of non-local user's presence objects.
189
+ */
190
+ const otherUsers = React.useMemo(() => {
191
+ return allUsers.filter((user) => !user.isLocalUser);
192
+ }, [allUsers]);
193
+ /**
194
+ * User facing: local user's presence object.
195
+ */
196
+ const localUser = React.useMemo(() => {
197
+ return allUsers.find((user) => user.isLocalUser);
198
+ }, [allUsers]);
199
+ const { container } = useFluidObjectsContext();
200
+ /**
201
+ * User facing: callback to update the local user's custom data for their follow state.
202
+ */
203
+ const update = React.useCallback((stateValue) => __awaiter(this, void 0, void 0, function* () {
204
+ if (!container) {
205
+ throw new ActionContainerNotJoinedError("liveFollowMode", "update");
206
+ }
207
+ if (liveFollowMode === undefined) {
208
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "update");
209
+ }
210
+ if (!liveFollowMode.isInitialized) {
211
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "update");
212
+ }
213
+ return yield liveFollowMode.update(stateValue);
214
+ }), [container, liveFollowMode]);
215
+ /**
216
+ * User facing: callback to start presenting.
217
+ */
218
+ const startPresenting = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
219
+ if (!container) {
220
+ throw new ActionContainerNotJoinedError("liveFollowMode", "startPresenting");
221
+ }
222
+ if (liveFollowMode === undefined) {
223
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "startPresenting");
224
+ }
225
+ if (!liveFollowMode.isInitialized) {
226
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "startPresenting");
227
+ }
228
+ return yield liveFollowMode.startPresenting();
229
+ }), [container, liveFollowMode]);
230
+ /**
231
+ * User facing: callback to stop presenting.
232
+ */
233
+ const stopPresenting = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
234
+ if (!container) {
235
+ throw new ActionContainerNotJoinedError("liveFollowMode", "stopPresenting");
236
+ }
237
+ if (liveFollowMode === undefined) {
238
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "stopPresenting");
239
+ }
240
+ if (!liveFollowMode.isInitialized) {
241
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "stopPresenting");
242
+ }
243
+ return yield liveFollowMode.stopPresenting();
244
+ }), [container, liveFollowMode]);
245
+ /**
246
+ * User facing: callback to suspend sync.
247
+ */
248
+ const beginSuspension = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
249
+ if (!container) {
250
+ throw new ActionContainerNotJoinedError("liveFollowMode", "syncToPresenter");
251
+ }
252
+ if (liveFollowMode === undefined) {
253
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "syncToPresenter");
254
+ }
255
+ if (!liveFollowMode.isInitialized) {
256
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "syncToPresenter");
257
+ }
258
+ return yield liveFollowMode.beginSuspension();
259
+ }), [container, liveFollowMode]);
260
+ /**
261
+ * User facing: callback to end current suspension.
262
+ */
263
+ const endSuspension = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
264
+ if (!container) {
265
+ throw new ActionContainerNotJoinedError("liveFollowMode", "syncToPresenter");
266
+ }
267
+ if (liveFollowMode === undefined) {
268
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "syncToPresenter");
269
+ }
270
+ if (!liveFollowMode.isInitialized) {
271
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "syncToPresenter");
272
+ }
273
+ return yield liveFollowMode.endSuspension();
274
+ }), [container, liveFollowMode]);
275
+ /**
276
+ * User facing: callback to follow a specific user.
277
+ */
278
+ const followUser = React.useCallback((userId) => __awaiter(this, void 0, void 0, function* () {
279
+ if (!container) {
280
+ throw new ActionContainerNotJoinedError("liveFollowMode", "followUser");
281
+ }
282
+ if (liveFollowMode === undefined) {
283
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "followUser");
284
+ }
285
+ if (!liveFollowMode.isInitialized) {
286
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "followUser");
287
+ }
288
+ return yield liveFollowMode.followUser(userId);
289
+ }), [container, liveFollowMode]);
290
+ /**
291
+ * User facing: callback to stop following a user.
292
+ */
293
+ const stopFollowing = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
294
+ if (!container) {
295
+ throw new ActionContainerNotJoinedError("liveFollowMode", "stopFollowing");
296
+ }
297
+ if (liveFollowMode === undefined) {
298
+ throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "stopFollowing");
299
+ }
300
+ if (!liveFollowMode.isInitialized) {
301
+ throw new ActionLiveDataObjectInitializedError("liveFollowMode", "stopFollowing");
302
+ }
303
+ return yield liveFollowMode.stopFollowing();
304
+ }), [container, liveFollowMode]);
305
+ /**
306
+ * Setup change listeners and start `LiveFollowMode` if needed
307
+ */
308
+ React.useEffect(() => {
309
+ if (liveFollowMode === undefined)
310
+ return;
311
+ const onPresenceChanged = () => {
312
+ const updatedLocalUsers = [];
313
+ liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.getUsers().forEach((user) => {
314
+ updatedLocalUsers.push(user);
315
+ });
316
+ setAllUsers(updatedLocalUsers);
317
+ };
318
+ liveFollowMode.on("presenceChanged", onPresenceChanged);
319
+ const onStateChanged = () => {
320
+ setState(liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.state);
321
+ };
322
+ liveFollowMode.on("stateChanged", onStateChanged);
323
+ if (liveFollowMode.initializeState ===
324
+ LiveDataObjectInitializeState.needed) {
325
+ liveFollowMode.initialize(isInitialDataCallback(initialData)
326
+ ? initialData()
327
+ : initialData, allowedRoles);
328
+ }
329
+ onPresenceChanged();
330
+ onStateChanged();
331
+ return () => {
332
+ liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.off("presenceChanged", onPresenceChanged);
333
+ liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.off("stateChanged", onStateChanged);
334
+ };
335
+ }, [liveFollowMode]);
336
+ return {
337
+ state,
338
+ localUser,
339
+ otherUsers,
340
+ allUsers,
341
+ liveFollowMode,
342
+ update,
343
+ startPresenting,
344
+ stopPresenting,
345
+ beginSuspension,
346
+ endSuspension,
347
+ followUser,
348
+ stopFollowing,
349
+ };
350
+ }
351
+ function isInitialDataCallback(value) {
352
+ return typeof value === "function";
353
+ }
354
+ //# sourceMappingURL=useLiveFollowMode.js.map