@microsoft/live-share-react 1.0.0-preview.8 → 1.0.1-preview.1

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 (220) hide show
  1. package/README.md +99 -34
  2. package/bin/index.d.ts +6 -6
  3. package/bin/index.js +6 -6
  4. package/bin/interfaces/LiveInterfaceExtensions.d.ts +25 -8
  5. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -1
  6. package/bin/interfaces/LiveInterfaceExtensions.js +5 -5
  7. package/bin/interfaces/index.d.ts +1 -1
  8. package/bin/interfaces/index.js +1 -1
  9. package/bin/internal/errors.d.ts +26 -0
  10. package/bin/internal/errors.d.ts.map +1 -0
  11. package/bin/internal/errors.js +39 -0
  12. package/bin/internal/errors.js.map +1 -0
  13. package/bin/internal/index.d.ts +4 -0
  14. package/bin/internal/index.d.ts.map +1 -0
  15. package/bin/internal/index.js +4 -0
  16. package/bin/internal/index.js.map +1 -0
  17. package/bin/internal/type-guards.d.ts +6 -0
  18. package/bin/internal/type-guards.d.ts.map +1 -0
  19. package/bin/internal/type-guards.js +8 -0
  20. package/bin/internal/type-guards.js.map +1 -0
  21. package/bin/{internal-hooks → internal}/useSharedStateRegistry.d.ts +30 -30
  22. package/bin/internal/useSharedStateRegistry.d.ts.map +1 -0
  23. package/bin/{internal-hooks → internal}/useSharedStateRegistry.js +101 -99
  24. package/bin/internal/useSharedStateRegistry.js.map +1 -0
  25. package/bin/live-hooks/index.d.ts +6 -6
  26. package/bin/live-hooks/index.js +6 -6
  27. package/bin/live-hooks/useLiveCanvas.d.ts +27 -27
  28. package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -1
  29. package/bin/live-hooks/useLiveCanvas.js +158 -166
  30. package/bin/live-hooks/useLiveCanvas.js.map +1 -1
  31. package/bin/live-hooks/useLiveEvent.d.ts +21 -21
  32. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
  33. package/bin/live-hooks/useLiveEvent.js +100 -85
  34. package/bin/live-hooks/useLiveEvent.js.map +1 -1
  35. package/bin/live-hooks/useLivePresence.d.ts +25 -25
  36. package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
  37. package/bin/live-hooks/useLivePresence.js +106 -92
  38. package/bin/live-hooks/useLivePresence.js.map +1 -1
  39. package/bin/live-hooks/useLiveState.d.ts +19 -19
  40. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  41. package/bin/live-hooks/useLiveState.js +79 -70
  42. package/bin/live-hooks/useLiveState.js.map +1 -1
  43. package/bin/live-hooks/useLiveTimer.d.ts +7 -7
  44. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
  45. package/bin/live-hooks/useLiveTimer.js +150 -131
  46. package/bin/live-hooks/useLiveTimer.js.map +1 -1
  47. package/bin/live-hooks/useMediaSynchronizer.d.ts +22 -22
  48. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
  49. package/bin/live-hooks/useMediaSynchronizer.js +206 -161
  50. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
  51. package/bin/providers/AzureProvider.d.ts +33 -33
  52. package/bin/providers/AzureProvider.d.ts.map +1 -1
  53. package/bin/providers/AzureProvider.js +101 -101
  54. package/bin/providers/AzureProvider.js.map +1 -1
  55. package/bin/providers/LiveShareProvider.d.ts +62 -41
  56. package/bin/providers/LiveShareProvider.d.ts.map +1 -1
  57. package/bin/providers/LiveShareProvider.js +68 -65
  58. package/bin/providers/LiveShareProvider.js.map +1 -1
  59. package/bin/providers/index.d.ts +2 -2
  60. package/bin/providers/index.js +2 -2
  61. package/bin/shared-hooks/index.d.ts +3 -4
  62. package/bin/shared-hooks/index.d.ts.map +1 -1
  63. package/bin/shared-hooks/index.js +3 -4
  64. package/bin/shared-hooks/index.js.map +1 -1
  65. package/bin/shared-hooks/useDynamicDDS.d.ts +18 -18
  66. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
  67. package/bin/shared-hooks/useDynamicDDS.js +67 -67
  68. package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
  69. package/bin/shared-hooks/useSharedMap.d.ts +21 -21
  70. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
  71. package/bin/shared-hooks/useSharedMap.js +112 -105
  72. package/bin/shared-hooks/useSharedMap.js.map +1 -1
  73. package/bin/shared-hooks/useSharedState.d.ts +20 -20
  74. package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
  75. package/bin/shared-hooks/useSharedState.js +72 -62
  76. package/bin/shared-hooks/useSharedState.js.map +1 -1
  77. package/bin/types/ActionTypes.d.ts +111 -29
  78. package/bin/types/ActionTypes.d.ts.map +1 -1
  79. package/bin/types/ActionTypes.js +5 -5
  80. package/bin/types/PropTypes.d.ts +7 -7
  81. package/bin/types/PropTypes.d.ts.map +1 -1
  82. package/bin/types/PropTypes.js +5 -5
  83. package/bin/types/ResultTypes.d.ts +174 -162
  84. package/bin/types/ResultTypes.d.ts.map +1 -1
  85. package/bin/types/ResultTypes.js +5 -5
  86. package/bin/types/index.d.ts +3 -3
  87. package/bin/types/index.js +3 -3
  88. package/bin/utils/index.d.ts +1 -1
  89. package/bin/utils/index.js +1 -1
  90. package/bin/utils/type-check.d.ts +14 -14
  91. package/bin/utils/type-check.js +53 -53
  92. package/package.json +18 -14
  93. package/src/interfaces/LiveInterfaceExtensions.ts +19 -2
  94. package/src/internal/errors.ts +48 -0
  95. package/src/internal/index.ts +3 -0
  96. package/src/internal/type-guards.ts +9 -0
  97. package/src/{internal-hooks → internal}/useSharedStateRegistry.ts +6 -5
  98. package/src/live-hooks/useLiveCanvas.ts +12 -20
  99. package/src/live-hooks/useLiveEvent.ts +41 -22
  100. package/src/live-hooks/useLivePresence.ts +52 -33
  101. package/src/live-hooks/useLiveState.ts +48 -53
  102. package/src/live-hooks/useLiveTimer.ts +50 -41
  103. package/src/live-hooks/useMediaSynchronizer.ts +108 -41
  104. package/src/providers/AzureProvider.tsx +3 -8
  105. package/src/providers/LiveShareProvider.tsx +46 -16
  106. package/src/shared-hooks/index.ts +0 -1
  107. package/src/shared-hooks/useDynamicDDS.ts +15 -8
  108. package/src/shared-hooks/useSharedMap.ts +48 -22
  109. package/src/shared-hooks/useSharedState.ts +15 -5
  110. package/src/types/ActionTypes.ts +100 -15
  111. package/src/types/ResultTypes.ts +23 -9
  112. package/bin/internal-hooks/index.d.ts +0 -2
  113. package/bin/internal-hooks/index.d.ts.map +0 -1
  114. package/bin/internal-hooks/index.js +0 -2
  115. package/bin/internal-hooks/index.js.map +0 -1
  116. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +0 -14
  117. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +0 -1
  118. package/bin/internal-hooks/useDynamicDDSRegistry.js +0 -142
  119. package/bin/internal-hooks/useDynamicDDSRegistry.js.map +0 -1
  120. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +0 -1
  121. package/bin/internal-hooks/useSharedStateRegistry.js.map +0 -1
  122. package/bin/internal-hooks/useStateRef.d.ts +0 -7
  123. package/bin/internal-hooks/useStateRef.d.ts.map +0 -1
  124. package/bin/internal-hooks/useStateRef.js +0 -15
  125. package/bin/internal-hooks/useStateRef.js.map +0 -1
  126. package/bin/live-hooks/useLiveAICompletion.d.ts +0 -29
  127. package/bin/live-hooks/useLiveAICompletion.d.ts.map +0 -1
  128. package/bin/live-hooks/useLiveAICompletion.js +0 -186
  129. package/bin/live-hooks/useLiveAICompletion.js.map +0 -1
  130. package/bin/live-hooks/useLiveCoPilot.d.ts +0 -28
  131. package/bin/live-hooks/useLiveCoPilot.d.ts.map +0 -1
  132. package/bin/live-hooks/useLiveCoPilot.js +0 -178
  133. package/bin/live-hooks/useLiveCoPilot.js.map +0 -1
  134. package/bin/live-share-turbo/AzureTurboClient.d.ts +0 -39
  135. package/bin/live-share-turbo/AzureTurboClient.d.ts.map +0 -1
  136. package/bin/live-share-turbo/AzureTurboClient.js +0 -56
  137. package/bin/live-share-turbo/AzureTurboClient.js.map +0 -1
  138. package/bin/live-share-turbo/LiveShareTurboClient.d.ts +0 -53
  139. package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +0 -1
  140. package/bin/live-share-turbo/LiveShareTurboClient.js +0 -69
  141. package/bin/live-share-turbo/LiveShareTurboClient.js.map +0 -1
  142. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +0 -31
  143. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +0 -1
  144. package/bin/live-share-turbo/dds-objects/TurboDataObject.js +0 -75
  145. package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +0 -1
  146. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +0 -48
  147. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +0 -1
  148. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +0 -104
  149. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +0 -1
  150. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +0 -28
  151. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +0 -1
  152. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +0 -68
  153. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +0 -1
  154. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +0 -60
  155. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +0 -1
  156. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +0 -111
  157. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +0 -1
  158. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +0 -77
  159. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +0 -1
  160. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +0 -137
  161. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +0 -1
  162. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +0 -30
  163. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +0 -1
  164. package/bin/live-share-turbo/dds-objects/TurboLiveState.js +0 -74
  165. package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +0 -1
  166. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +0 -61
  167. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +0 -1
  168. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +0 -108
  169. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +0 -1
  170. package/bin/live-share-turbo/dds-objects/index.d.ts +0 -8
  171. package/bin/live-share-turbo/dds-objects/index.d.ts.map +0 -1
  172. package/bin/live-share-turbo/dds-objects/index.js +0 -8
  173. package/bin/live-share-turbo/dds-objects/index.js.map +0 -1
  174. package/bin/live-share-turbo/index.d.ts +0 -5
  175. package/bin/live-share-turbo/index.d.ts.map +0 -1
  176. package/bin/live-share-turbo/index.js +0 -5
  177. package/bin/live-share-turbo/index.js.map +0 -1
  178. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +0 -15
  179. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +0 -1
  180. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +0 -2
  181. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +0 -1
  182. package/bin/live-share-turbo/interfaces/index.d.ts +0 -3
  183. package/bin/live-share-turbo/interfaces/index.d.ts.map +0 -1
  184. package/bin/live-share-turbo/interfaces/index.js +0 -3
  185. package/bin/live-share-turbo/interfaces/index.js.map +0 -1
  186. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +0 -39
  187. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +0 -1
  188. package/bin/live-share-turbo/internals/FluidTurboClient.js +0 -121
  189. package/bin/live-share-turbo/internals/FluidTurboClient.js.map +0 -1
  190. package/bin/live-share-turbo/internals/index.d.ts +0 -2
  191. package/bin/live-share-turbo/internals/index.d.ts.map +0 -1
  192. package/bin/live-share-turbo/internals/index.js +0 -2
  193. package/bin/live-share-turbo/internals/index.js.map +0 -1
  194. package/bin/live-share-turbo/internals/types.d.ts +0 -4
  195. package/bin/live-share-turbo/internals/types.d.ts.map +0 -1
  196. package/bin/live-share-turbo/internals/types.js +0 -2
  197. package/bin/live-share-turbo/internals/types.js.map +0 -1
  198. package/bin/providers/FluidContextProvider.d.ts +0 -34
  199. package/bin/providers/FluidContextProvider.d.ts.map +0 -1
  200. package/bin/providers/FluidContextProvider.js +0 -99
  201. package/bin/providers/FluidContextProvider.js.map +0 -1
  202. package/bin/providers/LiveShareContextProvider.d.ts +0 -42
  203. package/bin/providers/LiveShareContextProvider.d.ts.map +0 -1
  204. package/bin/providers/LiveShareContextProvider.js +0 -63
  205. package/bin/providers/LiveShareContextProvider.js.map +0 -1
  206. package/bin/shared-hooks/useLockedTask.d.ts +0 -11
  207. package/bin/shared-hooks/useLockedTask.d.ts.map +0 -1
  208. package/bin/shared-hooks/useLockedTask.js +0 -82
  209. package/bin/shared-hooks/useLockedTask.js.map +0 -1
  210. package/bin/shared-hooks/useTaskManager.d.ts +0 -13
  211. package/bin/shared-hooks/useTaskManager.d.ts.map +0 -1
  212. package/bin/shared-hooks/useTaskManager.js +0 -86
  213. package/bin/shared-hooks/useTaskManager.js.map +0 -1
  214. package/bin/utils/getContainerSchema.d.ts +0 -8
  215. package/bin/utils/getContainerSchema.d.ts.map +0 -1
  216. package/bin/utils/getContainerSchema.js +0 -41
  217. package/bin/utils/getContainerSchema.js.map +0 -1
  218. package/src/internal-hooks/index.ts +0 -1
  219. package/src/shared-hooks/useTaskManager.ts +0 -82
  220. package/tinylicious.log +0 -4
@@ -1,100 +1,102 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import React from "react";
6
- /**
7
- * Hook used internally to keep track of the SharedSetStateActionMap for each unique key. It sets state values for provided keys and updates components listening to the values.
8
- *
9
- * @param results IAzureContainerResults response or undefined
10
- * @returns ISharedStateRegistryResponse object
11
- */
12
- export const useSharedStateRegistry = (results) => {
13
- const registeredSharedSetStateActionMapRef = React.useRef(new Map());
14
- /**
15
- * @see ISharedStateRegistryResponse.registerSharedSetStateAction
16
- */
17
- const registerSharedSetStateAction = React.useCallback((uniqueKey, componentId, setLocalStateAction) => {
18
- let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
19
- if (actionsMap) {
20
- if (!actionsMap.has(componentId)) {
21
- actionsMap.set(componentId, setLocalStateAction);
22
- }
23
- }
24
- else {
25
- actionsMap = new Map();
26
- actionsMap.set(componentId, setLocalStateAction);
27
- registeredSharedSetStateActionMapRef.current.set(uniqueKey, actionsMap);
28
- }
29
- // Set initial values, if known
30
- const stateMap = results === null || results === void 0 ? void 0 : results.container.initialObjects.TURBO_STATE_MAP;
31
- const initialValue = stateMap === null || stateMap === void 0 ? void 0 : stateMap.get(uniqueKey);
32
- if (initialValue) {
33
- setLocalStateAction(initialValue);
34
- }
35
- }, [results]);
36
- /**
37
- * @see ISharedStateRegistryResponse.unregisterSharedSetStateAction
38
- */
39
- const unregisterSharedSetStateAction = React.useCallback((uniqueKey, componentId) => {
40
- let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
41
- if (actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.has(componentId)) {
42
- actionsMap.delete(componentId);
43
- }
44
- }, []);
45
- /**
46
- * @see ISharedStateRegistryResponse.updateSharedState
47
- */
48
- const updateSharedState = React.useCallback((uniqueKey, value) => {
49
- if (!results)
50
- return;
51
- const { container } = results;
52
- const stateMap = container.initialObjects.TURBO_STATE_MAP;
53
- stateMap.set(uniqueKey, value);
54
- }, [results]);
55
- /**
56
- * @see ISharedStateRegistryResponse.deleteSharedState
57
- */
58
- const deleteSharedState = React.useCallback((uniqueKey) => {
59
- if (!results)
60
- return;
61
- const { container } = results;
62
- let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
63
- actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.clear();
64
- const stateMap = container.initialObjects.TURBO_STATE_MAP;
65
- stateMap.delete(uniqueKey);
66
- }, [results]);
67
- React.useEffect(() => {
68
- if (!results)
69
- return;
70
- const { container } = results;
71
- const stateMap = container.initialObjects.TURBO_STATE_MAP;
72
- const valueChangedListener = (changed) => {
73
- if (registeredSharedSetStateActionMapRef.current.has(changed.key)) {
74
- const value = stateMap.get(changed.key);
75
- const actionMap = registeredSharedSetStateActionMapRef.current.get(changed.key);
76
- actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
77
- setLocalStateHandler(value);
78
- });
79
- }
80
- };
81
- stateMap.on("valueChanged", valueChangedListener);
82
- // Set initial values
83
- stateMap.forEach((value, key) => {
84
- const actionMap = registeredSharedSetStateActionMapRef.current.get(key);
85
- actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
86
- setLocalStateHandler(value);
87
- });
88
- });
89
- return () => {
90
- stateMap.off("valueChanged", valueChangedListener);
91
- };
92
- }, [results]);
93
- return {
94
- registerSharedSetStateAction,
95
- unregisterSharedSetStateAction,
96
- updateSharedState,
97
- deleteSharedState,
98
- };
99
- };
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import React from "react";
6
+ /**
7
+ * Hook used internally to keep track of the SharedSetStateActionMap for each unique key. It sets state values for provided keys and updates components listening to the values.
8
+ *
9
+ * @param results IAzureContainerResults response or undefined
10
+ * @returns ISharedStateRegistryResponse object
11
+ */
12
+ export const useSharedStateRegistry = (results) => {
13
+ const registeredSharedSetStateActionMapRef = React.useRef(new Map());
14
+ /**
15
+ * @see ISharedStateRegistryResponse.registerSharedSetStateAction
16
+ */
17
+ const registerSharedSetStateAction = React.useCallback((uniqueKey, componentId, setLocalStateAction) => {
18
+ let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
19
+ if (actionsMap) {
20
+ if (!actionsMap.has(componentId)) {
21
+ actionsMap.set(componentId, setLocalStateAction);
22
+ }
23
+ }
24
+ else {
25
+ actionsMap = new Map();
26
+ actionsMap.set(componentId, setLocalStateAction);
27
+ registeredSharedSetStateActionMapRef.current.set(uniqueKey, actionsMap);
28
+ }
29
+ // Set initial values, if known
30
+ const stateMap = results === null || results === void 0 ? void 0 : results.container.initialObjects.TURBO_STATE_MAP;
31
+ const initialValue = stateMap === null || stateMap === void 0 ? void 0 : stateMap.get(uniqueKey);
32
+ if (initialValue) {
33
+ setLocalStateAction(initialValue);
34
+ }
35
+ }, [results]);
36
+ /**
37
+ * @see ISharedStateRegistryResponse.unregisterSharedSetStateAction
38
+ */
39
+ const unregisterSharedSetStateAction = React.useCallback((uniqueKey, componentId) => {
40
+ let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
41
+ if (actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.has(componentId)) {
42
+ actionsMap.delete(componentId);
43
+ }
44
+ }, []);
45
+ /**
46
+ * @see ISharedStateRegistryResponse.updateSharedState
47
+ */
48
+ const updateSharedState = React.useCallback((uniqueKey, value) => {
49
+ if (!results)
50
+ return;
51
+ const { container } = results;
52
+ const stateMap = container.initialObjects
53
+ .TURBO_STATE_MAP;
54
+ stateMap.set(uniqueKey, value);
55
+ }, [results]);
56
+ /**
57
+ * @see ISharedStateRegistryResponse.deleteSharedState
58
+ */
59
+ const deleteSharedState = React.useCallback((uniqueKey) => {
60
+ if (!results)
61
+ return;
62
+ const { container } = results;
63
+ let actionsMap = registeredSharedSetStateActionMapRef.current.get(uniqueKey);
64
+ actionsMap === null || actionsMap === void 0 ? void 0 : actionsMap.clear();
65
+ const stateMap = container.initialObjects
66
+ .TURBO_STATE_MAP;
67
+ stateMap.delete(uniqueKey);
68
+ }, [results]);
69
+ React.useEffect(() => {
70
+ if (!results)
71
+ return;
72
+ const { container } = results;
73
+ const stateMap = container.initialObjects.TURBO_STATE_MAP;
74
+ const valueChangedListener = (changed) => {
75
+ if (registeredSharedSetStateActionMapRef.current.has(changed.key)) {
76
+ const value = stateMap.get(changed.key);
77
+ const actionMap = registeredSharedSetStateActionMapRef.current.get(changed.key);
78
+ actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
79
+ setLocalStateHandler(value);
80
+ });
81
+ }
82
+ };
83
+ stateMap.on("valueChanged", valueChangedListener);
84
+ // Set initial values
85
+ stateMap.forEach((value, key) => {
86
+ const actionMap = registeredSharedSetStateActionMapRef.current.get(key);
87
+ actionMap === null || actionMap === void 0 ? void 0 : actionMap.forEach((setLocalStateHandler) => {
88
+ setLocalStateHandler(value);
89
+ });
90
+ });
91
+ return () => {
92
+ stateMap.off("valueChanged", valueChangedListener);
93
+ };
94
+ }, [results]);
95
+ return {
96
+ registerSharedSetStateAction,
97
+ unregisterSharedSetStateAction,
98
+ updateSharedState,
99
+ deleteSharedState,
100
+ };
101
+ };
100
102
  //# sourceMappingURL=useSharedStateRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSharedStateRegistry.js","sourceRoot":"","sources":["../../src/internal/useSharedStateRegistry.ts"],"names":[],"mappings":"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"}
@@ -1,7 +1,7 @@
1
- export * from "./useLivePresence";
2
- export * from "./useLiveState";
3
- export * from "./useMediaSynchronizer";
4
- export * from "./useLiveEvent";
5
- export * from "./useLiveCanvas";
6
- export * from "./useLiveTimer";
1
+ export * from "./useLivePresence";
2
+ export * from "./useLiveState";
3
+ export * from "./useMediaSynchronizer";
4
+ export * from "./useLiveEvent";
5
+ export * from "./useLiveCanvas";
6
+ export * from "./useLiveTimer";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- export * from "./useLivePresence";
2
- export * from "./useLiveState";
3
- export * from "./useMediaSynchronizer";
4
- export * from "./useLiveEvent";
5
- export * from "./useLiveCanvas";
6
- export * from "./useLiveTimer";
1
+ export * from "./useLivePresence";
2
+ export * from "./useLiveState";
3
+ export * from "./useMediaSynchronizer";
4
+ export * from "./useLiveEvent";
5
+ export * from "./useLiveCanvas";
6
+ export * from "./useLiveTimer";
7
7
  //# sourceMappingURL=index.js.map
@@ -1,28 +1,28 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { CanvasReferencePoint, IBrush, InkingTool, IPoint, IUserInfo } from "@microsoft/live-share-canvas";
6
- import React from "react";
7
- import { IUseLiveCanvasResults } from "../types";
8
- /**
9
- * React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
10
- *
11
- * @remarks
12
- * Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
13
- * a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
14
- *
15
- * @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
16
- * @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
17
- * @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
18
- * @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
19
- * @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
20
- * @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
21
- * @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
22
- * @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
23
- * @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
24
- * @param localUserCursor Optional. Stateful `IUserInfo` object for the local user's metadata to display alongside their cursor. Defaults to undefined.
25
- * @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
26
- */
27
- export declare function useLiveCanvas(uniqueKey: string, canvasElementRef: React.RefObject<HTMLElement | null> | string, active?: boolean, tool?: InkingTool, lineBrush?: IBrush, offset?: IPoint, scale?: number, referencePoint?: CanvasReferencePoint, isCursorShared?: boolean, localUserCursor?: IUserInfo): IUseLiveCanvasResults;
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { CanvasReferencePoint, IBrush, InkingTool, IPoint } from "@microsoft/live-share-canvas";
6
+ import React from "react";
7
+ import { IUseLiveCanvasResults } from "../types";
8
+ /**
9
+ * React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
10
+ *
11
+ * @remarks
12
+ * Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
13
+ * a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
14
+ *
15
+ * @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
16
+ * @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
17
+ * @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
18
+ * @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
19
+ * @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
20
+ * @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
21
+ * @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
22
+ * @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
23
+ * @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
24
+ * @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
25
+ * @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
26
+ */
27
+ export declare function useLiveCanvas(uniqueKey: string, canvasElementRef: React.RefObject<HTMLElement | null> | string, active?: boolean, tool?: InkingTool, lineBrush?: IBrush, offset?: IPoint, scale?: number, referencePoint?: CanvasReferencePoint, isCursorShared?: boolean, localUserPictureUrl?: string): IUseLiveCanvasResults;
28
28
  //# sourceMappingURL=useLiveCanvas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLiveCanvas.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveCanvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,oBAAoB,EACpB,MAAM,EAEN,UAAU,EACV,MAAM,EACN,SAAS,EAEZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,MAAM,EAC9D,MAAM,CAAC,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,UAAU,EACjB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,oBAAoB,EACrC,cAAc,CAAC,EAAE,OAAO,EACxB,eAAe,CAAC,EAAE,SAAS,GAC5B,qBAAqB,CAoJvB"}
1
+ {"version":3,"file":"useLiveCanvas.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveCanvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,oBAAoB,EACpB,MAAM,EAEN,UAAU,EACV,MAAM,EAET,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,MAAM,EAC9D,MAAM,CAAC,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,UAAU,EACjB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,oBAAoB,EACrC,cAAc,CAAC,EAAE,OAAO,EACxB,mBAAmB,CAAC,EAAE,MAAM,GAC7B,qBAAqB,CA6IvB"}
@@ -1,167 +1,159 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { InkingManager, LiveCanvas, } from "@microsoft/live-share-canvas";
6
- import React from "react";
7
- import { useDynamicDDS } from "../shared-hooks";
8
- import { isRefObject } from "../utils";
9
- /**
10
- * React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
11
- *
12
- * @remarks
13
- * Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
14
- * a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
15
- *
16
- * @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
17
- * @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
18
- * @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
19
- * @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
20
- * @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
21
- * @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
22
- * @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
23
- * @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
24
- * @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
25
- * @param localUserCursor Optional. Stateful `IUserInfo` object for the local user's metadata to display alongside their cursor. Defaults to undefined.
26
- * @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
27
- */
28
- export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared, localUserCursor) {
29
- /**
30
- * User facing: inking manager instance
31
- */
32
- const [inkingManager, setInkingManager] = React.useState();
33
- /**
34
- * User facing: dynamically load the DDS for the given unique key.
35
- */
36
- const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
37
- /**
38
- * Setup the InkingManager and LiveCanvas
39
- */
40
- React.useEffect(() => {
41
- // if the component is already listening or liveCanvas is not yet initialized, return
42
- if (!liveCanvas)
43
- return;
44
- // get the canvas element from the ref or document
45
- let htmlElement;
46
- if (isRefObject(canvasElementRef)) {
47
- htmlElement = canvasElementRef.current;
48
- }
49
- else {
50
- htmlElement = document.getElementById(canvasElementRef);
51
- }
52
- if (htmlElement === null)
53
- return;
54
- // Create the InkingManager and initialize the liveCanvas with it
55
- const inkingManager = new InkingManager(htmlElement);
56
- setInkingManager(inkingManager);
57
- liveCanvas.initialize(inkingManager);
58
- // cleanup function to be called when the component is unmount
59
- return () => {
60
- liveCanvas.dispose();
61
- inkingManager.removeAllListeners();
62
- };
63
- }, [liveCanvas]);
64
- /**
65
- * Activate or deactivate the inkingManager based on the 'active' prop
66
- */
67
- React.useEffect(() => {
68
- if (inkingManager && active !== undefined) {
69
- if (active) {
70
- inkingManager.activate();
71
- }
72
- else {
73
- inkingManager.deactivate();
74
- }
75
- }
76
- }, [active, inkingManager]);
77
- /**
78
- * Sets the tool of the inkingManager based on the 'tool' prop
79
- */
80
- React.useEffect(() => {
81
- if (inkingManager && tool !== undefined) {
82
- inkingManager.tool = tool;
83
- }
84
- }, [tool, inkingManager]);
85
- /**
86
- * Sets the offset of the inkingManager based on the 'offset' prop
87
- */
88
- React.useEffect(() => {
89
- if (inkingManager && offset !== undefined) {
90
- inkingManager.offset = {
91
- x: offset.x,
92
- y: offset.y,
93
- };
94
- }
95
- }, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
96
- /**
97
- * Sets the scale of the inkingManager based on the 'scale' prop
98
- */
99
- React.useEffect(() => {
100
- if (inkingManager && scale !== undefined) {
101
- inkingManager.scale = scale;
102
- }
103
- }, [scale, inkingManager]);
104
- /**
105
- * Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
106
- */
107
- React.useEffect(() => {
108
- if (inkingManager && referencePoint !== undefined) {
109
- inkingManager.referencePoint = referencePoint;
110
- }
111
- }, [referencePoint, inkingManager]);
112
- /**
113
- * Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
114
- */
115
- React.useEffect(() => {
116
- if (inkingManager && lineBrush) {
117
- inkingManager.lineBrush = {
118
- color: lineBrush.color,
119
- tip: lineBrush.tip,
120
- tipSize: lineBrush.tipSize,
121
- type: lineBrush.type,
122
- endArrow: lineBrush.endArrow,
123
- };
124
- }
125
- }, [
126
- lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
127
- lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
128
- lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
129
- lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
130
- lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
131
- inkingManager,
132
- ]);
133
- /**
134
- * Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
135
- */
136
- React.useEffect(() => {
137
- if ((liveCanvas === null || liveCanvas === void 0 ? void 0 : liveCanvas.isCursorShared) !== undefined &&
138
- isCursorShared !== undefined) {
139
- liveCanvas.isCursorShared = isCursorShared;
140
- }
141
- }, [isCursorShared, liveCanvas === null || liveCanvas === void 0 ? void 0 : liveCanvas.isCursorShared]);
142
- /**
143
- * Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
144
- */
145
- React.useEffect(() => {
146
- if ((liveCanvas === null || liveCanvas === void 0 ? void 0 : liveCanvas.onGetLocalUserInfo) !== undefined && localUserCursor) {
147
- liveCanvas.onGetLocalUserInfo = () => {
148
- return {
149
- displayName: localUserCursor.displayName,
150
- pictureUri: localUserCursor.pictureUri,
151
- };
152
- };
153
- }
154
- }, [
155
- localUserCursor === null || localUserCursor === void 0 ? void 0 : localUserCursor.displayName,
156
- localUserCursor === null || localUserCursor === void 0 ? void 0 : localUserCursor.pictureUri,
157
- liveCanvas === null || liveCanvas === void 0 ? void 0 : liveCanvas.onGetLocalUserInfo,
158
- ]);
159
- /**
160
- * Return hook response
161
- */
162
- return {
163
- inkingManager,
164
- liveCanvas,
165
- };
166
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { InkingManager, LiveCanvas, } from "@microsoft/live-share-canvas";
6
+ import React from "react";
7
+ import { useDynamicDDS } from "../shared-hooks";
8
+ import { isRefObject } from "../utils";
9
+ /**
10
+ * React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
11
+ *
12
+ * @remarks
13
+ * Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
14
+ * a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
15
+ *
16
+ * @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
17
+ * @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
18
+ * @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
19
+ * @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
20
+ * @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
21
+ * @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
22
+ * @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
23
+ * @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
24
+ * @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
25
+ * @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
26
+ * @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
27
+ */
28
+ export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared, localUserPictureUrl) {
29
+ /**
30
+ * User facing: inking manager instance
31
+ */
32
+ const [inkingManager, setInkingManager] = React.useState();
33
+ /**
34
+ * User facing: dynamically load the DDS for the given unique key.
35
+ */
36
+ const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
37
+ /**
38
+ * Setup the InkingManager and LiveCanvas
39
+ */
40
+ React.useEffect(() => {
41
+ // if the component is already listening or liveCanvas is not yet initialized, return
42
+ if (!liveCanvas)
43
+ return;
44
+ // get the canvas element from the ref or document
45
+ let htmlElement;
46
+ if (isRefObject(canvasElementRef)) {
47
+ htmlElement = canvasElementRef.current;
48
+ }
49
+ else {
50
+ htmlElement = document.getElementById(canvasElementRef);
51
+ }
52
+ if (htmlElement === null)
53
+ return;
54
+ // Create the InkingManager and initialize the liveCanvas with it
55
+ const inkingManager = new InkingManager(htmlElement);
56
+ setInkingManager(inkingManager);
57
+ liveCanvas.initialize(inkingManager);
58
+ // cleanup function to be called when the component is unmount
59
+ return () => {
60
+ liveCanvas.dispose();
61
+ inkingManager.removeAllListeners();
62
+ };
63
+ }, [liveCanvas]);
64
+ /**
65
+ * Activate or deactivate the inkingManager based on the 'active' prop
66
+ */
67
+ React.useEffect(() => {
68
+ if (inkingManager && active !== undefined) {
69
+ if (active) {
70
+ inkingManager.activate();
71
+ }
72
+ else {
73
+ inkingManager.deactivate();
74
+ }
75
+ }
76
+ }, [active, inkingManager]);
77
+ /**
78
+ * Sets the tool of the inkingManager based on the 'tool' prop
79
+ */
80
+ React.useEffect(() => {
81
+ if (inkingManager && tool !== undefined) {
82
+ inkingManager.tool = tool;
83
+ }
84
+ }, [tool, inkingManager]);
85
+ /**
86
+ * Sets the offset of the inkingManager based on the 'offset' prop
87
+ */
88
+ React.useEffect(() => {
89
+ if (inkingManager && offset !== undefined) {
90
+ inkingManager.offset = {
91
+ x: offset.x,
92
+ y: offset.y,
93
+ };
94
+ }
95
+ }, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
96
+ /**
97
+ * Sets the scale of the inkingManager based on the 'scale' prop
98
+ */
99
+ React.useEffect(() => {
100
+ if (inkingManager && scale !== undefined) {
101
+ inkingManager.scale = scale;
102
+ }
103
+ }, [scale, inkingManager]);
104
+ /**
105
+ * Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
106
+ */
107
+ React.useEffect(() => {
108
+ if (inkingManager && referencePoint !== undefined) {
109
+ inkingManager.referencePoint = referencePoint;
110
+ }
111
+ }, [referencePoint, inkingManager]);
112
+ /**
113
+ * Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
114
+ */
115
+ React.useEffect(() => {
116
+ if (inkingManager && lineBrush) {
117
+ inkingManager.lineBrush = {
118
+ color: lineBrush.color,
119
+ tip: lineBrush.tip,
120
+ tipSize: lineBrush.tipSize,
121
+ type: lineBrush.type,
122
+ endArrow: lineBrush.endArrow,
123
+ };
124
+ }
125
+ }, [
126
+ lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
127
+ lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
128
+ lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
129
+ lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
130
+ lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
131
+ inkingManager,
132
+ ]);
133
+ /**
134
+ * Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
135
+ */
136
+ React.useEffect(() => {
137
+ if (liveCanvas && isCursorShared !== undefined) {
138
+ liveCanvas.isCursorShared = isCursorShared;
139
+ }
140
+ }, [isCursorShared, liveCanvas]);
141
+ /**
142
+ * Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
143
+ */
144
+ React.useEffect(() => {
145
+ if (liveCanvas && localUserPictureUrl) {
146
+ liveCanvas.onGetLocalUserPictureUrl = () => {
147
+ return localUserPictureUrl;
148
+ };
149
+ }
150
+ }, [localUserPictureUrl, liveCanvas]);
151
+ /**
152
+ * Return hook response
153
+ */
154
+ return {
155
+ inkingManager,
156
+ liveCanvas,
157
+ };
158
+ }
167
159
  //# sourceMappingURL=useLiveCanvas.js.map