@microsoft/live-share-react 2.0.0-internal.1 → 2.0.0-internal.11
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 +169 -164
- package/bin/cjs/index.d.ts +7 -0
- package/bin/cjs/index.d.ts.map +1 -0
- package/bin/cjs/index.js +23 -0
- package/bin/cjs/index.js.map +1 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts +26 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.js +7 -0
- package/bin/cjs/interfaces/LiveInterfaceExtensions.js.map +1 -0
- package/bin/cjs/interfaces/index.d.ts +2 -0
- package/bin/cjs/interfaces/index.d.ts.map +1 -0
- package/bin/cjs/interfaces/index.js +18 -0
- package/bin/cjs/interfaces/index.js.map +1 -0
- package/bin/cjs/internal/errors.d.ts +41 -0
- package/bin/cjs/internal/errors.d.ts.map +1 -0
- package/bin/cjs/internal/errors.js +48 -0
- package/bin/cjs/internal/errors.js.map +1 -0
- package/bin/cjs/internal/index.d.ts +3 -0
- package/bin/cjs/internal/index.d.ts.map +1 -0
- package/bin/cjs/internal/index.js +19 -0
- package/bin/cjs/internal/index.js.map +1 -0
- package/bin/cjs/internal/type-guards.d.ts +11 -0
- package/bin/cjs/internal/type-guards.d.ts.map +1 -0
- package/bin/cjs/internal/type-guards.js +24 -0
- package/bin/cjs/internal/type-guards.js.map +1 -0
- package/bin/cjs/live-hooks/index.d.ts +8 -0
- package/bin/cjs/live-hooks/index.d.ts.map +1 -0
- package/bin/cjs/live-hooks/index.js +24 -0
- package/bin/cjs/live-hooks/index.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveCanvas.d.ts +80 -0
- package/bin/cjs/live-hooks/useLiveCanvas.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveCanvas.js +244 -0
- package/bin/cjs/live-hooks/useLiveCanvas.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveEvent.d.ts +59 -0
- package/bin/cjs/live-hooks/useLiveEvent.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveEvent.js +150 -0
- package/bin/cjs/live-hooks/useLiveEvent.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.d.ts +163 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.js +360 -0
- package/bin/cjs/live-hooks/useLiveFollowMode.js.map +1 -0
- package/bin/cjs/live-hooks/useLivePresence.d.ts +76 -0
- package/bin/cjs/live-hooks/useLivePresence.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLivePresence.js +170 -0
- package/bin/cjs/live-hooks/useLivePresence.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveState.d.ts +66 -0
- package/bin/cjs/live-hooks/useLiveState.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveState.js +134 -0
- package/bin/cjs/live-hooks/useLiveState.js.map +1 -0
- package/bin/cjs/live-hooks/useLiveTimer.d.ts +80 -0
- package/bin/cjs/live-hooks/useLiveTimer.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useLiveTimer.js +233 -0
- package/bin/cjs/live-hooks/useLiveTimer.js.map +1 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts +86 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.js +301 -0
- package/bin/cjs/live-hooks/useMediaSynchronizer.js.map +1 -0
- package/bin/cjs/package.json +1 -0
- package/bin/cjs/providers/AzureProvider.d.ts +113 -0
- package/bin/cjs/providers/AzureProvider.d.ts.map +1 -0
- package/bin/cjs/providers/AzureProvider.js +127 -0
- package/bin/cjs/providers/AzureProvider.js.map +1 -0
- package/bin/cjs/providers/LiveShareProvider.d.ts +193 -0
- package/bin/cjs/providers/LiveShareProvider.d.ts.map +1 -0
- package/bin/cjs/providers/LiveShareProvider.js +205 -0
- package/bin/cjs/providers/LiveShareProvider.js.map +1 -0
- package/bin/cjs/providers/index.d.ts +3 -0
- package/bin/cjs/providers/index.d.ts.map +1 -0
- package/bin/cjs/providers/index.js +19 -0
- package/bin/cjs/providers/index.js.map +1 -0
- package/bin/cjs/shared-hooks/index.d.ts +7 -0
- package/bin/cjs/shared-hooks/index.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/index.js +23 -0
- package/bin/cjs/shared-hooks/index.js.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts +3 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.js +6 -0
- package/bin/cjs/shared-hooks/internals/tree-node-constants.js.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts +10 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.js +23 -0
- package/bin/cjs/shared-hooks/internals/tree-node-types.js.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts +33 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.js +193 -0
- package/bin/cjs/shared-hooks/internals/tree-node-utils.js.map +1 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.d.ts +23 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.js +87 -0
- package/bin/cjs/shared-hooks/useDynamicDDS.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedMap.d.ts +25 -0
- package/bin/cjs/shared-hooks/useSharedMap.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedMap.js +134 -0
- package/bin/cjs/shared-hooks/useSharedMap.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedState.d.ts +22 -0
- package/bin/cjs/shared-hooks/useSharedState.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedState.js +80 -0
- package/bin/cjs/shared-hooks/useSharedState.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts +37 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.js +120 -0
- package/bin/cjs/shared-hooks/useSharedStateRegistry.js.map +1 -0
- package/bin/cjs/shared-hooks/useSharedTree.d.ts +57 -0
- package/bin/cjs/shared-hooks/useSharedTree.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useSharedTree.js +123 -0
- package/bin/cjs/shared-hooks/useSharedTree.js.map +1 -0
- package/bin/cjs/shared-hooks/useTreeNode.d.ts +96 -0
- package/bin/cjs/shared-hooks/useTreeNode.d.ts.map +1 -0
- package/bin/cjs/shared-hooks/useTreeNode.js +135 -0
- package/bin/cjs/shared-hooks/useTreeNode.js.map +1 -0
- package/bin/cjs/types/ActionTypes.d.ts +112 -0
- package/bin/cjs/types/ActionTypes.d.ts.map +1 -0
- package/bin/cjs/types/ActionTypes.js +7 -0
- package/bin/cjs/types/ActionTypes.js.map +1 -0
- package/bin/cjs/types/PropTypes.d.ts +56 -0
- package/bin/cjs/types/PropTypes.d.ts.map +1 -0
- package/bin/cjs/types/PropTypes.js +7 -0
- package/bin/cjs/types/PropTypes.js.map +1 -0
- package/bin/cjs/types/ResultTypes.d.ts +334 -0
- package/bin/cjs/types/ResultTypes.d.ts.map +1 -0
- package/bin/cjs/types/ResultTypes.js +7 -0
- package/bin/cjs/types/ResultTypes.js.map +1 -0
- package/bin/cjs/types/index.d.ts +4 -0
- package/bin/cjs/types/index.d.ts.map +1 -0
- package/bin/cjs/types/index.js +20 -0
- package/bin/cjs/types/index.js.map +1 -0
- package/bin/cjs/utils/index.d.ts +2 -0
- package/bin/cjs/utils/index.d.ts.map +1 -0
- package/bin/cjs/utils/index.js +18 -0
- package/bin/cjs/utils/index.js.map +1 -0
- package/bin/cjs/utils/type-check.d.ts +15 -0
- package/bin/cjs/utils/type-check.d.ts.map +1 -0
- package/bin/cjs/utils/type-check.js +62 -0
- package/bin/cjs/utils/type-check.js.map +1 -0
- 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 +26 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
- package/bin/esm/interfaces/LiveInterfaceExtensions.js +6 -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 +41 -0
- package/bin/esm/internal/errors.d.ts.map +1 -0
- package/bin/esm/internal/errors.js +42 -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/esm/internal/type-guards.d.ts +11 -0
- package/bin/esm/internal/type-guards.d.ts.map +1 -0
- package/bin/esm/internal/type-guards.js +20 -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 +238 -0
- package/bin/esm/live-hooks/useLiveCanvas.js.map +1 -0
- package/bin/esm/live-hooks/useLiveEvent.d.ts +59 -0
- package/bin/esm/live-hooks/useLiveEvent.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveEvent.js +144 -0
- 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/esm/live-hooks/useLiveFollowMode.js +354 -0
- 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/esm/live-hooks/useLivePresence.js +164 -0
- package/bin/esm/live-hooks/useLivePresence.js.map +1 -0
- package/bin/esm/live-hooks/useLiveState.d.ts +66 -0
- package/bin/esm/live-hooks/useLiveState.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveState.js +128 -0
- package/bin/esm/live-hooks/useLiveState.js.map +1 -0
- package/bin/esm/live-hooks/useLiveTimer.d.ts +80 -0
- package/bin/esm/live-hooks/useLiveTimer.d.ts.map +1 -0
- package/bin/esm/live-hooks/useLiveTimer.js +227 -0
- 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/esm/live-hooks/useMediaSynchronizer.js +295 -0
- package/bin/esm/live-hooks/useMediaSynchronizer.js.map +1 -0
- package/bin/esm/providers/AzureProvider.d.ts +113 -0
- package/bin/esm/providers/AzureProvider.d.ts.map +1 -0
- package/bin/esm/providers/AzureProvider.js +119 -0
- package/bin/esm/providers/AzureProvider.js.map +1 -0
- package/bin/esm/providers/LiveShareProvider.d.ts +193 -0
- package/bin/esm/providers/LiveShareProvider.d.ts.map +1 -0
- package/bin/esm/providers/LiveShareProvider.js +197 -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 +188 -0
- package/bin/esm/shared-hooks/internals/tree-node-utils.js.map +1 -0
- package/bin/esm/shared-hooks/useDynamicDDS.d.ts +23 -0
- package/bin/esm/shared-hooks/useDynamicDDS.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useDynamicDDS.js +81 -0
- package/bin/esm/shared-hooks/useDynamicDDS.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedMap.d.ts +25 -0
- package/bin/esm/shared-hooks/useSharedMap.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedMap.js +128 -0
- package/bin/esm/shared-hooks/useSharedMap.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedState.d.ts +22 -0
- package/bin/esm/shared-hooks/useSharedState.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedState.js +74 -0
- package/bin/esm/shared-hooks/useSharedState.js.map +1 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts +37 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/esm/shared-hooks/useSharedStateRegistry.js +113 -0
- 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/esm/types/ActionTypes.d.ts +112 -0
- package/bin/esm/types/ActionTypes.d.ts.map +1 -0
- package/bin/esm/types/ActionTypes.js +6 -0
- package/bin/esm/types/ActionTypes.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 +6 -0
- package/bin/esm/types/PropTypes.js.map +1 -0
- package/bin/esm/types/ResultTypes.d.ts +334 -0
- package/bin/esm/types/ResultTypes.d.ts.map +1 -0
- package/bin/esm/types/ResultTypes.js +6 -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 +15 -0
- package/bin/esm/utils/type-check.d.ts.map +1 -0
- package/bin/esm/utils/type-check.js +54 -0
- package/bin/esm/utils/type-check.js.map +1 -0
- package/bin/live-hooks/useLiveCanvas.js +1 -1
- package/bin/live-hooks/useLiveCanvas.js.map +1 -1
- package/bin/live-hooks/useLiveState.d.ts.map +1 -1
- package/bin/live-hooks/useLiveState.js +6 -2
- package/bin/live-hooks/useLiveState.js.map +1 -1
- package/bin/live-hooks/useMediaSynchronizer.js +1 -1
- package/bin/live-hooks/useMediaSynchronizer.js.map +1 -1
- package/bin/providers/AzureProvider.js +2 -2
- package/bin/providers/AzureProvider.js.map +1 -1
- package/bin/providers/LiveShareProvider.js +3 -3
- package/bin/providers/LiveShareProvider.js.map +1 -1
- package/package.json +61 -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/PropTypes.ts +57 -0
- package/src/types/ResultTypes.ts +71 -17
- package/src/types/index.ts +3 -3
- package/src/utils/index.ts +1 -1
- package/tsconfig.cjs.json +14 -0
- package/tsconfig.json +65 -70
- package/.nycrc.json +0 -10
- package/tsconfig.build.json +0 -6
|
@@ -3,18 +3,16 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
CanvasReferencePoint,
|
|
8
|
-
IBrush,
|
|
9
|
-
InkingManager,
|
|
10
|
-
InkingTool,
|
|
11
|
-
IPoint,
|
|
12
|
-
LiveCanvas,
|
|
13
|
-
} from "@microsoft/live-share-canvas";
|
|
6
|
+
import { InkingManager, LiveCanvas } from "@microsoft/live-share-canvas";
|
|
14
7
|
import React from "react";
|
|
15
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
16
|
-
import {
|
|
17
|
-
|
|
8
|
+
import { useDynamicDDS } from "../shared-hooks/index.js";
|
|
9
|
+
import {
|
|
10
|
+
IUseLiveCanvasOptionalProps,
|
|
11
|
+
IUseLiveCanvasResults,
|
|
12
|
+
} from "../types/index.js";
|
|
13
|
+
import { isRefObject } from "../utils/index.js";
|
|
14
|
+
import { getRawNode } from "../shared-hooks/internals/tree-node-utils.js";
|
|
15
|
+
import { LiveDataObjectInitializeState } from "@microsoft/live-share";
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
@@ -26,27 +24,72 @@ import { isRefObject } from "../utils";
|
|
|
26
24
|
*
|
|
27
25
|
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
28
26
|
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
27
|
+
* @param props Optional. Other optional props.
|
|
28
|
+
* @param props.active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
29
|
+
* @param props.tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
30
|
+
* @param props.lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
31
|
+
* @param props.offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
32
|
+
* @param props.scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
33
|
+
* @param props.referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
34
|
+
* @param props.isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
35
|
+
* @param props.localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
|
|
36
|
+
* @param props.node Optional. A Fluid `LiveCanvasTree` `TreeNode` instance to swap out the underlying storage solution for strokes.
|
|
37
|
+
* To learn more, look at Fluid's [SharedTree](https://fluidframework.com/docs/data-structures/tree/) documentation.
|
|
38
|
+
* @param allowedRoles Optional. The user roles that are allowed to start/stop/pause the timer.
|
|
39
|
+
*
|
|
40
|
+
* @returns `IUseLiveCanvasResults` object that contains the `liveCanvas` data object and `inkingManager`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
```jsx
|
|
44
|
+
import { useLiveCanvas } from "@microsoft/live-share-react";
|
|
45
|
+
import { InkingTool } from "@microsoft/live-share-canvas";
|
|
46
|
+
import { useRef } from "react";
|
|
47
|
+
|
|
48
|
+
// Unique identifier that distinguishes this useLiveCanvas from others in your app
|
|
49
|
+
const UNIQUE_KEY = "CUSTOM-LIVE-CANVAS";
|
|
50
|
+
|
|
51
|
+
// Example component
|
|
52
|
+
export function ExampleLiveCanvas() {
|
|
53
|
+
const liveCanvasRef = useRef(null);
|
|
54
|
+
const { liveCanvas, inkingManager } = useLiveCanvas(
|
|
55
|
+
"CUSTOM-LIVE-CANVAS",
|
|
56
|
+
liveCanvasRef,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div style={{ position: "absolute"}}>
|
|
61
|
+
<div
|
|
62
|
+
ref={liveCanvasRef}
|
|
63
|
+
// Best practice is to not define inline styles
|
|
64
|
+
style={{ width: "556px", height: "224px" }}
|
|
65
|
+
/>
|
|
66
|
+
{!!liveCanvas && (
|
|
67
|
+
<div>
|
|
68
|
+
<button
|
|
69
|
+
onClick={() => {
|
|
70
|
+
inkingManager.tool = InkingTool.pen;
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{"Pen"}
|
|
74
|
+
</button>
|
|
75
|
+
<button
|
|
76
|
+
onClick={() => {
|
|
77
|
+
inkingManager.tool = InkingTool.laserPointer;
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
{"Laser pointer"}
|
|
81
|
+
</button>
|
|
82
|
+
</div>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
```
|
|
38
88
|
*/
|
|
39
89
|
export function useLiveCanvas(
|
|
40
90
|
uniqueKey: string,
|
|
41
91
|
canvasElementRef: React.RefObject<HTMLElement | null> | string,
|
|
42
|
-
|
|
43
|
-
tool?: InkingTool,
|
|
44
|
-
lineBrush?: IBrush,
|
|
45
|
-
offset?: IPoint,
|
|
46
|
-
scale?: number,
|
|
47
|
-
referencePoint?: CanvasReferencePoint,
|
|
48
|
-
isCursorShared?: boolean,
|
|
49
|
-
localUserPictureUrl?: string
|
|
92
|
+
props?: IUseLiveCanvasOptionalProps
|
|
50
93
|
): IUseLiveCanvasResults {
|
|
51
94
|
/**
|
|
52
95
|
* User facing: inking manager instance
|
|
@@ -61,103 +104,132 @@ export function useLiveCanvas(
|
|
|
61
104
|
LiveCanvas
|
|
62
105
|
);
|
|
63
106
|
|
|
107
|
+
// This should change less frequently then node if they are using `useTreeNode`
|
|
108
|
+
// We need the raw node anyways to apply event listeners
|
|
109
|
+
const rawNode = getRawNode(props?.node);
|
|
110
|
+
|
|
64
111
|
/**
|
|
65
112
|
* Setup the InkingManager and LiveCanvas
|
|
66
113
|
*/
|
|
114
|
+
React.useEffect(
|
|
115
|
+
() => {
|
|
116
|
+
// if the component is already listening or liveCanvas is not yet initialized, return
|
|
117
|
+
if (!liveCanvas) return;
|
|
118
|
+
// get the canvas element from the ref or document
|
|
119
|
+
let htmlElement: HTMLElement | null;
|
|
120
|
+
if (isRefObject(canvasElementRef)) {
|
|
121
|
+
htmlElement = canvasElementRef.current;
|
|
122
|
+
} else {
|
|
123
|
+
htmlElement = document.getElementById(canvasElementRef);
|
|
124
|
+
}
|
|
125
|
+
if (htmlElement === null) return;
|
|
126
|
+
// Clear out existing nodes
|
|
127
|
+
function removeAllChildren(node: HTMLElement | ChildNode) {
|
|
128
|
+
node.childNodes.forEach((childNode) => {
|
|
129
|
+
removeAllChildren(childNode);
|
|
130
|
+
childNode.remove();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
removeAllChildren(htmlElement);
|
|
134
|
+
// Create the InkingManager and initialize the liveCanvas with it
|
|
135
|
+
const inkingManager = new InkingManager(htmlElement);
|
|
136
|
+
setInkingManager(inkingManager);
|
|
137
|
+
liveCanvas.initialize(inkingManager, props?.allowedRoles, rawNode);
|
|
138
|
+
|
|
139
|
+
// cleanup function to be called when the component is unmount
|
|
140
|
+
return () => {
|
|
141
|
+
inkingManager.removeAllListeners();
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
// Intentionally ommitting rawNode from deps because we only want to initialize once,
|
|
145
|
+
// whereas rawNode may change many times.
|
|
146
|
+
[liveCanvas, props?.allowedRoles]
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Set the node if it changes while LiveCanvas is initialized
|
|
151
|
+
*/
|
|
67
152
|
React.useEffect(() => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
if (htmlElement === null) return;
|
|
78
|
-
// Create the InkingManager and initialize the liveCanvas with it
|
|
79
|
-
const inkingManager = new InkingManager(htmlElement);
|
|
80
|
-
setInkingManager(inkingManager);
|
|
81
|
-
liveCanvas.initialize(inkingManager);
|
|
82
|
-
|
|
83
|
-
// cleanup function to be called when the component is unmount
|
|
84
|
-
return () => {
|
|
85
|
-
// liveCanvas.dispose();
|
|
86
|
-
inkingManager.removeAllListeners();
|
|
87
|
-
};
|
|
88
|
-
}, [liveCanvas]);
|
|
153
|
+
if (
|
|
154
|
+
!rawNode ||
|
|
155
|
+
liveCanvas?.initializeState !==
|
|
156
|
+
LiveDataObjectInitializeState.succeeded
|
|
157
|
+
)
|
|
158
|
+
return;
|
|
159
|
+
liveCanvas.setTreeNode(rawNode);
|
|
160
|
+
}, [liveCanvas, rawNode]);
|
|
89
161
|
|
|
90
162
|
/**
|
|
91
163
|
* Activate or deactivate the inkingManager based on the 'active' prop
|
|
92
164
|
*/
|
|
93
165
|
React.useEffect(() => {
|
|
94
|
-
if (inkingManager && active !== undefined) {
|
|
95
|
-
if (active) {
|
|
166
|
+
if (inkingManager && props?.active !== undefined) {
|
|
167
|
+
if (props?.active) {
|
|
96
168
|
inkingManager.activate();
|
|
97
169
|
} else {
|
|
98
170
|
inkingManager.deactivate();
|
|
99
171
|
}
|
|
100
172
|
}
|
|
101
|
-
}, [active, inkingManager]);
|
|
173
|
+
}, [props?.active, inkingManager]);
|
|
102
174
|
|
|
103
175
|
/**
|
|
104
176
|
* Sets the tool of the inkingManager based on the 'tool' prop
|
|
105
177
|
*/
|
|
106
178
|
React.useEffect(() => {
|
|
107
|
-
if (inkingManager && tool !== undefined) {
|
|
108
|
-
inkingManager.tool = tool;
|
|
179
|
+
if (inkingManager && props?.tool !== undefined) {
|
|
180
|
+
inkingManager.tool = props.tool;
|
|
109
181
|
}
|
|
110
|
-
}, [tool, inkingManager]);
|
|
182
|
+
}, [props?.tool, inkingManager]);
|
|
111
183
|
|
|
112
184
|
/**
|
|
113
185
|
* Sets the offset of the inkingManager based on the 'offset' prop
|
|
114
186
|
*/
|
|
115
187
|
React.useEffect(() => {
|
|
116
|
-
if (inkingManager && offset !== undefined) {
|
|
188
|
+
if (inkingManager && props?.offset !== undefined) {
|
|
117
189
|
inkingManager.offset = {
|
|
118
|
-
x: offset.x,
|
|
119
|
-
y: offset.y,
|
|
190
|
+
x: props?.offset.x,
|
|
191
|
+
y: props?.offset.y,
|
|
120
192
|
};
|
|
121
193
|
}
|
|
122
|
-
}, [offset?.x, offset?.y, inkingManager]);
|
|
194
|
+
}, [props?.offset?.x, props?.offset?.y, inkingManager]);
|
|
123
195
|
|
|
124
196
|
/**
|
|
125
197
|
* Sets the scale of the inkingManager based on the 'scale' prop
|
|
126
198
|
*/
|
|
127
199
|
React.useEffect(() => {
|
|
128
|
-
if (inkingManager && scale !== undefined) {
|
|
129
|
-
inkingManager.scale = scale;
|
|
200
|
+
if (inkingManager && props?.scale !== undefined) {
|
|
201
|
+
inkingManager.scale = props?.scale;
|
|
130
202
|
}
|
|
131
|
-
}, [scale, inkingManager]);
|
|
203
|
+
}, [props?.scale, inkingManager]);
|
|
132
204
|
|
|
133
205
|
/**
|
|
134
206
|
* Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
|
|
135
207
|
*/
|
|
136
208
|
React.useEffect(() => {
|
|
137
|
-
if (inkingManager && referencePoint !== undefined) {
|
|
138
|
-
inkingManager.referencePoint = referencePoint;
|
|
209
|
+
if (inkingManager && props?.referencePoint !== undefined) {
|
|
210
|
+
inkingManager.referencePoint = props?.referencePoint;
|
|
139
211
|
}
|
|
140
|
-
}, [referencePoint, inkingManager]);
|
|
212
|
+
}, [props?.referencePoint, inkingManager]);
|
|
141
213
|
|
|
142
214
|
/**
|
|
143
215
|
* Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
|
|
144
216
|
*/
|
|
145
217
|
React.useEffect(() => {
|
|
146
|
-
if (inkingManager && lineBrush) {
|
|
218
|
+
if (inkingManager && props?.lineBrush) {
|
|
147
219
|
inkingManager.lineBrush = {
|
|
148
|
-
color: lineBrush.color,
|
|
149
|
-
tip: lineBrush.tip,
|
|
150
|
-
tipSize: lineBrush.tipSize,
|
|
151
|
-
type: lineBrush.type,
|
|
152
|
-
endArrow: lineBrush.endArrow,
|
|
220
|
+
color: props.lineBrush.color,
|
|
221
|
+
tip: props.lineBrush.tip,
|
|
222
|
+
tipSize: props.lineBrush.tipSize,
|
|
223
|
+
type: props.lineBrush.type,
|
|
224
|
+
endArrow: props.lineBrush.endArrow,
|
|
153
225
|
};
|
|
154
226
|
}
|
|
155
227
|
}, [
|
|
156
|
-
lineBrush?.color,
|
|
157
|
-
lineBrush?.tip,
|
|
158
|
-
lineBrush?.tipSize,
|
|
159
|
-
lineBrush?.type,
|
|
160
|
-
lineBrush?.endArrow,
|
|
228
|
+
props?.lineBrush?.color,
|
|
229
|
+
props?.lineBrush?.tip,
|
|
230
|
+
props?.lineBrush?.tipSize,
|
|
231
|
+
props?.lineBrush?.type,
|
|
232
|
+
props?.lineBrush?.endArrow,
|
|
161
233
|
inkingManager,
|
|
162
234
|
]);
|
|
163
235
|
|
|
@@ -165,21 +237,21 @@ export function useLiveCanvas(
|
|
|
165
237
|
* Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
|
|
166
238
|
*/
|
|
167
239
|
React.useEffect(() => {
|
|
168
|
-
if (liveCanvas && isCursorShared !== undefined) {
|
|
169
|
-
liveCanvas.isCursorShared = isCursorShared;
|
|
240
|
+
if (liveCanvas && props?.isCursorShared !== undefined) {
|
|
241
|
+
liveCanvas.isCursorShared = props.isCursorShared;
|
|
170
242
|
}
|
|
171
|
-
}, [isCursorShared, liveCanvas]);
|
|
243
|
+
}, [props?.isCursorShared, liveCanvas]);
|
|
172
244
|
|
|
173
245
|
/**
|
|
174
246
|
* Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
|
|
175
247
|
*/
|
|
176
248
|
React.useEffect(() => {
|
|
177
|
-
if (liveCanvas && localUserPictureUrl) {
|
|
249
|
+
if (liveCanvas && props?.localUserPictureUrl) {
|
|
178
250
|
liveCanvas.onGetLocalUserPictureUrl = (): string | undefined => {
|
|
179
|
-
return localUserPictureUrl;
|
|
251
|
+
return props.localUserPictureUrl;
|
|
180
252
|
};
|
|
181
253
|
}
|
|
182
|
-
}, [localUserPictureUrl, liveCanvas]);
|
|
254
|
+
}, [props?.localUserPictureUrl, liveCanvas]);
|
|
183
255
|
|
|
184
256
|
/**
|
|
185
257
|
* Return hook response
|
|
@@ -14,15 +14,15 @@ import {
|
|
|
14
14
|
IUseLiveEventResults,
|
|
15
15
|
OnReceivedLiveEventAction,
|
|
16
16
|
SendLiveEventAction,
|
|
17
|
-
} from "../types";
|
|
18
|
-
import { IReceiveLiveEvent } from "../interfaces";
|
|
19
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
17
|
+
} from "../types/index.js";
|
|
18
|
+
import { IReceiveLiveEvent } from "../interfaces/index.js";
|
|
19
|
+
import { useDynamicDDS } from "../shared-hooks/index.js";
|
|
20
20
|
import {
|
|
21
21
|
ActionContainerNotJoinedError,
|
|
22
22
|
ActionLiveDataObjectInitializedError,
|
|
23
23
|
ActionLiveDataObjectUndefinedError,
|
|
24
|
-
} from "../internal";
|
|
25
|
-
import { useFluidObjectsContext } from "../providers";
|
|
24
|
+
} from "../internal/index.js";
|
|
25
|
+
import { useFluidObjectsContext } from "../providers/index.js";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* React hook for using a Live Share `LiveEvent`.
|
|
@@ -38,6 +38,42 @@ import { useFluidObjectsContext } from "../providers";
|
|
|
38
38
|
* @param allowedRoles Optional. The meeting roles eligible to send events through this object.
|
|
39
39
|
* @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
|
|
40
40
|
* @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
```jsx
|
|
44
|
+
import { useLiveEvent } from "@microsoft/live-share-react";
|
|
45
|
+
|
|
46
|
+
const emojis = ["❤️", "😂", "👍", "👎"];
|
|
47
|
+
|
|
48
|
+
// Define a unique key that differentiates this usage of `useLiveEvent` from others in your app
|
|
49
|
+
const MY_UNIQUE_KEY = "event-key";
|
|
50
|
+
|
|
51
|
+
// Example component for using useLiveEvent
|
|
52
|
+
export const MyCustomEvent = () => {
|
|
53
|
+
const { latestEvent, liveEvent, sendEvent } = useLiveEvent(MY_UNIQUE_KEY);
|
|
54
|
+
|
|
55
|
+
// Render loading UI when creating LiveEvent instance for first time
|
|
56
|
+
if (!liveEvent) return <>Loading...</>;
|
|
57
|
+
|
|
58
|
+
// Render UI
|
|
59
|
+
return (
|
|
60
|
+
<div>
|
|
61
|
+
{`Latest event: ${latestEvent?.value}, from local user: ${latestEvent?.local}`}
|
|
62
|
+
{"Select a planet below:"}
|
|
63
|
+
{emojis.map((emoji) => (
|
|
64
|
+
<button
|
|
65
|
+
key={emoji}
|
|
66
|
+
onClick={() => {
|
|
67
|
+
sendEvent(emoji);
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
{emoji}
|
|
71
|
+
</button>
|
|
72
|
+
))}
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
```
|
|
41
77
|
*/
|
|
42
78
|
export function useLiveEvent<TEvent = any>(
|
|
43
79
|
uniqueKey: string,
|
|
@@ -68,7 +104,7 @@ export function useLiveEvent<TEvent = any>(
|
|
|
68
104
|
* User facing: callback to send event through `LiveEvent`
|
|
69
105
|
*/
|
|
70
106
|
const sendEvent: SendLiveEventAction<TEvent> = React.useCallback(
|
|
71
|
-
async (event: TEvent) => {
|
|
107
|
+
async (event: TEvent, targetClientId?: string) => {
|
|
72
108
|
if (!container) {
|
|
73
109
|
throw new ActionContainerNotJoinedError(
|
|
74
110
|
"liveEvent",
|
|
@@ -87,7 +123,7 @@ export function useLiveEvent<TEvent = any>(
|
|
|
87
123
|
"sendEvent"
|
|
88
124
|
);
|
|
89
125
|
}
|
|
90
|
-
return await liveEvent.send(event);
|
|
126
|
+
return await liveEvent.send(event, targetClientId);
|
|
91
127
|
},
|
|
92
128
|
[container, liveEvent]
|
|
93
129
|
);
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
IFollowModeState,
|
|
13
13
|
} from "@microsoft/live-share";
|
|
14
14
|
import React from "react";
|
|
15
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
16
|
-
import { useFluidObjectsContext } from "../providers";
|
|
15
|
+
import { useDynamicDDS } from "../shared-hooks/index.js";
|
|
16
|
+
import { useFluidObjectsContext } from "../providers/index.js";
|
|
17
17
|
import {
|
|
18
18
|
ActionContainerNotJoinedError,
|
|
19
19
|
ActionLiveDataObjectInitializedError,
|
|
20
20
|
ActionLiveDataObjectUndefinedError,
|
|
21
|
-
} from "../internal";
|
|
22
|
-
import { IUseLiveFollowModeResults } from "../types";
|
|
21
|
+
} from "../internal/index.js";
|
|
22
|
+
import { IUseLiveFollowModeResults } from "../types/index.js";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* React hook for using a Live Share `LiveFollowMode`.
|
|
@@ -36,6 +36,145 @@ import { IUseLiveFollowModeResults } from "../types";
|
|
|
36
36
|
* @param initialData The initial value for the local user's `stateValue`.
|
|
37
37
|
* @param allowedRoles Optional. The user roles that are allowed to present to use `startPresenting()` or `stopPresenting()`.
|
|
38
38
|
* @returns `IUseLiveFollowModeResults` results, which contains React stateful objects and callbacks.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
```jsx
|
|
42
|
+
import { FollowModeType } from "@microsoft/live-share";
|
|
43
|
+
import { useLiveFollowMode } from "@microsoft/live-share-react";
|
|
44
|
+
// As an example, we will use a fake component to denote what a 3D viewer might look like in an app
|
|
45
|
+
import { Example3DModelViewer } from "./components";
|
|
46
|
+
|
|
47
|
+
// Define a unique key that differentiates this usage of `useLiveFollowMode` from others in your app
|
|
48
|
+
const MY_UNIQUE_KEY = "follow-mode-key";
|
|
49
|
+
|
|
50
|
+
// Define the initial stateValue for the local user (optional).
|
|
51
|
+
const startingCameraPosition = {
|
|
52
|
+
x: 0,
|
|
53
|
+
y: 0,
|
|
54
|
+
z: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Example component for using useLiveFollowMode
|
|
58
|
+
export function MyLiveFollowMode() {
|
|
59
|
+
const {
|
|
60
|
+
state,
|
|
61
|
+
localUser,
|
|
62
|
+
otherUsers,
|
|
63
|
+
allUsers,
|
|
64
|
+
liveFollowMode,
|
|
65
|
+
update,
|
|
66
|
+
startPresenting,
|
|
67
|
+
stopPresenting,
|
|
68
|
+
beginSuspension,
|
|
69
|
+
endSuspension,
|
|
70
|
+
followUser,
|
|
71
|
+
stopFollowing,
|
|
72
|
+
} = useLiveFollowMode(MY_UNIQUE_KEY, startingCameraPosition);
|
|
73
|
+
|
|
74
|
+
// Example of an event listener for a camera position changed event.
|
|
75
|
+
// For something like a camera change event, you should use a debounce function.
|
|
76
|
+
function onCameraPositionChanged(position, isUserAction) {
|
|
77
|
+
// Broadcast change to other users so that they have their latest camera position
|
|
78
|
+
update(position);
|
|
79
|
+
// If the local user changed the position while following another user, we want to suspend.
|
|
80
|
+
// Note: helps to distinguish changes initiated by the local user (e.g., drag mouse) separately from other change events.
|
|
81
|
+
if (!isUserAction) return;
|
|
82
|
+
switch (state.type) {
|
|
83
|
+
case FollowModeType.followPresenter:
|
|
84
|
+
case FollowModeType.followUser: {
|
|
85
|
+
// This will trigger a "stateChanged" event update for the local user only.
|
|
86
|
+
followMode.beginSuspension();
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
default: {
|
|
90
|
+
// No need to suspend for other types
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Can optionally get the relevant user's presence object
|
|
97
|
+
const followingUser = liveFollowMode?.getUser(state.followingUserId);
|
|
98
|
+
|
|
99
|
+
// Render loading UI when creating LiveFollowMode instance for first time
|
|
100
|
+
if (!liveFollowMode) return <>Loading...</>;
|
|
101
|
+
|
|
102
|
+
// Render UI
|
|
103
|
+
return (
|
|
104
|
+
<div>
|
|
105
|
+
{state.type === FollowModeType.local && (
|
|
106
|
+
<div>
|
|
107
|
+
<p>{""}</p>
|
|
108
|
+
<button onClick={startPresenting}>
|
|
109
|
+
{"Start presenting"}
|
|
110
|
+
</button>
|
|
111
|
+
</div>
|
|
112
|
+
)}
|
|
113
|
+
{state.type === FollowModeType.activeFollowers && (
|
|
114
|
+
<div>
|
|
115
|
+
<p>{`${state.otherUsersCount} users are following you`}</p>
|
|
116
|
+
<button onClick={startPresenting}>
|
|
117
|
+
{"Present to all"}
|
|
118
|
+
</button>
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
{state.type === FollowModeType.activePresenter && (
|
|
122
|
+
<div>
|
|
123
|
+
<p>{`You are actively presenting to everyone`}</p>
|
|
124
|
+
<button onClick={stopPresenting}>
|
|
125
|
+
{"Stop presenting"}
|
|
126
|
+
</button>
|
|
127
|
+
</div>
|
|
128
|
+
)}
|
|
129
|
+
{state.type === FollowModeType.followPresenter && (
|
|
130
|
+
<div>
|
|
131
|
+
<p>{`${followingUser?.displayName} is presenting to everyone`}</p>
|
|
132
|
+
<button onClick={startPresenting}>{"Take control"}</button>
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
{state.type === FollowModeType.suspendFollowPresenter && (
|
|
136
|
+
<div>
|
|
137
|
+
<p>{`${followingUser?.displayName} is presenting to everyone`}</p>
|
|
138
|
+
<button onClick={endSuspension}>
|
|
139
|
+
{"Sync to presenter"}
|
|
140
|
+
</button>
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
143
|
+
{state.type === FollowModeType.followUser && (
|
|
144
|
+
<div>
|
|
145
|
+
<p>{`You are following ${followingUser?.displayName}`}</p>
|
|
146
|
+
<button onClick={stopFollowing}>{"Stop following"}</button>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
{state.type === FollowModeType.suspendFollowUser && (
|
|
150
|
+
<div>
|
|
151
|
+
<p>{`You were following ${followingUser?.displayName}`}</p>
|
|
152
|
+
<button onClick={stopFollowing}>
|
|
153
|
+
{"Resume following"}
|
|
154
|
+
</button>
|
|
155
|
+
</div>
|
|
156
|
+
)}
|
|
157
|
+
<div>
|
|
158
|
+
<p>{"Follow a specific user:"}</p>
|
|
159
|
+
{otherUsers.map((user) => (
|
|
160
|
+
<button
|
|
161
|
+
onClick={() => {
|
|
162
|
+
followUser(user.userId);
|
|
163
|
+
}}
|
|
164
|
+
key={user.userId}
|
|
165
|
+
>
|
|
166
|
+
{user.displayName}
|
|
167
|
+
</button>
|
|
168
|
+
))}
|
|
169
|
+
</div>
|
|
170
|
+
<Example3DModelViewer
|
|
171
|
+
cameraPosition={state.value}
|
|
172
|
+
onCameraPositionChanged={onCameraPositionChanged}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
```
|
|
39
178
|
*/
|
|
40
179
|
export function useLiveFollowMode<TData = any>(
|
|
41
180
|
uniqueKey: string,
|
|
@@ -63,12 +202,16 @@ export function useLiveFollowMode<TData = any>(
|
|
|
63
202
|
/**
|
|
64
203
|
* User facing: list of non-local user's presence objects.
|
|
65
204
|
*/
|
|
66
|
-
const otherUsers =
|
|
205
|
+
const otherUsers = React.useMemo(() => {
|
|
206
|
+
return allUsers.filter((user) => !user.isLocalUser);
|
|
207
|
+
}, [allUsers]);
|
|
67
208
|
|
|
68
209
|
/**
|
|
69
210
|
* User facing: local user's presence object.
|
|
70
211
|
*/
|
|
71
|
-
const localUser =
|
|
212
|
+
const localUser = React.useMemo(() => {
|
|
213
|
+
return allUsers.find((user) => user.isLocalUser);
|
|
214
|
+
}, [allUsers]);
|
|
72
215
|
|
|
73
216
|
const { container } = useFluidObjectsContext();
|
|
74
217
|
|