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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/README.md +88 -21
  2. package/package.json +13 -9
  3. package/src/live-hooks/useLiveCanvas.ts +11 -19
  4. package/src/live-hooks/useLiveEvent.ts +1 -1
  5. package/src/live-hooks/useLivePresence.ts +10 -9
  6. package/src/shared-hooks/index.ts +0 -1
  7. package/src/types/ActionTypes.ts +1 -1
  8. package/bin/index.d.ts +0 -7
  9. package/bin/index.d.ts.map +0 -1
  10. package/bin/index.js +0 -7
  11. package/bin/index.js.map +0 -1
  12. package/bin/interfaces/LiveInterfaceExtensions.d.ts +0 -9
  13. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
  14. package/bin/interfaces/LiveInterfaceExtensions.js +0 -6
  15. package/bin/interfaces/LiveInterfaceExtensions.js.map +0 -1
  16. package/bin/interfaces/index.d.ts +0 -2
  17. package/bin/interfaces/index.d.ts.map +0 -1
  18. package/bin/interfaces/index.js +0 -2
  19. package/bin/interfaces/index.js.map +0 -1
  20. package/bin/internal-hooks/index.d.ts +0 -2
  21. package/bin/internal-hooks/index.d.ts.map +0 -1
  22. package/bin/internal-hooks/index.js +0 -2
  23. package/bin/internal-hooks/index.js.map +0 -1
  24. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +0 -14
  25. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +0 -1
  26. package/bin/internal-hooks/useDynamicDDSRegistry.js +0 -142
  27. package/bin/internal-hooks/useDynamicDDSRegistry.js.map +0 -1
  28. package/bin/internal-hooks/useSharedStateRegistry.d.ts +0 -31
  29. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +0 -1
  30. package/bin/internal-hooks/useSharedStateRegistry.js +0 -100
  31. package/bin/internal-hooks/useSharedStateRegistry.js.map +0 -1
  32. package/bin/internal-hooks/useStateRef.d.ts +0 -7
  33. package/bin/internal-hooks/useStateRef.d.ts.map +0 -1
  34. package/bin/internal-hooks/useStateRef.js +0 -15
  35. package/bin/internal-hooks/useStateRef.js.map +0 -1
  36. package/bin/live-hooks/index.d.ts +0 -7
  37. package/bin/live-hooks/index.d.ts.map +0 -1
  38. package/bin/live-hooks/index.js +0 -7
  39. package/bin/live-hooks/index.js.map +0 -1
  40. package/bin/live-hooks/useLiveAICompletion.d.ts +0 -29
  41. package/bin/live-hooks/useLiveAICompletion.d.ts.map +0 -1
  42. package/bin/live-hooks/useLiveAICompletion.js +0 -186
  43. package/bin/live-hooks/useLiveAICompletion.js.map +0 -1
  44. package/bin/live-hooks/useLiveCanvas.d.ts +0 -28
  45. package/bin/live-hooks/useLiveCanvas.d.ts.map +0 -1
  46. package/bin/live-hooks/useLiveCanvas.js +0 -167
  47. package/bin/live-hooks/useLiveCanvas.js.map +0 -1
  48. package/bin/live-hooks/useLiveCoPilot.d.ts +0 -28
  49. package/bin/live-hooks/useLiveCoPilot.d.ts.map +0 -1
  50. package/bin/live-hooks/useLiveCoPilot.js +0 -178
  51. package/bin/live-hooks/useLiveCoPilot.js.map +0 -1
  52. package/bin/live-hooks/useLiveEvent.d.ts +0 -22
  53. package/bin/live-hooks/useLiveEvent.d.ts.map +0 -1
  54. package/bin/live-hooks/useLiveEvent.js +0 -86
  55. package/bin/live-hooks/useLiveEvent.js.map +0 -1
  56. package/bin/live-hooks/useLivePresence.d.ts +0 -26
  57. package/bin/live-hooks/useLivePresence.d.ts.map +0 -1
  58. package/bin/live-hooks/useLivePresence.js +0 -93
  59. package/bin/live-hooks/useLivePresence.js.map +0 -1
  60. package/bin/live-hooks/useLiveState.d.ts +0 -19
  61. package/bin/live-hooks/useLiveState.d.ts.map +0 -1
  62. package/bin/live-hooks/useLiveState.js +0 -61
  63. package/bin/live-hooks/useLiveState.js.map +0 -1
  64. package/bin/live-hooks/useLiveTimer.d.ts +0 -8
  65. package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
  66. package/bin/live-hooks/useLiveTimer.js +0 -132
  67. package/bin/live-hooks/useLiveTimer.js.map +0 -1
  68. package/bin/live-hooks/useMediaSynchronizer.d.ts +0 -23
  69. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
  70. package/bin/live-hooks/useMediaSynchronizer.js +0 -162
  71. package/bin/live-hooks/useMediaSynchronizer.js.map +0 -1
  72. package/bin/live-share-turbo/AzureTurboClient.d.ts +0 -39
  73. package/bin/live-share-turbo/AzureTurboClient.d.ts.map +0 -1
  74. package/bin/live-share-turbo/AzureTurboClient.js +0 -56
  75. package/bin/live-share-turbo/AzureTurboClient.js.map +0 -1
  76. package/bin/live-share-turbo/LiveShareTurboClient.d.ts +0 -53
  77. package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +0 -1
  78. package/bin/live-share-turbo/LiveShareTurboClient.js +0 -69
  79. package/bin/live-share-turbo/LiveShareTurboClient.js.map +0 -1
  80. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +0 -31
  81. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +0 -1
  82. package/bin/live-share-turbo/dds-objects/TurboDataObject.js +0 -75
  83. package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +0 -1
  84. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +0 -48
  85. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +0 -1
  86. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +0 -104
  87. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +0 -1
  88. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +0 -28
  89. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +0 -1
  90. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +0 -68
  91. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +0 -1
  92. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +0 -60
  93. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +0 -1
  94. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +0 -111
  95. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +0 -1
  96. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +0 -77
  97. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +0 -1
  98. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +0 -137
  99. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +0 -1
  100. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +0 -30
  101. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +0 -1
  102. package/bin/live-share-turbo/dds-objects/TurboLiveState.js +0 -74
  103. package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +0 -1
  104. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +0 -61
  105. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +0 -1
  106. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +0 -108
  107. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +0 -1
  108. package/bin/live-share-turbo/dds-objects/index.d.ts +0 -8
  109. package/bin/live-share-turbo/dds-objects/index.d.ts.map +0 -1
  110. package/bin/live-share-turbo/dds-objects/index.js +0 -8
  111. package/bin/live-share-turbo/dds-objects/index.js.map +0 -1
  112. package/bin/live-share-turbo/index.d.ts +0 -5
  113. package/bin/live-share-turbo/index.d.ts.map +0 -1
  114. package/bin/live-share-turbo/index.js +0 -5
  115. package/bin/live-share-turbo/index.js.map +0 -1
  116. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +0 -15
  117. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +0 -1
  118. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +0 -2
  119. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +0 -1
  120. package/bin/live-share-turbo/interfaces/index.d.ts +0 -3
  121. package/bin/live-share-turbo/interfaces/index.d.ts.map +0 -1
  122. package/bin/live-share-turbo/interfaces/index.js +0 -3
  123. package/bin/live-share-turbo/interfaces/index.js.map +0 -1
  124. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +0 -39
  125. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +0 -1
  126. package/bin/live-share-turbo/internals/FluidTurboClient.js +0 -121
  127. package/bin/live-share-turbo/internals/FluidTurboClient.js.map +0 -1
  128. package/bin/live-share-turbo/internals/index.d.ts +0 -2
  129. package/bin/live-share-turbo/internals/index.d.ts.map +0 -1
  130. package/bin/live-share-turbo/internals/index.js +0 -2
  131. package/bin/live-share-turbo/internals/index.js.map +0 -1
  132. package/bin/live-share-turbo/internals/types.d.ts +0 -4
  133. package/bin/live-share-turbo/internals/types.d.ts.map +0 -1
  134. package/bin/live-share-turbo/internals/types.js +0 -2
  135. package/bin/live-share-turbo/internals/types.js.map +0 -1
  136. package/bin/providers/AzureProvider.d.ts +0 -34
  137. package/bin/providers/AzureProvider.d.ts.map +0 -1
  138. package/bin/providers/AzureProvider.js +0 -102
  139. package/bin/providers/AzureProvider.js.map +0 -1
  140. package/bin/providers/FluidContextProvider.d.ts +0 -34
  141. package/bin/providers/FluidContextProvider.d.ts.map +0 -1
  142. package/bin/providers/FluidContextProvider.js +0 -99
  143. package/bin/providers/FluidContextProvider.js.map +0 -1
  144. package/bin/providers/LiveShareContextProvider.d.ts +0 -42
  145. package/bin/providers/LiveShareContextProvider.d.ts.map +0 -1
  146. package/bin/providers/LiveShareContextProvider.js +0 -63
  147. package/bin/providers/LiveShareContextProvider.js.map +0 -1
  148. package/bin/providers/LiveShareProvider.d.ts +0 -42
  149. package/bin/providers/LiveShareProvider.d.ts.map +0 -1
  150. package/bin/providers/LiveShareProvider.js +0 -66
  151. package/bin/providers/LiveShareProvider.js.map +0 -1
  152. package/bin/providers/index.d.ts +0 -3
  153. package/bin/providers/index.d.ts.map +0 -1
  154. package/bin/providers/index.js +0 -3
  155. package/bin/providers/index.js.map +0 -1
  156. package/bin/shared-hooks/index.d.ts +0 -5
  157. package/bin/shared-hooks/index.d.ts.map +0 -1
  158. package/bin/shared-hooks/index.js +0 -5
  159. package/bin/shared-hooks/index.js.map +0 -1
  160. package/bin/shared-hooks/useDynamicDDS.d.ts +0 -19
  161. package/bin/shared-hooks/useDynamicDDS.d.ts.map +0 -1
  162. package/bin/shared-hooks/useDynamicDDS.js +0 -68
  163. package/bin/shared-hooks/useDynamicDDS.js.map +0 -1
  164. package/bin/shared-hooks/useLockedTask.d.ts +0 -11
  165. package/bin/shared-hooks/useLockedTask.d.ts.map +0 -1
  166. package/bin/shared-hooks/useLockedTask.js +0 -82
  167. package/bin/shared-hooks/useLockedTask.js.map +0 -1
  168. package/bin/shared-hooks/useSharedMap.d.ts +0 -22
  169. package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
  170. package/bin/shared-hooks/useSharedMap.js +0 -106
  171. package/bin/shared-hooks/useSharedMap.js.map +0 -1
  172. package/bin/shared-hooks/useSharedState.d.ts +0 -21
  173. package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
  174. package/bin/shared-hooks/useSharedState.js +0 -63
  175. package/bin/shared-hooks/useSharedState.js.map +0 -1
  176. package/bin/shared-hooks/useTaskManager.d.ts +0 -13
  177. package/bin/shared-hooks/useTaskManager.d.ts.map +0 -1
  178. package/bin/shared-hooks/useTaskManager.js +0 -86
  179. package/bin/shared-hooks/useTaskManager.js.map +0 -1
  180. package/bin/types/ActionTypes.d.ts +0 -30
  181. package/bin/types/ActionTypes.d.ts.map +0 -1
  182. package/bin/types/ActionTypes.js +0 -6
  183. package/bin/types/ActionTypes.js.map +0 -1
  184. package/bin/types/PropTypes.d.ts +0 -8
  185. package/bin/types/PropTypes.d.ts.map +0 -1
  186. package/bin/types/PropTypes.js +0 -6
  187. package/bin/types/PropTypes.js.map +0 -1
  188. package/bin/types/ResultTypes.d.ts +0 -163
  189. package/bin/types/ResultTypes.d.ts.map +0 -1
  190. package/bin/types/ResultTypes.js +0 -6
  191. package/bin/types/ResultTypes.js.map +0 -1
  192. package/bin/types/index.d.ts +0 -4
  193. package/bin/types/index.d.ts.map +0 -1
  194. package/bin/types/index.js +0 -4
  195. package/bin/types/index.js.map +0 -1
  196. package/bin/utils/getContainerSchema.d.ts +0 -8
  197. package/bin/utils/getContainerSchema.d.ts.map +0 -1
  198. package/bin/utils/getContainerSchema.js +0 -41
  199. package/bin/utils/getContainerSchema.js.map +0 -1
  200. package/bin/utils/index.d.ts +0 -2
  201. package/bin/utils/index.d.ts.map +0 -1
  202. package/bin/utils/index.js +0 -2
  203. package/bin/utils/index.js.map +0 -1
  204. package/bin/utils/type-check.d.ts +0 -15
  205. package/bin/utils/type-check.d.ts.map +0 -1
  206. package/bin/utils/type-check.js +0 -54
  207. package/bin/utils/type-check.js.map +0 -1
  208. package/src/shared-hooks/useTaskManager.ts +0 -82
  209. package/tinylicious.log +0 -4
@@ -1,28 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { UserMeetingRole } from "@microsoft/live-share";
6
- import { IUseLiveCoPilotResults } from "../types";
7
- /**
8
- * React hook for using a Live Share Turbo `LiveCoPilot`. Intended for use with OpenAI's Completion API.
9
- *
10
- * @remarks
11
- * Use this hook to set up an `LiveCoPilot` object, which is used for using AI completions collaboratively at minimal cost.
12
- *
13
- * @param uniqueKey the unique key for the `LiveCoPilot`. If one does not yet exist, a new one.
14
- * @param onGetCompletion React useCallback function that returns a Promise<string> for the latest `promptValue`. Function is intended to
15
- * communicate with a backend API that uses OpenAI's Completion API.
16
- * @param allowedRoles Optional. The meeting roles eligible to send events through this object.
17
- * @param defaultPromptValue Optional. Text that sets the default prompt value. Default value is an empty string.
18
- * @param autoCompletions Optional. Stateful boolean that when true, will automatically send completions when the `promptValue` changes. Default value is true.
19
- * @param debounceDelayMilliseconds Optional. Stateful number that changes the debounce interval when `autoCompletions` is true. Default value is 1000.
20
- * @param lockPrompt Optional. Stateful boolean that when true, will restrict prompt changes to only the user with `haveCompletionLock` set to true. Default
21
- * value is false.
22
- * @param lockCompletion Optional. Stateful boolean that when true, will restrict manual completion changes to only the user with `haveCompletionLock`
23
- * set to true. This does not impact the `autoCompletions` setting, because `autoCompletions` already has this behavior. Default value is false.
24
- *
25
- * @returns IUseLiveCoPilotResults object that contains stateful responses and callback methods from `LiveCoPilot`.
26
- */
27
- export declare const useLiveCoPilot: (uniqueKey: string, onGetCompletion: (promptValue: string) => Promise<string>, allowedRoles?: UserMeetingRole[], defaultPromptValue?: string, autoCompletions?: boolean, debounceDelayMilliseconds?: number, lockPrompt?: boolean, lockCompletion?: boolean) => IUseLiveCoPilotResults;
28
- //# sourceMappingURL=useLiveCoPilot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveCoPilot.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveCoPilot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,cACZ,MAAM,iCACc,MAAM,KAAK,QAAQ,MAAM,CAAC,iBAC1C,eAAe,EAAE,uBACX,MAAM,oBACT,OAAO,8BACG,MAAM,eACrB,OAAO,mBACH,OAAO,KACzB,sBA4LF,CAAC"}
@@ -1,178 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- import { LiveCoPilot, LiveCoPilotEvents } from "@microsoft/live-share-turbo";
15
- import React from "react";
16
- import { useDynamicDDS } from "../shared-hooks";
17
- /**
18
- * React hook for using a Live Share Turbo `LiveCoPilot`. Intended for use with OpenAI's Completion API.
19
- *
20
- * @remarks
21
- * Use this hook to set up an `LiveCoPilot` object, which is used for using AI completions collaboratively at minimal cost.
22
- *
23
- * @param uniqueKey the unique key for the `LiveCoPilot`. If one does not yet exist, a new one.
24
- * @param onGetCompletion React useCallback function that returns a Promise<string> for the latest `promptValue`. Function is intended to
25
- * communicate with a backend API that uses OpenAI's Completion API.
26
- * @param allowedRoles Optional. The meeting roles eligible to send events through this object.
27
- * @param defaultPromptValue Optional. Text that sets the default prompt value. Default value is an empty string.
28
- * @param autoCompletions Optional. Stateful boolean that when true, will automatically send completions when the `promptValue` changes. Default value is true.
29
- * @param debounceDelayMilliseconds Optional. Stateful number that changes the debounce interval when `autoCompletions` is true. Default value is 1000.
30
- * @param lockPrompt Optional. Stateful boolean that when true, will restrict prompt changes to only the user with `haveCompletionLock` set to true. Default
31
- * value is false.
32
- * @param lockCompletion Optional. Stateful boolean that when true, will restrict manual completion changes to only the user with `haveCompletionLock`
33
- * set to true. This does not impact the `autoCompletions` setting, because `autoCompletions` already has this behavior. Default value is false.
34
- *
35
- * @returns IUseLiveCoPilotResults object that contains stateful responses and callback methods from `LiveCoPilot`.
36
- */
37
- export const useLiveCoPilot = (uniqueKey, onGetCompletion, allowedRoles, defaultPromptValue, autoCompletions, debounceDelayMilliseconds, lockPrompt, lockCompletion) => {
38
- /**
39
- * @see IUseLiveCoPilotResults["promptValue"]
40
- */
41
- const [promptValue, setPromptValue] = React.useState("");
42
- /**
43
- * @see IUseLiveCoPilotResults["completionValue"]
44
- */
45
- const [completionValue, setCompletionValue] = React.useState();
46
- /**
47
- * @see IUseLiveCoPilotResults["haveCompletionLock"]
48
- */
49
- const [haveCompletionLock, setHaveCompletionLock] = React.useState(false);
50
- /**
51
- * User facing: dynamically load the DDS for the given unique key.
52
- */
53
- const { dds: liveCoPilot } = useDynamicDDS(uniqueKey, LiveCoPilot);
54
- /**
55
- * @see IUseLiveCoPilotResults["changePrompt"]
56
- */
57
- const changePrompt = React.useCallback((value) => {
58
- if (liveCoPilot === undefined) {
59
- console.error(new Error("Cannot call emitEvent when liveEvent is undefined"));
60
- return;
61
- }
62
- if (!liveCoPilot.isInitialized) {
63
- console.error(new Error("Cannot call emitEvent while liveEvent is not started"));
64
- return;
65
- }
66
- return liveCoPilot.changePrompt(value);
67
- }, [liveCoPilot]);
68
- /**
69
- * @see IUseLiveCoPilotResults["changePrompt"]
70
- */
71
- const sendCompletion = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
72
- if (liveCoPilot === undefined) {
73
- throw new Error("Cannot call sendCompletion while `liveCoPilot` is undefined");
74
- }
75
- if (!liveCoPilot.isInitialized) {
76
- throw new Error("Cannot call sendCompletion while `liveCoPilot` is not initialized");
77
- }
78
- return liveCoPilot.sendCompletion();
79
- }), [liveCoPilot]);
80
- /**
81
- * Sets up the `LiveCoPilot` instance.
82
- */
83
- React.useEffect(() => {
84
- if (liveCoPilot === undefined)
85
- return;
86
- // Register event listeners
87
- const onPromptChanged = (promptValue, local, completionValuePromise) => __awaiter(void 0, void 0, void 0, function* () {
88
- setPromptValue(promptValue);
89
- if (!liveCoPilot.haveValidCompletionValue) {
90
- setCompletionValue(undefined);
91
- }
92
- try {
93
- const completionValue = yield completionValuePromise;
94
- setCompletionValue(completionValue);
95
- }
96
- catch (_a) {
97
- // We do nothing, since this typically fails as a result of a new prompt value replacing the old on, permissions changing, etc.
98
- }
99
- });
100
- const onLockGranted = () => {
101
- setHaveCompletionLock(true);
102
- };
103
- const onLockLost = () => {
104
- setHaveCompletionLock(true);
105
- };
106
- liveCoPilot.on(LiveCoPilotEvents.promptChanged, onPromptChanged);
107
- liveCoPilot.on(LiveCoPilotEvents.lockGranted, onLockGranted);
108
- liveCoPilot.on(LiveCoPilotEvents.lockLost, onLockLost);
109
- if (!liveCoPilot.isInitialized) {
110
- // Initialize the LiveCoPilot instance
111
- liveCoPilot.initialize(onGetCompletion, allowedRoles, defaultPromptValue);
112
- }
113
- return () => {
114
- // on unmount, remove event listeners
115
- liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.off(LiveCoPilotEvents.promptChanged, onPromptChanged);
116
- liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.off(LiveCoPilotEvents.lockGranted, onLockGranted);
117
- liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.off(LiveCoPilotEvents.lockLost, onLockLost);
118
- };
119
- }, [liveCoPilot]);
120
- /**
121
- * Sets the onGetCompletion of the `liveCoPilot` based on the 'onGetCompletion' prop
122
- */
123
- React.useEffect(() => {
124
- if ((liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.isInitialized) === true &&
125
- onGetCompletion !== undefined) {
126
- liveCoPilot.onGetCompletion = onGetCompletion;
127
- }
128
- }, [liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.isInitialized, onGetCompletion]);
129
- /**
130
- * Sets the autoCompletions of the `liveCoPilot` based on the 'autoCompletions' prop
131
- */
132
- React.useEffect(() => {
133
- if (liveCoPilot !== undefined &&
134
- autoCompletions !== undefined &&
135
- liveCoPilot.autoCompletions !== autoCompletions) {
136
- liveCoPilot.autoCompletions = autoCompletions;
137
- }
138
- }, [liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.autoCompletions, autoCompletions]);
139
- /**
140
- * Sets the debounceDelayMilliseconds of the `liveCoPilot` based on the 'debounceDelayMilliseconds' prop
141
- */
142
- React.useEffect(() => {
143
- if (liveCoPilot !== undefined &&
144
- debounceDelayMilliseconds !== undefined &&
145
- liveCoPilot.debounceDelayMilliseconds !== debounceDelayMilliseconds) {
146
- liveCoPilot.debounceDelayMilliseconds = debounceDelayMilliseconds;
147
- }
148
- }, [liveCoPilot, debounceDelayMilliseconds]);
149
- /**
150
- * Sets the lockPrompt of the `liveCoPilot` based on the 'lockPrompt' prop
151
- */
152
- React.useEffect(() => {
153
- if (liveCoPilot !== undefined &&
154
- lockPrompt !== undefined &&
155
- liveCoPilot.lockPrompt !== lockPrompt) {
156
- liveCoPilot.lockPrompt = lockPrompt;
157
- }
158
- }, [liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.lockPrompt, lockPrompt]);
159
- /**
160
- * Sets the lockCompletion of the `liveCoPilot` based on the 'lockCompletion' prop
161
- */
162
- React.useEffect(() => {
163
- if (liveCoPilot !== undefined &&
164
- lockCompletion !== undefined &&
165
- liveCoPilot.lockCompletion !== lockCompletion) {
166
- liveCoPilot.lockCompletion = lockCompletion;
167
- }
168
- }, [liveCoPilot === null || liveCoPilot === void 0 ? void 0 : liveCoPilot.lockCompletion, lockCompletion]);
169
- return {
170
- changePrompt,
171
- completionValue,
172
- haveCompletionLock,
173
- liveCoPilot,
174
- promptValue,
175
- sendCompletion,
176
- };
177
- };
178
- //# sourceMappingURL=useLiveCoPilot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveCoPilot.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveCoPilot.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAGH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC1B,SAAiB,EACjB,eAAyD,EACzD,YAAgC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U,KAAK,UAAU,EACvC;YACE,WAAW,CAAC,UAAU,GAAG,UAAU,CAAC;SACvC;IACL,CAAC,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAE1C;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IACI,WAAW,KAAK,SAAS;YACzB,cAAc,KAAK,SAAS;YAC5B,WAAW,CAAC,cAAc,KAAK,cAAc,EAC/C;YACE,WAAW,CAAC,cAAc,GAAG,cAAc,CAAC;SAC/C;IACL,CAAC,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;IAElD,OAAO;QACH,YAAY;QACZ,eAAe;QACf,kBAAkB;QAClB,WAAW;QACX,WAAW;QACX,cAAc;KACjB,CAAC;AACN,CAAC,CAAC"}
@@ -1,22 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { UserMeetingRole } from "@microsoft/live-share";
6
- import { IUseLiveEventResults, OnReceivedLiveEventAction } from "../types";
7
- /**
8
- * React hook for using a Live Share `LiveEvent`.
9
- *
10
- * @remarks
11
- * Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
12
- * such as when sending push notifications or reactions.
13
- *
14
- * @template TEvent Optional typing for events sent & received. Default is `object` type.
15
- * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
16
- * will be created, otherwise it will use the existing one.
17
- * @param allowedRoles Optional. The meeting roles eligible to send events through this object.
18
- * @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
19
- * @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
20
- */
21
- export declare function useLiveEvent<TEvent extends object = object>(uniqueKey: string, allowedRoles?: UserMeetingRole[], onReceivedEvent?: OnReceivedLiveEventAction<TEvent>): IUseLiveEventResults<TEvent>;
22
- //# sourceMappingURL=useLiveEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveEvent.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EACpB,yBAAyB,EAE5B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EACvD,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,eAAe,CAAC,EAAE,yBAAyB,CAAC,MAAM,CAAC,GACpD,oBAAoB,CAAC,MAAM,CAAC,CA+E9B"}
@@ -1,86 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { LiveEventEvents, LiveEvent, } from "@microsoft/live-share";
6
- import React from "react";
7
- import { useDynamicDDS } from "../shared-hooks";
8
- /**
9
- * React hook for using a Live Share `LiveEvent`.
10
- *
11
- * @remarks
12
- * Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
13
- * such as when sending push notifications or reactions.
14
- *
15
- * @template TEvent Optional typing for events sent & received. Default is `object` type.
16
- * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
17
- * will be created, otherwise it will use the existing one.
18
- * @param allowedRoles Optional. The meeting roles eligible to send events through this object.
19
- * @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
20
- * @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
21
- */
22
- export function useLiveEvent(uniqueKey, allowedRoles, onReceivedEvent) {
23
- /**
24
- * Stateful latest event (user facing) and its non-user-facing setter method.
25
- */
26
- const [latestEvent, setLatestReceived] = React.useState();
27
- /**
28
- * Reference for all received/sent events. The current value of this is user-facing. Because
29
- * this is always set at the same time as latestEvent, it is effectively a stateful value.
30
- */
31
- const allEventsRef = React.useRef([]);
32
- /**
33
- * User facing: dynamically load the DDS for the given unique key.
34
- */
35
- const { dds: liveEvent } = useDynamicDDS(uniqueKey, LiveEvent);
36
- /**
37
- * User facing: callback to send event through `LiveEvent`
38
- */
39
- const sendEvent = React.useCallback((event) => {
40
- if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined) {
41
- console.error(new Error("Cannot call emitEvent when liveEvent is undefined"));
42
- return;
43
- }
44
- if (!liveEvent.isInitialized) {
45
- console.error(new Error("Cannot call emitEvent while liveEvent is not started"));
46
- return;
47
- }
48
- liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.sendEvent(event);
49
- }, [liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized]);
50
- /**
51
- * Setup change listeners and start `LiveEvent` if needed
52
- */
53
- React.useEffect(() => {
54
- if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined)
55
- return;
56
- // Register event listener
57
- const onEventReceived = (event, local) => {
58
- // If developer passed the optional onReceivedEvent callback, we
59
- // call it.
60
- onReceivedEvent === null || onReceivedEvent === void 0 ? void 0 : onReceivedEvent(event, local);
61
- // Set the received event to our local state
62
- const received = {
63
- event: event,
64
- local,
65
- };
66
- allEventsRef.current = [...allEventsRef.current, received];
67
- setLatestReceived(received);
68
- };
69
- liveEvent.on(LiveEventEvents.received, onEventReceived);
70
- if (!liveEvent.isInitialized) {
71
- // Start live event
72
- liveEvent.initialize(allowedRoles);
73
- }
74
- return () => {
75
- // on unmount, remove event listeners
76
- liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.off(LiveEventEvents.received, onEventReceived);
77
- };
78
- }, [liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized]);
79
- return {
80
- latestEvent,
81
- allEvents: allEventsRef.current,
82
- sendEvent,
83
- liveEvent,
84
- };
85
- }
86
- //# sourceMappingURL=useLiveEvent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,eAAe,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,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CAAY,SAAS,EAAE,SAAS,CAAC,CAAC;IAE1E;;OAEG;IACH,MAAM,SAAS,GAAgC,KAAK,CAAC,WAAW,CAC5D,CAAC,KAAa,EAAE,EAAE;QACd,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,aAAa,MAAK,SAAS,EAAE;YACxC,OAAO,CAAC,KAAK,CACT,IAAI,KAAK,CACL,mDAAmD,CACtD,CACJ,CAAC;YACF,OAAO;SACV;QACD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,OAAO,CAAC,KAAK,CACT,IAAI,KAAK,CACL,sDAAsD,CACzD,CACJ,CAAC;YACF,OAAO;SACV;QACD,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,EACD,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,aAAa,CAAC,CAC7B,CAAC;IAEF;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,aAAa,MAAK,SAAS;YACtC,OAAO;QACX,0BAA0B;QAC1B,MAAM,eAAe,GAAG,CAAC,KAAU,EAAE,KAAc,EAAE,EAAE;YACnD,gEAAgE;YAChE,WAAW;YACX,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,KAAe,EAAE,KAAK,CAAC,CAAC;YAC1C,4CAA4C;YAC5C,MAAM,QAAQ,GAA8B;gBACxC,KAAK,EAAE,KAAe;gBACtB,KAAK;aACR,CAAC;YACF,YAAY,CAAC,OAAO,GAAG,CAAC,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC3D,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC;QACF,SAAS,CAAC,EAAE,CAAC,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACxD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,mBAAmB;YACnB,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;SACtC;QAED,OAAO,GAAG,EAAE;YACR,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,aAAT,SAAS,uBAAT,SAAS,CAAE,aAAa,CAAC,CAAC,CAAC;IAE/B,OAAO;QACH,WAAW;QACX,SAAS,EAAE,YAAY,CAAC,OAAO;QAC/B,SAAS;QACT,SAAS;KACZ,CAAC;AACN,CAAC"}
@@ -1,26 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { PresenceState } 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
-
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 uniqueKey Optional. The unique key for `LivePresence`. If one does not yet exist, a new one
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>(userId?: string | undefined, initialData?: TData | undefined, initialPresenceState?: PresenceState, uniqueKey?: string): IUseLivePresenceResults<TData>;
26
- //# sourceMappingURL=useLivePresence.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLivePresence.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,aAAa,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACzD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,EAC3B,WAAW,CAAC,EAAE,KAAK,GAAG,SAAS,EAC/B,oBAAoB,GAAE,aAAoC,EAC1D,SAAS,GAAE,MAAyB,GACrC,uBAAuB,CAAC,KAAK,CAAC,CAsFhC"}
@@ -1,93 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { PresenceState, LivePresence, } from "@microsoft/live-share";
6
- import React from "react";
7
- import { useDynamicDDS } from "../shared-hooks";
8
- /**
9
- * React hook for using a Live Share `LivePresence`.
10
- *
11
- * @remarks
12
- * Use this hook if you want to track presence for who is currently using this component, such as
13
- * who is online or who is viewing a specific document. With presence, you can sent along any custom
14
- * user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
15
- *
16
- * @template TData Optional typing for the custom user presence data object. Default is `object` type.
17
-
18
- * @param userId Optional. The unique ID for a user. If none is provided, a random UUID will be generated.
19
- * @param initialData Optional. Initial presence data object for the user.
20
- * @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
21
- * @param uniqueKey Optional. The unique key for `LivePresence`. If one does not yet exist, a new one
22
- * will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
23
- * @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
24
- * to update the local user's presence and the `LivePresence` Fluid object.
25
- */
26
- export function useLivePresence(userId, initialData, initialPresenceState = PresenceState.online, uniqueKey = ":<dds-default>") {
27
- /**
28
- * Stateful all user presence list and its non-user-facing setter method.
29
- */
30
- const [allUsers, setAllUsers] = React.useState([]);
31
- /**
32
- * User facing: dynamically load the DDS for the given unique key.
33
- */
34
- const { dds: livePresence } = useDynamicDDS(uniqueKey, (LivePresence));
35
- /**
36
- * User facing: list of non-local user's presence objects.
37
- */
38
- const otherUsers = React.useMemo(() => {
39
- return [...allUsers.filter((user) => !user.isLocalUser)];
40
- }, [allUsers]);
41
- /**
42
- * User facing: local user's presence object.
43
- */
44
- const localUser = React.useMemo(() => {
45
- return allUsers.find((user) => user.isLocalUser);
46
- }, [allUsers]);
47
- /**
48
- * User facing: callback to update the local user's presence.
49
- */
50
- const updatePresence = React.useCallback((state, data) => {
51
- if (!livePresence) {
52
- console.error(new Error("Cannot call updatePresence when presence is undefined"));
53
- return;
54
- }
55
- if (!livePresence.isInitialized) {
56
- console.error(new Error("Cannot call updatePresence while presence is not started"));
57
- return;
58
- }
59
- livePresence.updatePresence(state, data);
60
- }, [livePresence]);
61
- /**
62
- * Setup change listeners and start `LivePresence` if needed
63
- */
64
- React.useEffect(() => {
65
- if (livePresence === undefined)
66
- return;
67
- const onPresenceChanged = () => {
68
- const updatedLocalUsers = [];
69
- livePresence === null || livePresence === void 0 ? void 0 : livePresence.forEach((user) => {
70
- updatedLocalUsers.push(user);
71
- });
72
- setAllUsers(updatedLocalUsers);
73
- };
74
- livePresence.on("presenceChanged", onPresenceChanged);
75
- if (!livePresence.isInitialized) {
76
- livePresence.initialize(userId, initialData, initialPresenceState);
77
- }
78
- else {
79
- onPresenceChanged();
80
- }
81
- return () => {
82
- livePresence === null || livePresence === void 0 ? void 0 : livePresence.off("presenceChanged", onPresenceChanged);
83
- };
84
- }, [livePresence]);
85
- return {
86
- localUser,
87
- otherUsers,
88
- allUsers,
89
- livePresence,
90
- updatePresence,
91
- };
92
- }
93
- //# sourceMappingURL=useLivePresence.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLivePresence.js","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,aAAa,EACb,YAAY,GACf,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,MAA2B,EAC3B,WAA+B,EAC/B,uBAAsC,aAAa,CAAC,MAAM,EAC1D,YAAoB,gBAAgB;IAEpC;;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,CAAsB,SAAS,EAAE,CAAA,YAAmB,CAAA,CAAC,CAAC;IAEjG;;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,CAAC,CAAC,CAAC;YACH,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACnC,CAAC,CAAC;QACF,YAAY,CAAC,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAEtD,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE;YAC7B,YAAY,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,oBAAoB,CAAC,CAAC;SACtE;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"}
@@ -1,19 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { UserMeetingRole } from "@microsoft/live-share";
6
- import { 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
- */
18
- export declare function useLiveState<TState = any>(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction<TState>];
19
- //# sourceMappingURL=useLiveState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveState.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CACxB,MAAM,GAAG,GAAG,EAEZ,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC,CA2DtC"}
@@ -1,61 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { LiveState } from "@microsoft/live-share";
6
- import React from "react";
7
- import { useDynamicDDS } from "../shared-hooks";
8
- /**
9
- * React hook for using a Live Share `LiveState`.
10
- *
11
- * @remarks
12
- * Use this hook if you want to synchronize app state that will reset when all users leave the session.
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
- */
19
- export function useLiveState(uniqueKey, initialState, allowedRoles) {
20
- const [currentState, setCurrentState] = React.useState(initialState);
21
- /**
22
- * User facing: dynamically load the DDS for the given unique key.
23
- */
24
- const { dds: liveState } = useDynamicDDS(uniqueKey, (LiveState));
25
- /**
26
- * Change state callback that is user facing
27
- */
28
- const setState = React.useCallback((state) => {
29
- if (!liveState) {
30
- console.error(new Error("Cannot call changeState when liveState is undefined"));
31
- return;
32
- }
33
- if (!liveState.isInitialized) {
34
- console.error(new Error("Cannot call changeState while liveState is not started"));
35
- return;
36
- }
37
- liveState.set(state);
38
- }, [liveState]);
39
- /**
40
- * Setup change listeners and start `LiveState` if needed
41
- */
42
- React.useEffect(() => {
43
- if (liveState === undefined)
44
- return;
45
- const onStateChanged = (state) => {
46
- setCurrentState(state);
47
- };
48
- liveState.on("stateChanged", onStateChanged);
49
- if (!liveState.isInitialized) {
50
- liveState.initialize(initialState, allowedRoles);
51
- }
52
- if (JSON.stringify(liveState.state) !== JSON.stringify(initialState)) {
53
- onStateChanged(liveState.state);
54
- }
55
- return () => {
56
- liveState === null || liveState === void 0 ? void 0 : liveState.off("stateChanged", onStateChanged);
57
- };
58
- }, [liveState]);
59
- return [currentState, setState];
60
- }
61
- //# sourceMappingURL=useLiveState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveState.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAGxB,SAAiB,EACjB,YAAoB,EACpB,YAAgC;IAEhC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAS,YAAY,CAAC,CAAC;IAC7E;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CACpC,SAAS,EACT,CAAA,SAAiB,CAAA,CACpB,CAAC;IAEF;;OAEG;IACH,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAC9B,CAAC,KAAa,EAAE,EAAE;QACd,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO,CAAC,KAAK,CACT,IAAI,KAAK,CACL,qDAAqD,CACxD,CACJ,CAAC;YACF,OAAO;SACV;QACD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,OAAO,CAAC,KAAK,CACT,IAAI,KAAK,CACL,wDAAwD,CAC3D,CACJ,CAAC;YACF,OAAO;SACV;QACD,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC,EACD,CAAC,SAAS,CAAC,CACd,CAAC;IAEF;;OAEG;IACH,KAAK,CAAC,SAAS,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,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,SAAS,CAAC,UAAU,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;SACpD;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE;YAClE,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACnC;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,CAAC,CAAC;AACpC,CAAC"}
@@ -1,8 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { UserMeetingRole } from "@microsoft/live-share";
6
- import { 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
@@ -1 +0,0 @@
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,CAqJtB"}