@microsoft/live-share-react 1.0.0-preview.5

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 (233) hide show
  1. package/.nycrc.json +10 -0
  2. package/LICENSE +87 -0
  3. package/README.md +543 -0
  4. package/bin/index.d.ts +7 -0
  5. package/bin/index.d.ts.map +1 -0
  6. package/bin/index.js +7 -0
  7. package/bin/index.js.map +1 -0
  8. package/bin/interfaces/LiveInterfaceExtensions.d.ts +9 -0
  9. package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
  10. package/bin/interfaces/LiveInterfaceExtensions.js +6 -0
  11. package/bin/interfaces/LiveInterfaceExtensions.js.map +1 -0
  12. package/bin/interfaces/index.d.ts +2 -0
  13. package/bin/interfaces/index.d.ts.map +1 -0
  14. package/bin/interfaces/index.js +2 -0
  15. package/bin/interfaces/index.js.map +1 -0
  16. package/bin/internal-hooks/index.d.ts +2 -0
  17. package/bin/internal-hooks/index.d.ts.map +1 -0
  18. package/bin/internal-hooks/index.js +2 -0
  19. package/bin/internal-hooks/index.js.map +1 -0
  20. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts +14 -0
  21. package/bin/internal-hooks/useDynamicDDSRegistry.d.ts.map +1 -0
  22. package/bin/internal-hooks/useDynamicDDSRegistry.js +142 -0
  23. package/bin/internal-hooks/useDynamicDDSRegistry.js.map +1 -0
  24. package/bin/internal-hooks/useSharedStateRegistry.d.ts +31 -0
  25. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +1 -0
  26. package/bin/internal-hooks/useSharedStateRegistry.js +100 -0
  27. package/bin/internal-hooks/useSharedStateRegistry.js.map +1 -0
  28. package/bin/internal-hooks/useStateRef.d.ts +7 -0
  29. package/bin/internal-hooks/useStateRef.d.ts.map +1 -0
  30. package/bin/internal-hooks/useStateRef.js +15 -0
  31. package/bin/internal-hooks/useStateRef.js.map +1 -0
  32. package/bin/live-hooks/index.d.ts +7 -0
  33. package/bin/live-hooks/index.d.ts.map +1 -0
  34. package/bin/live-hooks/index.js +7 -0
  35. package/bin/live-hooks/index.js.map +1 -0
  36. package/bin/live-hooks/useLiveAICompletion.d.ts +29 -0
  37. package/bin/live-hooks/useLiveAICompletion.d.ts.map +1 -0
  38. package/bin/live-hooks/useLiveAICompletion.js +186 -0
  39. package/bin/live-hooks/useLiveAICompletion.js.map +1 -0
  40. package/bin/live-hooks/useLiveCanvas.d.ts +28 -0
  41. package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -0
  42. package/bin/live-hooks/useLiveCanvas.js +167 -0
  43. package/bin/live-hooks/useLiveCanvas.js.map +1 -0
  44. package/bin/live-hooks/useLiveCoPilot.d.ts +28 -0
  45. package/bin/live-hooks/useLiveCoPilot.d.ts.map +1 -0
  46. package/bin/live-hooks/useLiveCoPilot.js +178 -0
  47. package/bin/live-hooks/useLiveCoPilot.js.map +1 -0
  48. package/bin/live-hooks/useLiveEvent.d.ts +22 -0
  49. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -0
  50. package/bin/live-hooks/useLiveEvent.js +86 -0
  51. package/bin/live-hooks/useLiveEvent.js.map +1 -0
  52. package/bin/live-hooks/useLivePresence.d.ts +26 -0
  53. package/bin/live-hooks/useLivePresence.d.ts.map +1 -0
  54. package/bin/live-hooks/useLivePresence.js +93 -0
  55. package/bin/live-hooks/useLivePresence.js.map +1 -0
  56. package/bin/live-hooks/useLiveState.d.ts +20 -0
  57. package/bin/live-hooks/useLiveState.d.ts.map +1 -0
  58. package/bin/live-hooks/useLiveState.js +71 -0
  59. package/bin/live-hooks/useLiveState.js.map +1 -0
  60. package/bin/live-hooks/useLiveTimer.d.ts +8 -0
  61. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -0
  62. package/bin/live-hooks/useLiveTimer.js +132 -0
  63. package/bin/live-hooks/useLiveTimer.js.map +1 -0
  64. package/bin/live-hooks/useMediaSynchronizer.d.ts +23 -0
  65. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
  66. package/bin/live-hooks/useMediaSynchronizer.js +162 -0
  67. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -0
  68. package/bin/live-share-turbo/AzureTurboClient.d.ts +39 -0
  69. package/bin/live-share-turbo/AzureTurboClient.d.ts.map +1 -0
  70. package/bin/live-share-turbo/AzureTurboClient.js +56 -0
  71. package/bin/live-share-turbo/AzureTurboClient.js.map +1 -0
  72. package/bin/live-share-turbo/LiveShareTurboClient.d.ts +53 -0
  73. package/bin/live-share-turbo/LiveShareTurboClient.d.ts.map +1 -0
  74. package/bin/live-share-turbo/LiveShareTurboClient.js +69 -0
  75. package/bin/live-share-turbo/LiveShareTurboClient.js.map +1 -0
  76. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts +31 -0
  77. package/bin/live-share-turbo/dds-objects/TurboDataObject.d.ts.map +1 -0
  78. package/bin/live-share-turbo/dds-objects/TurboDataObject.js +75 -0
  79. package/bin/live-share-turbo/dds-objects/TurboDataObject.js.map +1 -0
  80. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts +48 -0
  81. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.d.ts.map +1 -0
  82. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js +104 -0
  83. package/bin/live-share-turbo/dds-objects/TurboLiveCanvas.js.map +1 -0
  84. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts +28 -0
  85. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.d.ts.map +1 -0
  86. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js +68 -0
  87. package/bin/live-share-turbo/dds-objects/TurboLiveEvent.js.map +1 -0
  88. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts +60 -0
  89. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.d.ts.map +1 -0
  90. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js +111 -0
  91. package/bin/live-share-turbo/dds-objects/TurboLiveMediaSession.js.map +1 -0
  92. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts +77 -0
  93. package/bin/live-share-turbo/dds-objects/TurboLivePresence.d.ts.map +1 -0
  94. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js +137 -0
  95. package/bin/live-share-turbo/dds-objects/TurboLivePresence.js.map +1 -0
  96. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts +30 -0
  97. package/bin/live-share-turbo/dds-objects/TurboLiveState.d.ts.map +1 -0
  98. package/bin/live-share-turbo/dds-objects/TurboLiveState.js +74 -0
  99. package/bin/live-share-turbo/dds-objects/TurboLiveState.js.map +1 -0
  100. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts +61 -0
  101. package/bin/live-share-turbo/dds-objects/TurboSharedMap.d.ts.map +1 -0
  102. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js +108 -0
  103. package/bin/live-share-turbo/dds-objects/TurboSharedMap.js.map +1 -0
  104. package/bin/live-share-turbo/dds-objects/index.d.ts +8 -0
  105. package/bin/live-share-turbo/dds-objects/index.d.ts.map +1 -0
  106. package/bin/live-share-turbo/dds-objects/index.js +8 -0
  107. package/bin/live-share-turbo/dds-objects/index.js.map +1 -0
  108. package/bin/live-share-turbo/index.d.ts +5 -0
  109. package/bin/live-share-turbo/index.d.ts.map +1 -0
  110. package/bin/live-share-turbo/index.js +5 -0
  111. package/bin/live-share-turbo/index.js.map +1 -0
  112. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts +15 -0
  113. package/bin/live-share-turbo/interfaces/IFluidTurboClient.d.ts.map +1 -0
  114. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js +2 -0
  115. package/bin/live-share-turbo/interfaces/IFluidTurboClient.js.map +1 -0
  116. package/bin/live-share-turbo/interfaces/index.d.ts +3 -0
  117. package/bin/live-share-turbo/interfaces/index.d.ts.map +1 -0
  118. package/bin/live-share-turbo/interfaces/index.js +3 -0
  119. package/bin/live-share-turbo/interfaces/index.js.map +1 -0
  120. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts +39 -0
  121. package/bin/live-share-turbo/internals/FluidTurboClient.d.ts.map +1 -0
  122. package/bin/live-share-turbo/internals/FluidTurboClient.js +121 -0
  123. package/bin/live-share-turbo/internals/FluidTurboClient.js.map +1 -0
  124. package/bin/live-share-turbo/internals/index.d.ts +2 -0
  125. package/bin/live-share-turbo/internals/index.d.ts.map +1 -0
  126. package/bin/live-share-turbo/internals/index.js +2 -0
  127. package/bin/live-share-turbo/internals/index.js.map +1 -0
  128. package/bin/live-share-turbo/internals/types.d.ts +4 -0
  129. package/bin/live-share-turbo/internals/types.d.ts.map +1 -0
  130. package/bin/live-share-turbo/internals/types.js +2 -0
  131. package/bin/live-share-turbo/internals/types.js.map +1 -0
  132. package/bin/providers/AzureProvider.d.ts +34 -0
  133. package/bin/providers/AzureProvider.d.ts.map +1 -0
  134. package/bin/providers/AzureProvider.js +102 -0
  135. package/bin/providers/AzureProvider.js.map +1 -0
  136. package/bin/providers/FluidContextProvider.d.ts +34 -0
  137. package/bin/providers/FluidContextProvider.d.ts.map +1 -0
  138. package/bin/providers/FluidContextProvider.js +99 -0
  139. package/bin/providers/FluidContextProvider.js.map +1 -0
  140. package/bin/providers/LiveShareContextProvider.d.ts +42 -0
  141. package/bin/providers/LiveShareContextProvider.d.ts.map +1 -0
  142. package/bin/providers/LiveShareContextProvider.js +63 -0
  143. package/bin/providers/LiveShareContextProvider.js.map +1 -0
  144. package/bin/providers/LiveShareProvider.d.ts +42 -0
  145. package/bin/providers/LiveShareProvider.d.ts.map +1 -0
  146. package/bin/providers/LiveShareProvider.js +66 -0
  147. package/bin/providers/LiveShareProvider.js.map +1 -0
  148. package/bin/providers/index.d.ts +3 -0
  149. package/bin/providers/index.d.ts.map +1 -0
  150. package/bin/providers/index.js +3 -0
  151. package/bin/providers/index.js.map +1 -0
  152. package/bin/shared-hooks/index.d.ts +5 -0
  153. package/bin/shared-hooks/index.d.ts.map +1 -0
  154. package/bin/shared-hooks/index.js +5 -0
  155. package/bin/shared-hooks/index.js.map +1 -0
  156. package/bin/shared-hooks/useDynamicDDS.d.ts +19 -0
  157. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -0
  158. package/bin/shared-hooks/useDynamicDDS.js +68 -0
  159. package/bin/shared-hooks/useDynamicDDS.js.map +1 -0
  160. package/bin/shared-hooks/useLockedTask.d.ts +11 -0
  161. package/bin/shared-hooks/useLockedTask.d.ts.map +1 -0
  162. package/bin/shared-hooks/useLockedTask.js +82 -0
  163. package/bin/shared-hooks/useLockedTask.js.map +1 -0
  164. package/bin/shared-hooks/useSharedMap.d.ts +22 -0
  165. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -0
  166. package/bin/shared-hooks/useSharedMap.js +106 -0
  167. package/bin/shared-hooks/useSharedMap.js.map +1 -0
  168. package/bin/shared-hooks/useSharedState.d.ts +21 -0
  169. package/bin/shared-hooks/useSharedState.d.ts.map +1 -0
  170. package/bin/shared-hooks/useSharedState.js +63 -0
  171. package/bin/shared-hooks/useSharedState.js.map +1 -0
  172. package/bin/shared-hooks/useTaskManager.d.ts +13 -0
  173. package/bin/shared-hooks/useTaskManager.d.ts.map +1 -0
  174. package/bin/shared-hooks/useTaskManager.js +86 -0
  175. package/bin/shared-hooks/useTaskManager.js.map +1 -0
  176. package/bin/types/ActionTypes.d.ts +30 -0
  177. package/bin/types/ActionTypes.d.ts.map +1 -0
  178. package/bin/types/ActionTypes.js +6 -0
  179. package/bin/types/ActionTypes.js.map +1 -0
  180. package/bin/types/PropTypes.d.ts +8 -0
  181. package/bin/types/PropTypes.d.ts.map +1 -0
  182. package/bin/types/PropTypes.js +6 -0
  183. package/bin/types/PropTypes.js.map +1 -0
  184. package/bin/types/ResultTypes.d.ts +163 -0
  185. package/bin/types/ResultTypes.d.ts.map +1 -0
  186. package/bin/types/ResultTypes.js +6 -0
  187. package/bin/types/ResultTypes.js.map +1 -0
  188. package/bin/types/index.d.ts +4 -0
  189. package/bin/types/index.d.ts.map +1 -0
  190. package/bin/types/index.js +4 -0
  191. package/bin/types/index.js.map +1 -0
  192. package/bin/utils/getContainerSchema.d.ts +8 -0
  193. package/bin/utils/getContainerSchema.d.ts.map +1 -0
  194. package/bin/utils/getContainerSchema.js +41 -0
  195. package/bin/utils/getContainerSchema.js.map +1 -0
  196. package/bin/utils/index.d.ts +2 -0
  197. package/bin/utils/index.d.ts.map +1 -0
  198. package/bin/utils/index.js +2 -0
  199. package/bin/utils/index.js.map +1 -0
  200. package/bin/utils/type-check.d.ts +15 -0
  201. package/bin/utils/type-check.d.ts.map +1 -0
  202. package/bin/utils/type-check.js +54 -0
  203. package/bin/utils/type-check.js.map +1 -0
  204. package/package.json +47 -0
  205. package/src/index.ts +6 -0
  206. package/src/interfaces/LiveInterfaceExtensions.ts +9 -0
  207. package/src/interfaces/index.ts +1 -0
  208. package/src/internal-hooks/index.ts +1 -0
  209. package/src/internal-hooks/useSharedStateRegistry.ts +163 -0
  210. package/src/live-hooks/index.ts +6 -0
  211. package/src/live-hooks/useLiveCanvas.ts +198 -0
  212. package/src/live-hooks/useLiveEvent.ts +117 -0
  213. package/src/live-hooks/useLivePresence.ts +124 -0
  214. package/src/live-hooks/useLiveState.ts +108 -0
  215. package/src/live-hooks/useLiveTimer.ts +184 -0
  216. package/src/live-hooks/useMediaSynchronizer.ts +200 -0
  217. package/src/providers/AzureProvider.tsx +177 -0
  218. package/src/providers/LiveShareProvider.tsx +140 -0
  219. package/src/providers/index.ts +2 -0
  220. package/src/shared-hooks/index.ts +4 -0
  221. package/src/shared-hooks/useDynamicDDS.ts +71 -0
  222. package/src/shared-hooks/useSharedMap.ts +132 -0
  223. package/src/shared-hooks/useSharedState.ts +85 -0
  224. package/src/shared-hooks/useTaskManager.ts +82 -0
  225. package/src/types/ActionTypes.ts +76 -0
  226. package/src/types/PropTypes.ts +10 -0
  227. package/src/types/ResultTypes.ts +187 -0
  228. package/src/types/index.ts +3 -0
  229. package/src/utils/index.ts +1 -0
  230. package/src/utils/type-check.ts +69 -0
  231. package/tinylicious.log +4 -0
  232. package/tsconfig.build.json +6 -0
  233. package/tsconfig.json +72 -0
@@ -0,0 +1,163 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { AzureContainerServices } from "@fluidframework/azure-client";
6
+ import { ITimerConfig, LivePresenceUser, LiveEvent, LivePresence, LiveTimer } from "@microsoft/live-share";
7
+ import { InkingManager, LiveCanvas } from "@microsoft/live-share-canvas";
8
+ import { CoordinationWaitPoint, ExtendedMediaMetadata, MediaPlayerSynchronizer } from "@microsoft/live-share-media";
9
+ import { IFluidContainer, SharedMap } from "fluid-framework";
10
+ import { IReceiveLiveEvent } from "../interfaces";
11
+ import { OnPauseTimerAction, OnPlayTimerAction, OnStartTimerAction, OnUpdateLivePresenceAction, SendLiveEventAction } from "./ActionTypes";
12
+ export interface IAzureContainerResults {
13
+ /**
14
+ * Fluid Container.
15
+ */
16
+ container: IFluidContainer;
17
+ /**
18
+ * Azure container services which has information such as current socket connections.
19
+ */
20
+ services: AzureContainerServices;
21
+ }
22
+ export interface ILiveShareContainerResults extends IAzureContainerResults {
23
+ /**
24
+ * Whether the local user/client initially created the container.
25
+ */
26
+ created: boolean;
27
+ }
28
+ export interface IUseSharedMapResults<TData> {
29
+ /**
30
+ * Stateful map of most recent values from `SharedMap`.
31
+ */
32
+ map: ReadonlyMap<string, TData>;
33
+ /**
34
+ * Callback method to set/replace new entries in the `SharedMap`.
35
+ */
36
+ setEntry: (key: string, value: TData) => void;
37
+ /**
38
+ * Callback method to delete an existing entry in the `SharedMap`.
39
+ */
40
+ deleteEntry: (key: string) => void;
41
+ /**
42
+ * The Fluid `SharedMap` object, should you want to use it directly.
43
+ */
44
+ sharedMap: SharedMap | undefined;
45
+ }
46
+ export interface IUseLiveEventResults<TEvent extends object = object> {
47
+ /**
48
+ * The most recent event that has been received in the session.
49
+ */
50
+ latestEvent: IReceiveLiveEvent<TEvent> | undefined;
51
+ /**
52
+ * All received events since initializing this component, sorted from oldest -> newest.
53
+ */
54
+ allEvents: IReceiveLiveEvent<TEvent>[];
55
+ /**
56
+ * Callback method to send a new event to users in the session.
57
+ */
58
+ sendEvent: SendLiveEventAction<TEvent>;
59
+ /**
60
+ * The `LiveEvent` object, should you want to use it directly.
61
+ */
62
+ liveEvent: LiveEvent | undefined;
63
+ }
64
+ export interface IUseLiveTimerResults {
65
+ /**
66
+ * The current timer configuration.
67
+ */
68
+ timerConfig: ITimerConfig | undefined;
69
+ /**
70
+ * The time remaining in milliseconds.
71
+ */
72
+ milliRemaining: number | undefined;
73
+ /**
74
+ * The `LiveTimer` object, should you want to use it directly.
75
+ */
76
+ liveTimer: LiveTimer | undefined;
77
+ /**
78
+ * Start timer callback.
79
+ */
80
+ start: OnStartTimerAction;
81
+ /**
82
+ * Play timer callback.
83
+ */
84
+ play: OnPlayTimerAction;
85
+ /**
86
+ * Pause timer callback.
87
+ */
88
+ pause: OnPauseTimerAction;
89
+ }
90
+ export interface IUseLivePresenceResults<TData extends object = object> {
91
+ /**
92
+ * The local user's presence object.
93
+ */
94
+ localUser: LivePresenceUser<TData> | undefined;
95
+ /**
96
+ * List of non-local user's presence objects.
97
+ */
98
+ otherUsers: LivePresenceUser<TData>[];
99
+ /**
100
+ * List of all user's presence objects.
101
+ */
102
+ allUsers: LivePresenceUser<TData>[];
103
+ /**
104
+ * Live Share `LivePresence` object, should you want to use it directly.
105
+ */
106
+ livePresence: LivePresence<TData> | undefined;
107
+ /**
108
+ * Callback method to update the local user's presence.
109
+ */
110
+ updatePresence: OnUpdateLivePresenceAction<TData>;
111
+ }
112
+ export interface IUseMediaSynchronizerResults {
113
+ /**
114
+ * Stateful boolean on whether the session has an active suspension.
115
+ */
116
+ suspended: boolean;
117
+ /**
118
+ * Callback to initiate a play action for the group media session.
119
+ */
120
+ play: () => void;
121
+ /**
122
+ * Callback to initiate a pause action for the group media session.
123
+ */
124
+ pause: () => void;
125
+ /**
126
+ * Callback to initiate a seek action for the group media session.
127
+ *
128
+ * @param time timestamp of the video in seconds to seek to
129
+ */
130
+ seekTo: (time: number) => void;
131
+ /**
132
+ * Callback to change the track for the group media session.
133
+ * @param track media metadata object, track src string, or null
134
+ */
135
+ setTrack: (track: Partial<ExtendedMediaMetadata> | string | null) => void;
136
+ /**
137
+ * Begin a new suspension. If a wait point is not set, the suspension will only impact the
138
+ * local user.
139
+ *
140
+ * @param waitPoint Optional. Point in track to set the suspension at.
141
+ * @see CoordinationWaitPoint
142
+ */
143
+ beginSuspension: (waitPoint?: CoordinationWaitPoint) => void;
144
+ /**
145
+ * End the currently active exception.
146
+ */
147
+ endSuspension: () => void;
148
+ /**
149
+ * Live Share `MediaPlayerSynchronizer` object, should you want to use it directly.
150
+ */
151
+ mediaSynchronizer: MediaPlayerSynchronizer | undefined;
152
+ }
153
+ export interface IUseLiveCanvasResults {
154
+ /**
155
+ * Inking manager for the canvas, which is synchronized by `liveCanvas`. It is set when loaded and undefined while loading.
156
+ */
157
+ inkingManager: InkingManager | undefined;
158
+ /**
159
+ * Live Canvas data object which synchronizes inking & cursors in the session. It is set when loaded and undefined while loading.
160
+ */
161
+ liveCanvas: LiveCanvas | undefined;
162
+ }
163
+ //# sourceMappingURL=ResultTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResultTypes.d.ts","sourceRoot":"","sources":["../../src/types/ResultTypes.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=ResultTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResultTypes.js","sourceRoot":"","sources":["../../src/types/ResultTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,4 @@
1
+ export * from "./ActionTypes";
2
+ export * from "./ResultTypes";
3
+ export * from "./PropTypes";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./ActionTypes";
2
+ export * from "./ResultTypes";
3
+ export * from "./PropTypes";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,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 { ContainerSchema, LoadableObjectClass } from "fluid-framework";
6
+ export declare function getContainerSchema(additionalDynamicObjectTypes: LoadableObjectClass<any>[] | undefined): ContainerSchema;
7
+ export declare function getLiveShareContainerSchema(additionalDynamicObjectTypes: LoadableObjectClass<any>[] | undefined): ContainerSchema;
8
+ //# sourceMappingURL=getContainerSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getContainerSchema.d.ts","sourceRoot":"","sources":["../../src/utils/getContainerSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EACH,eAAe,EACf,mBAAmB,EAItB,MAAM,iBAAiB,CAAC;AAUzB,wBAAgB,kBAAkB,CAC9B,4BAA4B,EAAE,mBAAmB,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,GACrE,eAAe,CAUjB;AAED,wBAAgB,2BAA2B,CACvC,4BAA4B,EAAE,mBAAmB,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,mBAgBvE"}
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { LiveEvent, LivePresence, LiveState, LiveTimer, } from "@microsoft/live-share";
6
+ import { LiveCanvas } from "@microsoft/live-share-canvas";
7
+ import { LiveMediaSession } from "@microsoft/live-share-media";
8
+ import { SharedDirectory, SharedMap, SharedString, } from "fluid-framework";
9
+ const schema = {
10
+ initialObjects: {
11
+ stateMap: SharedMap,
12
+ dynamicObjects: SharedMap,
13
+ },
14
+ dynamicObjectTypes: [SharedMap, SharedString, SharedDirectory],
15
+ };
16
+ export function getContainerSchema(additionalDynamicObjectTypes) {
17
+ const _additionalDynamicObjectTypes = additionalDynamicObjectTypes !== null && additionalDynamicObjectTypes !== void 0 ? additionalDynamicObjectTypes : [];
18
+ return {
19
+ initialObjects: schema.initialObjects,
20
+ dynamicObjectTypes: [
21
+ ...schema.dynamicObjectTypes,
22
+ ..._additionalDynamicObjectTypes,
23
+ ],
24
+ };
25
+ }
26
+ export function getLiveShareContainerSchema(additionalDynamicObjectTypes) {
27
+ const liveShareDynamicObjects = [
28
+ LiveEvent,
29
+ LivePresence,
30
+ LiveState,
31
+ LiveMediaSession,
32
+ LiveTimer,
33
+ LiveCanvas,
34
+ ];
35
+ const _additionalDynamicObjectTypes = additionalDynamicObjectTypes !== null && additionalDynamicObjectTypes !== void 0 ? additionalDynamicObjectTypes : [];
36
+ return getContainerSchema([
37
+ ...liveShareDynamicObjects,
38
+ ..._additionalDynamicObjectTypes,
39
+ ]);
40
+ }
41
+ //# sourceMappingURL=getContainerSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getContainerSchema.js","sourceRoot":"","sources":["../../src/utils/getContainerSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,SAAS,EACT,YAAY,EACZ,SAAS,EACT,SAAS,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAGH,eAAe,EACf,SAAS,EACT,YAAY,GACf,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,GAAoB;IAC5B,cAAc,EAAE;QACZ,QAAQ,EAAE,SAAS;QACnB,cAAc,EAAE,SAAS;KAC5B;IACD,kBAAkB,EAAE,CAAC,SAAS,EAAE,YAAY,EAAE,eAAe,CAAC;CACjE,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAC9B,4BAAoE;IAEpE,MAAM,6BAA6B,GAC/B,4BAA4B,aAA5B,4BAA4B,cAA5B,4BAA4B,GAAI,EAAE,CAAC;IACvC,OAAO;QACH,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,kBAAkB,EAAE;YAChB,GAAG,MAAM,CAAC,kBAAmB;YAC7B,GAAG,6BAA6B;SACnC;KACJ,CAAC;AACN,CAAC;AAED,MAAM,UAAU,2BAA2B,CACvC,4BAAoE;IAEpE,MAAM,uBAAuB,GAA+B;QACxD,SAAS;QACT,YAAY;QACZ,SAAS;QACT,gBAAgB;QAChB,SAAS;QACT,UAAU;KACb,CAAC;IACF,MAAM,6BAA6B,GAC/B,4BAA4B,aAA5B,4BAA4B,cAA5B,4BAA4B,GAAI,EAAE,CAAC;IACvC,OAAO,kBAAkB,CAAC;QACtB,GAAG,uBAAuB;QAC1B,GAAG,6BAA6B;KACnC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./type-check";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./type-check";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { ExtendedMediaMetadata, IMediaPlayer } from "@microsoft/live-share-media";
6
+ import React from "react";
7
+ export declare function isRefObject<T>(value: any): value is React.RefObject<T>;
8
+ export declare function isMediaElement(value: any): value is IMediaPlayer;
9
+ export declare function isExtendedMediaMetadata(value: any): value is ExtendedMediaMetadata;
10
+ export declare function isMap(value: any): value is Map<string, any>;
11
+ export declare function isEntries(value: any): value is readonly (readonly [string, any])[];
12
+ export declare function isJSON(value: any): value is {
13
+ [key: string]: any;
14
+ };
15
+ //# sourceMappingURL=type-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-check.d.ts","sourceRoot":"","sources":["../../src/utils/type-check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,qBAAqB,EACrB,YAAY,EACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAEtE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,YAAY,CAoBhE;AAED,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,GAAG,GACX,KAAK,IAAI,qBAAqB,CAEhC;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAE3D;AAED,wBAAgB,SAAS,CACrB,KAAK,EAAE,GAAG,GACX,KAAK,IAAI,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAU9C;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAOlE"}
@@ -0,0 +1,54 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ export function isRefObject(value) {
6
+ return value.current === null || !!value.current;
7
+ }
8
+ export function isMediaElement(value) {
9
+ if (value) {
10
+ return (value.currentSrc !== undefined &&
11
+ value.currentTime !== undefined &&
12
+ value.duration !== undefined &&
13
+ value.ended !== undefined &&
14
+ value.muted !== undefined &&
15
+ value.paused !== undefined &&
16
+ value.playbackRate !== undefined &&
17
+ value.src !== undefined &&
18
+ value.volume !== undefined &&
19
+ value.load !== undefined &&
20
+ value.pause !== undefined &&
21
+ value.play !== undefined &&
22
+ value.addEventListener !== undefined &&
23
+ value.removeEventListener !== undefined);
24
+ }
25
+ return false;
26
+ }
27
+ export function isExtendedMediaMetadata(value) {
28
+ return value === null || !!(value === null || value === void 0 ? void 0 : value.trackIdentifier);
29
+ }
30
+ export function isMap(value) {
31
+ return value instanceof Map;
32
+ }
33
+ export function isEntries(value) {
34
+ try {
35
+ const tryValue = value;
36
+ if (typeof tryValue[0][0] === "string") {
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ catch (error) {
42
+ return false;
43
+ }
44
+ }
45
+ export function isJSON(value) {
46
+ try {
47
+ const tryValue = value;
48
+ return Object.keys(tryValue).length > 0;
49
+ }
50
+ catch (error) {
51
+ return false;
52
+ }
53
+ }
54
+ //# sourceMappingURL=type-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-check.js","sourceRoot":"","sources":["../../src/utils/type-check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,MAAM,UAAU,WAAW,CAAI,KAAU;IACrC,OAAO,KAAK,CAAC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAU;IACrC,IAAI,KAAK,EAAE;QACP,OAAO,CACH,KAAK,CAAC,UAAU,KAAK,SAAS;YAC9B,KAAK,CAAC,WAAW,KAAK,SAAS;YAC/B,KAAK,CAAC,QAAQ,KAAK,SAAS;YAC5B,KAAK,CAAC,KAAK,KAAK,SAAS;YACzB,KAAK,CAAC,KAAK,KAAK,SAAS;YACzB,KAAK,CAAC,MAAM,KAAK,SAAS;YAC1B,KAAK,CAAC,YAAY,KAAK,SAAS;YAChC,KAAK,CAAC,GAAG,KAAK,SAAS;YACvB,KAAK,CAAC,MAAM,KAAK,SAAS;YAC1B,KAAK,CAAC,IAAI,KAAK,SAAS;YACxB,KAAK,CAAC,KAAK,KAAK,SAAS;YACzB,KAAK,CAAC,IAAI,KAAK,SAAS;YACxB,KAAK,CAAC,gBAAgB,KAAK,SAAS;YACpC,KAAK,CAAC,mBAAmB,KAAK,SAAS,CAC1C,CAAC;KACL;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,uBAAuB,CACnC,KAAU;IAEV,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,eAAe,CAAA,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAU;IAC5B,OAAO,KAAK,YAAY,GAAG,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,SAAS,CACrB,KAAU;IAEV,IAAI;QACA,MAAM,QAAQ,GAAG,KAAyC,CAAC;QAC3D,IAAI,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;YACpC,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;KAChB;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,KAAK,CAAC;KAChB;AACL,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAU;IAC7B,IAAI;QACA,MAAM,QAAQ,GAAG,KAA+B,CAAC;QACjD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;KAC3C;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,KAAK,CAAC;KAChB;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@microsoft/live-share-react",
3
+ "version": "1.0.0-preview.5",
4
+ "description": "Build collaborative React apps using Microsoft's Fluid & Live Share frameworks with ease.",
5
+ "author": "Microsoft",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "main": "./bin/index.js",
8
+ "types": "./bin/index.d.ts",
9
+ "scripts": {
10
+ "clean": "npx shx rm -rf bin",
11
+ "build": "tsc -p tsconfig.build.json",
12
+ "typecheck": "tsc"
13
+ },
14
+ "dependencies": {
15
+ "@fluidframework/azure-client": "~1.0.2",
16
+ "@fluid-experimental/task-manager": "~1.2.3",
17
+ "@microsoft/live-share": "1.0.0-preview.4",
18
+ "@microsoft/live-share-canvas": "1.0.0-preview.4",
19
+ "@microsoft/live-share-media": "1.0.0-preview.4",
20
+ "@microsoft/live-share-turbo": "1.0.0-preview.4",
21
+ "fluid-framework": "~1.2.3",
22
+ "url": "^0.11.0",
23
+ "uuid": "^8.3.2"
24
+ },
25
+ "devDependencies": {
26
+ "@babel/core": "^7.12.3",
27
+ "@fluidframework/test-client-utils": "~1.2.3",
28
+ "@types/react": "^18.0.0",
29
+ "@types/react-dom": "^18.0.0",
30
+ "@types/uuid": "^8.3.4",
31
+ "babel-loader": "^7.1.5",
32
+ "typescript": "^4.6.4"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "^16.8.0 || ^17 || ^18",
36
+ "react-dom": "^16.8.0 || ^17 || ^18"
37
+ },
38
+ "repository": {
39
+ "directory": "packages/live-share-react",
40
+ "type": "git",
41
+ "url": "https://github.com/microsoft/live-share-sdk"
42
+ },
43
+ "homepage": "https://aka.ms/teamsliveshare",
44
+ "bugs": {
45
+ "url": "https://github.com/microsoft/live-share-sdk/issues"
46
+ }
47
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./providers";
2
+ export * from "./shared-hooks";
3
+ export * from "./live-hooks";
4
+ export * from "./types";
5
+ export * from "./providers";
6
+ export * from "./interfaces";
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ export interface IReceiveLiveEvent<TEvent extends object = object> {
7
+ event: TEvent;
8
+ local: boolean;
9
+ }
@@ -0,0 +1 @@
1
+ export * from "./LiveInterfaceExtensions";
@@ -0,0 +1 @@
1
+ export * from "./useSharedStateRegistry";
@@ -0,0 +1,163 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ import { IValueChanged, SharedMap } from "fluid-framework";
7
+ import React from "react";
8
+ import {
9
+ DeleteSharedStateAction,
10
+ IAzureContainerResults,
11
+ RegisterSharedSetStateAction,
12
+ SetLocalStateAction,
13
+ UnregisterSharedSetStateAction,
14
+ UpdateSharedStateAction,
15
+ } from "../types";
16
+
17
+ export interface ISharedStateRegistryResponse {
18
+ /**
19
+ * Register a set state action callback
20
+ */
21
+ registerSharedSetStateAction: RegisterSharedSetStateAction;
22
+ /**
23
+ * Unregister a set state action callback
24
+ */
25
+ unregisterSharedSetStateAction: UnregisterSharedSetStateAction;
26
+ /**
27
+ * Setter callback to update the shared state
28
+ */
29
+ updateSharedState: UpdateSharedStateAction;
30
+ /**
31
+ * Delete a shared state value
32
+ */
33
+ deleteSharedState: DeleteSharedStateAction;
34
+ }
35
+
36
+ /**
37
+ * 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.
38
+ *
39
+ * @param results IAzureContainerResults response or undefined
40
+ * @returns ISharedStateRegistryResponse object
41
+ */
42
+ export const useSharedStateRegistry = (
43
+ results: IAzureContainerResults | undefined
44
+ ): ISharedStateRegistryResponse => {
45
+ const registeredSharedSetStateActionMapRef = React.useRef<
46
+ Map<string, Map<string, SetLocalStateAction>>
47
+ >(new Map());
48
+
49
+ /**
50
+ * @see ISharedStateRegistryResponse.registerSharedSetStateAction
51
+ */
52
+ const registerSharedSetStateAction = React.useCallback(
53
+ (
54
+ uniqueKey: string,
55
+ componentId: string,
56
+ setLocalStateAction: SetLocalStateAction
57
+ ) => {
58
+ let actionsMap =
59
+ registeredSharedSetStateActionMapRef.current.get(uniqueKey);
60
+ if (actionsMap) {
61
+ if (!actionsMap.has(componentId)) {
62
+ actionsMap.set(componentId, setLocalStateAction);
63
+ }
64
+ } else {
65
+ actionsMap = new Map<string, SetLocalStateAction>();
66
+ actionsMap.set(componentId, setLocalStateAction);
67
+ registeredSharedSetStateActionMapRef.current.set(
68
+ uniqueKey,
69
+ actionsMap
70
+ );
71
+ }
72
+ // Set initial values, if known
73
+ const stateMap = results?.container.initialObjects.TURBO_STATE_MAP as
74
+ | SharedMap
75
+ | undefined;
76
+ const initialValue = stateMap?.get(uniqueKey);
77
+ if (initialValue) {
78
+ setLocalStateAction(initialValue);
79
+ }
80
+ },
81
+ [results]
82
+ );
83
+
84
+ /**
85
+ * @see ISharedStateRegistryResponse.unregisterSharedSetStateAction
86
+ */
87
+ const unregisterSharedSetStateAction = React.useCallback(
88
+ (uniqueKey: string, componentId: string) => {
89
+ let actionsMap =
90
+ registeredSharedSetStateActionMapRef.current.get(uniqueKey);
91
+ if (actionsMap?.has(componentId)) {
92
+ actionsMap.delete(componentId);
93
+ }
94
+ },
95
+ []
96
+ );
97
+
98
+ /**
99
+ * @see ISharedStateRegistryResponse.updateSharedState
100
+ */
101
+ const updateSharedState: UpdateSharedStateAction = React.useCallback(
102
+ (uniqueKey: string, value: any) => {
103
+ if (!results) return;
104
+ const { container } = results;
105
+ const stateMap = container.initialObjects.TURBO_STATE_MAP as SharedMap;
106
+ stateMap.set(uniqueKey, value);
107
+ },
108
+ [results]
109
+ );
110
+
111
+ /**
112
+ * @see ISharedStateRegistryResponse.deleteSharedState
113
+ */
114
+ const deleteSharedState: DeleteSharedStateAction = React.useCallback(
115
+ (uniqueKey: string) => {
116
+ if (!results) return;
117
+ const { container } = results;
118
+ let actionsMap =
119
+ registeredSharedSetStateActionMapRef.current.get(uniqueKey);
120
+ actionsMap?.clear();
121
+ const stateMap = container.initialObjects.TURBO_STATE_MAP as SharedMap;
122
+ stateMap.delete(uniqueKey);
123
+ },
124
+ [results]
125
+ );
126
+
127
+ React.useEffect(() => {
128
+ if (!results) return;
129
+ const { container } = results;
130
+ const stateMap = container.initialObjects.TURBO_STATE_MAP as SharedMap;
131
+ const valueChangedListener = (changed: IValueChanged): void => {
132
+ if (registeredSharedSetStateActionMapRef.current.has(changed.key)) {
133
+ const value = stateMap.get(changed.key);
134
+ const actionMap =
135
+ registeredSharedSetStateActionMapRef.current.get(
136
+ changed.key
137
+ );
138
+ actionMap?.forEach((setLocalStateHandler) => {
139
+ setLocalStateHandler(value);
140
+ });
141
+ }
142
+ };
143
+ stateMap.on("valueChanged", valueChangedListener);
144
+ // Set initial values
145
+ stateMap.forEach((value: any, key: string) => {
146
+ const actionMap =
147
+ registeredSharedSetStateActionMapRef.current.get(key);
148
+ actionMap?.forEach((setLocalStateHandler) => {
149
+ setLocalStateHandler(value);
150
+ });
151
+ });
152
+ return () => {
153
+ stateMap.off("valueChanged", valueChangedListener);
154
+ };
155
+ }, [results]);
156
+
157
+ return {
158
+ registerSharedSetStateAction,
159
+ unregisterSharedSetStateAction,
160
+ updateSharedState,
161
+ deleteSharedState,
162
+ };
163
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./useLivePresence";
2
+ export * from "./useLiveState";
3
+ export * from "./useMediaSynchronizer";
4
+ export * from "./useLiveEvent";
5
+ export * from "./useLiveCanvas";
6
+ export * from "./useLiveTimer";