@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.
- package/README.md +3 -3
- package/bin/index.d.ts +6 -6
- package/bin/index.js +6 -6
- package/bin/interfaces/LiveInterfaceExtensions.d.ts +8 -8
- package/bin/interfaces/LiveInterfaceExtensions.js +5 -5
- package/bin/interfaces/index.d.ts +1 -1
- package/bin/interfaces/index.js +1 -1
- package/bin/internal-hooks/index.d.ts +1 -1
- package/bin/internal-hooks/index.js +1 -1
- package/bin/internal-hooks/useSharedStateRegistry.d.ts +30 -30
- package/bin/internal-hooks/useSharedStateRegistry.d.ts.map +1 -1
- package/bin/internal-hooks/useSharedStateRegistry.js +101 -99
- package/bin/internal-hooks/useSharedStateRegistry.js.map +1 -1
- package/bin/live-hooks/index.d.ts +6 -6
- package/bin/live-hooks/index.js +6 -6
- package/bin/live-hooks/useLiveCanvas.d.ts +27 -27
- package/bin/live-hooks/useLiveCanvas.js +158 -158
- package/bin/live-hooks/useLiveEvent.d.ts +21 -21
- package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
- package/bin/live-hooks/useLiveEvent.js +92 -85
- package/bin/live-hooks/useLiveEvent.js.map +1 -1
- package/bin/live-hooks/useLivePresence.d.ts +25 -25
- package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
- package/bin/live-hooks/useLivePresence.js +101 -92
- package/bin/live-hooks/useLivePresence.js.map +1 -1
- package/bin/live-hooks/useLiveState.d.ts +19 -18
- package/bin/live-hooks/useLiveState.d.ts.map +1 -1
- package/bin/live-hooks/useLiveState.js +72 -60
- package/bin/live-hooks/useLiveState.js.map +1 -1
- package/bin/live-hooks/useLiveTimer.d.ts +7 -7
- package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
- package/bin/live-hooks/useLiveTimer.js +144 -131
- package/bin/live-hooks/useLiveTimer.js.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.d.ts +22 -22
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.js +184 -161
- package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
- package/bin/providers/AzureProvider.d.ts +33 -33
- package/bin/providers/AzureProvider.d.ts.map +1 -1
- package/bin/providers/AzureProvider.js +101 -101
- package/bin/providers/AzureProvider.js.map +1 -1
- package/bin/providers/LiveShareProvider.d.ts +62 -41
- package/bin/providers/LiveShareProvider.d.ts.map +1 -1
- package/bin/providers/LiveShareProvider.js +68 -65
- package/bin/providers/LiveShareProvider.js.map +1 -1
- package/bin/providers/index.d.ts +2 -2
- package/bin/providers/index.js +2 -2
- package/bin/shared-hooks/index.d.ts +3 -3
- package/bin/shared-hooks/index.js +3 -3
- package/bin/shared-hooks/useDynamicDDS.d.ts +18 -18
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -1
- package/bin/shared-hooks/useDynamicDDS.js +67 -67
- package/bin/shared-hooks/useDynamicDDS.js.map +1 -1
- package/bin/shared-hooks/useSharedMap.d.ts +21 -21
- package/bin/shared-hooks/useSharedMap.d.ts.map +1 -1
- package/bin/shared-hooks/useSharedMap.js +105 -105
- package/bin/shared-hooks/useSharedMap.js.map +1 -1
- package/bin/shared-hooks/useSharedState.d.ts +20 -20
- package/bin/shared-hooks/useSharedState.d.ts.map +1 -1
- package/bin/shared-hooks/useSharedState.js +66 -62
- package/bin/shared-hooks/useSharedState.js.map +1 -1
- package/bin/types/ActionTypes.d.ts +105 -29
- package/bin/types/ActionTypes.d.ts.map +1 -1
- package/bin/types/ActionTypes.js +5 -5
- package/bin/types/PropTypes.d.ts +7 -7
- package/bin/types/PropTypes.d.ts.map +1 -1
- package/bin/types/PropTypes.js +5 -5
- package/bin/types/ResultTypes.d.ts +174 -162
- package/bin/types/ResultTypes.d.ts.map +1 -1
- package/bin/types/ResultTypes.js +5 -5
- package/bin/types/index.d.ts +3 -3
- package/bin/types/index.js +3 -3
- package/bin/utils/index.d.ts +1 -1
- package/bin/utils/index.js +1 -1
- package/bin/utils/type-check.d.ts +14 -14
- package/bin/utils/type-check.js +53 -53
- package/package.json +13 -13
- package/src/internal-hooks/useSharedStateRegistry.ts +6 -5
- package/src/live-hooks/useLiveEvent.ts +14 -18
- package/src/live-hooks/useLivePresence.ts +13 -7
- package/src/live-hooks/useLiveState.ts +8 -6
- package/src/live-hooks/useLiveTimer.ts +21 -18
- package/src/live-hooks/useMediaSynchronizer.ts +37 -27
- package/src/providers/AzureProvider.tsx +2 -7
- package/src/providers/LiveShareProvider.tsx +45 -15
- package/src/shared-hooks/useDynamicDDS.ts +15 -8
- package/src/shared-hooks/useSharedMap.ts +17 -10
- package/src/shared-hooks/useSharedState.ts +5 -1
- package/src/types/ActionTypes.ts +89 -11
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
livePresence
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"useLivePresence.js","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"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"}
|
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"useLiveState.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CACxB,SAAiB,EACjB,YAAoB,EACpB,YAAgC;IAEhC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GACjC,KAAK,CAAC,QAAQ,CAAS,YAAY,CAAC,CAAC;IACzC;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CACpC,SAAS,EACT,CAAA,SAAiB,CAAA,CACpB,CAAC;IAEF;;;;OAIG;IACH,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAC9B,CAAO,KAAa,EAAE,EAAE;QACpB,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,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,
|
|
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"}
|