@microsoft/live-share-react 2.0.0-internal.2 → 2.0.0-internal.20
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/LICENSE +64 -61
- package/README.md +175 -164
- package/bin/esm/index.d.ts +7 -0
- package/bin/esm/index.d.ts.map +1 -0
- package/bin/esm/index.js +7 -0
- package/bin/esm/index.js.map +1 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.js.map +1 -0
- package/bin/esm/interfaces/index.d.ts +2 -0
- package/bin/esm/interfaces/index.d.ts.map +1 -0
- package/bin/esm/interfaces/index.js +2 -0
- package/bin/esm/interfaces/index.js.map +1 -0
- package/bin/esm/internal/errors.d.ts.map +1 -0
- package/bin/esm/internal/errors.js.map +1 -0
- package/bin/esm/internal/index.d.ts +3 -0
- package/bin/esm/internal/index.d.ts.map +1 -0
- package/bin/esm/internal/index.js +3 -0
- package/bin/esm/internal/index.js.map +1 -0
- package/bin/{internal → esm/internal}/type-guards.d.ts +1 -1
- package/bin/esm/internal/type-guards.d.ts.map +1 -0
- package/bin/esm/internal/type-guards.js.map +1 -0
- package/bin/esm/live-hooks/index.d.ts +8 -0
- package/bin/esm/live-hooks/index.d.ts.map +1 -0
- package/bin/esm/live-hooks/index.js +8 -0
- package/bin/esm/live-hooks/index.js.map +1 -0
- package/bin/esm/live-hooks/useLiveCanvas.d.ts +80 -0
- package/bin/esm/live-hooks/useLiveCanvas.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveCanvas.js +237 -0
- package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveEvent.d.ts +37 -1
- package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveEvent.js +45 -18
- package/bin/esm/live-hooks/useLiveEvent.js.map +1 -0
- package/bin/esm/live-hooks/useLiveFollowMode.d.ts +163 -0
- package/bin/esm/live-hooks/useLiveFollowMode.d.ts.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveFollowMode.js +173 -39
- package/bin/esm/live-hooks/useLiveFollowMode.js.map +1 -0
- package/bin/esm/live-hooks/useLivePresence.d.ts +76 -0
- package/bin/esm/live-hooks/useLivePresence.d.ts.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLivePresence.js +74 -25
- package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveState.d.ts +46 -1
- package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveState.js +58 -18
- package/bin/esm/live-hooks/useLiveState.js.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveTimer.d.ts +56 -1
- package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useLiveTimer.js +80 -34
- package/bin/esm/live-hooks/useLiveTimer.js.map +1 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.d.ts +86 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
- package/bin/{live-hooks → esm/live-hooks}/useMediaSynchronizer.js +89 -37
- package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
- package/bin/{providers → esm/providers}/AzureProvider.d.ts +9 -9
- package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
- package/bin/{providers → esm/providers}/AzureProvider.js +28 -33
- package/bin/esm/providers/AzureProvider.js.map +1 -0
- package/bin/{providers → esm/providers}/LiveShareProvider.d.ts +106 -4
- package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
- package/bin/esm/providers/LiveShareProvider.js +196 -0
- package/bin/esm/providers/LiveShareProvider.js.map +1 -0
- package/bin/esm/providers/index.d.ts +3 -0
- package/bin/esm/providers/index.d.ts.map +1 -0
- package/bin/esm/providers/index.js +3 -0
- package/bin/esm/providers/index.js.map +1 -0
- package/bin/esm/shared-hooks/index.d.ts +7 -0
- package/bin/esm/shared-hooks/index.d.ts.map +1 -0
- package/bin/esm/shared-hooks/index.js +7 -0
- package/bin/esm/shared-hooks/index.js.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts +3 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.js +3 -0
- package/bin/esm/shared-hooks/internals/tree-node-constants.js.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.d.ts +10 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.js +18 -0
- package/bin/esm/shared-hooks/internals/tree-node-types.js.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts +33 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.js +186 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useDynamicDDS.d.ts +4 -4
- package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useDynamicDDS.js +22 -22
- package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useSharedMap.d.ts +4 -2
- package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useSharedMap.js +28 -14
- package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useSharedState.d.ts +1 -1
- package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useSharedState.js +2 -2
- package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useSharedStateRegistry.d.ts +1 -1
- package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/{shared-hooks → esm/shared-hooks}/useSharedStateRegistry.js +35 -24
- package/bin/esm/shared-hooks/useSharedStateRegistry.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedTree.d.ts +57 -0
- package/bin/esm/shared-hooks/useSharedTree.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedTree.js +117 -0
- package/bin/esm/shared-hooks/useSharedTree.js.map +1 -0
- package/bin/esm/shared-hooks/useTreeNode.d.ts +96 -0
- package/bin/esm/shared-hooks/useTreeNode.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useTreeNode.js +132 -0
- package/bin/esm/shared-hooks/useTreeNode.js.map +1 -0
- package/bin/{types → esm/types}/ActionTypes.d.ts +7 -7
- package/bin/esm/types/ActionTypes.d.ts.map +1 -0
- package/bin/esm/types/ActionTypes.js.map +1 -0
- package/bin/esm/types/FluidMap.d.ts +151 -0
- package/bin/esm/types/FluidMap.d.ts.map +1 -0
- package/bin/esm/types/FluidMap.js +24 -0
- package/bin/esm/types/FluidMap.js.map +1 -0
- package/bin/esm/types/PropTypes.d.ts +56 -0
- package/bin/esm/types/PropTypes.d.ts.map +1 -0
- package/bin/esm/types/PropTypes.js.map +1 -0
- package/bin/{types → esm/types}/ResultTypes.d.ts +62 -18
- package/bin/esm/types/ResultTypes.d.ts.map +1 -0
- package/bin/esm/types/ResultTypes.js.map +1 -0
- package/bin/esm/types/index.d.ts +4 -0
- package/bin/esm/types/index.d.ts.map +1 -0
- package/bin/esm/types/index.js +4 -0
- package/bin/esm/types/index.js.map +1 -0
- package/bin/esm/utils/index.d.ts +2 -0
- package/bin/esm/utils/index.d.ts.map +1 -0
- package/bin/esm/utils/index.js +2 -0
- package/bin/esm/utils/index.js.map +1 -0
- package/bin/esm/utils/type-check.d.ts.map +1 -0
- package/bin/{utils → esm/utils}/type-check.js +1 -1
- package/bin/esm/utils/type-check.js.map +1 -0
- package/package.json +51 -47
- package/src/index.ts +6 -6
- package/src/interfaces/index.ts +1 -1
- package/src/internal/index.ts +2 -2
- package/src/internal/type-guards.ts +1 -1
- package/src/live-hooks/index.ts +7 -7
- package/src/live-hooks/useLiveCanvas.ts +154 -82
- package/src/live-hooks/useLiveEvent.ts +43 -7
- package/src/live-hooks/useLiveFollowMode.ts +149 -6
- package/src/live-hooks/useLivePresence.ts +80 -17
- package/src/live-hooks/useLiveState.ts +54 -6
- package/src/live-hooks/useLiveTimer.ts +59 -4
- package/src/live-hooks/useMediaSynchronizer.ts +71 -6
- package/src/providers/AzureProvider.tsx +21 -21
- package/src/providers/LiveShareProvider.tsx +115 -13
- package/src/providers/index.ts +2 -2
- package/src/shared-hooks/index.ts +6 -4
- package/src/shared-hooks/internals/tree-node-constants.ts +2 -0
- package/src/shared-hooks/internals/tree-node-types.ts +26 -0
- package/src/shared-hooks/internals/tree-node-utils.ts +269 -0
- package/src/shared-hooks/useDynamicDDS.ts +28 -17
- package/src/shared-hooks/useSharedMap.ts +42 -17
- package/src/shared-hooks/useSharedState.ts +6 -3
- package/src/shared-hooks/useSharedStateRegistry.ts +44 -22
- package/src/shared-hooks/useSharedTree.ts +144 -0
- package/src/shared-hooks/useTreeNode.ts +147 -0
- package/src/types/ActionTypes.ts +13 -9
- package/src/types/FluidMap.ts +169 -0
- package/src/types/PropTypes.ts +57 -0
- package/src/types/ResultTypes.ts +88 -17
- package/src/types/index.ts +3 -3
- package/src/utils/index.ts +1 -1
- package/tsconfig.json +64 -70
- package/.nycrc.json +0 -10
- package/bin/index.d.ts +0 -7
- package/bin/index.d.ts.map +0 -1
- package/bin/index.js +0 -7
- package/bin/index.js.map +0 -1
- package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +0 -1
- package/bin/interfaces/LiveInterfaceExtensions.js.map +0 -1
- package/bin/interfaces/index.d.ts +0 -2
- package/bin/interfaces/index.d.ts.map +0 -1
- package/bin/interfaces/index.js +0 -2
- package/bin/interfaces/index.js.map +0 -1
- package/bin/internal/errors.d.ts.map +0 -1
- package/bin/internal/errors.js.map +0 -1
- package/bin/internal/index.d.ts +0 -3
- package/bin/internal/index.d.ts.map +0 -1
- package/bin/internal/index.js +0 -3
- package/bin/internal/index.js.map +0 -1
- package/bin/internal/type-guards.d.ts.map +0 -1
- package/bin/internal/type-guards.js.map +0 -1
- package/bin/live-hooks/index.d.ts +0 -8
- package/bin/live-hooks/index.d.ts.map +0 -1
- package/bin/live-hooks/index.js +0 -8
- package/bin/live-hooks/index.js.map +0 -1
- package/bin/live-hooks/useLiveCanvas.d.ts +0 -29
- package/bin/live-hooks/useLiveCanvas.d.ts.map +0 -1
- package/bin/live-hooks/useLiveCanvas.js +0 -160
- package/bin/live-hooks/useLiveCanvas.js.map +0 -1
- package/bin/live-hooks/useLiveEvent.d.ts.map +0 -1
- package/bin/live-hooks/useLiveEvent.js.map +0 -1
- package/bin/live-hooks/useLiveFollowMode.d.ts +0 -24
- package/bin/live-hooks/useLiveFollowMode.d.ts.map +0 -1
- package/bin/live-hooks/useLiveFollowMode.js.map +0 -1
- package/bin/live-hooks/useLivePresence.d.ts +0 -26
- package/bin/live-hooks/useLivePresence.d.ts.map +0 -1
- package/bin/live-hooks/useLivePresence.js.map +0 -1
- package/bin/live-hooks/useLiveState.d.ts.map +0 -1
- package/bin/live-hooks/useLiveState.js.map +0 -1
- package/bin/live-hooks/useLiveTimer.d.ts.map +0 -1
- package/bin/live-hooks/useLiveTimer.js.map +0 -1
- package/bin/live-hooks/useMediaSynchronizer.d.ts +0 -25
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +0 -1
- package/bin/live-hooks/useMediaSynchronizer.js.map +0 -1
- package/bin/providers/AzureProvider.d.ts.map +0 -1
- package/bin/providers/AzureProvider.js.map +0 -1
- package/bin/providers/LiveShareProvider.d.ts.map +0 -1
- package/bin/providers/LiveShareProvider.js +0 -95
- package/bin/providers/LiveShareProvider.js.map +0 -1
- package/bin/providers/index.d.ts +0 -3
- package/bin/providers/index.d.ts.map +0 -1
- package/bin/providers/index.js +0 -3
- package/bin/providers/index.js.map +0 -1
- package/bin/shared-hooks/index.d.ts +0 -5
- package/bin/shared-hooks/index.d.ts.map +0 -1
- package/bin/shared-hooks/index.js +0 -5
- package/bin/shared-hooks/index.js.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +0 -1
- package/bin/shared-hooks/useDynamicDDS.js.map +0 -1
- package/bin/shared-hooks/useSharedMap.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedMap.js.map +0 -1
- package/bin/shared-hooks/useSharedState.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedState.js.map +0 -1
- package/bin/shared-hooks/useSharedStateRegistry.d.ts.map +0 -1
- package/bin/shared-hooks/useSharedStateRegistry.js.map +0 -1
- package/bin/types/ActionTypes.d.ts.map +0 -1
- package/bin/types/ActionTypes.js.map +0 -1
- package/bin/types/PropTypes.d.ts +0 -8
- package/bin/types/PropTypes.d.ts.map +0 -1
- package/bin/types/PropTypes.js.map +0 -1
- package/bin/types/ResultTypes.d.ts.map +0 -1
- package/bin/types/ResultTypes.js.map +0 -1
- package/bin/types/index.d.ts +0 -4
- package/bin/types/index.d.ts.map +0 -1
- package/bin/types/index.js +0 -4
- package/bin/types/index.js.map +0 -1
- package/bin/utils/index.d.ts +0 -2
- package/bin/utils/index.d.ts.map +0 -1
- package/bin/utils/index.js +0 -2
- package/bin/utils/index.js.map +0 -1
- package/bin/utils/type-check.d.ts.map +0 -1
- package/bin/utils/type-check.js.map +0 -1
- package/tsconfig.build.json +0 -6
- /package/bin/{interfaces → esm/interfaces}/LiveInterfaceExtensions.d.ts +0 -0
- /package/bin/{interfaces → esm/interfaces}/LiveInterfaceExtensions.js +0 -0
- /package/bin/{internal → esm/internal}/errors.d.ts +0 -0
- /package/bin/{internal → esm/internal}/errors.js +0 -0
- /package/bin/{internal → esm/internal}/type-guards.js +0 -0
- /package/bin/{types → esm/types}/ActionTypes.js +0 -0
- /package/bin/{types → esm/types}/PropTypes.js +0 -0
- /package/bin/{types → esm/types}/ResultTypes.js +0 -0
- /package/bin/{utils → esm/utils}/type-check.d.ts +0 -0
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
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
5
|
import { LiveDataObjectInitializeState, LiveState, } from "@microsoft/live-share";
|
|
15
6
|
import React from "react";
|
|
16
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
17
|
-
import { useFluidObjectsContext } from "../providers";
|
|
18
|
-
import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, isPrevStateCallback, } from "../internal";
|
|
7
|
+
import { useDynamicDDS } from "../shared-hooks/index.js";
|
|
8
|
+
import { useFluidObjectsContext } from "../providers/index.js";
|
|
9
|
+
import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, isPrevStateCallback, } from "../internal/index.js";
|
|
19
10
|
/**
|
|
20
11
|
* React hook for using a Live Share `LiveState`.
|
|
21
12
|
*
|
|
@@ -28,6 +19,51 @@ import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, Ac
|
|
|
28
19
|
* @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
|
|
29
20
|
* @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value.
|
|
30
21
|
* The setter returns a void promise, which will throw if the user does not have the required roles to set.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
```jsx
|
|
25
|
+
import { useLiveState } from "@microsoft/live-share-react";
|
|
26
|
+
|
|
27
|
+
const planets = [
|
|
28
|
+
"Mercury",
|
|
29
|
+
"Venus",
|
|
30
|
+
"Earth",
|
|
31
|
+
"Mars",
|
|
32
|
+
"Jupiter",
|
|
33
|
+
"Saturn",
|
|
34
|
+
"Uranus",
|
|
35
|
+
"Neptune",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
// Define a unique key that differentiates this usage of `useLiveState` from others in your app
|
|
39
|
+
const MY_UNIQUE_KEY = "selected-planet-key";
|
|
40
|
+
|
|
41
|
+
// Example component for using useLiveState
|
|
42
|
+
export const MyCustomState = () => {
|
|
43
|
+
const [planet, setPlanet, liveState] = useLiveState(MY_UNIQUE_KEY, planets[0]);
|
|
44
|
+
|
|
45
|
+
// Render loading UI when creating LiveState instance for first time
|
|
46
|
+
if (!liveState) return <>Loading...</>;
|
|
47
|
+
|
|
48
|
+
// Render UI
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
{`Current planet: ${planet}`}
|
|
52
|
+
{"Select a planet below:"}
|
|
53
|
+
{planets.map((planet) => (
|
|
54
|
+
<button
|
|
55
|
+
key={planet}
|
|
56
|
+
onClick={() => {
|
|
57
|
+
setPlanet(planet);
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
{planet}
|
|
61
|
+
</button>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
```
|
|
31
67
|
*/
|
|
32
68
|
export function useLiveState(uniqueKey, initialState, allowedRoles) {
|
|
33
69
|
const [currentState, setCurrentState] = React.useState(initialState);
|
|
@@ -41,7 +77,7 @@ export function useLiveState(uniqueKey, initialState, allowedRoles) {
|
|
|
41
77
|
* @param state TState to set
|
|
42
78
|
* @returns void promise, which will throw if the user does not have the required roles
|
|
43
79
|
*/
|
|
44
|
-
const setState = React.useCallback((state) =>
|
|
80
|
+
const setState = React.useCallback(async (state) => {
|
|
45
81
|
if (!container) {
|
|
46
82
|
throw new ActionContainerNotJoinedError("liveState", "setState");
|
|
47
83
|
}
|
|
@@ -54,8 +90,8 @@ export function useLiveState(uniqueKey, initialState, allowedRoles) {
|
|
|
54
90
|
const valueToSet = isPrevStateCallback(state)
|
|
55
91
|
? state(liveState.state)
|
|
56
92
|
: state;
|
|
57
|
-
return
|
|
58
|
-
}
|
|
93
|
+
return await liveState.set(valueToSet);
|
|
94
|
+
}, [container, liveState]);
|
|
59
95
|
/**
|
|
60
96
|
* Setup change listeners and start `LiveState` if needed
|
|
61
97
|
*/
|
|
@@ -67,11 +103,15 @@ export function useLiveState(uniqueKey, initialState, allowedRoles) {
|
|
|
67
103
|
};
|
|
68
104
|
liveState.on("stateChanged", onStateChanged);
|
|
69
105
|
if (liveState.initializeState === LiveDataObjectInitializeState.needed) {
|
|
70
|
-
liveState
|
|
106
|
+
liveState
|
|
107
|
+
.initialize(initialState, allowedRoles)
|
|
108
|
+
.then(() => onStateChanged(liveState.state));
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
onStateChanged(liveState.state);
|
|
71
112
|
}
|
|
72
|
-
onStateChanged(liveState.state);
|
|
73
113
|
return () => {
|
|
74
|
-
liveState
|
|
114
|
+
liveState?.off("stateChanged", onStateChanged);
|
|
75
115
|
};
|
|
76
116
|
}, [liveState]);
|
|
77
117
|
return [currentState, setState, liveState];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveState.js","sourceRoot":"","sources":["../../../src/live-hooks/useLiveState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,6BAA6B,EAC7B,SAAS,GAEZ,MAAM,uBAAuB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AAO,MAAM,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3C,CAAC,EACD,CAAC,SAAS,EAAE,SAAS,CAAC,CACzB,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,IACI,SAAS,CAAC,eAAe,KAAK,6BAA6B,CAAC,MAAM,EACpE,CAAC;YACC,SAAS;iBACJ,UAAU,CAAC,YAAY,EAAE,YAAY,CAAC;iBACtC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACJ,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,GAAG,EAAE;YACR,SAAS,EAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QACnD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CAAC,YAAY,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
import { UserMeetingRole } from "@microsoft/live-share";
|
|
6
|
-
import { IUseLiveTimerResults, OnTimerDidFinishAction, OnTimerDidPauseAction, OnTimerDidPlayAction, OnTimerDidStartAction, OnTimerTickAction } from "../types";
|
|
6
|
+
import { IUseLiveTimerResults, OnTimerDidFinishAction, OnTimerDidPauseAction, OnTimerDidPlayAction, OnTimerDidStartAction, OnTimerTickAction } from "../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* React hook for using Live Share's `LiveTimer` DDS.
|
|
9
9
|
*
|
|
@@ -20,6 +20,61 @@ import { IUseLiveTimerResults, OnTimerDidFinishAction, OnTimerDidPauseAction, On
|
|
|
20
20
|
* @param onPlay Optional. event handler callback for when the timer is resumed.
|
|
21
21
|
* @param onFinish Optional. event handler callback for when the timer finishes.
|
|
22
22
|
* @returns results and callbacks exposed via the hook.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
```jsx
|
|
26
|
+
import { useLiveTimer } from "@microsoft/live-share-react";
|
|
27
|
+
|
|
28
|
+
// Define a unique key that differentiates this usage of `useLiveTimer` from others in your app
|
|
29
|
+
const MY_UNIQUE_KEY = "timer-key";
|
|
30
|
+
|
|
31
|
+
// Example component for using useLiveTimer
|
|
32
|
+
export function CountdownTimer() {
|
|
33
|
+
const {
|
|
34
|
+
milliRemaining,
|
|
35
|
+
timerConfig,
|
|
36
|
+
liveTimer,
|
|
37
|
+
start,
|
|
38
|
+
pause,
|
|
39
|
+
play,
|
|
40
|
+
} = useLiveTimer("TIMER-ID");
|
|
41
|
+
|
|
42
|
+
// Render loading UI when creating LiveTimer instance for first time
|
|
43
|
+
if (!liveTimer) return <>Loading...</>;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div>
|
|
47
|
+
<button
|
|
48
|
+
onClick={() => {
|
|
49
|
+
start(60 * 1000);
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
{timerConfig === undefined ? "Start" : "Reset"}
|
|
53
|
+
</button>
|
|
54
|
+
{timerConfig !== undefined && (
|
|
55
|
+
<button
|
|
56
|
+
onClick={() => {
|
|
57
|
+
if (timerConfig.running) {
|
|
58
|
+
pause();
|
|
59
|
+
} else {
|
|
60
|
+
play();
|
|
61
|
+
}
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
{timerConfig.running ? "Pause" : "Play"}
|
|
65
|
+
</button>
|
|
66
|
+
)}
|
|
67
|
+
{milliRemaining !== undefined && (
|
|
68
|
+
<p>
|
|
69
|
+
{`${Math.round(milliRemaining / 1000)} / ${
|
|
70
|
+
Math.round(timerConfig.duration) / 1000
|
|
71
|
+
}`}
|
|
72
|
+
</p>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
23
78
|
*/
|
|
24
79
|
export declare function useLiveTimer(uniqueKey: string, allowedRoles?: UserMeetingRole[], tickRate?: number, onTick?: OnTimerTickAction, onStart?: OnTimerDidStartAction, onPause?: OnTimerDidPauseAction, onPlay?: OnTimerDidPlayAction, onFinish?: OnTimerDidFinishAction): IUseLiveTimerResults;
|
|
25
80
|
//# sourceMappingURL=useLiveTimer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveTimer.d.ts","sourceRoot":"","sources":["../../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGH,eAAe,EAGlB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EAIpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,mBAAmB,CAAC;AAS3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,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,CA8JtB"}
|
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
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
5
|
import { LiveTimerEvents, LiveTimer, LiveDataObjectInitializeState, } from "@microsoft/live-share";
|
|
15
6
|
import React from "react";
|
|
16
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
17
|
-
import { useFluidObjectsContext } from "../providers";
|
|
18
|
-
import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal";
|
|
7
|
+
import { useDynamicDDS } from "../shared-hooks/index.js";
|
|
8
|
+
import { useFluidObjectsContext } from "../providers/index.js";
|
|
9
|
+
import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal/index.js";
|
|
19
10
|
/**
|
|
20
11
|
* React hook for using Live Share's `LiveTimer` DDS.
|
|
21
12
|
*
|
|
@@ -32,6 +23,61 @@ import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, Ac
|
|
|
32
23
|
* @param onPlay Optional. event handler callback for when the timer is resumed.
|
|
33
24
|
* @param onFinish Optional. event handler callback for when the timer finishes.
|
|
34
25
|
* @returns results and callbacks exposed via the hook.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
```jsx
|
|
29
|
+
import { useLiveTimer } from "@microsoft/live-share-react";
|
|
30
|
+
|
|
31
|
+
// Define a unique key that differentiates this usage of `useLiveTimer` from others in your app
|
|
32
|
+
const MY_UNIQUE_KEY = "timer-key";
|
|
33
|
+
|
|
34
|
+
// Example component for using useLiveTimer
|
|
35
|
+
export function CountdownTimer() {
|
|
36
|
+
const {
|
|
37
|
+
milliRemaining,
|
|
38
|
+
timerConfig,
|
|
39
|
+
liveTimer,
|
|
40
|
+
start,
|
|
41
|
+
pause,
|
|
42
|
+
play,
|
|
43
|
+
} = useLiveTimer("TIMER-ID");
|
|
44
|
+
|
|
45
|
+
// Render loading UI when creating LiveTimer instance for first time
|
|
46
|
+
if (!liveTimer) return <>Loading...</>;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div>
|
|
50
|
+
<button
|
|
51
|
+
onClick={() => {
|
|
52
|
+
start(60 * 1000);
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{timerConfig === undefined ? "Start" : "Reset"}
|
|
56
|
+
</button>
|
|
57
|
+
{timerConfig !== undefined && (
|
|
58
|
+
<button
|
|
59
|
+
onClick={() => {
|
|
60
|
+
if (timerConfig.running) {
|
|
61
|
+
pause();
|
|
62
|
+
} else {
|
|
63
|
+
play();
|
|
64
|
+
}
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{timerConfig.running ? "Pause" : "Play"}
|
|
68
|
+
</button>
|
|
69
|
+
)}
|
|
70
|
+
{milliRemaining !== undefined && (
|
|
71
|
+
<p>
|
|
72
|
+
{`${Math.round(milliRemaining / 1000)} / ${
|
|
73
|
+
Math.round(timerConfig.duration) / 1000
|
|
74
|
+
}`}
|
|
75
|
+
</p>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
35
81
|
*/
|
|
36
82
|
export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart, onPause, onPlay, onFinish) {
|
|
37
83
|
/**
|
|
@@ -52,7 +98,7 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
52
98
|
* @param duration the duration for the timer in milliseconds
|
|
53
99
|
* @returns void promise that will throw when user does not have required roles
|
|
54
100
|
*/
|
|
55
|
-
const start = React.useCallback((duration) =>
|
|
101
|
+
const start = React.useCallback(async (duration) => {
|
|
56
102
|
if (!container) {
|
|
57
103
|
throw new ActionContainerNotJoinedError("liveTimer", "start");
|
|
58
104
|
}
|
|
@@ -62,13 +108,13 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
62
108
|
if (!liveTimer.isInitialized) {
|
|
63
109
|
throw new ActionLiveDataObjectInitializedError("liveTimer", "start");
|
|
64
110
|
}
|
|
65
|
-
return
|
|
66
|
-
}
|
|
111
|
+
return await liveTimer.start(duration);
|
|
112
|
+
}, [container, liveTimer]);
|
|
67
113
|
/**
|
|
68
114
|
* Callback to send event through `LiveTimer`
|
|
69
115
|
* @returns void promise that will throw when user does not have required roles
|
|
70
116
|
*/
|
|
71
|
-
const play = React.useCallback(() =>
|
|
117
|
+
const play = React.useCallback(async () => {
|
|
72
118
|
if (!container) {
|
|
73
119
|
throw new ActionContainerNotJoinedError("liveTimer", "play");
|
|
74
120
|
}
|
|
@@ -78,13 +124,13 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
78
124
|
if (!liveTimer.isInitialized) {
|
|
79
125
|
throw new ActionLiveDataObjectInitializedError("liveTimer", "play");
|
|
80
126
|
}
|
|
81
|
-
return
|
|
82
|
-
}
|
|
127
|
+
return await liveTimer.play();
|
|
128
|
+
}, [container, liveTimer]);
|
|
83
129
|
/**
|
|
84
130
|
* Callback to send event through `LiveTimer`
|
|
85
131
|
* @returns void promise that will throw when user does not have required roles
|
|
86
132
|
*/
|
|
87
|
-
const pause = React.useCallback(() =>
|
|
133
|
+
const pause = React.useCallback(async () => {
|
|
88
134
|
if (!container) {
|
|
89
135
|
throw new ActionContainerNotJoinedError("liveTimer", "pause");
|
|
90
136
|
}
|
|
@@ -94,8 +140,8 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
94
140
|
if (!liveTimer.isInitialized) {
|
|
95
141
|
throw new ActionLiveDataObjectInitializedError("liveTimer", "pause");
|
|
96
142
|
}
|
|
97
|
-
return
|
|
98
|
-
}
|
|
143
|
+
return await liveTimer.pause();
|
|
144
|
+
}, [container, liveTimer]);
|
|
99
145
|
/**
|
|
100
146
|
* Setup change listeners and start `LiveTimer` if needed
|
|
101
147
|
*/
|
|
@@ -112,25 +158,25 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
112
158
|
};
|
|
113
159
|
const onDidStart = (config) => {
|
|
114
160
|
onTimerConfigChange(config);
|
|
115
|
-
onStart
|
|
161
|
+
onStart?.(config);
|
|
116
162
|
setMilliRemaining(config.duration);
|
|
117
163
|
};
|
|
118
164
|
const onDidFinish = (config) => {
|
|
119
165
|
onTimerConfigChange(config);
|
|
120
|
-
onFinish
|
|
166
|
+
onFinish?.(config);
|
|
121
167
|
setMilliRemaining(0);
|
|
122
168
|
};
|
|
123
169
|
const onDidPlay = (config) => {
|
|
124
170
|
onTimerConfigChange(config);
|
|
125
|
-
onPlay
|
|
171
|
+
onPlay?.(config);
|
|
126
172
|
};
|
|
127
173
|
const onDidPause = (config) => {
|
|
128
174
|
onTimerConfigChange(config);
|
|
129
|
-
onPause
|
|
175
|
+
onPause?.(config);
|
|
130
176
|
};
|
|
131
177
|
const onDidTick = (milliseconds) => {
|
|
132
178
|
setMilliRemaining(milliseconds);
|
|
133
|
-
onTick
|
|
179
|
+
onTick?.(milliseconds);
|
|
134
180
|
};
|
|
135
181
|
liveTimer.on(LiveTimerEvents.started, onDidStart);
|
|
136
182
|
liveTimer.on(LiveTimerEvents.finished, onDidFinish);
|
|
@@ -143,11 +189,11 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
143
189
|
}
|
|
144
190
|
return () => {
|
|
145
191
|
// on unmount, remove event listeners
|
|
146
|
-
liveTimer
|
|
147
|
-
liveTimer
|
|
148
|
-
liveTimer
|
|
149
|
-
liveTimer
|
|
150
|
-
liveTimer
|
|
192
|
+
liveTimer?.off(LiveTimerEvents.started, onDidStart);
|
|
193
|
+
liveTimer?.off(LiveTimerEvents.finished, onDidFinish);
|
|
194
|
+
liveTimer?.off(LiveTimerEvents.played, onDidPlay);
|
|
195
|
+
liveTimer?.off(LiveTimerEvents.paused, onDidPause);
|
|
196
|
+
liveTimer?.off(LiveTimerEvents.onTick, onDidTick);
|
|
151
197
|
};
|
|
152
198
|
}, [liveTimer, onTick, onStart, onFinish, onPlay, onPause]);
|
|
153
199
|
/**
|
|
@@ -155,11 +201,11 @@ export function useLiveTimer(uniqueKey, allowedRoles, tickRate, onTick, onStart,
|
|
|
155
201
|
*/
|
|
156
202
|
React.useEffect(() => {
|
|
157
203
|
if (tickRate !== undefined &&
|
|
158
|
-
|
|
159
|
-
tickRate !==
|
|
204
|
+
liveTimer?.tickRate !== undefined &&
|
|
205
|
+
tickRate !== liveTimer?.tickRate) {
|
|
160
206
|
liveTimer.tickRate = tickRate;
|
|
161
207
|
}
|
|
162
|
-
}, [tickRate, liveTimer
|
|
208
|
+
}, [tickRate, liveTimer?.tickRate]);
|
|
163
209
|
return {
|
|
164
210
|
liveTimer,
|
|
165
211
|
milliRemaining,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveTimer.js","sourceRoot":"","sources":["../../../src/live-hooks/useLiveTimer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAEf,SAAS,EACT,6BAA6B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAA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|
@@ -0,0 +1,86 @@
|
|
|
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 React from "react";
|
|
7
|
+
import { ExtendedMediaMetadata, IMediaPlayer } from "@microsoft/live-share-media";
|
|
8
|
+
import { IUseMediaSynchronizerResults } from "../types/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* React hook for using a Live Share media `MediaPlayerSynchronizer`.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Use this hook if you want to synchronize the playback position of a video or audio element during a Live Share session.
|
|
14
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
15
|
+
*
|
|
16
|
+
* @param uniqueKey uniqueKey value for the `LiveMediaSession` DDS object used by `MediaPlayerSynchronizer`.
|
|
17
|
+
* @param mediaPlayerElement React RefObject containing object/element conforming to IMediaPlayer interface, `IMediaPlayer` object, or string id for <video> / <audio> element.
|
|
18
|
+
* @param initialTrack initial track to load. Either ExtendedMediaMetadata, trackId string, or null.
|
|
19
|
+
* @param allowedRoles Optional. Array of user roles that are eligible to modify group playback state.
|
|
20
|
+
* @param viewOnly Optional. Flag for whether or not the media synchronizer should be in viewOnly mode.
|
|
21
|
+
* @param canSendPositionUpdates Optional. Controls whether or not the local client is allowed to send position updates to the group.
|
|
22
|
+
* @returns IUseMediaSynchronizerResults object.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
```jsx
|
|
26
|
+
import { useMediaSynchronizer } from "@microsoft/live-share-react";
|
|
27
|
+
import { UserMeetingRole } from "@microsoft/live-share";
|
|
28
|
+
import { MediaPlayerSynchronizerEvents } from "@microsoft/live-share-media";
|
|
29
|
+
import { useRef, useEffect } from "react";
|
|
30
|
+
|
|
31
|
+
const ALLOWED_ROLES = [UserMeetingRole.organizer, UserMeetingRole.presenter];
|
|
32
|
+
|
|
33
|
+
const INITIAL_TRACK = "<YOUR_VIDEO_URL>";
|
|
34
|
+
|
|
35
|
+
// Define a unique key that distinguishes this `useMediaSynchronizer` from others in your app
|
|
36
|
+
const UNIQUE_KEY = "MEDIA-SESSION-ID";
|
|
37
|
+
|
|
38
|
+
export function VideoPlayer() {
|
|
39
|
+
const videoRef = useRef(null);
|
|
40
|
+
const { play, pause, seekTo, mediaSynchronizer } = useMediaSynchronizer(
|
|
41
|
+
UNIQUE_KEY,
|
|
42
|
+
videoRef,
|
|
43
|
+
INITIAL_TRACK,
|
|
44
|
+
ALLOWED_ROLES
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Listen for groupaction events (optional)
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
// Listen for player group actions for errors (e.g., play error)
|
|
50
|
+
const onGroupAction = (evt: IMediaPlayerSynchronizerEvent) => {
|
|
51
|
+
// See which user made the change (e.g., to display a notification)
|
|
52
|
+
const clientInfo = await synchronizer.mediaSession.getClientInfo(evt.details.clientId);
|
|
53
|
+
};
|
|
54
|
+
mediaSynchronizer?.addEventListener(
|
|
55
|
+
MediaPlayerSynchronizerEvents.groupaction,
|
|
56
|
+
onGroupAction
|
|
57
|
+
);
|
|
58
|
+
return () => {
|
|
59
|
+
mediaSynchronizer?.removeEventListener(
|
|
60
|
+
MediaPlayerSynchronizerEvents.groupaction,
|
|
61
|
+
onGroupAction
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
}, [mediaSynchronizer]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div>
|
|
68
|
+
<video ref={videoRef} />
|
|
69
|
+
<button onClick={play}>
|
|
70
|
+
Play
|
|
71
|
+
</button>
|
|
72
|
+
<button onClick={pause}>
|
|
73
|
+
Pause
|
|
74
|
+
</button>
|
|
75
|
+
<button onClick={() => {
|
|
76
|
+
seekTo(0);
|
|
77
|
+
}}>
|
|
78
|
+
Start over
|
|
79
|
+
</button>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
*/
|
|
85
|
+
export declare function useMediaSynchronizer(uniqueKey: string, mediaPlayerElement: React.RefObject<IMediaPlayer> | IMediaPlayer | string | null, initialTrack: Partial<ExtendedMediaMetadata> | string | null, allowedRoles?: UserMeetingRole[], viewOnly?: boolean, canSendPositionUpdates?: boolean): IUseMediaSynchronizerResults;
|
|
86
|
+
//# sourceMappingURL=useMediaSynchronizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaSynchronizer.d.ts","sourceRoot":"","sources":["../../../src/live-hooks/useMediaSynchronizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEH,qBAAqB,EACrB,YAAY,EAIf,MAAM,6BAA6B,CAAC;AAOrC,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAOjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,wBAAgB,oBAAoB,CAChC,SAAS,EAAE,MAAM,EACjB,kBAAkB,EACZ,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,GAC7B,YAAY,GACZ,MAAM,GACN,IAAI,EACV,YAAY,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,MAAM,GAAG,IAAI,EAC5D,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,QAAQ,CAAC,EAAE,OAAO,EAClB,sBAAsB,CAAC,EAAE,OAAO,GACjC,4BAA4B,CAiP9B"}
|