@microsoft/live-share-react 1.4.0-preview.0 → 1.4.2-preview.0

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 (283) hide show
  1. package/bin/cjs/index.d.ts +7 -0
  2. package/bin/cjs/index.d.ts.map +1 -0
  3. package/bin/cjs/index.js +23 -0
  4. package/bin/cjs/index.js.map +1 -0
  5. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +26 -0
  6. package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  7. package/bin/cjs/interfaces/LiveInterfaceExtensions.js +7 -0
  8. package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +1 -0
  9. package/bin/cjs/interfaces/index.d.ts +2 -0
  10. package/bin/cjs/interfaces/index.d.ts.map +1 -0
  11. package/bin/cjs/interfaces/index.js +18 -0
  12. package/bin/cjs/interfaces/index.js.map +1 -0
  13. package/bin/cjs/internal/errors.d.ts +41 -0
  14. package/bin/cjs/internal/errors.d.ts.map +1 -0
  15. package/bin/cjs/internal/errors.js +48 -0
  16. package/bin/cjs/internal/errors.js.map +1 -0
  17. package/bin/cjs/internal/index.d.ts +3 -0
  18. package/bin/cjs/internal/index.d.ts.map +1 -0
  19. package/bin/cjs/internal/index.js +19 -0
  20. package/bin/cjs/internal/index.js.map +1 -0
  21. package/bin/cjs/internal/type-guards.d.ts +11 -0
  22. package/bin/cjs/internal/type-guards.d.ts.map +1 -0
  23. package/bin/cjs/internal/type-guards.js +24 -0
  24. package/bin/cjs/internal/type-guards.js.map +1 -0
  25. package/bin/cjs/live-hooks/index.d.ts +8 -0
  26. package/bin/cjs/live-hooks/index.d.ts.map +1 -0
  27. package/bin/cjs/live-hooks/index.js +24 -0
  28. package/bin/cjs/live-hooks/index.js.map +1 -0
  29. package/bin/cjs/live-hooks/useLiveCanvas.d.ts +80 -0
  30. package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +1 -0
  31. package/bin/cjs/live-hooks/useLiveCanvas.js +244 -0
  32. package/bin/cjs/live-hooks/useLiveCanvas.js.map +1 -0
  33. package/bin/cjs/live-hooks/useLiveEvent.d.ts +59 -0
  34. package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +1 -0
  35. package/bin/cjs/live-hooks/useLiveEvent.js +150 -0
  36. package/bin/cjs/live-hooks/useLiveEvent.js.map +1 -0
  37. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +163 -0
  38. package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  39. package/bin/cjs/live-hooks/useLiveFollowMode.js +360 -0
  40. package/bin/cjs/live-hooks/useLiveFollowMode.js.map +1 -0
  41. package/bin/cjs/live-hooks/useLivePresence.d.ts +76 -0
  42. package/bin/cjs/live-hooks/useLivePresence.d.ts.map +1 -0
  43. package/bin/cjs/live-hooks/useLivePresence.js +170 -0
  44. package/bin/cjs/live-hooks/useLivePresence.js.map +1 -0
  45. package/bin/cjs/live-hooks/useLiveState.d.ts +66 -0
  46. package/bin/cjs/live-hooks/useLiveState.d.ts.map +1 -0
  47. package/bin/cjs/live-hooks/useLiveState.js +134 -0
  48. package/bin/cjs/live-hooks/useLiveState.js.map +1 -0
  49. package/bin/cjs/live-hooks/useLiveTimer.d.ts +80 -0
  50. package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +1 -0
  51. package/bin/cjs/live-hooks/useLiveTimer.js +233 -0
  52. package/bin/cjs/live-hooks/useLiveTimer.js.map +1 -0
  53. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +86 -0
  54. package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  55. package/bin/cjs/live-hooks/useMediaSynchronizer.js +301 -0
  56. package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +1 -0
  57. package/bin/cjs/package.json +1 -0
  58. package/bin/cjs/providers/AzureProvider.d.ts +113 -0
  59. package/bin/cjs/providers/AzureProvider.d.ts.map +1 -0
  60. package/bin/cjs/providers/AzureProvider.js +127 -0
  61. package/bin/cjs/providers/AzureProvider.js.map +1 -0
  62. package/bin/cjs/providers/LiveShareProvider.d.ts +193 -0
  63. package/bin/cjs/providers/LiveShareProvider.d.ts.map +1 -0
  64. package/bin/cjs/providers/LiveShareProvider.js +205 -0
  65. package/bin/cjs/providers/LiveShareProvider.js.map +1 -0
  66. package/bin/cjs/providers/index.d.ts +3 -0
  67. package/bin/cjs/providers/index.d.ts.map +1 -0
  68. package/bin/cjs/providers/index.js +19 -0
  69. package/bin/cjs/providers/index.js.map +1 -0
  70. package/bin/cjs/shared-hooks/index.d.ts +7 -0
  71. package/bin/cjs/shared-hooks/index.d.ts.map +1 -0
  72. package/bin/cjs/shared-hooks/index.js +23 -0
  73. package/bin/cjs/shared-hooks/index.js.map +1 -0
  74. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  75. package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  76. package/bin/cjs/shared-hooks/internals/tree-node-constants.js +6 -0
  77. package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +1 -0
  78. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +10 -0
  79. package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  80. package/bin/cjs/shared-hooks/internals/tree-node-types.js +23 -0
  81. package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +1 -0
  82. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  83. package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  84. package/bin/cjs/shared-hooks/internals/tree-node-utils.js +193 -0
  85. package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +1 -0
  86. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +23 -0
  87. package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  88. package/bin/cjs/shared-hooks/useDynamicDDS.js +87 -0
  89. package/bin/cjs/shared-hooks/useDynamicDDS.js.map +1 -0
  90. package/bin/cjs/shared-hooks/useSharedMap.d.ts +25 -0
  91. package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +1 -0
  92. package/bin/cjs/shared-hooks/useSharedMap.js +134 -0
  93. package/bin/cjs/shared-hooks/useSharedMap.js.map +1 -0
  94. package/bin/cjs/shared-hooks/useSharedState.d.ts +22 -0
  95. package/bin/cjs/shared-hooks/useSharedState.d.ts.map +1 -0
  96. package/bin/cjs/shared-hooks/useSharedState.js +80 -0
  97. package/bin/cjs/shared-hooks/useSharedState.js.map +1 -0
  98. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +37 -0
  99. package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  100. package/bin/cjs/shared-hooks/useSharedStateRegistry.js +120 -0
  101. package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +1 -0
  102. package/bin/cjs/shared-hooks/useSharedTree.d.ts +57 -0
  103. package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +1 -0
  104. package/bin/cjs/shared-hooks/useSharedTree.js +123 -0
  105. package/bin/cjs/shared-hooks/useSharedTree.js.map +1 -0
  106. package/bin/cjs/shared-hooks/useTreeNode.d.ts +96 -0
  107. package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +1 -0
  108. package/bin/cjs/shared-hooks/useTreeNode.js +135 -0
  109. package/bin/cjs/shared-hooks/useTreeNode.js.map +1 -0
  110. package/bin/cjs/types/ActionTypes.d.ts +112 -0
  111. package/bin/cjs/types/ActionTypes.d.ts.map +1 -0
  112. package/bin/cjs/types/ActionTypes.js +7 -0
  113. package/bin/cjs/types/ActionTypes.js.map +1 -0
  114. package/bin/cjs/types/PropTypes.d.ts +56 -0
  115. package/bin/cjs/types/PropTypes.d.ts.map +1 -0
  116. package/bin/cjs/types/PropTypes.js +7 -0
  117. package/bin/cjs/types/PropTypes.js.map +1 -0
  118. package/bin/cjs/types/ResultTypes.d.ts +334 -0
  119. package/bin/cjs/types/ResultTypes.d.ts.map +1 -0
  120. package/bin/cjs/types/ResultTypes.js +7 -0
  121. package/bin/cjs/types/ResultTypes.js.map +1 -0
  122. package/bin/cjs/types/index.d.ts +4 -0
  123. package/bin/cjs/types/index.d.ts.map +1 -0
  124. package/bin/cjs/types/index.js +20 -0
  125. package/bin/cjs/types/index.js.map +1 -0
  126. package/bin/cjs/utils/index.d.ts +2 -0
  127. package/bin/cjs/utils/index.d.ts.map +1 -0
  128. package/bin/cjs/utils/index.js +18 -0
  129. package/bin/cjs/utils/index.js.map +1 -0
  130. package/bin/cjs/utils/type-check.d.ts +15 -0
  131. package/bin/cjs/utils/type-check.d.ts.map +1 -0
  132. package/bin/cjs/utils/type-check.js +62 -0
  133. package/bin/cjs/utils/type-check.js.map +1 -0
  134. package/bin/esm/index.d.ts +7 -0
  135. package/bin/esm/index.d.ts.map +1 -0
  136. package/bin/esm/index.js +7 -0
  137. package/bin/esm/index.js.map +1 -0
  138. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts +26 -0
  139. package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  140. package/bin/esm/interfaces/LiveInterfaceExtensions.js +6 -0
  141. package/bin/esm/interfaces/LiveInterfaceExtensions.js.map +1 -0
  142. package/bin/esm/interfaces/index.d.ts +2 -0
  143. package/bin/esm/interfaces/index.d.ts.map +1 -0
  144. package/bin/esm/interfaces/index.js +2 -0
  145. package/bin/esm/interfaces/index.js.map +1 -0
  146. package/bin/esm/internal/errors.d.ts +41 -0
  147. package/bin/esm/internal/errors.d.ts.map +1 -0
  148. package/bin/esm/internal/errors.js +42 -0
  149. package/bin/esm/internal/errors.js.map +1 -0
  150. package/bin/esm/internal/index.d.ts +3 -0
  151. package/bin/esm/internal/index.d.ts.map +1 -0
  152. package/bin/esm/internal/index.js +3 -0
  153. package/bin/esm/internal/index.js.map +1 -0
  154. package/bin/esm/internal/type-guards.d.ts +11 -0
  155. package/bin/esm/internal/type-guards.d.ts.map +1 -0
  156. package/bin/esm/internal/type-guards.js +20 -0
  157. package/bin/esm/internal/type-guards.js.map +1 -0
  158. package/bin/esm/live-hooks/index.d.ts +8 -0
  159. package/bin/esm/live-hooks/index.d.ts.map +1 -0
  160. package/bin/esm/live-hooks/index.js +8 -0
  161. package/bin/esm/live-hooks/index.js.map +1 -0
  162. package/bin/esm/live-hooks/useLiveCanvas.d.ts +80 -0
  163. package/bin/esm/live-hooks/useLiveCanvas.d.ts.map +1 -0
  164. package/bin/esm/live-hooks/useLiveCanvas.js +238 -0
  165. package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
  166. package/bin/esm/live-hooks/useLiveEvent.d.ts +59 -0
  167. package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
  168. package/bin/esm/live-hooks/useLiveEvent.js +144 -0
  169. package/bin/esm/live-hooks/useLiveEvent.js.map +1 -0
  170. package/bin/esm/live-hooks/useLiveFollowMode.d.ts +163 -0
  171. package/bin/esm/live-hooks/useLiveFollowMode.d.ts.map +1 -0
  172. package/bin/esm/live-hooks/useLiveFollowMode.js +354 -0
  173. package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -0
  174. package/bin/esm/live-hooks/useLivePresence.d.ts +76 -0
  175. package/bin/esm/live-hooks/useLivePresence.d.ts.map +1 -0
  176. package/bin/esm/live-hooks/useLivePresence.js +164 -0
  177. package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
  178. package/bin/esm/live-hooks/useLiveState.d.ts +66 -0
  179. package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
  180. package/bin/esm/live-hooks/useLiveState.js +128 -0
  181. package/bin/esm/live-hooks/useLiveState.js.map +1 -0
  182. package/bin/esm/live-hooks/useLiveTimer.d.ts +80 -0
  183. package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
  184. package/bin/esm/live-hooks/useLiveTimer.js +227 -0
  185. package/bin/esm/live-hooks/useLiveTimer.js.map +1 -0
  186. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts +86 -0
  187. package/bin/esm/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  188. package/bin/esm/live-hooks/useMediaSynchronizer.js +295 -0
  189. package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
  190. package/bin/esm/providers/AzureProvider.d.ts +113 -0
  191. package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
  192. package/bin/esm/providers/AzureProvider.js +119 -0
  193. package/bin/esm/providers/AzureProvider.js.map +1 -0
  194. package/bin/esm/providers/LiveShareProvider.d.ts +193 -0
  195. package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
  196. package/bin/esm/providers/LiveShareProvider.js +197 -0
  197. package/bin/esm/providers/LiveShareProvider.js.map +1 -0
  198. package/bin/esm/providers/index.d.ts +3 -0
  199. package/bin/esm/providers/index.d.ts.map +1 -0
  200. package/bin/esm/providers/index.js +3 -0
  201. package/bin/esm/providers/index.js.map +1 -0
  202. package/bin/esm/shared-hooks/index.d.ts +7 -0
  203. package/bin/esm/shared-hooks/index.d.ts.map +1 -0
  204. package/bin/esm/shared-hooks/index.js +7 -0
  205. package/bin/esm/shared-hooks/index.js.map +1 -0
  206. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts +3 -0
  207. package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
  208. package/bin/esm/shared-hooks/internals/tree-node-constants.js +3 -0
  209. package/bin/esm/shared-hooks/internals/tree-node-constants.js.map +1 -0
  210. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts +10 -0
  211. package/bin/esm/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
  212. package/bin/esm/shared-hooks/internals/tree-node-types.js +18 -0
  213. package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -0
  214. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts +33 -0
  215. package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
  216. package/bin/esm/shared-hooks/internals/tree-node-utils.js +188 -0
  217. package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
  218. package/bin/esm/shared-hooks/useDynamicDDS.d.ts +23 -0
  219. package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  220. package/bin/esm/shared-hooks/useDynamicDDS.js +81 -0
  221. package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
  222. package/bin/esm/shared-hooks/useSharedMap.d.ts +25 -0
  223. package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
  224. package/bin/esm/shared-hooks/useSharedMap.js +128 -0
  225. package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
  226. package/bin/esm/shared-hooks/useSharedState.d.ts +22 -0
  227. package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
  228. package/bin/esm/shared-hooks/useSharedState.js +74 -0
  229. package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
  230. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts +37 -0
  231. package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
  232. package/bin/esm/shared-hooks/useSharedStateRegistry.js +113 -0
  233. package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -0
  234. package/bin/esm/shared-hooks/useSharedTree.d.ts +57 -0
  235. package/bin/esm/shared-hooks/useSharedTree.d.ts.map +1 -0
  236. package/bin/esm/shared-hooks/useSharedTree.js +117 -0
  237. package/bin/esm/shared-hooks/useSharedTree.js.map +1 -0
  238. package/bin/esm/shared-hooks/useTreeNode.d.ts +96 -0
  239. package/bin/esm/shared-hooks/useTreeNode.d.ts.map +1 -0
  240. package/bin/esm/shared-hooks/useTreeNode.js +132 -0
  241. package/bin/esm/shared-hooks/useTreeNode.js.map +1 -0
  242. package/bin/esm/types/ActionTypes.d.ts +112 -0
  243. package/bin/esm/types/ActionTypes.d.ts.map +1 -0
  244. package/bin/esm/types/ActionTypes.js +6 -0
  245. package/bin/esm/types/ActionTypes.js.map +1 -0
  246. package/bin/esm/types/PropTypes.d.ts +56 -0
  247. package/bin/esm/types/PropTypes.d.ts.map +1 -0
  248. package/bin/esm/types/PropTypes.js +6 -0
  249. package/bin/esm/types/PropTypes.js.map +1 -0
  250. package/bin/esm/types/ResultTypes.d.ts +334 -0
  251. package/bin/esm/types/ResultTypes.d.ts.map +1 -0
  252. package/bin/esm/types/ResultTypes.js +6 -0
  253. package/bin/esm/types/ResultTypes.js.map +1 -0
  254. package/bin/esm/types/index.d.ts +4 -0
  255. package/bin/esm/types/index.d.ts.map +1 -0
  256. package/bin/esm/types/index.js +4 -0
  257. package/bin/esm/types/index.js.map +1 -0
  258. package/bin/esm/utils/index.d.ts +2 -0
  259. package/bin/esm/utils/index.d.ts.map +1 -0
  260. package/bin/esm/utils/index.js +2 -0
  261. package/bin/esm/utils/index.js.map +1 -0
  262. package/bin/esm/utils/type-check.d.ts +15 -0
  263. package/bin/esm/utils/type-check.d.ts.map +1 -0
  264. package/bin/esm/utils/type-check.js +54 -0
  265. package/bin/esm/utils/type-check.js.map +1 -0
  266. package/bin/internal/errors.d.ts +15 -0
  267. package/bin/internal/errors.d.ts.map +1 -1
  268. package/bin/internal/errors.js.map +1 -1
  269. package/bin/internal/type-guards.d.ts +5 -0
  270. package/bin/internal/type-guards.d.ts.map +1 -1
  271. package/bin/internal/type-guards.js +12 -0
  272. package/bin/internal/type-guards.js.map +1 -1
  273. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  274. package/bin/live-hooks/useLiveState.js +6 -2
  275. package/bin/live-hooks/useLiveState.js.map +1 -1
  276. package/bin/providers/LiveShareProvider.d.ts.map +1 -1
  277. package/bin/providers/LiveShareProvider.js +8 -0
  278. package/bin/providers/LiveShareProvider.js.map +1 -1
  279. package/package.json +50 -50
  280. package/src/internal/errors.ts +16 -0
  281. package/src/internal/type-guards.ts +12 -0
  282. package/src/live-hooks/useLiveState.ts +5 -2
  283. package/src/providers/LiveShareProvider.tsx +12 -0
@@ -0,0 +1,66 @@
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/index.js";
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
+ * @example
21
+ ```jsx
22
+ import { useLiveState } from "@microsoft/live-share-react";
23
+
24
+ const planets = [
25
+ "Mercury",
26
+ "Venus",
27
+ "Earth",
28
+ "Mars",
29
+ "Jupiter",
30
+ "Saturn",
31
+ "Uranus",
32
+ "Neptune",
33
+ ];
34
+
35
+ // Define a unique key that differentiates this usage of `useLiveState` from others in your app
36
+ const MY_UNIQUE_KEY = "selected-planet-key";
37
+
38
+ // Example component for using useLiveState
39
+ export const MyCustomState = () => {
40
+ const [planet, setPlanet, liveState] = useLiveState(MY_UNIQUE_KEY, planets[0]);
41
+
42
+ // Render loading UI when creating LiveState instance for first time
43
+ if (!liveState) return <>Loading...</>;
44
+
45
+ // Render UI
46
+ return (
47
+ <div>
48
+ {`Current planet: ${planet}`}
49
+ {"Select a planet below:"}
50
+ {planets.map((planet) => (
51
+ <button
52
+ key={planet}
53
+ onClick={() => {
54
+ setPlanet(planet);
55
+ }}
56
+ >
57
+ {planet}
58
+ </button>
59
+ ))}
60
+ </div>
61
+ );
62
+ };
63
+ ```
64
+ */
65
+ export declare function useLiveState<TState = any>(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction<TState>, LiveState<TState> | undefined];
66
+ //# sourceMappingURL=useLiveState.d.ts.map
@@ -0,0 +1 @@
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,mBAAmB,CAAC;AAUvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;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"}
@@ -0,0 +1,128 @@
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/index.js";
17
+ import { useFluidObjectsContext } from "../providers/index.js";
18
+ import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, isPrevStateCallback, } from "../internal/index.js";
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
+ * @example
33
+ ```jsx
34
+ import { useLiveState } from "@microsoft/live-share-react";
35
+
36
+ const planets = [
37
+ "Mercury",
38
+ "Venus",
39
+ "Earth",
40
+ "Mars",
41
+ "Jupiter",
42
+ "Saturn",
43
+ "Uranus",
44
+ "Neptune",
45
+ ];
46
+
47
+ // Define a unique key that differentiates this usage of `useLiveState` from others in your app
48
+ const MY_UNIQUE_KEY = "selected-planet-key";
49
+
50
+ // Example component for using useLiveState
51
+ export const MyCustomState = () => {
52
+ const [planet, setPlanet, liveState] = useLiveState(MY_UNIQUE_KEY, planets[0]);
53
+
54
+ // Render loading UI when creating LiveState instance for first time
55
+ if (!liveState) return <>Loading...</>;
56
+
57
+ // Render UI
58
+ return (
59
+ <div>
60
+ {`Current planet: ${planet}`}
61
+ {"Select a planet below:"}
62
+ {planets.map((planet) => (
63
+ <button
64
+ key={planet}
65
+ onClick={() => {
66
+ setPlanet(planet);
67
+ }}
68
+ >
69
+ {planet}
70
+ </button>
71
+ ))}
72
+ </div>
73
+ );
74
+ };
75
+ ```
76
+ */
77
+ export function useLiveState(uniqueKey, initialState, allowedRoles) {
78
+ const [currentState, setCurrentState] = React.useState(initialState);
79
+ /**
80
+ * User facing: dynamically load the DDS for the given unique key.
81
+ */
82
+ const { dds: liveState } = useDynamicDDS(uniqueKey, (LiveState));
83
+ const { container } = useFluidObjectsContext();
84
+ /**
85
+ * Change state callback that is user facing
86
+ * @param state TState to set
87
+ * @returns void promise, which will throw if the user does not have the required roles
88
+ */
89
+ const setState = React.useCallback((state) => __awaiter(this, void 0, void 0, function* () {
90
+ if (!container) {
91
+ throw new ActionContainerNotJoinedError("liveState", "setState");
92
+ }
93
+ if (liveState === undefined) {
94
+ throw new ActionLiveDataObjectUndefinedError("liveState", "setState");
95
+ }
96
+ if (!liveState.isInitialized) {
97
+ throw new ActionLiveDataObjectInitializedError("liveState", "setState");
98
+ }
99
+ const valueToSet = isPrevStateCallback(state)
100
+ ? state(liveState.state)
101
+ : state;
102
+ return yield liveState.set(valueToSet);
103
+ }), [container, liveState]);
104
+ /**
105
+ * Setup change listeners and start `LiveState` if needed
106
+ */
107
+ React.useEffect(() => {
108
+ if (liveState === undefined)
109
+ return;
110
+ const onStateChanged = (state) => {
111
+ setCurrentState(state);
112
+ };
113
+ liveState.on("stateChanged", onStateChanged);
114
+ if (liveState.initializeState === LiveDataObjectInitializeState.needed) {
115
+ liveState
116
+ .initialize(initialState, allowedRoles)
117
+ .then(() => onStateChanged(liveState.state));
118
+ }
119
+ else {
120
+ onStateChanged(liveState.state);
121
+ }
122
+ return () => {
123
+ liveState === null || liveState === void 0 ? void 0 : liveState.off("stateChanged", onStateChanged);
124
+ };
125
+ }, [liveState]);
126
+ return [currentState, setState, liveState];
127
+ }
128
+ //# sourceMappingURL=useLiveState.js.map
@@ -0,0 +1 @@
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,0BAA0B,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAA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S,CAAC,GAAG,EAAE;QACjB,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO;QAEpC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE;YACrC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC,CAAC;QACF,SAAS,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QAC7C,IACI,SAAS,CAAC,eAAe,KAAK,6BAA6B,CAAC,MAAM,EACpE,CAAC;YACC,SAAS;iBACJ,UAAU,CAAC,YAAY,EAAE,YAAY,CAAC;iBACtC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACJ,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,GAAG,EAAE;YACR,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QACnD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CAAC,YAAY,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,80 @@
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 { IUseLiveTimerResults, OnTimerDidFinishAction, OnTimerDidPauseAction, OnTimerDidPlayAction, OnTimerDidStartAction, OnTimerTickAction } from "../types/index.js";
7
+ /**
8
+ * React hook for using Live Share's `LiveTimer` DDS.
9
+ *
10
+ * @remarks
11
+ * Use this hook to create a synchronized countdown timer in your app or to schedule synchronized tasks.
12
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
13
+ *
14
+ * @param uniqueKey the unique key for the `LiveTimer`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
15
+ * @param allowedRoles Optional. the user roles that are allowed to start/stop/pause the timer.
16
+ * @param tickRate Optional. the interval in which the `milliRemaining` state should be updated and the `onTick` callback will trigger.
17
+ * @param onTick Optional. event handler callback for when an active timer ticks.
18
+ * @param onStart Optional. event handler callback for when the timer is started.
19
+ * @param onPause Optional. event handler callback for when the timer is paused.
20
+ * @param onPlay Optional. event handler callback for when the timer is resumed.
21
+ * @param onFinish Optional. event handler callback for when the timer finishes.
22
+ * @returns results and callbacks exposed via the hook.
23
+ *
24
+ * @example
25
+ ```jsx
26
+ import { useLiveTimer } from "@microsoft/live-share-react";
27
+
28
+ // Define a unique key that differentiates this usage of `useLiveTimer` from others in your app
29
+ const MY_UNIQUE_KEY = "timer-key";
30
+
31
+ // Example component for using useLiveTimer
32
+ export function CountdownTimer() {
33
+ const {
34
+ milliRemaining,
35
+ timerConfig,
36
+ liveTimer,
37
+ start,
38
+ pause,
39
+ play,
40
+ } = useLiveTimer("TIMER-ID");
41
+
42
+ // Render loading UI when creating LiveTimer instance for first time
43
+ if (!liveTimer) return <>Loading...</>;
44
+
45
+ return (
46
+ <div>
47
+ <button
48
+ onClick={() => {
49
+ start(60 * 1000);
50
+ }}
51
+ >
52
+ {timerConfig === undefined ? "Start" : "Reset"}
53
+ </button>
54
+ {timerConfig !== undefined && (
55
+ <button
56
+ onClick={() => {
57
+ if (timerConfig.running) {
58
+ pause();
59
+ } else {
60
+ play();
61
+ }
62
+ }}
63
+ >
64
+ {timerConfig.running ? "Pause" : "Play"}
65
+ </button>
66
+ )}
67
+ {milliRemaining !== undefined && (
68
+ <p>
69
+ {`${Math.round(milliRemaining / 1000)} / ${
70
+ Math.round(timerConfig.duration) / 1000
71
+ }`}
72
+ </p>
73
+ )}
74
+ </div>
75
+ );
76
+ }
77
+ ```
78
+ */
79
+ export declare function useLiveTimer(uniqueKey: string, allowedRoles?: UserMeetingRole[], tickRate?: number, onTick?: OnTimerTickAction, onStart?: OnTimerDidStartAction, onPause?: OnTimerDidPauseAction, onPlay?: OnTimerDidPlayAction, onFinish?: OnTimerDidFinishAction): IUseLiveTimerResults;
80
+ //# sourceMappingURL=useLiveTimer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveTimer.d.ts","sourceRoot":"","sources":["../../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGH,eAAe,EAGlB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EAIpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,mBAAmB,CAAC;AAS3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,wBAAgB,YAAY,CACxB,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,qBAAqB,EAC/B,OAAO,CAAC,EAAE,qBAAqB,EAC/B,MAAM,CAAC,EAAE,oBAAoB,EAC7B,QAAQ,CAAC,EAAE,sBAAsB,GAClC,oBAAoB,CA8JtB"}
@@ -0,0 +1,227 @@
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 { LiveTimerEvents, LiveTimer, LiveDataObjectInitializeState, } 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 Live Share's `LiveTimer` DDS.
21
+ *
22
+ * @remarks
23
+ * Use this hook to create a synchronized countdown timer in your app or to schedule synchronized tasks.
24
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
25
+ *
26
+ * @param uniqueKey the unique key for the `LiveTimer`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
27
+ * @param allowedRoles Optional. the user roles that are allowed to start/stop/pause the timer.
28
+ * @param tickRate Optional. the interval in which the `milliRemaining` state should be updated and the `onTick` callback will trigger.
29
+ * @param onTick Optional. event handler callback for when an active timer ticks.
30
+ * @param onStart Optional. event handler callback for when the timer is started.
31
+ * @param onPause Optional. event handler callback for when the timer is paused.
32
+ * @param onPlay Optional. event handler callback for when the timer is resumed.
33
+ * @param onFinish Optional. event handler callback for when the timer finishes.
34
+ * @returns results and callbacks exposed via the hook.
35
+ *
36
+ * @example
37
+ ```jsx
38
+ import { useLiveTimer } from "@microsoft/live-share-react";
39
+
40
+ // Define a unique key that differentiates this usage of `useLiveTimer` from others in your app
41
+ const MY_UNIQUE_KEY = "timer-key";
42
+
43
+ // Example component for using useLiveTimer
44
+ export function CountdownTimer() {
45
+ const {
46
+ milliRemaining,
47
+ timerConfig,
48
+ liveTimer,
49
+ start,
50
+ pause,
51
+ play,
52
+ } = useLiveTimer("TIMER-ID");
53
+
54
+ // Render loading UI when creating LiveTimer instance for first time
55
+ if (!liveTimer) return <>Loading...</>;
56
+
57
+ return (
58
+ <div>
59
+ <button
60
+ onClick={() => {
61
+ start(60 * 1000);
62
+ }}
63
+ >
64
+ {timerConfig === undefined ? "Start" : "Reset"}
65
+ </button>
66
+ {timerConfig !== undefined && (
67
+ <button
68
+ onClick={() => {
69
+ if (timerConfig.running) {
70
+ pause();
71
+ } else {
72
+ play();
73
+ }
74
+ }}
75
+ >
76
+ {timerConfig.running ? "Pause" : "Play"}
77
+ </button>
78
+ )}
79
+ {milliRemaining !== undefined && (
80
+ <p>
81
+ {`${Math.round(milliRemaining / 1000)} / ${
82
+ Math.round(timerConfig.duration) / 1000
83
+ }`}
84
+ </p>
85
+ )}
86
+ </div>
87
+ );
88
+ }
89
+ ```
90
+ */
91
+ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart, onPause, onPlay, onFinish) {
92
+ /**
93
+ * User facing: Stateful timer config.
94
+ */
95
+ const [timerConfig, setTimerConfig] = React.useState();
96
+ /**
97
+ * User facing: Stateful time remaining.
98
+ */
99
+ const [milliRemaining, setMilliRemaining] = React.useState();
100
+ /**
101
+ * User facing: dynamically load the DDS for the given unique key.
102
+ */
103
+ const { dds: liveTimer } = useDynamicDDS(uniqueKey, LiveTimer);
104
+ const { container } = useFluidObjectsContext();
105
+ /**
106
+ * Callback to send event through `LiveTimer`
107
+ * @param duration the duration for the timer in milliseconds
108
+ * @returns void promise that will throw when user does not have required roles
109
+ */
110
+ const start = React.useCallback((duration) => __awaiter(this, void 0, void 0, function* () {
111
+ if (!container) {
112
+ throw new ActionContainerNotJoinedError("liveTimer", "start");
113
+ }
114
+ if (liveTimer === undefined) {
115
+ throw new ActionLiveDataObjectUndefinedError("liveTimer", "start");
116
+ }
117
+ if (!liveTimer.isInitialized) {
118
+ throw new ActionLiveDataObjectInitializedError("liveTimer", "start");
119
+ }
120
+ return yield liveTimer.start(duration);
121
+ }), [container, liveTimer]);
122
+ /**
123
+ * Callback to send event through `LiveTimer`
124
+ * @returns void promise that will throw when user does not have required roles
125
+ */
126
+ const play = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
127
+ if (!container) {
128
+ throw new ActionContainerNotJoinedError("liveTimer", "play");
129
+ }
130
+ if (liveTimer === undefined) {
131
+ throw new ActionLiveDataObjectUndefinedError("liveTimer", "play");
132
+ }
133
+ if (!liveTimer.isInitialized) {
134
+ throw new ActionLiveDataObjectInitializedError("liveTimer", "play");
135
+ }
136
+ return yield liveTimer.play();
137
+ }), [container, liveTimer]);
138
+ /**
139
+ * Callback to send event through `LiveTimer`
140
+ * @returns void promise that will throw when user does not have required roles
141
+ */
142
+ const pause = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
143
+ if (!container) {
144
+ throw new ActionContainerNotJoinedError("liveTimer", "pause");
145
+ }
146
+ if (liveTimer === undefined) {
147
+ throw new ActionLiveDataObjectUndefinedError("liveTimer", "pause");
148
+ }
149
+ if (!liveTimer.isInitialized) {
150
+ throw new ActionLiveDataObjectInitializedError("liveTimer", "pause");
151
+ }
152
+ return yield liveTimer.pause();
153
+ }), [container, liveTimer]);
154
+ /**
155
+ * Setup change listeners and start `LiveTimer` if needed
156
+ */
157
+ React.useEffect(() => {
158
+ if (liveTimer === undefined)
159
+ return;
160
+ // Reset default values, which is needed for when the `id` changes and a new DDS is loaded.
161
+ // React does not re-render if the values are already set to defaults (e.g., initial DDS).
162
+ setTimerConfig(undefined);
163
+ setMilliRemaining(undefined);
164
+ // Register event listeners
165
+ const onTimerConfigChange = (config) => {
166
+ setTimerConfig(config);
167
+ };
168
+ const onDidStart = (config) => {
169
+ onTimerConfigChange(config);
170
+ onStart === null || onStart === void 0 ? void 0 : onStart(config);
171
+ setMilliRemaining(config.duration);
172
+ };
173
+ const onDidFinish = (config) => {
174
+ onTimerConfigChange(config);
175
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish(config);
176
+ setMilliRemaining(0);
177
+ };
178
+ const onDidPlay = (config) => {
179
+ onTimerConfigChange(config);
180
+ onPlay === null || onPlay === void 0 ? void 0 : onPlay(config);
181
+ };
182
+ const onDidPause = (config) => {
183
+ onTimerConfigChange(config);
184
+ onPause === null || onPause === void 0 ? void 0 : onPause(config);
185
+ };
186
+ const onDidTick = (milliseconds) => {
187
+ setMilliRemaining(milliseconds);
188
+ onTick === null || onTick === void 0 ? void 0 : onTick(milliseconds);
189
+ };
190
+ liveTimer.on(LiveTimerEvents.started, onDidStart);
191
+ liveTimer.on(LiveTimerEvents.finished, onDidFinish);
192
+ liveTimer.on(LiveTimerEvents.played, onDidPlay);
193
+ liveTimer.on(LiveTimerEvents.paused, onDidPause);
194
+ liveTimer.on(LiveTimerEvents.onTick, onDidTick);
195
+ if (liveTimer.initializeState === LiveDataObjectInitializeState.needed) {
196
+ // Start live event
197
+ liveTimer.initialize(allowedRoles);
198
+ }
199
+ return () => {
200
+ // on unmount, remove event listeners
201
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.started, onDidStart);
202
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.finished, onDidFinish);
203
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.played, onDidPlay);
204
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.paused, onDidPause);
205
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.onTick, onDidTick);
206
+ };
207
+ }, [liveTimer, onTick, onStart, onFinish, onPlay, onPause]);
208
+ /**
209
+ * Change tick rate if changes in props
210
+ */
211
+ React.useEffect(() => {
212
+ if (tickRate !== undefined &&
213
+ (liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate) !== undefined &&
214
+ tickRate !== (liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate)) {
215
+ liveTimer.tickRate = tickRate;
216
+ }
217
+ }, [tickRate, liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate]);
218
+ return {
219
+ liveTimer,
220
+ milliRemaining,
221
+ pause,
222
+ play,
223
+ start,
224
+ timerConfig,
225
+ };
226
+ }
227
+ //# sourceMapping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AAS,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAE5D;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IACI,QAAQ,KAAK,SAAS;YACtB,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,MAAK,SAAS;YACjC,QAAQ,MAAK,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAA,EAClC,CAAC;YACC,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAClC,CAAC;IACL,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,CAAC,CAAC,CAAC;IAEpC,OAAO;QACH,SAAS;QACT,cAAc;QACd,KAAK;QACL,IAAI;QACJ,KAAK;QACL,WAAW;KACd,CAAC;AACN,CAAC"}
@@ -0,0 +1,86 @@
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 React from "react";
7
+ import { ExtendedMediaMetadata, IMediaPlayer } from "@microsoft/live-share-media";
8
+ import { IUseMediaSynchronizerResults } from "../types/index.js";
9
+ /**
10
+ * React hook for using a Live Share media `MediaPlayerSynchronizer`.
11
+ *
12
+ * @remarks
13
+ * Use this hook if you want to synchronize the playback position of a video or audio element during a Live Share session.
14
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
15
+ *
16
+ * @param uniqueKey uniqueKey value for the `LiveMediaSession` DDS object used by `MediaPlayerSynchronizer`.
17
+ * @param mediaPlayerElement React RefObject containing object/element conforming to IMediaPlayer interface, `IMediaPlayer` object, or string id for <video> / <audio> element.
18
+ * @param initialTrack initial track to load. Either ExtendedMediaMetadata, trackId string, or null.
19
+ * @param allowedRoles Optional. Array of user roles that are eligible to modify group playback state.
20
+ * @param viewOnly Optional. Flag for whether or not the media synchronizer should be in viewOnly mode.
21
+ * @param canSendPositionUpdates Optional. Controls whether or not the local client is allowed to send position updates to the group.
22
+ * @returns IUseMediaSynchronizerResults object.
23
+ *
24
+ * @example
25
+ ```jsx
26
+ import { useMediaSynchronizer } from "@microsoft/live-share-react";
27
+ import { UserMeetingRole } from "@microsoft/live-share";
28
+ import { MediaPlayerSynchronizerEvents } from "@microsoft/live-share-media";
29
+ import { useRef, useEffect } from "react";
30
+
31
+ const ALLOWED_ROLES = [UserMeetingRole.organizer, UserMeetingRole.presenter];
32
+
33
+ const INITIAL_TRACK = "<YOUR_VIDEO_URL>";
34
+
35
+ // Define a unique key that distinguishes this `useMediaSynchronizer` from others in your app
36
+ const UNIQUE_KEY = "MEDIA-SESSION-ID";
37
+
38
+ export function VideoPlayer() {
39
+ const videoRef = useRef(null);
40
+ const { play, pause, seekTo, mediaSynchronizer } = useMediaSynchronizer(
41
+ UNIQUE_KEY,
42
+ videoRef,
43
+ INITIAL_TRACK,
44
+ ALLOWED_ROLES
45
+ );
46
+
47
+ // Listen for groupaction events (optional)
48
+ useEffect(() => {
49
+ // Listen for player group actions for errors (e.g., play error)
50
+ const onGroupAction = (evt: IMediaPlayerSynchronizerEvent) => {
51
+ // See which user made the change (e.g., to display a notification)
52
+ const clientInfo = await synchronizer.mediaSession.getClientInfo(evt.details.clientId);
53
+ };
54
+ mediaSynchronizer?.addEventListener(
55
+ MediaPlayerSynchronizerEvents.groupaction,
56
+ onGroupAction
57
+ );
58
+ return () => {
59
+ mediaSynchronizer?.removeEventListener(
60
+ MediaPlayerSynchronizerEvents.groupaction,
61
+ onGroupAction
62
+ );
63
+ };
64
+ }, [mediaSynchronizer]);
65
+
66
+ return (
67
+ <div>
68
+ <video ref={videoRef} />
69
+ <button onClick={play}>
70
+ Play
71
+ </button>
72
+ <button onClick={pause}>
73
+ Pause
74
+ </button>
75
+ <button onClick={() => {
76
+ seekTo(0);
77
+ }}>
78
+ Start over
79
+ </button>
80
+ </div>
81
+ );
82
+ }
83
+ ```
84
+ */
85
+ export declare function useMediaSynchronizer(uniqueKey: string, mediaPlayerElement: React.RefObject<IMediaPlayer> | IMediaPlayer | string | null, initialTrack: Partial<ExtendedMediaMetadata> | string | null, allowedRoles?: UserMeetingRole[], viewOnly?: boolean, canSendPositionUpdates?: boolean): IUseMediaSynchronizerResults;
86
+ //# sourceMappingURL=useMediaSynchronizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMediaSynchronizer.d.ts","sourceRoot":"","sources":["../../../src/live-hooks/useMediaSynchronizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEH,qBAAqB,EACrB,YAAY,EAIf,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAOjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,MAAM,EACjB,kBAAkB,EACZ,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,GAC7B,YAAY,GACZ,MAAM,GACN,IAAI,EACV,YAAY,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,MAAM,GAAG,IAAI,EAC5D,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,QAAQ,CAAC,EAAE,OAAO,EAClB,sBAAsB,CAAC,EAAE,OAAO,GACjC,4BAA4B,CAiP9B"}