@microsoft/live-share-react 1.4.0-preview.0 → 1.4.1-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 +8 -8
  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,134 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the Microsoft Live Share SDK License.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.useLiveState = useLiveState;
20
+ const live_share_1 = require("@microsoft/live-share");
21
+ const react_1 = __importDefault(require("react"));
22
+ const index_js_1 = require("../shared-hooks/index.js");
23
+ const index_js_2 = require("../providers/index.js");
24
+ const index_js_3 = require("../internal/index.js");
25
+ /**
26
+ * React hook for using a Live Share `LiveState`.
27
+ *
28
+ * @remarks
29
+ * Use this hook if you want to synchronize app state that will reset when all users leave the session.
30
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
31
+ *
32
+ * @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.
33
+ * @param initialState Optional. the initial state value of type TState
34
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
35
+ * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
36
+ * The setter returns a void promise, which will throw if the user does not have the required roles to set.
37
+ *
38
+ * @example
39
+ ```jsx
40
+ import { useLiveState } from "@microsoft/live-share-react";
41
+
42
+ const planets = [
43
+ "Mercury",
44
+ "Venus",
45
+ "Earth",
46
+ "Mars",
47
+ "Jupiter",
48
+ "Saturn",
49
+ "Uranus",
50
+ "Neptune",
51
+ ];
52
+
53
+ // Define a unique key that differentiates this usage of `useLiveState` from others in your app
54
+ const MY_UNIQUE_KEY = "selected-planet-key";
55
+
56
+ // Example component for using useLiveState
57
+ export const MyCustomState = () => {
58
+ const [planet, setPlanet, liveState] = useLiveState(MY_UNIQUE_KEY, planets[0]);
59
+
60
+ // Render loading UI when creating LiveState instance for first time
61
+ if (!liveState) return <>Loading...</>;
62
+
63
+ // Render UI
64
+ return (
65
+ <div>
66
+ {`Current planet: ${planet}`}
67
+ {"Select a planet below:"}
68
+ {planets.map((planet) => (
69
+ <button
70
+ key={planet}
71
+ onClick={() => {
72
+ setPlanet(planet);
73
+ }}
74
+ >
75
+ {planet}
76
+ </button>
77
+ ))}
78
+ </div>
79
+ );
80
+ };
81
+ ```
82
+ */
83
+ function useLiveState(uniqueKey, initialState, allowedRoles) {
84
+ const [currentState, setCurrentState] = react_1.default.useState(initialState);
85
+ /**
86
+ * User facing: dynamically load the DDS for the given unique key.
87
+ */
88
+ const { dds: liveState } = (0, index_js_1.useDynamicDDS)(uniqueKey, (live_share_1.LiveState));
89
+ const { container } = (0, index_js_2.useFluidObjectsContext)();
90
+ /**
91
+ * Change state callback that is user facing
92
+ * @param state TState to set
93
+ * @returns void promise, which will throw if the user does not have the required roles
94
+ */
95
+ const setState = react_1.default.useCallback((state) => __awaiter(this, void 0, void 0, function* () {
96
+ if (!container) {
97
+ throw new index_js_3.ActionContainerNotJoinedError("liveState", "setState");
98
+ }
99
+ if (liveState === undefined) {
100
+ throw new index_js_3.ActionLiveDataObjectUndefinedError("liveState", "setState");
101
+ }
102
+ if (!liveState.isInitialized) {
103
+ throw new index_js_3.ActionLiveDataObjectInitializedError("liveState", "setState");
104
+ }
105
+ const valueToSet = (0, index_js_3.isPrevStateCallback)(state)
106
+ ? state(liveState.state)
107
+ : state;
108
+ return yield liveState.set(valueToSet);
109
+ }), [container, liveState]);
110
+ /**
111
+ * Setup change listeners and start `LiveState` if needed
112
+ */
113
+ react_1.default.useEffect(() => {
114
+ if (liveState === undefined)
115
+ return;
116
+ const onStateChanged = (state) => {
117
+ setCurrentState(state);
118
+ };
119
+ liveState.on("stateChanged", onStateChanged);
120
+ if (liveState.initializeState === live_share_1.LiveDataObjectInitializeState.needed) {
121
+ liveState
122
+ .initialize(initialState, allowedRoles)
123
+ .then(() => onStateChanged(liveState.state));
124
+ }
125
+ else {
126
+ onStateChanged(liveState.state);
127
+ }
128
+ return () => {
129
+ liveState === null || liveState === void 0 ? void 0 : liveState.off("stateChanged", onStateChanged);
130
+ };
131
+ }, [liveState]);
132
+ return [currentState, setState, liveState];
133
+ }
134
+ //# sourceMappingURL=useLiveState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveState.js","sourceRoot":"","sources":["../../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;AA4EH,oCA4EC;AAtJD,sDAI+B;AAC/B,kDAA0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S,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,0CAA6B,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,233 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the Microsoft Live Share SDK License.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.useLiveTimer = useLiveTimer;
20
+ const live_share_1 = require("@microsoft/live-share");
21
+ const react_1 = __importDefault(require("react"));
22
+ const index_js_1 = require("../shared-hooks/index.js");
23
+ const index_js_2 = require("../providers/index.js");
24
+ const index_js_3 = require("../internal/index.js");
25
+ /**
26
+ * React hook for using Live Share's `LiveTimer` DDS.
27
+ *
28
+ * @remarks
29
+ * Use this hook to create a synchronized countdown timer in your app or to schedule synchronized tasks.
30
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
31
+ *
32
+ * @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.
33
+ * @param allowedRoles Optional. the user roles that are allowed to start/stop/pause the timer.
34
+ * @param tickRate Optional. the interval in which the `milliRemaining` state should be updated and the `onTick` callback will trigger.
35
+ * @param onTick Optional. event handler callback for when an active timer ticks.
36
+ * @param onStart Optional. event handler callback for when the timer is started.
37
+ * @param onPause Optional. event handler callback for when the timer is paused.
38
+ * @param onPlay Optional. event handler callback for when the timer is resumed.
39
+ * @param onFinish Optional. event handler callback for when the timer finishes.
40
+ * @returns results and callbacks exposed via the hook.
41
+ *
42
+ * @example
43
+ ```jsx
44
+ import { useLiveTimer } from "@microsoft/live-share-react";
45
+
46
+ // Define a unique key that differentiates this usage of `useLiveTimer` from others in your app
47
+ const MY_UNIQUE_KEY = "timer-key";
48
+
49
+ // Example component for using useLiveTimer
50
+ export function CountdownTimer() {
51
+ const {
52
+ milliRemaining,
53
+ timerConfig,
54
+ liveTimer,
55
+ start,
56
+ pause,
57
+ play,
58
+ } = useLiveTimer("TIMER-ID");
59
+
60
+ // Render loading UI when creating LiveTimer instance for first time
61
+ if (!liveTimer) return <>Loading...</>;
62
+
63
+ return (
64
+ <div>
65
+ <button
66
+ onClick={() => {
67
+ start(60 * 1000);
68
+ }}
69
+ >
70
+ {timerConfig === undefined ? "Start" : "Reset"}
71
+ </button>
72
+ {timerConfig !== undefined && (
73
+ <button
74
+ onClick={() => {
75
+ if (timerConfig.running) {
76
+ pause();
77
+ } else {
78
+ play();
79
+ }
80
+ }}
81
+ >
82
+ {timerConfig.running ? "Pause" : "Play"}
83
+ </button>
84
+ )}
85
+ {milliRemaining !== undefined && (
86
+ <p>
87
+ {`${Math.round(milliRemaining / 1000)} / ${
88
+ Math.round(timerConfig.duration) / 1000
89
+ }`}
90
+ </p>
91
+ )}
92
+ </div>
93
+ );
94
+ }
95
+ ```
96
+ */
97
+ function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart, onPause, onPlay, onFinish) {
98
+ /**
99
+ * User facing: Stateful timer config.
100
+ */
101
+ const [timerConfig, setTimerConfig] = react_1.default.useState();
102
+ /**
103
+ * User facing: Stateful time remaining.
104
+ */
105
+ const [milliRemaining, setMilliRemaining] = react_1.default.useState();
106
+ /**
107
+ * User facing: dynamically load the DDS for the given unique key.
108
+ */
109
+ const { dds: liveTimer } = (0, index_js_1.useDynamicDDS)(uniqueKey, live_share_1.LiveTimer);
110
+ const { container } = (0, index_js_2.useFluidObjectsContext)();
111
+ /**
112
+ * Callback to send event through `LiveTimer`
113
+ * @param duration the duration for the timer in milliseconds
114
+ * @returns void promise that will throw when user does not have required roles
115
+ */
116
+ const start = react_1.default.useCallback((duration) => __awaiter(this, void 0, void 0, function* () {
117
+ if (!container) {
118
+ throw new index_js_3.ActionContainerNotJoinedError("liveTimer", "start");
119
+ }
120
+ if (liveTimer === undefined) {
121
+ throw new index_js_3.ActionLiveDataObjectUndefinedError("liveTimer", "start");
122
+ }
123
+ if (!liveTimer.isInitialized) {
124
+ throw new index_js_3.ActionLiveDataObjectInitializedError("liveTimer", "start");
125
+ }
126
+ return yield liveTimer.start(duration);
127
+ }), [container, liveTimer]);
128
+ /**
129
+ * Callback to send event through `LiveTimer`
130
+ * @returns void promise that will throw when user does not have required roles
131
+ */
132
+ const play = react_1.default.useCallback(() => __awaiter(this, void 0, void 0, function* () {
133
+ if (!container) {
134
+ throw new index_js_3.ActionContainerNotJoinedError("liveTimer", "play");
135
+ }
136
+ if (liveTimer === undefined) {
137
+ throw new index_js_3.ActionLiveDataObjectUndefinedError("liveTimer", "play");
138
+ }
139
+ if (!liveTimer.isInitialized) {
140
+ throw new index_js_3.ActionLiveDataObjectInitializedError("liveTimer", "play");
141
+ }
142
+ return yield liveTimer.play();
143
+ }), [container, liveTimer]);
144
+ /**
145
+ * Callback to send event through `LiveTimer`
146
+ * @returns void promise that will throw when user does not have required roles
147
+ */
148
+ const pause = react_1.default.useCallback(() => __awaiter(this, void 0, void 0, function* () {
149
+ if (!container) {
150
+ throw new index_js_3.ActionContainerNotJoinedError("liveTimer", "pause");
151
+ }
152
+ if (liveTimer === undefined) {
153
+ throw new index_js_3.ActionLiveDataObjectUndefinedError("liveTimer", "pause");
154
+ }
155
+ if (!liveTimer.isInitialized) {
156
+ throw new index_js_3.ActionLiveDataObjectInitializedError("liveTimer", "pause");
157
+ }
158
+ return yield liveTimer.pause();
159
+ }), [container, liveTimer]);
160
+ /**
161
+ * Setup change listeners and start `LiveTimer` if needed
162
+ */
163
+ react_1.default.useEffect(() => {
164
+ if (liveTimer === undefined)
165
+ return;
166
+ // Reset default values, which is needed for when the `id` changes and a new DDS is loaded.
167
+ // React does not re-render if the values are already set to defaults (e.g., initial DDS).
168
+ setTimerConfig(undefined);
169
+ setMilliRemaining(undefined);
170
+ // Register event listeners
171
+ const onTimerConfigChange = (config) => {
172
+ setTimerConfig(config);
173
+ };
174
+ const onDidStart = (config) => {
175
+ onTimerConfigChange(config);
176
+ onStart === null || onStart === void 0 ? void 0 : onStart(config);
177
+ setMilliRemaining(config.duration);
178
+ };
179
+ const onDidFinish = (config) => {
180
+ onTimerConfigChange(config);
181
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish(config);
182
+ setMilliRemaining(0);
183
+ };
184
+ const onDidPlay = (config) => {
185
+ onTimerConfigChange(config);
186
+ onPlay === null || onPlay === void 0 ? void 0 : onPlay(config);
187
+ };
188
+ const onDidPause = (config) => {
189
+ onTimerConfigChange(config);
190
+ onPause === null || onPause === void 0 ? void 0 : onPause(config);
191
+ };
192
+ const onDidTick = (milliseconds) => {
193
+ setMilliRemaining(milliseconds);
194
+ onTick === null || onTick === void 0 ? void 0 : onTick(milliseconds);
195
+ };
196
+ liveTimer.on(live_share_1.LiveTimerEvents.started, onDidStart);
197
+ liveTimer.on(live_share_1.LiveTimerEvents.finished, onDidFinish);
198
+ liveTimer.on(live_share_1.LiveTimerEvents.played, onDidPlay);
199
+ liveTimer.on(live_share_1.LiveTimerEvents.paused, onDidPause);
200
+ liveTimer.on(live_share_1.LiveTimerEvents.onTick, onDidTick);
201
+ if (liveTimer.initializeState === live_share_1.LiveDataObjectInitializeState.needed) {
202
+ // Start live event
203
+ liveTimer.initialize(allowedRoles);
204
+ }
205
+ return () => {
206
+ // on unmount, remove event listeners
207
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(live_share_1.LiveTimerEvents.started, onDidStart);
208
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(live_share_1.LiveTimerEvents.finished, onDidFinish);
209
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(live_share_1.LiveTimerEvents.played, onDidPlay);
210
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(live_share_1.LiveTimerEvents.paused, onDidPause);
211
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(live_share_1.LiveTimerEvents.onTick, onDidTick);
212
+ };
213
+ }, [liveTimer, onTick, onStart, onFinish, onPlay, onPause]);
214
+ /**
215
+ * Change tick rate if changes in props
216
+ */
217
+ react_1.default.useEffect(() => {
218
+ if (tickRate !== undefined &&
219
+ (liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate) !== undefined &&
220
+ tickRate !== (liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate)) {
221
+ liveTimer.tickRate = tickRate;
222
+ }
223
+ }, [tickRate, liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate]);
224
+ return {
225
+ liveTimer,
226
+ milliRemaining,
227
+ pause,
228
+ play,
229
+ start,
230
+ timerConfig,
231
+ };
232
+ }
233
+ //# sourceMappingURL=useLiveTimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveTimer.js","sourceRoot":"","sources":["../../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;AAqGH,oCAuKC;AA1QD,sDAM+B;AAC/B,kDAA0B;AAY1B,uDAAyD;AACzD,oDAA+D;AAC/D,mDAI8B;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,SAAgB,YAAY,CACxB,SAAiB,EACjB,YAAgC,EAChC,QAAiB,EACjB,MAA0B,EAC1B,OAA+B,EAC/B,OAA+B,EAC/B,MAA6B,EAC7B,QAAiC;IAEjC;;OAEG;IACH,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,EAAgB,CAAC;IACrE;;OAEG;IACH,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,eAAK,CAAC,QAAQ,EAAU,CAAC;IACrE;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAa,EAAY,SAAS,EAAE,sBAAS,CAAC,CAAC;IAE1E,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,iCAAsB,GAAE,CAAC;IAE/C;;;;OAIG;IACH,MAAM,KAAK,GAAuB,eAAK,CAAC,WAAW,CAC/C,CAAO,QAAgB,EAAE,EAAE;QACvB,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,IAAI,wCAA6B,C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SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,4BAAe,CAAC,MAAM,EAAE,SAAS,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,eAAK,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"}