@microsoft/live-share-react 1.0.0-preview.12 → 1.0.0-preview.14

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 (90) hide show
  1. package/README.md +3 -3
  2. package/bin/index.d.ts +6 -6
  3. package/bin/index.js +6 -6
  4. package/bin/interfaces/LiveInterfaceExtensions.d.ts +8 -8
  5. package/bin/interfaces/LiveInterfaceExtensions.js +5 -5
  6. package/bin/interfaces/index.d.ts +1 -1
  7. package/bin/interfaces/index.js +1 -1
  8. package/bin/internal-hooks/index.d.ts +1 -1
  9. package/bin/internal-hooks/index.js +1 -1
  10. package/bin/internal-hooks/useSharedStateRegistry.d.ts +30 -30
  11. package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +1 -1
  12. package/bin/internal-hooks/useSharedStateRegistry.js +101 -99
  13. package/bin/internal-hooks/useSharedStateRegistry.js.map +1 -1
  14. package/bin/live-hooks/index.d.ts +6 -6
  15. package/bin/live-hooks/index.js +6 -6
  16. package/bin/live-hooks/useLiveCanvas.d.ts +27 -27
  17. package/bin/live-hooks/useLiveCanvas.js +158 -158
  18. package/bin/live-hooks/useLiveEvent.d.ts +21 -21
  19. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
  20. package/bin/live-hooks/useLiveEvent.js +92 -85
  21. package/bin/live-hooks/useLiveEvent.js.map +1 -1
  22. package/bin/live-hooks/useLivePresence.d.ts +25 -25
  23. package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
  24. package/bin/live-hooks/useLivePresence.js +101 -92
  25. package/bin/live-hooks/useLivePresence.js.map +1 -1
  26. package/bin/live-hooks/useLiveState.d.ts +19 -18
  27. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  28. package/bin/live-hooks/useLiveState.js +72 -60
  29. package/bin/live-hooks/useLiveState.js.map +1 -1
  30. package/bin/live-hooks/useLiveTimer.d.ts +7 -7
  31. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
  32. package/bin/live-hooks/useLiveTimer.js +144 -131
  33. package/bin/live-hooks/useLiveTimer.js.map +1 -1
  34. package/bin/live-hooks/useMediaSynchronizer.d.ts +22 -22
  35. package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
  36. package/bin/live-hooks/useMediaSynchronizer.js +184 -161
  37. package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
  38. package/bin/providers/AzureProvider.d.ts +33 -33
  39. package/bin/providers/AzureProvider.d.ts.map +1 -1
  40. package/bin/providers/AzureProvider.js +101 -101
  41. package/bin/providers/AzureProvider.js.map +1 -1
  42. package/bin/providers/LiveShareProvider.d.ts +62 -41
  43. package/bin/providers/LiveShareProvider.d.ts.map +1 -1
  44. package/bin/providers/LiveShareProvider.js +68 -65
  45. package/bin/providers/LiveShareProvider.js.map +1 -1
  46. package/bin/providers/index.d.ts +2 -2
  47. package/bin/providers/index.js +2 -2
  48. package/bin/shared-hooks/index.d.ts +3 -3
  49. package/bin/shared-hooks/index.js +3 -3
  50. package/bin/shared-hooks/useDynamicDDS.d.ts +18 -18
  51. package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
  52. package/bin/shared-hooks/useDynamicDDS.js +67 -67
  53. package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
  54. package/bin/shared-hooks/useSharedMap.d.ts +21 -21
  55. package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
  56. package/bin/shared-hooks/useSharedMap.js +105 -105
  57. package/bin/shared-hooks/useSharedMap.js.map +1 -1
  58. package/bin/shared-hooks/useSharedState.d.ts +20 -20
  59. package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
  60. package/bin/shared-hooks/useSharedState.js +66 -62
  61. package/bin/shared-hooks/useSharedState.js.map +1 -1
  62. package/bin/types/ActionTypes.d.ts +105 -29
  63. package/bin/types/ActionTypes.d.ts.map +1 -1
  64. package/bin/types/ActionTypes.js +5 -5
  65. package/bin/types/PropTypes.d.ts +7 -7
  66. package/bin/types/PropTypes.d.ts.map +1 -1
  67. package/bin/types/PropTypes.js +5 -5
  68. package/bin/types/ResultTypes.d.ts +174 -162
  69. package/bin/types/ResultTypes.d.ts.map +1 -1
  70. package/bin/types/ResultTypes.js +5 -5
  71. package/bin/types/index.d.ts +3 -3
  72. package/bin/types/index.js +3 -3
  73. package/bin/utils/index.d.ts +1 -1
  74. package/bin/utils/index.js +1 -1
  75. package/bin/utils/type-check.d.ts +14 -14
  76. package/bin/utils/type-check.js +53 -53
  77. package/package.json +13 -13
  78. package/src/internal-hooks/useSharedStateRegistry.ts +6 -5
  79. package/src/live-hooks/useLiveEvent.ts +14 -18
  80. package/src/live-hooks/useLivePresence.ts +13 -7
  81. package/src/live-hooks/useLiveState.ts +8 -6
  82. package/src/live-hooks/useLiveTimer.ts +21 -18
  83. package/src/live-hooks/useMediaSynchronizer.ts +37 -27
  84. package/src/providers/AzureProvider.tsx +2 -7
  85. package/src/providers/LiveShareProvider.tsx +45 -15
  86. package/src/shared-hooks/useDynamicDDS.ts +15 -8
  87. package/src/shared-hooks/useSharedMap.ts +17 -10
  88. package/src/shared-hooks/useSharedState.ts +5 -1
  89. package/src/types/ActionTypes.ts +89 -11
  90. package/src/types/ResultTypes.ts +22 -8
@@ -1,93 +1,102 @@
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(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((data, state) => {
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.update(data, state);
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(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
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import { PresenceState, LivePresence, } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks";
17
+ /**
18
+ * React hook for using a Live Share `LivePresence`.
19
+ *
20
+ * @remarks
21
+ * Use this hook if you want to track presence for who is currently using this component, such as
22
+ * who is online or who is viewing a specific document. With presence, you can sent along any custom
23
+ * user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
24
+ *
25
+ * @template TData Optional typing for the custom user presence data object. Default is `object` type.
26
+ * @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one
27
+ * @param userId Optional. The unique ID for a user. If none is provided, a random UUID will be generated.
28
+ * @param initialData Optional. Initial presence data object for the user.
29
+ * @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
30
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
31
+ * will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
32
+ * @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
33
+ * to update the local user's presence and the `LivePresence` Fluid object.
34
+ */
35
+ export function useLivePresence(uniqueKey, initialData, initialPresenceState = PresenceState.online, allowedRoles) {
36
+ /**
37
+ * Stateful all user presence list and its non-user-facing setter method.
38
+ */
39
+ const [allUsers, setAllUsers] = React.useState([]);
40
+ /**
41
+ * User facing: dynamically load the DDS for the given unique key.
42
+ */
43
+ const { dds: livePresence } = useDynamicDDS(uniqueKey, (LivePresence));
44
+ /**
45
+ * User facing: list of non-local user's presence objects.
46
+ */
47
+ const otherUsers = React.useMemo(() => {
48
+ return [...allUsers.filter((user) => !user.isLocalUser)];
49
+ }, [allUsers]);
50
+ /**
51
+ * User facing: local user's presence object.
52
+ */
53
+ const localUser = React.useMemo(() => {
54
+ return allUsers.find((user) => user.isLocalUser);
55
+ }, [allUsers]);
56
+ /**
57
+ * User facing: callback to update the local user's presence.
58
+ */
59
+ const updatePresence = React.useCallback((data, state) => __awaiter(this, void 0, void 0, function* () {
60
+ if (!livePresence) {
61
+ console.error(new Error("Cannot call updatePresence when presence is undefined"));
62
+ return;
63
+ }
64
+ if (!livePresence.isInitialized) {
65
+ console.error(new Error("Cannot call updatePresence while presence is not started"));
66
+ return;
67
+ }
68
+ return yield livePresence.update(data, state);
69
+ }), [livePresence]);
70
+ /**
71
+ * Setup change listeners and start `LivePresence` if needed
72
+ */
73
+ React.useEffect(() => {
74
+ if (livePresence === undefined)
75
+ return;
76
+ const onPresenceChanged = () => {
77
+ const updatedLocalUsers = [];
78
+ livePresence === null || livePresence === void 0 ? void 0 : livePresence.getUsers().forEach((user) => {
79
+ updatedLocalUsers.push(user);
80
+ });
81
+ setAllUsers(updatedLocalUsers);
82
+ };
83
+ livePresence.on("presenceChanged", onPresenceChanged);
84
+ if (!livePresence.isInitialized) {
85
+ livePresence.initialize(initialData, initialPresenceState, allowedRoles);
86
+ }
87
+ else {
88
+ onPresenceChanged();
89
+ }
90
+ return () => {
91
+ livePresence === null || livePresence === void 0 ? void 0 : livePresence.off("presenceChanged", onPresenceChanged);
92
+ };
93
+ }, [livePresence]);
94
+ return {
95
+ localUser,
96
+ otherUsers,
97
+ allUsers,
98
+ livePresence,
99
+ updatePresence,
100
+ };
101
+ }
93
102
  //# sourceMappingURL=useLivePresence.js.map
@@ -1 +1 @@
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,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,CACvC,SAAS,EACT,CAAA,YAAmB,CAAA,CACtB,CAAC;IAEF;;OAEG;IACH,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAA4B,GAAG,EAAE;QAC7D,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7D,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf;;OAEG;IACH,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAsC,GAAG,EAAE;QACtE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf;;OAEG;IACH,MAA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ACT,UAAU;QACV,QAAQ;QACR,YAAY;QACZ,cAAc;KACjB,CAAC;AACN,CAAC"}
@@ -1,19 +1,20 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { UserMeetingRole } from "@microsoft/live-share";
6
- import { SetLiveStateAction } from "../types";
7
- /**
8
- * React hook for using a Live Share `LiveState`.
9
- *
10
- * @remarks
11
- * Use this hook if you want to synchronize app state that will reset when all users leave the session.
12
- *
13
- * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
14
- * @param initialState Optional. the initial state value of type TState
15
- * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
16
- * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
17
- */
18
- export declare function useLiveState<TState = any>(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction<TState>];
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { UserMeetingRole } from "@microsoft/live-share";
6
+ import { SetLiveStateAction } from "../types";
7
+ /**
8
+ * React hook for using a Live Share `LiveState`.
9
+ *
10
+ * @remarks
11
+ * Use this hook if you want to synchronize app state that will reset when all users leave the session.
12
+ *
13
+ * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
14
+ * @param initialState Optional. the initial state value of type TState
15
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
16
+ * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
17
+ * The setter returns a void promise, which will throw if the user does not have the required roles to set.
18
+ */
19
+ export declare function useLiveState<TState = any>(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction<TState>];
19
20
  //# sourceMappingURL=useLiveState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLiveState.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C;;;;;;;;;;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
+ {"version":3,"file":"useLiveState.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAG,GAAG,EACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC,CA8DtC"}
@@ -1,61 +1,73 @@
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
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ import { LiveState } from "@microsoft/live-share";
15
+ import React from "react";
16
+ import { useDynamicDDS } from "../shared-hooks";
17
+ /**
18
+ * React hook for using a Live Share `LiveState`.
19
+ *
20
+ * @remarks
21
+ * Use this hook if you want to synchronize app state that will reset when all users leave the session.
22
+ *
23
+ * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one will be created, otherwise it will use the existing one.
24
+ * @param initialState Optional. the initial state value of type TState
25
+ * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
26
+ * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
27
+ * The setter returns a void promise, which will throw if the user does not have the required roles to set.
28
+ */
29
+ export function useLiveState(uniqueKey, initialState, allowedRoles) {
30
+ const [currentState, setCurrentState] = React.useState(initialState);
31
+ /**
32
+ * User facing: dynamically load the DDS for the given unique key.
33
+ */
34
+ const { dds: liveState } = useDynamicDDS(uniqueKey, (LiveState));
35
+ /**
36
+ * Change state callback that is user facing
37
+ * @param state TState to set
38
+ * @returns void promise, which will throw if the user does not have the required roles
39
+ */
40
+ const setState = React.useCallback((state) => __awaiter(this, void 0, void 0, function* () {
41
+ if (!liveState) {
42
+ console.error(new Error("Cannot call changeState when liveState is undefined"));
43
+ return;
44
+ }
45
+ if (!liveState.isInitialized) {
46
+ console.error(new Error("Cannot call changeState while liveState is not started"));
47
+ return;
48
+ }
49
+ return yield liveState.set(state);
50
+ }), [liveState]);
51
+ /**
52
+ * Setup change listeners and start `LiveState` if needed
53
+ */
54
+ React.useEffect(() => {
55
+ if (liveState === undefined)
56
+ return;
57
+ const onStateChanged = (state) => {
58
+ setCurrentState(state);
59
+ };
60
+ liveState.on("stateChanged", onStateChanged);
61
+ if (!liveState.isInitialized) {
62
+ liveState.initialize(initialState, allowedRoles);
63
+ }
64
+ if (JSON.stringify(liveState.state) !== JSON.stringify(initialState)) {
65
+ onStateChanged(liveState.state);
66
+ }
67
+ return () => {
68
+ liveState === null || liveState === void 0 ? void 0 : liveState.off("stateChanged", onStateChanged);
69
+ };
70
+ }, [liveState]);
71
+ return [currentState, setState];
72
+ }
61
73
  //# sourceMappingURL=useLiveState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLiveState.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;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;QAC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AS,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,OAAO,MAAM,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,CAAA,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 +1,8 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { UserMeetingRole } from "@microsoft/live-share";
6
- import { IUseLiveTimerResults, OnTimerDidFinishAction, OnTimerDidPauseAction, OnTimerDidPlayAction, OnTimerDidStartAction, OnTimerTickAction } from "../types";
7
- export declare function useLiveTimer(uniqueKey: string, allowedRoles?: UserMeetingRole[], tickRate?: number, onTick?: OnTimerTickAction, onStart?: OnTimerDidStartAction, onPause?: OnTimerDidPauseAction, onPlay?: OnTimerDidPlayAction, onFinish?: OnTimerDidFinishAction): IUseLiveTimerResults;
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
8
  //# sourceMappingURL=useLiveTimer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLiveTimer.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGH,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EAIpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,UAAU,CAAC;AAGlB,wBAAgB,YAAY,CACxB,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,qBAAqB,EAC/B,OAAO,CAAC,EAAE,qBAAqB,EAC/B,MAAM,CAAC,EAAE,oBAAoB,EAC7B,QAAQ,CAAC,EAAE,sBAAsB,GAClC,oBAAoB,CAqJtB"}
1
+ {"version":3,"file":"useLiveTimer.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGH,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EAIpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,UAAU,CAAC;AAGlB,wBAAgB,YAAY,CACxB,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,qBAAqB,EAC/B,OAAO,CAAC,EAAE,qBAAqB,EAC/B,MAAM,CAAC,EAAE,oBAAoB,EAC7B,QAAQ,CAAC,EAAE,sBAAsB,GAClC,oBAAoB,CAwJtB"}