@microsoft/live-share-react 2.0.0-internal.17 → 2.0.0-internal.19

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 (289) hide show
  1. package/README.md +6 -0
  2. package/bin/esm/live-hooks/useLiveCanvas.js +29 -30
  3. package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -1
  4. package/bin/esm/live-hooks/useLiveEvent.js +6 -15
  5. package/bin/esm/live-hooks/useLiveEvent.js.map +1 -1
  6. package/bin/esm/live-hooks/useLiveFollowMode.js +25 -34
  7. package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -1
  8. package/bin/esm/live-hooks/useLivePresence.js +5 -14
  9. package/bin/esm/live-hooks/useLivePresence.js.map +1 -1
  10. package/bin/esm/live-hooks/useLiveState.js +4 -13
  11. package/bin/esm/live-hooks/useLiveState.js.map +1 -1
  12. package/bin/esm/live-hooks/useLiveTimer.js +22 -31
  13. package/bin/esm/live-hooks/useLiveTimer.js.map +1 -1
  14. package/bin/esm/live-hooks/useMediaSynchronizer.js +24 -33
  15. package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -1
  16. package/bin/esm/providers/AzureProvider.js +22 -27
  17. package/bin/esm/providers/AzureProvider.js.map +1 -1
  18. package/bin/esm/providers/LiveShareProvider.js +20 -21
  19. package/bin/esm/providers/LiveShareProvider.js.map +1 -1
  20. package/bin/esm/shared-hooks/internals/tree-node-types.js +1 -1
  21. package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -1
  22. package/bin/esm/shared-hooks/internals/tree-node-utils.js +2 -4
  23. package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -1
  24. package/bin/esm/shared-hooks/useDynamicDDS.js +3 -12
  25. package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -1
  26. package/bin/esm/shared-hooks/useSharedMap.js +1 -1
  27. package/bin/esm/shared-hooks/useSharedMap.js.map +1 -1
  28. package/bin/esm/shared-hooks/useSharedStateRegistry.js +13 -10
  29. package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -1
  30. package/bin/esm/shared-hooks/useSharedTree.js +4 -4
  31. package/bin/esm/shared-hooks/useSharedTree.js.map +1 -1
  32. package/bin/esm/types/FluidMap.d.ts +151 -0
  33. package/bin/esm/types/FluidMap.d.ts.map +1 -0
  34. package/bin/esm/types/FluidMap.js +24 -0
  35. package/bin/esm/types/FluidMap.js.map +1 -0
  36. package/bin/esm/types/ResultTypes.d.ts +15 -1
  37. package/bin/esm/types/ResultTypes.d.ts.map +1 -1
  38. package/bin/esm/utils/type-check.js +1 -1
  39. package/bin/esm/utils/type-check.js.map +1 -1
  40. package/package.json +11 -21
  41. package/src/types/FluidMap.ts +169 -0
  42. package/src/types/ResultTypes.ts +18 -1
  43. package/tsconfig.json +3 -4
  44. package/bin/cjs/index.d.ts +0 -7
  45. package/bin/cjs/index.d.ts.map +0 -1
  46. package/bin/cjs/index.js +0 -23
  47. package/bin/cjs/index.js.map +0 -1
  48. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +0 -26
  49. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
  50. package/bin/cjs/interfaces/LiveInterfaceExtensions.js +0 -7
  51. package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +0 -1
  52. package/bin/cjs/interfaces/index.d.ts +0 -2
  53. package/bin/cjs/interfaces/index.d.ts.map +0 -1
  54. package/bin/cjs/interfaces/index.js +0 -18
  55. package/bin/cjs/interfaces/index.js.map +0 -1
  56. package/bin/cjs/internal/errors.d.ts +0 -41
  57. package/bin/cjs/internal/errors.d.ts.map +0 -1
  58. package/bin/cjs/internal/errors.js +0 -48
  59. package/bin/cjs/internal/errors.js.map +0 -1
  60. package/bin/cjs/internal/index.d.ts +0 -3
  61. package/bin/cjs/internal/index.d.ts.map +0 -1
  62. package/bin/cjs/internal/index.js +0 -19
  63. package/bin/cjs/internal/index.js.map +0 -1
  64. package/bin/cjs/internal/type-guards.d.ts +0 -11
  65. package/bin/cjs/internal/type-guards.d.ts.map +0 -1
  66. package/bin/cjs/internal/type-guards.js +0 -24
  67. package/bin/cjs/internal/type-guards.js.map +0 -1
  68. package/bin/cjs/live-hooks/index.d.ts +0 -8
  69. package/bin/cjs/live-hooks/index.d.ts.map +0 -1
  70. package/bin/cjs/live-hooks/index.js +0 -24
  71. package/bin/cjs/live-hooks/index.js.map +0 -1
  72. package/bin/cjs/live-hooks/useLiveCanvas.d.ts +0 -80
  73. package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +0 -1
  74. package/bin/cjs/live-hooks/useLiveCanvas.js +0 -244
  75. package/bin/cjs/live-hooks/useLiveCanvas.js.map +0 -1
  76. package/bin/cjs/live-hooks/useLiveEvent.d.ts +0 -59
  77. package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +0 -1
  78. package/bin/cjs/live-hooks/useLiveEvent.js +0 -150
  79. package/bin/cjs/live-hooks/useLiveEvent.js.map +0 -1
  80. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +0 -163
  81. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +0 -1
  82. package/bin/cjs/live-hooks/useLiveFollowMode.js +0 -360
  83. package/bin/cjs/live-hooks/useLiveFollowMode.js.map +0 -1
  84. package/bin/cjs/live-hooks/useLivePresence.d.ts +0 -76
  85. package/bin/cjs/live-hooks/useLivePresence.d.ts.map +0 -1
  86. package/bin/cjs/live-hooks/useLivePresence.js +0 -170
  87. package/bin/cjs/live-hooks/useLivePresence.js.map +0 -1
  88. package/bin/cjs/live-hooks/useLiveState.d.ts +0 -66
  89. package/bin/cjs/live-hooks/useLiveState.d.ts.map +0 -1
  90. package/bin/cjs/live-hooks/useLiveState.js +0 -134
  91. package/bin/cjs/live-hooks/useLiveState.js.map +0 -1
  92. package/bin/cjs/live-hooks/useLiveTimer.d.ts +0 -80
  93. package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +0 -1
  94. package/bin/cjs/live-hooks/useLiveTimer.js +0 -233
  95. package/bin/cjs/live-hooks/useLiveTimer.js.map +0 -1
  96. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +0 -86
  97. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
  98. package/bin/cjs/live-hooks/useMediaSynchronizer.js +0 -301
  99. package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +0 -1
  100. package/bin/cjs/package.json +0 -1
  101. package/bin/cjs/providers/AzureProvider.d.ts +0 -113
  102. package/bin/cjs/providers/AzureProvider.d.ts.map +0 -1
  103. package/bin/cjs/providers/AzureProvider.js +0 -127
  104. package/bin/cjs/providers/AzureProvider.js.map +0 -1
  105. package/bin/cjs/providers/LiveShareProvider.d.ts +0 -193
  106. package/bin/cjs/providers/LiveShareProvider.d.ts.map +0 -1
  107. package/bin/cjs/providers/LiveShareProvider.js +0 -205
  108. package/bin/cjs/providers/LiveShareProvider.js.map +0 -1
  109. package/bin/cjs/providers/index.d.ts +0 -3
  110. package/bin/cjs/providers/index.d.ts.map +0 -1
  111. package/bin/cjs/providers/index.js +0 -19
  112. package/bin/cjs/providers/index.js.map +0 -1
  113. package/bin/cjs/shared-hooks/index.d.ts +0 -7
  114. package/bin/cjs/shared-hooks/index.d.ts.map +0 -1
  115. package/bin/cjs/shared-hooks/index.js +0 -23
  116. package/bin/cjs/shared-hooks/index.js.map +0 -1
  117. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +0 -3
  118. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +0 -1
  119. package/bin/cjs/shared-hooks/internals/tree-node-constants.js +0 -6
  120. package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +0 -1
  121. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +0 -10
  122. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +0 -1
  123. package/bin/cjs/shared-hooks/internals/tree-node-types.js +0 -23
  124. package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +0 -1
  125. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +0 -33
  126. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +0 -1
  127. package/bin/cjs/shared-hooks/internals/tree-node-utils.js +0 -193
  128. package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +0 -1
  129. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +0 -23
  130. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +0 -1
  131. package/bin/cjs/shared-hooks/useDynamicDDS.js +0 -87
  132. package/bin/cjs/shared-hooks/useDynamicDDS.js.map +0 -1
  133. package/bin/cjs/shared-hooks/useSharedMap.d.ts +0 -25
  134. package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +0 -1
  135. package/bin/cjs/shared-hooks/useSharedMap.js +0 -134
  136. package/bin/cjs/shared-hooks/useSharedMap.js.map +0 -1
  137. package/bin/cjs/shared-hooks/useSharedState.d.ts +0 -22
  138. package/bin/cjs/shared-hooks/useSharedState.d.ts.map +0 -1
  139. package/bin/cjs/shared-hooks/useSharedState.js +0 -80
  140. package/bin/cjs/shared-hooks/useSharedState.js.map +0 -1
  141. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +0 -37
  142. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
  143. package/bin/cjs/shared-hooks/useSharedStateRegistry.js +0 -120
  144. package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +0 -1
  145. package/bin/cjs/shared-hooks/useSharedTree.d.ts +0 -57
  146. package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +0 -1
  147. package/bin/cjs/shared-hooks/useSharedTree.js +0 -123
  148. package/bin/cjs/shared-hooks/useSharedTree.js.map +0 -1
  149. package/bin/cjs/shared-hooks/useTreeNode.d.ts +0 -96
  150. package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +0 -1
  151. package/bin/cjs/shared-hooks/useTreeNode.js +0 -135
  152. package/bin/cjs/shared-hooks/useTreeNode.js.map +0 -1
  153. package/bin/cjs/types/ActionTypes.d.ts +0 -112
  154. package/bin/cjs/types/ActionTypes.d.ts.map +0 -1
  155. package/bin/cjs/types/ActionTypes.js +0 -7
  156. package/bin/cjs/types/ActionTypes.js.map +0 -1
  157. package/bin/cjs/types/PropTypes.d.ts +0 -56
  158. package/bin/cjs/types/PropTypes.d.ts.map +0 -1
  159. package/bin/cjs/types/PropTypes.js +0 -7
  160. package/bin/cjs/types/PropTypes.js.map +0 -1
  161. package/bin/cjs/types/ResultTypes.d.ts +0 -334
  162. package/bin/cjs/types/ResultTypes.d.ts.map +0 -1
  163. package/bin/cjs/types/ResultTypes.js +0 -7
  164. package/bin/cjs/types/ResultTypes.js.map +0 -1
  165. package/bin/cjs/types/index.d.ts +0 -4
  166. package/bin/cjs/types/index.d.ts.map +0 -1
  167. package/bin/cjs/types/index.js +0 -20
  168. package/bin/cjs/types/index.js.map +0 -1
  169. package/bin/cjs/utils/index.d.ts +0 -2
  170. package/bin/cjs/utils/index.d.ts.map +0 -1
  171. package/bin/cjs/utils/index.js +0 -18
  172. package/bin/cjs/utils/index.js.map +0 -1
  173. package/bin/cjs/utils/type-check.d.ts +0 -15
  174. package/bin/cjs/utils/type-check.d.ts.map +0 -1
  175. package/bin/cjs/utils/type-check.js +0 -62
  176. package/bin/cjs/utils/type-check.js.map +0 -1
  177. package/bin/index.d.ts +0 -7
  178. package/bin/index.d.ts.map +0 -1
  179. package/bin/index.js +0 -7
  180. package/bin/index.js.map +0 -1
  181. package/bin/interfaces/LiveInterfaceExtensions.d.ts +0 -26
  182. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
  183. package/bin/interfaces/LiveInterfaceExtensions.js +0 -6
  184. package/bin/interfaces/LiveInterfaceExtensions.js.map +0 -1
  185. package/bin/interfaces/index.d.ts +0 -2
  186. package/bin/interfaces/index.d.ts.map +0 -1
  187. package/bin/interfaces/index.js +0 -2
  188. package/bin/interfaces/index.js.map +0 -1
  189. package/bin/internal/errors.d.ts +0 -41
  190. package/bin/internal/errors.d.ts.map +0 -1
  191. package/bin/internal/errors.js +0 -42
  192. package/bin/internal/errors.js.map +0 -1
  193. package/bin/internal/index.d.ts +0 -3
  194. package/bin/internal/index.d.ts.map +0 -1
  195. package/bin/internal/index.js +0 -3
  196. package/bin/internal/index.js.map +0 -1
  197. package/bin/internal/type-guards.d.ts +0 -11
  198. package/bin/internal/type-guards.d.ts.map +0 -1
  199. package/bin/internal/type-guards.js +0 -20
  200. package/bin/internal/type-guards.js.map +0 -1
  201. package/bin/live-hooks/index.d.ts +0 -8
  202. package/bin/live-hooks/index.d.ts.map +0 -1
  203. package/bin/live-hooks/index.js +0 -8
  204. package/bin/live-hooks/index.js.map +0 -1
  205. package/bin/live-hooks/useLiveCanvas.d.ts +0 -29
  206. package/bin/live-hooks/useLiveCanvas.d.ts.map +0 -1
  207. package/bin/live-hooks/useLiveCanvas.js +0 -160
  208. package/bin/live-hooks/useLiveCanvas.js.map +0 -1
  209. package/bin/live-hooks/useLiveEvent.d.ts +0 -23
  210. package/bin/live-hooks/useLiveEvent.d.ts.map +0 -1
  211. package/bin/live-hooks/useLiveEvent.js +0 -108
  212. package/bin/live-hooks/useLiveEvent.js.map +0 -1
  213. package/bin/live-hooks/useLiveFollowMode.d.ts +0 -24
  214. package/bin/live-hooks/useLiveFollowMode.d.ts.map +0 -1
  215. package/bin/live-hooks/useLiveFollowMode.js +0 -211
  216. package/bin/live-hooks/useLiveFollowMode.js.map +0 -1
  217. package/bin/live-hooks/useLivePresence.d.ts +0 -26
  218. package/bin/live-hooks/useLivePresence.d.ts.map +0 -1
  219. package/bin/live-hooks/useLivePresence.js +0 -106
  220. package/bin/live-hooks/useLivePresence.js.map +0 -1
  221. package/bin/live-hooks/useLiveState.d.ts +0 -21
  222. package/bin/live-hooks/useLiveState.d.ts.map +0 -1
  223. package/bin/live-hooks/useLiveState.js +0 -83
  224. package/bin/live-hooks/useLiveState.js.map +0 -1
  225. package/bin/live-hooks/useLiveTimer.d.ts +0 -25
  226. package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
  227. package/bin/live-hooks/useLiveTimer.js +0 -172
  228. package/bin/live-hooks/useLiveTimer.js.map +0 -1
  229. package/bin/live-hooks/useMediaSynchronizer.d.ts +0 -25
  230. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
  231. package/bin/live-hooks/useMediaSynchronizer.js +0 -234
  232. package/bin/live-hooks/useMediaSynchronizer.js.map +0 -1
  233. package/bin/providers/AzureProvider.d.ts +0 -113
  234. package/bin/providers/AzureProvider.d.ts.map +0 -1
  235. package/bin/providers/AzureProvider.js +0 -119
  236. package/bin/providers/AzureProvider.js.map +0 -1
  237. package/bin/providers/LiveShareProvider.d.ts +0 -91
  238. package/bin/providers/LiveShareProvider.d.ts.map +0 -1
  239. package/bin/providers/LiveShareProvider.js +0 -95
  240. package/bin/providers/LiveShareProvider.js.map +0 -1
  241. package/bin/providers/index.d.ts +0 -3
  242. package/bin/providers/index.d.ts.map +0 -1
  243. package/bin/providers/index.js +0 -3
  244. package/bin/providers/index.js.map +0 -1
  245. package/bin/shared-hooks/index.d.ts +0 -5
  246. package/bin/shared-hooks/index.d.ts.map +0 -1
  247. package/bin/shared-hooks/index.js +0 -5
  248. package/bin/shared-hooks/index.js.map +0 -1
  249. package/bin/shared-hooks/useDynamicDDS.d.ts +0 -23
  250. package/bin/shared-hooks/useDynamicDDS.d.ts.map +0 -1
  251. package/bin/shared-hooks/useDynamicDDS.js +0 -72
  252. package/bin/shared-hooks/useDynamicDDS.js.map +0 -1
  253. package/bin/shared-hooks/useSharedMap.d.ts +0 -23
  254. package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
  255. package/bin/shared-hooks/useSharedMap.js +0 -114
  256. package/bin/shared-hooks/useSharedMap.js.map +0 -1
  257. package/bin/shared-hooks/useSharedState.d.ts +0 -22
  258. package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
  259. package/bin/shared-hooks/useSharedState.js +0 -74
  260. package/bin/shared-hooks/useSharedState.js.map +0 -1
  261. package/bin/shared-hooks/useSharedStateRegistry.d.ts +0 -37
  262. package/bin/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
  263. package/bin/shared-hooks/useSharedStateRegistry.js +0 -105
  264. package/bin/shared-hooks/useSharedStateRegistry.js.map +0 -1
  265. package/bin/types/ActionTypes.d.ts +0 -112
  266. package/bin/types/ActionTypes.d.ts.map +0 -1
  267. package/bin/types/ActionTypes.js +0 -6
  268. package/bin/types/ActionTypes.js.map +0 -1
  269. package/bin/types/PropTypes.d.ts +0 -8
  270. package/bin/types/PropTypes.d.ts.map +0 -1
  271. package/bin/types/PropTypes.js +0 -6
  272. package/bin/types/PropTypes.js.map +0 -1
  273. package/bin/types/ResultTypes.d.ts +0 -302
  274. package/bin/types/ResultTypes.d.ts.map +0 -1
  275. package/bin/types/ResultTypes.js +0 -6
  276. package/bin/types/ResultTypes.js.map +0 -1
  277. package/bin/types/index.d.ts +0 -4
  278. package/bin/types/index.d.ts.map +0 -1
  279. package/bin/types/index.js +0 -4
  280. package/bin/types/index.js.map +0 -1
  281. package/bin/utils/index.d.ts +0 -2
  282. package/bin/utils/index.d.ts.map +0 -1
  283. package/bin/utils/index.js +0 -2
  284. package/bin/utils/index.js.map +0 -1
  285. package/bin/utils/type-check.d.ts +0 -15
  286. package/bin/utils/type-check.d.ts.map +0 -1
  287. package/bin/utils/type-check.js +0 -54
  288. package/bin/utils/type-check.js.map +0 -1
  289. package/tsconfig.cjs.json +0 -14
@@ -1,108 +0,0 @@
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";
17
- import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal";
18
- import { useFluidObjectsContext } from "../providers";
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
- export function useLiveEvent(uniqueKey, allowedRoles, onReceivedEvent) {
35
- /**
36
- * Stateful latest event (user facing) and its non-user-facing setter method.
37
- */
38
- const [latestEvent, setLatestReceived] = React.useState();
39
- /**
40
- * Reference for all received/sent events. The current value of this is user-facing. Because
41
- * this is always set at the same time as latestEvent, it is effectively a stateful value.
42
- */
43
- const allEventsRef = React.useRef([]);
44
- /**
45
- * User facing: dynamically load the DDS for the given unique key.
46
- */
47
- const { dds: liveEvent } = useDynamicDDS(uniqueKey, (LiveEvent));
48
- const { container } = useFluidObjectsContext();
49
- /**
50
- * User facing: callback to send event through `LiveEvent`
51
- */
52
- const sendEvent = React.useCallback((event) => __awaiter(this, void 0, void 0, function* () {
53
- if (!container) {
54
- throw new ActionContainerNotJoinedError("liveEvent", "sendEvent");
55
- }
56
- if (liveEvent === undefined) {
57
- throw new ActionLiveDataObjectUndefinedError("liveEvent", "sendEvent");
58
- }
59
- if (!liveEvent.isInitialized) {
60
- throw new ActionLiveDataObjectInitializedError("liveEvent", "sendEvent");
61
- }
62
- return yield liveEvent.send(event);
63
- }), [container, liveEvent]);
64
- /**
65
- * Setup change listeners and start `LiveEvent` if needed
66
- */
67
- React.useEffect(() => {
68
- if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined)
69
- return;
70
- // Register event listener
71
- const onEventReceived = (event, local, clientId, timestamp) => {
72
- // If developer passed the optional onReceivedEvent callback, we
73
- // call it.
74
- onReceivedEvent === null || onReceivedEvent === void 0 ? void 0 : onReceivedEvent(event, local);
75
- // Set the received event to our local state
76
- const received = {
77
- value: event,
78
- local,
79
- clientId,
80
- timestamp,
81
- };
82
- allEventsRef.current = [...allEventsRef.current, received];
83
- setLatestReceived(received);
84
- };
85
- // Reset the events list if it allEventRef.current is non-empty.
86
- // This happens when the `id` a developer provides changes on the fly.
87
- if (allEventsRef.current.length > 0) {
88
- allEventsRef.current = [];
89
- setLatestReceived(undefined);
90
- }
91
- liveEvent.on(LiveEventEvents.received, onEventReceived);
92
- if (liveEvent.initializeState === LiveDataObjectInitializeState.needed) {
93
- // Start live event
94
- liveEvent.initialize(allowedRoles);
95
- }
96
- return () => {
97
- // on unmount, remove event listeners
98
- liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.off(LiveEventEvents.received, onEventReceived);
99
- };
100
- }, [liveEvent]);
101
- return {
102
- latestEvent,
103
- allEvents: allEventsRef.current,
104
- sendEvent,
105
- liveEvent,
106
- };
107
- }
108
- //# sourceMappingURL=useLiveEvent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EACH,eAAe,E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,SAAS;QACT,SAAS;KACZ,CAAC;AACN,CAAC"}
@@ -1,24 +0,0 @@
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";
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
- export declare function useLiveFollowMode<TData = any>(uniqueKey: string, initialData: TData | (() => TData), allowedRoles?: UserMeetingRole[]): IUseLiveFollowModeResults<TData>;
24
- //# sourceMappingURL=useLiveFollowMode.d.ts.map
@@ -1 +0,0 @@
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,UAAU,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;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,CA2QlC"}
@@ -1,211 +0,0 @@
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";
17
- import { useFluidObjectsContext } from "../providers";
18
- import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal";
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
- export function useLiveFollowMode(uniqueKey, initialData, allowedRoles) {
36
- /**
37
- * Stateful follow state.
38
- */
39
- const [state, setState] = React.useState();
40
- /**
41
- * Stateful all user presence list and its non-user-facing setter method.
42
- */
43
- const [allUsers, setAllUsers] = React.useState([]);
44
- /**
45
- * User facing: dynamically load the DDS for the given unique key.
46
- */
47
- const { dds: liveFollowMode } = useDynamicDDS(uniqueKey, (LiveFollowMode));
48
- /**
49
- * User facing: list of non-local user's presence objects.
50
- */
51
- const otherUsers = allUsers.filter((user) => !user.isLocalUser);
52
- /**
53
- * User facing: local user's presence object.
54
- */
55
- const localUser = allUsers.find((user) => user.isLocalUser);
56
- const { container } = useFluidObjectsContext();
57
- /**
58
- * User facing: callback to update the local user's custom data for their follow state.
59
- */
60
- const update = React.useCallback((stateValue) => __awaiter(this, void 0, void 0, function* () {
61
- if (!container) {
62
- throw new ActionContainerNotJoinedError("liveFollowMode", "update");
63
- }
64
- if (liveFollowMode === undefined) {
65
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "update");
66
- }
67
- if (!liveFollowMode.isInitialized) {
68
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "update");
69
- }
70
- return yield liveFollowMode.update(stateValue);
71
- }), [container, liveFollowMode]);
72
- /**
73
- * User facing: callback to start presenting.
74
- */
75
- const startPresenting = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
76
- if (!container) {
77
- throw new ActionContainerNotJoinedError("liveFollowMode", "startPresenting");
78
- }
79
- if (liveFollowMode === undefined) {
80
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "startPresenting");
81
- }
82
- if (!liveFollowMode.isInitialized) {
83
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "startPresenting");
84
- }
85
- return yield liveFollowMode.startPresenting();
86
- }), [container, liveFollowMode]);
87
- /**
88
- * User facing: callback to stop presenting.
89
- */
90
- const stopPresenting = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
91
- if (!container) {
92
- throw new ActionContainerNotJoinedError("liveFollowMode", "stopPresenting");
93
- }
94
- if (liveFollowMode === undefined) {
95
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "stopPresenting");
96
- }
97
- if (!liveFollowMode.isInitialized) {
98
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "stopPresenting");
99
- }
100
- return yield liveFollowMode.stopPresenting();
101
- }), [container, liveFollowMode]);
102
- /**
103
- * User facing: callback to suspend sync.
104
- */
105
- const beginSuspension = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
106
- if (!container) {
107
- throw new ActionContainerNotJoinedError("liveFollowMode", "syncToPresenter");
108
- }
109
- if (liveFollowMode === undefined) {
110
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "syncToPresenter");
111
- }
112
- if (!liveFollowMode.isInitialized) {
113
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "syncToPresenter");
114
- }
115
- return yield liveFollowMode.beginSuspension();
116
- }), [container, liveFollowMode]);
117
- /**
118
- * User facing: callback to end current suspension.
119
- */
120
- const endSuspension = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
121
- if (!container) {
122
- throw new ActionContainerNotJoinedError("liveFollowMode", "syncToPresenter");
123
- }
124
- if (liveFollowMode === undefined) {
125
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "syncToPresenter");
126
- }
127
- if (!liveFollowMode.isInitialized) {
128
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "syncToPresenter");
129
- }
130
- return yield liveFollowMode.endSuspension();
131
- }), [container, liveFollowMode]);
132
- /**
133
- * User facing: callback to follow a specific user.
134
- */
135
- const followUser = React.useCallback((userId) => __awaiter(this, void 0, void 0, function* () {
136
- if (!container) {
137
- throw new ActionContainerNotJoinedError("liveFollowMode", "followUser");
138
- }
139
- if (liveFollowMode === undefined) {
140
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "followUser");
141
- }
142
- if (!liveFollowMode.isInitialized) {
143
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "followUser");
144
- }
145
- return yield liveFollowMode.followUser(userId);
146
- }), [container, liveFollowMode]);
147
- /**
148
- * User facing: callback to stop following a user.
149
- */
150
- const stopFollowing = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
151
- if (!container) {
152
- throw new ActionContainerNotJoinedError("liveFollowMode", "stopFollowing");
153
- }
154
- if (liveFollowMode === undefined) {
155
- throw new ActionLiveDataObjectUndefinedError("liveFollowMode", "stopFollowing");
156
- }
157
- if (!liveFollowMode.isInitialized) {
158
- throw new ActionLiveDataObjectInitializedError("liveFollowMode", "stopFollowing");
159
- }
160
- return yield liveFollowMode.stopFollowing();
161
- }), [container, liveFollowMode]);
162
- /**
163
- * Setup change listeners and start `LiveFollowMode` if needed
164
- */
165
- React.useEffect(() => {
166
- if (liveFollowMode === undefined)
167
- return;
168
- const onPresenceChanged = () => {
169
- const updatedLocalUsers = [];
170
- liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.getUsers().forEach((user) => {
171
- updatedLocalUsers.push(user);
172
- });
173
- setAllUsers(updatedLocalUsers);
174
- };
175
- liveFollowMode.on("presenceChanged", onPresenceChanged);
176
- const onStateChanged = () => {
177
- setState(liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.state);
178
- };
179
- liveFollowMode.on("stateChanged", onStateChanged);
180
- if (liveFollowMode.initializeState ===
181
- LiveDataObjectInitializeState.needed) {
182
- liveFollowMode.initialize(isInitialDataCallback(initialData)
183
- ? initialData()
184
- : initialData, allowedRoles);
185
- }
186
- onPresenceChanged();
187
- onStateChanged();
188
- return () => {
189
- liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.off("presenceChanged", onPresenceChanged);
190
- liveFollowMode === null || liveFollowMode === void 0 ? void 0 : liveFollowMode.off("stateChanged", onStateChanged);
191
- };
192
- }, [liveFollowMode]);
193
- return {
194
- state,
195
- localUser,
196
- otherUsers,
197
- allUsers,
198
- liveFollowMode,
199
- update,
200
- startPresenting,
201
- stopPresenting,
202
- beginSuspension,
203
- endSuspension,
204
- followUser,
205
- stopFollowing,
206
- };
207
- }
208
- function isInitialDataCallback(value) {
209
- return typeof value === "function";
210
- }
211
- //# sourceMappingURL=useLiveFollowMode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveFollowMode.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveFollowMode.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EAGH,6BAA6B,EAC7B,cAAc,GAGjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACH,6BAA6B,EAC7B,oCAAoC,EACpC,kCAAkC,GACrC,MAAM,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,iBAAiB,CAC7B,SAAiB,EACjB,WAAkC,EAClC,YAAgC;IAEhC;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,EAA2B,CAAC;IACpE;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ,CAE5C,EAAE,CAAC,CAAC;IACN;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,aAAa,CACzC,SAAS,EACT,CAAA,cAAqB,CAAA,CACxB,CAAC;IAEF;;OAEG;IACH,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEhE;;OAEG;IACH,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE5D,MAAM,EAAE,SAAS,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAE/C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AC;AACN,CAAC;AAED,SAAS,qBAAqB,CAAQ,KAAU;IAC5C,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACvC,CAAC"}
@@ -1,26 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { PresenceState, UserMeetingRole } from "@microsoft/live-share";
6
- import { IUseLivePresenceResults } from "../types";
7
- /**
8
- * React hook for using a Live Share `LivePresence`.
9
- *
10
- * @remarks
11
- * Use this hook if you want to track presence for who is currently using this component, such as
12
- * who is online or who is viewing a specific document. With presence, you can sent along any custom
13
- * user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
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
- * @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one will be created.
18
- * @param initialData Optional. Initial presence data object for the user. Can be value or a function to get the value.
19
- * @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
20
- * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
21
- * will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
22
- * @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
23
- * to update the local user's presence and the `LivePresence` Fluid object.
24
- */
25
- export declare function useLivePresence<TData extends object = object>(uniqueKey: string, initialData?: TData | (() => TData) | undefined, initialPresenceState?: PresenceState, allowedRoles?: UserMeetingRole[]): IUseLivePresenceResults<TData>;
26
- //# sourceMappingURL=useLivePresence.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLivePresence.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,aAAa,EAEb,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAA8B,MAAM,UAAU,CAAC;AAS/E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACzD,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,SAAS,EAC/C,oBAAoB,GAAE,aAAoC,EAC1D,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,uBAAuB,CAAC,KAAK,CAAC,CAgGhC"}
@@ -1,106 +0,0 @@
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 { PresenceState, LivePresence, LiveDataObjectInitializeState, } from "@microsoft/live-share";
15
- import React from "react";
16
- import { useDynamicDDS } from "../shared-hooks";
17
- import { useFluidObjectsContext } from "../providers";
18
- import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal";
19
- /**
20
- * React hook for using a Live Share `LivePresence`.
21
- *
22
- * @remarks
23
- * Use this hook if you want to track presence for who is currently using this component, such as
24
- * who is online or who is viewing a specific document. With presence, you can sent along any custom
25
- * user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
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
- * @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one will be created.
30
- * @param initialData Optional. Initial presence data object for the user. Can be value or a function to get the value.
31
- * @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
32
- * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
33
- * will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
34
- * @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
35
- * to update the local user's presence and the `LivePresence` Fluid object.
36
- */
37
- export function useLivePresence(uniqueKey, initialData, initialPresenceState = PresenceState.online, allowedRoles) {
38
- /**
39
- * Stateful all user presence list and its non-user-facing setter method.
40
- */
41
- const [allUsers, setAllUsers] = React.useState([]);
42
- /**
43
- * User facing: dynamically load the DDS for the given unique key.
44
- */
45
- const { dds: livePresence } = useDynamicDDS(uniqueKey, (LivePresence));
46
- /**
47
- * User facing: list of non-local user's presence objects.
48
- */
49
- const otherUsers = allUsers.filter((user) => !user.isLocalUser);
50
- /**
51
- * User facing: local user's presence object.
52
- */
53
- const localUser = allUsers.find((user) => user.isLocalUser);
54
- const { container } = useFluidObjectsContext();
55
- /**
56
- * User facing: callback to update the local user's presence.
57
- */
58
- const updatePresence = React.useCallback((data, state) => __awaiter(this, void 0, void 0, function* () {
59
- if (!container) {
60
- throw new ActionContainerNotJoinedError("livePresence", "updatePresence");
61
- }
62
- if (livePresence === undefined) {
63
- throw new ActionLiveDataObjectUndefinedError("livePresence", "updatePresence");
64
- }
65
- if (!livePresence.isInitialized) {
66
- throw new ActionLiveDataObjectInitializedError("livePresence", "updatePresence");
67
- }
68
- return yield livePresence.update(data, state);
69
- }), [container, livePresence]);
70
- /**
71
- * Setup change listeners and start `LivePresence` if needed
72
- */
73
- React.useEffect(() => {
74
- if (livePresence === undefined)
75
- return;
76
- const onPresenceChanged = () => {
77
- const updatedLocalUsers = [];
78
- livePresence === null || livePresence === void 0 ? void 0 : livePresence.getUsers().forEach((user) => {
79
- updatedLocalUsers.push(user);
80
- });
81
- setAllUsers(updatedLocalUsers);
82
- };
83
- livePresence.on("presenceChanged", onPresenceChanged);
84
- if (livePresence.initializeState ===
85
- LiveDataObjectInitializeState.needed) {
86
- livePresence.initialize(isInitialDataCallback(initialData)
87
- ? initialData()
88
- : initialData, initialPresenceState, allowedRoles);
89
- }
90
- onPresenceChanged();
91
- return () => {
92
- livePresence === null || livePresence === void 0 ? void 0 : livePresence.off("presenceChanged", onPresenceChanged);
93
- };
94
- }, [livePresence]);
95
- return {
96
- localUser,
97
- otherUsers,
98
- allUsers,
99
- livePresence,
100
- updatePresence,
101
- };
102
- }
103
- function isInitialDataCallback(value) {
104
- return typeof value === "function";
105
- }
106
- //# sourceMappingURL=useLivePresence.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLivePresence.js","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EAEH,aAAa,EACb,YAAY,EAEZ,6BAA6B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACH,6BAA6B,EAC7B,oCAAoC,EACpC,kCAAkC,GACrC,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC3B,SAAiB,EACjB,WAA+C,EAC/C,uBAAsC,aAAa,CAAC,MAAM,EAC1D,YAAgC;IAEhC;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ,CAC1C,EAAE,CACL,CAAC;IACF;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,aAAa,CACvC,SAAS,EACT,CAAA,YAAmB,CAAA,CACtB,CAAC;IAEF;;OAEG;IACH,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAA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AiB,EAAE,iBAAiB,CAAC,CAAC;QAEtD,IACI,YAAY,CAAC,eAAe;YAC5B,6BAA6B,CAAC,MAAM,EACtC;YACE,YAAY,CAAC,UAAU,CACnB,qBAAqB,CAAQ,WAAW,CAAC;gBACrC,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,EACjB,oBAAoB,EACpB,YAAY,CACf,CAAC;SACL;QACD,iBAAiB,EAAE,CAAC;QAEpB,OAAO,GAAG,EAAE;YACR,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC5D,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,OAAO;QACH,SAAS;QACT,UAAU;QACV,QAAQ;QACR,YAAY;QACZ,cAAc;KACjB,CAAC;AACN,CAAC;AAED,SAAS,qBAAqB,CAAQ,KAAU;IAC5C,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACvC,CAAC"}
@@ -1,21 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { LiveState, UserMeetingRole } from "@microsoft/live-share";
6
- import { SetLiveStateAction } from "../types";
7
- /**
8
- * React hook for using a Live Share `LiveState`.
9
- *
10
- * @remarks
11
- * Use this hook if you want to synchronize app state that will reset when all users leave the session.
12
- * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
13
- *
14
- * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
15
- * @param initialState Optional. the initial state value of type TState
16
- * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
17
- * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
18
- * The setter returns a void promise, which will throw if the user does not have the required roles to set.
19
- */
20
- export declare function useLiveState<TState = any>(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction<TState>, LiveState<TState> | undefined];
21
- //# sourceMappingURL=useLiveState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveState.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,SAAS,EACT,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAU9C;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAG,GAAG,EACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAwErE"}
@@ -1,83 +0,0 @@
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, LiveState, } from "@microsoft/live-share";
15
- import React from "react";
16
- import { useDynamicDDS } from "../shared-hooks";
17
- import { useFluidObjectsContext } from "../providers";
18
- import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, isPrevStateCallback, } from "../internal";
19
- /**
20
- * React hook for using a Live Share `LiveState`.
21
- *
22
- * @remarks
23
- * Use this hook if you want to synchronize app state that will reset when all users leave the session.
24
- * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
25
- *
26
- * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
27
- * @param initialState Optional. the initial state value of type TState
28
- * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
29
- * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
30
- * The setter returns a void promise, which will throw if the user does not have the required roles to set.
31
- */
32
- export function useLiveState(uniqueKey, initialState, allowedRoles) {
33
- const [currentState, setCurrentState] = React.useState(initialState);
34
- /**
35
- * User facing: dynamically load the DDS for the given unique key.
36
- */
37
- const { dds: liveState } = useDynamicDDS(uniqueKey, (LiveState));
38
- const { container } = useFluidObjectsContext();
39
- /**
40
- * Change state callback that is user facing
41
- * @param state TState to set
42
- * @returns void promise, which will throw if the user does not have the required roles
43
- */
44
- const setState = React.useCallback((state) => __awaiter(this, void 0, void 0, function* () {
45
- if (!container) {
46
- throw new ActionContainerNotJoinedError("liveState", "setState");
47
- }
48
- if (liveState === undefined) {
49
- throw new ActionLiveDataObjectUndefinedError("liveState", "setState");
50
- }
51
- if (!liveState.isInitialized) {
52
- throw new ActionLiveDataObjectInitializedError("liveState", "setState");
53
- }
54
- const valueToSet = isPrevStateCallback(state)
55
- ? state(liveState.state)
56
- : state;
57
- return yield liveState.set(valueToSet);
58
- }), [container, liveState]);
59
- /**
60
- * Setup change listeners and start `LiveState` if needed
61
- */
62
- React.useEffect(() => {
63
- if (liveState === undefined)
64
- return;
65
- const onStateChanged = (state) => {
66
- setCurrentState(state);
67
- };
68
- liveState.on("stateChanged", onStateChanged);
69
- if (liveState.initializeState === LiveDataObjectInitializeState.needed) {
70
- liveState
71
- .initialize(initialState, allowedRoles)
72
- .then(() => onStateChanged(liveState.state));
73
- }
74
- else {
75
- onStateChanged(liveState.state);
76
- }
77
- return () => {
78
- liveState === null || liveState === void 0 ? void 0 : liveState.off("stateChanged", onStateChanged);
79
- };
80
- }, [liveState]);
81
- return [currentState, setState, liveState];
82
- }
83
- //# sourceMappingURL=useLiveState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveState.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EACH,6BAA6B,EAC7B,SAAS,GAEZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACH,6BAA6B,EAC7B,oCAAoC,EACpC,kCAAkC,EAClC,mBAAmB,GACtB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CACxB,SAAiB,EACjB,YAAoB,EACpB,YAAgC;IAEhC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GACjC,KAAK,CAAC,QAAQ,CAAS,YAAY,CAAC,CAAC;IACzC;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CACpC,SAAS,EACT,CAAA,SAAiB,CAAA,CACpB,CAAC;IAEF,MAAM,EAAE,SAAS,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAE/C;;;;OAIG;IACH,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAC9B,CAAO,KAA+C,EAAE,EAAE;QACtD,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,6BAA6B,CACnC,WAAW,EACX,UAAU,CACb,CAAC;SACL;QACD,IAAI,SAAS,KAAK,SAAS,EAAE;YACzB,MAAM,IAAI,kCAAkC,CACxC,WAAW,EACX,UAAU,CACb,CAAC;SACL;QACD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,MAAM,IAAI,oCA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