@microsoft/live-share-react 1.0.0-preview.11 → 1.0.0-preview.13

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 (215) hide show
  1. package/README.md +3 -3
  2. package/bin/index.d.ts +7 -0
  3. package/bin/index.d.ts.map +1 -0
  4. package/bin/index.js +7 -0
  5. package/bin/index.js.map +1 -0
  6. package/bin/interfaces/LiveInterfaceExtensions.d.ts +9 -0
  7. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  8. package/bin/interfaces/LiveInterfaceExtensions.js +6 -0
  9. package/bin/interfaces/LiveInterfaceExtensions.js.map +1 -0
  10. package/bin/interfaces/index.d.ts +2 -0
  11. package/bin/interfaces/index.d.ts.map +1 -0
  12. package/bin/interfaces/index.js +2 -0
  13. package/bin/interfaces/index.js.map +1 -0
  14. package/bin/internal-hooks/index.d.ts +2 -0
  15. package/bin/internal-hooks/index.d.ts.map +1 -0
  16. package/bin/internal-hooks/index.js +2 -0
  17. package/bin/internal-hooks/index.js.map +1 -0
  18. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +14 -0
  19. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +1 -0
  20. package/bin/internal-hooks/useDynamicDDSRegistry.js +142 -0
  21. package/bin/internal-hooks/useDynamicDDSRegistry.js.map +1 -0
  22. package/bin/internal-hooks/useSharedStateRegistry.d.ts +31 -0
  23. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +1 -0
  24. package/bin/internal-hooks/useSharedStateRegistry.js +102 -0
  25. package/bin/internal-hooks/useSharedStateRegistry.js.map +1 -0
  26. package/bin/internal-hooks/useStateRef.d.ts +7 -0
  27. package/bin/internal-hooks/useStateRef.d.ts.map +1 -0
  28. package/bin/internal-hooks/useStateRef.js +15 -0
  29. package/bin/internal-hooks/useStateRef.js.map +1 -0
  30. package/bin/live-hooks/index.d.ts +7 -0
  31. package/bin/live-hooks/index.d.ts.map +1 -0
  32. package/bin/live-hooks/index.js +7 -0
  33. package/bin/live-hooks/index.js.map +1 -0
  34. package/bin/live-hooks/useLiveAICompletion.d.ts +29 -0
  35. package/bin/live-hooks/useLiveAICompletion.d.ts.map +1 -0
  36. package/bin/live-hooks/useLiveAICompletion.js +186 -0
  37. package/bin/live-hooks/useLiveAICompletion.js.map +1 -0
  38. package/bin/live-hooks/useLiveCanvas.d.ts +28 -0
  39. package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -0
  40. package/bin/live-hooks/useLiveCanvas.js +159 -0
  41. package/bin/live-hooks/useLiveCanvas.js.map +1 -0
  42. package/bin/live-hooks/useLiveCoPilot.d.ts +28 -0
  43. package/bin/live-hooks/useLiveCoPilot.d.ts.map +1 -0
  44. package/bin/live-hooks/useLiveCoPilot.js +178 -0
  45. package/bin/live-hooks/useLiveCoPilot.js.map +1 -0
  46. package/bin/live-hooks/useLiveEvent.d.ts +22 -0
  47. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -0
  48. package/bin/live-hooks/useLiveEvent.js +93 -0
  49. package/bin/live-hooks/useLiveEvent.js.map +1 -0
  50. package/bin/live-hooks/useLivePresence.d.ts +26 -0
  51. package/bin/live-hooks/useLivePresence.d.ts.map +1 -0
  52. package/bin/live-hooks/useLivePresence.js +102 -0
  53. package/bin/live-hooks/useLivePresence.js.map +1 -0
  54. package/bin/live-hooks/useLiveState.d.ts +20 -0
  55. package/bin/live-hooks/useLiveState.d.ts.map +1 -0
  56. package/bin/live-hooks/useLiveState.js +73 -0
  57. package/bin/live-hooks/useLiveState.js.map +1 -0
  58. package/bin/live-hooks/useLiveTimer.d.ts +8 -0
  59. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -0
  60. package/bin/live-hooks/useLiveTimer.js +145 -0
  61. package/bin/live-hooks/useLiveTimer.js.map +1 -0
  62. package/bin/live-hooks/useMediaSynchronizer.d.ts +23 -0
  63. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  64. package/bin/live-hooks/useMediaSynchronizer.js +185 -0
  65. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -0
  66. package/bin/live-share-turbo/AzureTurboClient.d.ts +39 -0
  67. package/bin/live-share-turbo/AzureTurboClient.d.ts.map +1 -0
  68. package/bin/live-share-turbo/AzureTurboClient.js +56 -0
  69. package/bin/live-share-turbo/AzureTurboClient.js.map +1 -0
  70. package/bin/live-share-turbo/LiveShareTurboClient.d.ts +53 -0
  71. package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +1 -0
  72. package/bin/live-share-turbo/LiveShareTurboClient.js +69 -0
  73. package/bin/live-share-turbo/LiveShareTurboClient.js.map +1 -0
  74. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +31 -0
  75. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +1 -0
  76. package/bin/live-share-turbo/dds-objects/TurboDataObject.js +75 -0
  77. package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +1 -0
  78. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +48 -0
  79. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +1 -0
  80. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +104 -0
  81. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +1 -0
  82. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +28 -0
  83. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +1 -0
  84. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +68 -0
  85. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +1 -0
  86. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +60 -0
  87. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +1 -0
  88. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +111 -0
  89. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +1 -0
  90. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +77 -0
  91. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +1 -0
  92. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +137 -0
  93. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +1 -0
  94. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +30 -0
  95. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +1 -0
  96. package/bin/live-share-turbo/dds-objects/TurboLiveState.js +74 -0
  97. package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +1 -0
  98. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +61 -0
  99. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +1 -0
  100. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +108 -0
  101. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +1 -0
  102. package/bin/live-share-turbo/dds-objects/index.d.ts +8 -0
  103. package/bin/live-share-turbo/dds-objects/index.d.ts.map +1 -0
  104. package/bin/live-share-turbo/dds-objects/index.js +8 -0
  105. package/bin/live-share-turbo/dds-objects/index.js.map +1 -0
  106. package/bin/live-share-turbo/index.d.ts +5 -0
  107. package/bin/live-share-turbo/index.d.ts.map +1 -0
  108. package/bin/live-share-turbo/index.js +5 -0
  109. package/bin/live-share-turbo/index.js.map +1 -0
  110. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +15 -0
  111. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +1 -0
  112. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +2 -0
  113. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +1 -0
  114. package/bin/live-share-turbo/interfaces/index.d.ts +3 -0
  115. package/bin/live-share-turbo/interfaces/index.d.ts.map +1 -0
  116. package/bin/live-share-turbo/interfaces/index.js +3 -0
  117. package/bin/live-share-turbo/interfaces/index.js.map +1 -0
  118. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +39 -0
  119. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +1 -0
  120. package/bin/live-share-turbo/internals/FluidTurboClient.js +121 -0
  121. package/bin/live-share-turbo/internals/FluidTurboClient.js.map +1 -0
  122. package/bin/live-share-turbo/internals/index.d.ts +2 -0
  123. package/bin/live-share-turbo/internals/index.d.ts.map +1 -0
  124. package/bin/live-share-turbo/internals/index.js +2 -0
  125. package/bin/live-share-turbo/internals/index.js.map +1 -0
  126. package/bin/live-share-turbo/internals/types.d.ts +4 -0
  127. package/bin/live-share-turbo/internals/types.d.ts.map +1 -0
  128. package/bin/live-share-turbo/internals/types.js +2 -0
  129. package/bin/live-share-turbo/internals/types.js.map +1 -0
  130. package/bin/providers/AzureProvider.d.ts +34 -0
  131. package/bin/providers/AzureProvider.d.ts.map +1 -0
  132. package/bin/providers/AzureProvider.js +102 -0
  133. package/bin/providers/AzureProvider.js.map +1 -0
  134. package/bin/providers/FluidContextProvider.d.ts +34 -0
  135. package/bin/providers/FluidContextProvider.d.ts.map +1 -0
  136. package/bin/providers/FluidContextProvider.js +99 -0
  137. package/bin/providers/FluidContextProvider.js.map +1 -0
  138. package/bin/providers/LiveShareContextProvider.d.ts +42 -0
  139. package/bin/providers/LiveShareContextProvider.d.ts.map +1 -0
  140. package/bin/providers/LiveShareContextProvider.js +63 -0
  141. package/bin/providers/LiveShareContextProvider.js.map +1 -0
  142. package/bin/providers/LiveShareProvider.d.ts +63 -0
  143. package/bin/providers/LiveShareProvider.d.ts.map +1 -0
  144. package/bin/providers/LiveShareProvider.js +69 -0
  145. package/bin/providers/LiveShareProvider.js.map +1 -0
  146. package/bin/providers/index.d.ts +3 -0
  147. package/bin/providers/index.d.ts.map +1 -0
  148. package/bin/providers/index.js +3 -0
  149. package/bin/providers/index.js.map +1 -0
  150. package/bin/shared-hooks/index.d.ts +4 -0
  151. package/bin/shared-hooks/index.d.ts.map +1 -0
  152. package/bin/shared-hooks/index.js +4 -0
  153. package/bin/shared-hooks/index.js.map +1 -0
  154. package/bin/shared-hooks/useDynamicDDS.d.ts +19 -0
  155. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  156. package/bin/shared-hooks/useDynamicDDS.js +68 -0
  157. package/bin/shared-hooks/useDynamicDDS.js.map +1 -0
  158. package/bin/shared-hooks/useLockedTask.d.ts +11 -0
  159. package/bin/shared-hooks/useLockedTask.d.ts.map +1 -0
  160. package/bin/shared-hooks/useLockedTask.js +82 -0
  161. package/bin/shared-hooks/useLockedTask.js.map +1 -0
  162. package/bin/shared-hooks/useSharedMap.d.ts +22 -0
  163. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -0
  164. package/bin/shared-hooks/useSharedMap.js +106 -0
  165. package/bin/shared-hooks/useSharedMap.js.map +1 -0
  166. package/bin/shared-hooks/useSharedState.d.ts +21 -0
  167. package/bin/shared-hooks/useSharedState.d.ts.map +1 -0
  168. package/bin/shared-hooks/useSharedState.js +67 -0
  169. package/bin/shared-hooks/useSharedState.js.map +1 -0
  170. package/bin/shared-hooks/useTaskManager.d.ts +13 -0
  171. package/bin/shared-hooks/useTaskManager.d.ts.map +1 -0
  172. package/bin/shared-hooks/useTaskManager.js +86 -0
  173. package/bin/shared-hooks/useTaskManager.js.map +1 -0
  174. package/bin/types/ActionTypes.d.ts +106 -0
  175. package/bin/types/ActionTypes.d.ts.map +1 -0
  176. package/bin/types/ActionTypes.js +6 -0
  177. package/bin/types/ActionTypes.js.map +1 -0
  178. package/bin/types/PropTypes.d.ts +8 -0
  179. package/bin/types/PropTypes.d.ts.map +1 -0
  180. package/bin/types/PropTypes.js +6 -0
  181. package/bin/types/PropTypes.js.map +1 -0
  182. package/bin/types/ResultTypes.d.ts +175 -0
  183. package/bin/types/ResultTypes.d.ts.map +1 -0
  184. package/bin/types/ResultTypes.js +6 -0
  185. package/bin/types/ResultTypes.js.map +1 -0
  186. package/bin/types/index.d.ts +4 -0
  187. package/bin/types/index.d.ts.map +1 -0
  188. package/bin/types/index.js +4 -0
  189. package/bin/types/index.js.map +1 -0
  190. package/bin/utils/getContainerSchema.d.ts +8 -0
  191. package/bin/utils/getContainerSchema.d.ts.map +1 -0
  192. package/bin/utils/getContainerSchema.js +41 -0
  193. package/bin/utils/getContainerSchema.js.map +1 -0
  194. package/bin/utils/index.d.ts +2 -0
  195. package/bin/utils/index.d.ts.map +1 -0
  196. package/bin/utils/index.js +2 -0
  197. package/bin/utils/index.js.map +1 -0
  198. package/bin/utils/type-check.d.ts +15 -0
  199. package/bin/utils/type-check.d.ts.map +1 -0
  200. package/bin/utils/type-check.js +54 -0
  201. package/bin/utils/type-check.js.map +1 -0
  202. package/package.json +13 -13
  203. package/src/internal-hooks/useSharedStateRegistry.ts +6 -5
  204. package/src/live-hooks/useLiveEvent.ts +14 -18
  205. package/src/live-hooks/useLivePresence.ts +13 -7
  206. package/src/live-hooks/useLiveState.ts +8 -6
  207. package/src/live-hooks/useLiveTimer.ts +21 -18
  208. package/src/live-hooks/useMediaSynchronizer.ts +37 -27
  209. package/src/providers/AzureProvider.tsx +2 -7
  210. package/src/providers/LiveShareProvider.tsx +45 -15
  211. package/src/shared-hooks/useDynamicDDS.ts +15 -8
  212. package/src/shared-hooks/useSharedMap.ts +17 -10
  213. package/src/shared-hooks/useSharedState.ts +5 -1
  214. package/src/types/ActionTypes.ts +89 -11
  215. package/src/types/ResultTypes.ts +22 -8
@@ -0,0 +1,93 @@
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, } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks";
17
+ /**
18
+ * React hook for using a Live Share `LiveEvent`.
19
+ *
20
+ * @remarks
21
+ * Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
22
+ * such as when sending push notifications or reactions.
23
+ *
24
+ * @template TEvent Optional typing for events sent & received. Default is `object` type.
25
+ * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
26
+ * will be created, otherwise it will use the existing one.
27
+ * @param allowedRoles Optional. The meeting roles eligible to send events through this object.
28
+ * @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
29
+ * @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
30
+ */
31
+ export function useLiveEvent(uniqueKey, allowedRoles, onReceivedEvent) {
32
+ /**
33
+ * Stateful latest event (user facing) and its non-user-facing setter method.
34
+ */
35
+ const [latestEvent, setLatestReceived] = React.useState();
36
+ /**
37
+ * Reference for all received/sent events. The current value of this is user-facing. Because
38
+ * this is always set at the same time as latestEvent, it is effectively a stateful value.
39
+ */
40
+ const allEventsRef = React.useRef([]);
41
+ /**
42
+ * User facing: dynamically load the DDS for the given unique key.
43
+ */
44
+ const { dds: liveEvent } = useDynamicDDS(uniqueKey, (LiveEvent));
45
+ /**
46
+ * User facing: callback to send event through `LiveEvent`
47
+ */
48
+ const sendEvent = React.useCallback((event) => __awaiter(this, void 0, void 0, function* () {
49
+ if (liveEvent === undefined) {
50
+ throw new Error("Cannot call emitEvent when liveEvent is undefined");
51
+ }
52
+ if (!liveEvent.isInitialized) {
53
+ throw new Error("Cannot call emitEvent while liveEvent is not started");
54
+ }
55
+ return yield liveEvent.send(event);
56
+ }), [liveEvent]);
57
+ /**
58
+ * Setup change listeners and start `LiveEvent` if needed
59
+ */
60
+ React.useEffect(() => {
61
+ if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined)
62
+ return;
63
+ // Register event listener
64
+ const onEventReceived = (event, local) => {
65
+ // If developer passed the optional onReceivedEvent callback, we
66
+ // call it.
67
+ onReceivedEvent === null || onReceivedEvent === void 0 ? void 0 : onReceivedEvent(event, local);
68
+ // Set the received event to our local state
69
+ const received = {
70
+ event: event,
71
+ local,
72
+ };
73
+ allEventsRef.current = [...allEventsRef.current, received];
74
+ setLatestReceived(received);
75
+ };
76
+ liveEvent.on(LiveEventEvents.received, onEventReceived);
77
+ if (!liveEvent.isInitialized) {
78
+ // Start live event
79
+ liveEvent.initialize(allowedRoles);
80
+ }
81
+ return () => {
82
+ // on unmount, remove event listeners
83
+ liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.off(LiveEventEvents.received, onEventReceived);
84
+ };
85
+ }, [liveEvent]);
86
+ return {
87
+ latestEvent,
88
+ allEvents: allEventsRef.current,
89
+ sendEvent,
90
+ liveEvent,
91
+ };
92
+ }
93
+ //# sourceMappingURL=useLiveEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EACH,eAAe,EAEf,SAAS,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CACxB,SAAiB,EACjB,YAAgC,EAChC,eAAmD;IAEnD;;OAEG;IACH,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,GAClC,KAAK,CAAC,QAAQ,EAA6B,CAAC;IAChD;;;OAGG;IACH,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAA8B,EAAE,CAAC,CAAC;IACnE;;OAEG;IACH,MAAM,E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R,qCAAqC;YACrC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC9D,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACH,WAAW;QACX,SAAS,EAAE,YAAY,CAAC,OAAO;QAC/B,SAAS;QACT,SAAS;KACZ,CAAC;AACN,CAAC"}
@@ -0,0 +1,26 @@
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
+ *
15
+ * @template TData Optional typing for the custom user presence data object. Default is `object` type.
16
+ * @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one
17
+ * @param userId Optional. The unique ID for a user. If none is provided, a random UUID will be generated.
18
+ * @param initialData Optional. Initial presence data object for the user.
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 | undefined, initialPresenceState?: PresenceState, allowedRoles?: UserMeetingRole[]): IUseLivePresenceResults<TData>;
26
+ //# sourceMappingURL=useLivePresence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLivePresence.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,aAAa,EAEb,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAA8B,MAAM,UAAU,CAAC;AAG/E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACzD,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,KAAK,GAAG,SAAS,EAC/B,oBAAoB,GAAE,aAAoC,EAC1D,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,uBAAuB,CAAC,KAAK,CAAC,CA4FhC"}
@@ -0,0 +1,102 @@
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, } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks";
17
+ /**
18
+ * React hook for using a Live Share `LivePresence`.
19
+ *
20
+ * @remarks
21
+ * Use this hook if you want to track presence for who is currently using this component, such as
22
+ * who is online or who is viewing a specific document. With presence, you can sent along any custom
23
+ * user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
24
+ *
25
+ * @template TData Optional typing for the custom user presence data object. Default is `object` type.
26
+ * @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one
27
+ * @param userId Optional. The unique ID for a user. If none is provided, a random UUID will be generated.
28
+ * @param initialData Optional. Initial presence data object for the user.
29
+ * @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
30
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
31
+ * will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
32
+ * @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
33
+ * to update the local user's presence and the `LivePresence` Fluid object.
34
+ */
35
+ export function useLivePresence(uniqueKey, initialData, initialPresenceState = PresenceState.online, allowedRoles) {
36
+ /**
37
+ * Stateful all user presence list and its non-user-facing setter method.
38
+ */
39
+ const [allUsers, setAllUsers] = React.useState([]);
40
+ /**
41
+ * User facing: dynamically load the DDS for the given unique key.
42
+ */
43
+ const { dds: livePresence } = useDynamicDDS(uniqueKey, (LivePresence));
44
+ /**
45
+ * User facing: list of non-local user's presence objects.
46
+ */
47
+ const otherUsers = React.useMemo(() => {
48
+ return [...allUsers.filter((user) => !user.isLocalUser)];
49
+ }, [allUsers]);
50
+ /**
51
+ * User facing: local user's presence object.
52
+ */
53
+ const localUser = React.useMemo(() => {
54
+ return allUsers.find((user) => user.isLocalUser);
55
+ }, [allUsers]);
56
+ /**
57
+ * User facing: callback to update the local user's presence.
58
+ */
59
+ const updatePresence = React.useCallback((data, state) => __awaiter(this, void 0, void 0, function* () {
60
+ if (!livePresence) {
61
+ console.error(new Error("Cannot call updatePresence when presence is undefined"));
62
+ return;
63
+ }
64
+ if (!livePresence.isInitialized) {
65
+ console.error(new Error("Cannot call updatePresence while presence is not started"));
66
+ return;
67
+ }
68
+ return yield livePresence.update(data, state);
69
+ }), [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.isInitialized) {
85
+ livePresence.initialize(initialData, initialPresenceState, allowedRoles);
86
+ }
87
+ else {
88
+ onPresenceChanged();
89
+ }
90
+ return () => {
91
+ livePresence === null || livePresence === void 0 ? void 0 : livePresence.off("presenceChanged", onPresenceChanged);
92
+ };
93
+ }, [livePresence]);
94
+ return {
95
+ localUser,
96
+ otherUsers,
97
+ allUsers,
98
+ livePresence,
99
+ updatePresence,
100
+ };
101
+ }
102
+ //# sourceMappingURL=useLivePresence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLivePresence.js","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EAEH,aAAa,EACb,YAAY,GAEf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC3B,SAAiB,EACjB,WAA+B,EAC/B,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,KAAK,CAAC,OAAO,CAA4B,GAAG,EAAE;QAC7D,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC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AAI,CAAC,YAAY,CAAC,aAAa,EAAE;YAC7B,YAAY,CAAC,UAAU,CACnB,WAAW,EACX,oBAAoB,EACpB,YAAY,CACf,CAAC;SACL;aAAM;YACH,iBAAiB,EAAE,CAAC;SACvB;QAED,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"}
@@ -0,0 +1,20 @@
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 { 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
+ *
13
+ * @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.
14
+ * @param initialState Optional. the initial state value of type TState
15
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
16
+ * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
17
+ * The setter returns a void promise, which will throw if the user does not have the required roles to set.
18
+ */
19
+ export declare function useLiveState<TState = any>(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction<TState>];
20
+ //# 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,EAAa,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C;;;;;;;;;;;GAWG;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,CAAC,CA8DtC"}
@@ -0,0 +1,73 @@
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 { LiveState } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks";
17
+ /**
18
+ * React hook for using a Live Share `LiveState`.
19
+ *
20
+ * @remarks
21
+ * Use this hook if you want to synchronize app state that will reset when all users leave the session.
22
+ *
23
+ * @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.
24
+ * @param initialState Optional. the initial state value of type TState
25
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
26
+ * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
27
+ * The setter returns a void promise, which will throw if the user does not have the required roles to set.
28
+ */
29
+ export function useLiveState(uniqueKey, initialState, allowedRoles) {
30
+ const [currentState, setCurrentState] = React.useState(initialState);
31
+ /**
32
+ * User facing: dynamically load the DDS for the given unique key.
33
+ */
34
+ const { dds: liveState } = useDynamicDDS(uniqueKey, (LiveState));
35
+ /**
36
+ * Change state callback that is user facing
37
+ * @param state TState to set
38
+ * @returns void promise, which will throw if the user does not have the required roles
39
+ */
40
+ const setState = React.useCallback((state) => __awaiter(this, void 0, void 0, function* () {
41
+ if (!liveState) {
42
+ console.error(new Error("Cannot call changeState when liveState is undefined"));
43
+ return;
44
+ }
45
+ if (!liveState.isInitialized) {
46
+ console.error(new Error("Cannot call changeState while liveState is not started"));
47
+ return;
48
+ }
49
+ return yield liveState.set(state);
50
+ }), [liveState]);
51
+ /**
52
+ * Setup change listeners and start `LiveState` if needed
53
+ */
54
+ React.useEffect(() => {
55
+ if (liveState === undefined)
56
+ return;
57
+ const onStateChanged = (state) => {
58
+ setCurrentState(state);
59
+ };
60
+ liveState.on("stateChanged", onStateChanged);
61
+ if (!liveState.isInitialized) {
62
+ liveState.initialize(initialState, allowedRoles);
63
+ }
64
+ if (JSON.stringify(liveState.state) !== JSON.stringify(initialState)) {
65
+ onStateChanged(liveState.state);
66
+ }
67
+ return () => {
68
+ liveState === null || liveState === void 0 ? void 0 : liveState.off("stateChanged", onStateChanged);
69
+ };
70
+ }, [liveState]);
71
+ return [currentState, setState];
72
+ }
73
+ //# 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,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;GAWG;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;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AAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,8 @@
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";
7
+ export declare function useLiveTimer(uniqueKey: string, allowedRoles?: UserMeetingRole[], tickRate?: number, onTick?: OnTimerTickAction, onStart?: OnTimerDidStartAction, onPause?: OnTimerDidPauseAction, onPlay?: OnTimerDidPlayAction, onFinish?: OnTimerDidFinishAction): IUseLiveTimerResults;
8
+ //# 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,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EAIpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,UAAU,CAAC;AAGlB,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,CAwJtB"}
@@ -0,0 +1,145 @@
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, } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks";
17
+ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart, onPause, onPlay, onFinish) {
18
+ /**
19
+ * User facing: Stateful timer config.
20
+ */
21
+ const [timerConfig, setTimerConfig] = React.useState();
22
+ /**
23
+ * User facing: Stateful time remaining.
24
+ */
25
+ const [milliRemaining, setMilliRemaining] = React.useState();
26
+ /**
27
+ * User facing: dynamically load the DDS for the given unique key.
28
+ */
29
+ const { dds: liveTimer } = useDynamicDDS(uniqueKey, LiveTimer);
30
+ /**
31
+ * Callback to send event through `LiveTimer`
32
+ * @param duration the duration for the timer in milliseconds
33
+ * @returns void promise that will throw when user does not have required roles
34
+ */
35
+ const start = React.useCallback((duration) => __awaiter(this, void 0, void 0, function* () {
36
+ if (liveTimer === undefined) {
37
+ console.error(new Error("Cannot call start when liveTimer is undefined"));
38
+ return;
39
+ }
40
+ if (!liveTimer.isInitialized) {
41
+ console.error(new Error("Cannot call start while liveTimer is not started"));
42
+ return;
43
+ }
44
+ return yield liveTimer.start(duration);
45
+ }), [liveTimer]);
46
+ /**
47
+ * Callback to send event through `LiveTimer`
48
+ * @returns void promise that will throw when user does not have required roles
49
+ */
50
+ const play = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
51
+ if (liveTimer === undefined) {
52
+ console.error(new Error("Cannot call play when liveTimer is undefined"));
53
+ return;
54
+ }
55
+ if (!liveTimer.isInitialized) {
56
+ console.error(new Error("Cannot call play while liveTimer is not started"));
57
+ return;
58
+ }
59
+ return yield liveTimer.play();
60
+ }), [liveTimer]);
61
+ /**
62
+ * Callback to send event through `LiveTimer`
63
+ * @returns void promise that will throw when user does not have required roles
64
+ */
65
+ const pause = React.useCallback(() => __awaiter(this, void 0, void 0, function* () {
66
+ if (liveTimer === undefined) {
67
+ console.error(new Error("Cannot call pause when liveTimer is undefined"));
68
+ return;
69
+ }
70
+ if (!liveTimer.isInitialized) {
71
+ console.error(new Error("Cannot call pause while liveTimer is not started"));
72
+ return;
73
+ }
74
+ return yield liveTimer.pause();
75
+ }), [liveTimer]);
76
+ /**
77
+ * Setup change listeners and start `LiveTimer` if needed
78
+ */
79
+ React.useEffect(() => {
80
+ if (liveTimer === undefined)
81
+ return;
82
+ // Register event listeners
83
+ const onTimerConfigChange = (config) => {
84
+ setTimerConfig(config);
85
+ };
86
+ const onDidStart = (config) => {
87
+ onTimerConfigChange(config);
88
+ onStart === null || onStart === void 0 ? void 0 : onStart(config);
89
+ setMilliRemaining(config.duration);
90
+ };
91
+ const onDidFinish = (config) => {
92
+ onTimerConfigChange(config);
93
+ onFinish === null || onFinish === void 0 ? void 0 : onFinish(config);
94
+ setMilliRemaining(0);
95
+ };
96
+ const onDidPlay = (config) => {
97
+ onTimerConfigChange(config);
98
+ onPlay === null || onPlay === void 0 ? void 0 : onPlay(config);
99
+ };
100
+ const onDidPause = (config) => {
101
+ onTimerConfigChange(config);
102
+ onPause === null || onPause === void 0 ? void 0 : onPause(config);
103
+ };
104
+ const onDidTick = (milliseconds) => {
105
+ setMilliRemaining(milliseconds);
106
+ onTick === null || onTick === void 0 ? void 0 : onTick(milliseconds);
107
+ };
108
+ liveTimer.on(LiveTimerEvents.started, onDidStart);
109
+ liveTimer.on(LiveTimerEvents.finished, onDidFinish);
110
+ liveTimer.on(LiveTimerEvents.played, onDidPlay);
111
+ liveTimer.on(LiveTimerEvents.paused, onDidPause);
112
+ liveTimer.on(LiveTimerEvents.onTick, onDidTick);
113
+ if (!liveTimer.isInitialized) {
114
+ // Start live event
115
+ liveTimer.initialize(allowedRoles);
116
+ }
117
+ return () => {
118
+ // on unmount, remove event listeners
119
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.started, onDidStart);
120
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.finished, onDidFinish);
121
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.played, onDidPlay);
122
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.paused, onDidPause);
123
+ liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.off(LiveTimerEvents.onTick, onDidTick);
124
+ };
125
+ }, [liveTimer, onTick, onStart, onFinish, onPlay, onPause]);
126
+ /**
127
+ * Change tick rate if changes in props
128
+ */
129
+ React.useEffect(() => {
130
+ if (tickRate !== undefined &&
131
+ (liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate) !== undefined &&
132
+ tickRate !== (liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate)) {
133
+ liveTimer.tickRate = tickRate;
134
+ }
135
+ }, [tickRate, liveTimer === null || liveTimer === void 0 ? void 0 : liveTimer.tickRate]);
136
+ return {
137
+ liveTimer,
138
+ milliRemaining,
139
+ pause,
140
+ play,
141
+ start,
142
+ timerConfig,
143
+ };
144
+ }
145
+ //# sourceMappingURL=useLiveTimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLiveTimer.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EAEH,eAAe,EAEf,SAAS,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;A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AS,CAAE,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YAClD,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YACnD,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,eAAe,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,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;YACE,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC;SACjC;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,23 @@
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";
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
+ *
15
+ * @param uniqueKey uniqueKey value for the `LiveMediaSession` DDS object used by `MediaPlayerSynchronizer`.
16
+ * @param mediaPlayerElementRef React RefObject containing object/element conforming to IMediaPlayer interface or string id for <video> / <audio> element.
17
+ * @param initialTrack initial track to load. Either ExtendedMediaMetadata, trackId string, or null.
18
+ * @param allowedRoles Optional. Array of user roles that are eligible to modify group playback state.
19
+ * @param viewOnly Optional. Flag for whether or not the media synchronizer should be in viewOnly mode.
20
+ * @returns IUseMediaSynchronizerResults object.
21
+ */
22
+ export declare function useMediaSynchronizer(uniqueKey: string, mediaPlayerElementRef: React.RefObject<IMediaPlayer> | string, initialTrack: Partial<ExtendedMediaMetadata> | string | null, allowedRoles?: UserMeetingRole[], viewOnly?: boolean): IUseMediaSynchronizerResults;
23
+ //# 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,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEH,qBAAqB,EACrB,YAAY,EAIf,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,MAAM,EACjB,qBAAqB,EAAE,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,MAAM,EAC7D,YAAY,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,MAAM,GAAG,IAAI,EAC5D,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,QAAQ,CAAC,EAAE,OAAO,GACnB,4BAA4B,CA2K9B"}