@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,159 +1,159 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
import { InkingManager, LiveCanvas, } from "@microsoft/live-share-canvas";
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { useDynamicDDS } from "../shared-hooks";
|
|
8
|
-
import { isRefObject } from "../utils";
|
|
9
|
-
/**
|
|
10
|
-
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
14
|
-
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
15
|
-
*
|
|
16
|
-
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
17
|
-
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
18
|
-
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
19
|
-
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
20
|
-
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
21
|
-
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
22
|
-
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
23
|
-
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
24
|
-
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
25
|
-
* @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
|
|
26
|
-
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
27
|
-
*/
|
|
28
|
-
export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared, localUserPictureUrl) {
|
|
29
|
-
/**
|
|
30
|
-
* User facing: inking manager instance
|
|
31
|
-
*/
|
|
32
|
-
const [inkingManager, setInkingManager] = React.useState();
|
|
33
|
-
/**
|
|
34
|
-
* User facing: dynamically load the DDS for the given unique key.
|
|
35
|
-
*/
|
|
36
|
-
const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
|
|
37
|
-
/**
|
|
38
|
-
* Setup the InkingManager and LiveCanvas
|
|
39
|
-
*/
|
|
40
|
-
React.useEffect(() => {
|
|
41
|
-
// if the component is already listening or liveCanvas is not yet initialized, return
|
|
42
|
-
if (!liveCanvas)
|
|
43
|
-
return;
|
|
44
|
-
// get the canvas element from the ref or document
|
|
45
|
-
let htmlElement;
|
|
46
|
-
if (isRefObject(canvasElementRef)) {
|
|
47
|
-
htmlElement = canvasElementRef.current;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
htmlElement = document.getElementById(canvasElementRef);
|
|
51
|
-
}
|
|
52
|
-
if (htmlElement === null)
|
|
53
|
-
return;
|
|
54
|
-
// Create the InkingManager and initialize the liveCanvas with it
|
|
55
|
-
const inkingManager = new InkingManager(htmlElement);
|
|
56
|
-
setInkingManager(inkingManager);
|
|
57
|
-
liveCanvas.initialize(inkingManager);
|
|
58
|
-
// cleanup function to be called when the component is unmount
|
|
59
|
-
return () => {
|
|
60
|
-
liveCanvas.dispose();
|
|
61
|
-
inkingManager.removeAllListeners();
|
|
62
|
-
};
|
|
63
|
-
}, [liveCanvas]);
|
|
64
|
-
/**
|
|
65
|
-
* Activate or deactivate the inkingManager based on the 'active' prop
|
|
66
|
-
*/
|
|
67
|
-
React.useEffect(() => {
|
|
68
|
-
if (inkingManager && active !== undefined) {
|
|
69
|
-
if (active) {
|
|
70
|
-
inkingManager.activate();
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
inkingManager.deactivate();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, [active, inkingManager]);
|
|
77
|
-
/**
|
|
78
|
-
* Sets the tool of the inkingManager based on the 'tool' prop
|
|
79
|
-
*/
|
|
80
|
-
React.useEffect(() => {
|
|
81
|
-
if (inkingManager && tool !== undefined) {
|
|
82
|
-
inkingManager.tool = tool;
|
|
83
|
-
}
|
|
84
|
-
}, [tool, inkingManager]);
|
|
85
|
-
/**
|
|
86
|
-
* Sets the offset of the inkingManager based on the 'offset' prop
|
|
87
|
-
*/
|
|
88
|
-
React.useEffect(() => {
|
|
89
|
-
if (inkingManager && offset !== undefined) {
|
|
90
|
-
inkingManager.offset = {
|
|
91
|
-
x: offset.x,
|
|
92
|
-
y: offset.y,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
|
|
96
|
-
/**
|
|
97
|
-
* Sets the scale of the inkingManager based on the 'scale' prop
|
|
98
|
-
*/
|
|
99
|
-
React.useEffect(() => {
|
|
100
|
-
if (inkingManager && scale !== undefined) {
|
|
101
|
-
inkingManager.scale = scale;
|
|
102
|
-
}
|
|
103
|
-
}, [scale, inkingManager]);
|
|
104
|
-
/**
|
|
105
|
-
* Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
|
|
106
|
-
*/
|
|
107
|
-
React.useEffect(() => {
|
|
108
|
-
if (inkingManager && referencePoint !== undefined) {
|
|
109
|
-
inkingManager.referencePoint = referencePoint;
|
|
110
|
-
}
|
|
111
|
-
}, [referencePoint, inkingManager]);
|
|
112
|
-
/**
|
|
113
|
-
* Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
|
|
114
|
-
*/
|
|
115
|
-
React.useEffect(() => {
|
|
116
|
-
if (inkingManager && lineBrush) {
|
|
117
|
-
inkingManager.lineBrush = {
|
|
118
|
-
color: lineBrush.color,
|
|
119
|
-
tip: lineBrush.tip,
|
|
120
|
-
tipSize: lineBrush.tipSize,
|
|
121
|
-
type: lineBrush.type,
|
|
122
|
-
endArrow: lineBrush.endArrow,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}, [
|
|
126
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
|
|
127
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
|
|
128
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
|
|
129
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
|
|
130
|
-
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
|
|
131
|
-
inkingManager,
|
|
132
|
-
]);
|
|
133
|
-
/**
|
|
134
|
-
* Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
|
|
135
|
-
*/
|
|
136
|
-
React.useEffect(() => {
|
|
137
|
-
if (liveCanvas && isCursorShared !== undefined) {
|
|
138
|
-
liveCanvas.isCursorShared = isCursorShared;
|
|
139
|
-
}
|
|
140
|
-
}, [isCursorShared, liveCanvas]);
|
|
141
|
-
/**
|
|
142
|
-
* Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
|
|
143
|
-
*/
|
|
144
|
-
React.useEffect(() => {
|
|
145
|
-
if (liveCanvas && localUserPictureUrl) {
|
|
146
|
-
liveCanvas.onGetLocalUserPictureUrl = () => {
|
|
147
|
-
return localUserPictureUrl;
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}, [localUserPictureUrl, liveCanvas]);
|
|
151
|
-
/**
|
|
152
|
-
* Return hook response
|
|
153
|
-
*/
|
|
154
|
-
return {
|
|
155
|
-
inkingManager,
|
|
156
|
-
liveCanvas,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { InkingManager, LiveCanvas, } from "@microsoft/live-share-canvas";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { useDynamicDDS } from "../shared-hooks";
|
|
8
|
+
import { isRefObject } from "../utils";
|
|
9
|
+
/**
|
|
10
|
+
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
14
|
+
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
15
|
+
*
|
|
16
|
+
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
17
|
+
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
18
|
+
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
19
|
+
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
20
|
+
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
21
|
+
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
22
|
+
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
23
|
+
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
24
|
+
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
25
|
+
* @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
|
|
26
|
+
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
27
|
+
*/
|
|
28
|
+
export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared, localUserPictureUrl) {
|
|
29
|
+
/**
|
|
30
|
+
* User facing: inking manager instance
|
|
31
|
+
*/
|
|
32
|
+
const [inkingManager, setInkingManager] = React.useState();
|
|
33
|
+
/**
|
|
34
|
+
* User facing: dynamically load the DDS for the given unique key.
|
|
35
|
+
*/
|
|
36
|
+
const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
|
|
37
|
+
/**
|
|
38
|
+
* Setup the InkingManager and LiveCanvas
|
|
39
|
+
*/
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
// if the component is already listening or liveCanvas is not yet initialized, return
|
|
42
|
+
if (!liveCanvas)
|
|
43
|
+
return;
|
|
44
|
+
// get the canvas element from the ref or document
|
|
45
|
+
let htmlElement;
|
|
46
|
+
if (isRefObject(canvasElementRef)) {
|
|
47
|
+
htmlElement = canvasElementRef.current;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
htmlElement = document.getElementById(canvasElementRef);
|
|
51
|
+
}
|
|
52
|
+
if (htmlElement === null)
|
|
53
|
+
return;
|
|
54
|
+
// Create the InkingManager and initialize the liveCanvas with it
|
|
55
|
+
const inkingManager = new InkingManager(htmlElement);
|
|
56
|
+
setInkingManager(inkingManager);
|
|
57
|
+
liveCanvas.initialize(inkingManager);
|
|
58
|
+
// cleanup function to be called when the component is unmount
|
|
59
|
+
return () => {
|
|
60
|
+
liveCanvas.dispose();
|
|
61
|
+
inkingManager.removeAllListeners();
|
|
62
|
+
};
|
|
63
|
+
}, [liveCanvas]);
|
|
64
|
+
/**
|
|
65
|
+
* Activate or deactivate the inkingManager based on the 'active' prop
|
|
66
|
+
*/
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
if (inkingManager && active !== undefined) {
|
|
69
|
+
if (active) {
|
|
70
|
+
inkingManager.activate();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
inkingManager.deactivate();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [active, inkingManager]);
|
|
77
|
+
/**
|
|
78
|
+
* Sets the tool of the inkingManager based on the 'tool' prop
|
|
79
|
+
*/
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (inkingManager && tool !== undefined) {
|
|
82
|
+
inkingManager.tool = tool;
|
|
83
|
+
}
|
|
84
|
+
}, [tool, inkingManager]);
|
|
85
|
+
/**
|
|
86
|
+
* Sets the offset of the inkingManager based on the 'offset' prop
|
|
87
|
+
*/
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (inkingManager && offset !== undefined) {
|
|
90
|
+
inkingManager.offset = {
|
|
91
|
+
x: offset.x,
|
|
92
|
+
y: offset.y,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
|
|
96
|
+
/**
|
|
97
|
+
* Sets the scale of the inkingManager based on the 'scale' prop
|
|
98
|
+
*/
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
if (inkingManager && scale !== undefined) {
|
|
101
|
+
inkingManager.scale = scale;
|
|
102
|
+
}
|
|
103
|
+
}, [scale, inkingManager]);
|
|
104
|
+
/**
|
|
105
|
+
* Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
|
|
106
|
+
*/
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (inkingManager && referencePoint !== undefined) {
|
|
109
|
+
inkingManager.referencePoint = referencePoint;
|
|
110
|
+
}
|
|
111
|
+
}, [referencePoint, inkingManager]);
|
|
112
|
+
/**
|
|
113
|
+
* Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
|
|
114
|
+
*/
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (inkingManager && lineBrush) {
|
|
117
|
+
inkingManager.lineBrush = {
|
|
118
|
+
color: lineBrush.color,
|
|
119
|
+
tip: lineBrush.tip,
|
|
120
|
+
tipSize: lineBrush.tipSize,
|
|
121
|
+
type: lineBrush.type,
|
|
122
|
+
endArrow: lineBrush.endArrow,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, [
|
|
126
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
|
|
127
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
|
|
128
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
|
|
129
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
|
|
130
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
|
|
131
|
+
inkingManager,
|
|
132
|
+
]);
|
|
133
|
+
/**
|
|
134
|
+
* Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
|
|
135
|
+
*/
|
|
136
|
+
React.useEffect(() => {
|
|
137
|
+
if (liveCanvas && isCursorShared !== undefined) {
|
|
138
|
+
liveCanvas.isCursorShared = isCursorShared;
|
|
139
|
+
}
|
|
140
|
+
}, [isCursorShared, liveCanvas]);
|
|
141
|
+
/**
|
|
142
|
+
* Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
|
|
143
|
+
*/
|
|
144
|
+
React.useEffect(() => {
|
|
145
|
+
if (liveCanvas && localUserPictureUrl) {
|
|
146
|
+
liveCanvas.onGetLocalUserPictureUrl = () => {
|
|
147
|
+
return localUserPictureUrl;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}, [localUserPictureUrl, liveCanvas]);
|
|
151
|
+
/**
|
|
152
|
+
* Return hook response
|
|
153
|
+
*/
|
|
154
|
+
return {
|
|
155
|
+
inkingManager,
|
|
156
|
+
liveCanvas,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
159
|
//# sourceMappingURL=useLiveCanvas.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
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 { IUseLiveEventResults, OnReceivedLiveEventAction } from "../types";
|
|
7
|
-
/**
|
|
8
|
-
* React hook for using a Live Share `LiveEvent`.
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
|
|
12
|
-
* such as when sending push notifications or reactions.
|
|
13
|
-
*
|
|
14
|
-
* @template TEvent Optional typing for events sent & received. Default is `object` type.
|
|
15
|
-
* @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
|
|
16
|
-
* will be created, otherwise it will use the existing one.
|
|
17
|
-
* @param allowedRoles Optional. The meeting roles eligible to send events through this object.
|
|
18
|
-
* @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
|
|
19
|
-
* @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
|
|
20
|
-
*/
|
|
21
|
-
export declare function useLiveEvent<TEvent extends object = object>(uniqueKey: string, allowedRoles?: UserMeetingRole[], onReceivedEvent?: OnReceivedLiveEventAction<TEvent>): IUseLiveEventResults<TEvent>;
|
|
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 { IUseLiveEventResults, OnReceivedLiveEventAction } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* React hook for using a Live Share `LiveEvent`.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
|
|
12
|
+
* such as when sending push notifications or reactions.
|
|
13
|
+
*
|
|
14
|
+
* @template TEvent Optional typing for events sent & received. Default is `object` type.
|
|
15
|
+
* @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
|
|
16
|
+
* will be created, otherwise it will use the existing one.
|
|
17
|
+
* @param allowedRoles Optional. The meeting roles eligible to send events through this object.
|
|
18
|
+
* @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
|
|
19
|
+
* @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useLiveEvent<TEvent extends object = object>(uniqueKey: string, allowedRoles?: UserMeetingRole[], onReceivedEvent?: OnReceivedLiveEventAction<TEvent>): IUseLiveEventResults<TEvent>;
|
|
22
22
|
//# sourceMappingURL=useLiveEvent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLiveEvent.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EACpB,yBAAyB,EAE5B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EACvD,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,eAAe,CAAC,EAAE,yBAAyB,CAAC,MAAM,CAAC,GACpD,oBAAoB,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"useLiveEvent.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAElB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EACpB,yBAAyB,EAE5B,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EACvD,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,eAAe,CAAC,EAAE,yBAAyB,CAAC,MAAM,CAAC,GACpD,oBAAoB,CAAC,MAAM,CAAC,CA2E9B"}
|
|
@@ -1,86 +1,93 @@
|
|
|
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
|
-
const
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
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 { LiveEventEvents, LiveEvent, } from "@microsoft/live-share";
|
|
15
|
+
import React from "react";
|
|
16
|
+
import { useDynamicDDS } from "../shared-hooks";
|
|
17
|
+
/**
|
|
18
|
+
* React hook for using a Live Share `LiveEvent`.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
|
|
22
|
+
* such as when sending push notifications or reactions.
|
|
23
|
+
*
|
|
24
|
+
* @template TEvent Optional typing for events sent & received. Default is `object` type.
|
|
25
|
+
* @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
|
|
26
|
+
* will be created, otherwise it will use the existing one.
|
|
27
|
+
* @param allowedRoles Optional. The meeting roles eligible to send events through this object.
|
|
28
|
+
* @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
|
|
29
|
+
* @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
|
|
30
|
+
*/
|
|
31
|
+
export function useLiveEvent(uniqueKey, allowedRoles, onReceivedEvent) {
|
|
32
|
+
/**
|
|
33
|
+
* Stateful latest event (user facing) and its non-user-facing setter method.
|
|
34
|
+
*/
|
|
35
|
+
const [latestEvent, setLatestReceived] = React.useState();
|
|
36
|
+
/**
|
|
37
|
+
* Reference for all received/sent events. The current value of this is user-facing. Because
|
|
38
|
+
* this is always set at the same time as latestEvent, it is effectively a stateful value.
|
|
39
|
+
*/
|
|
40
|
+
const allEventsRef = React.useRef([]);
|
|
41
|
+
/**
|
|
42
|
+
* User facing: dynamically load the DDS for the given unique key.
|
|
43
|
+
*/
|
|
44
|
+
const { dds: liveEvent } = useDynamicDDS(uniqueKey, (LiveEvent));
|
|
45
|
+
/**
|
|
46
|
+
* User facing: callback to send event through `LiveEvent`
|
|
47
|
+
*/
|
|
48
|
+
const sendEvent = React.useCallback((event) => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (liveEvent === undefined) {
|
|
50
|
+
throw new Error("Cannot call emitEvent when liveEvent is undefined");
|
|
51
|
+
}
|
|
52
|
+
if (!liveEvent.isInitialized) {
|
|
53
|
+
throw new Error("Cannot call emitEvent while liveEvent is not started");
|
|
54
|
+
}
|
|
55
|
+
return yield liveEvent.send(event);
|
|
56
|
+
}), [liveEvent]);
|
|
57
|
+
/**
|
|
58
|
+
* Setup change listeners and start `LiveEvent` if needed
|
|
59
|
+
*/
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined)
|
|
62
|
+
return;
|
|
63
|
+
// Register event listener
|
|
64
|
+
const onEventReceived = (event, local) => {
|
|
65
|
+
// If developer passed the optional onReceivedEvent callback, we
|
|
66
|
+
// call it.
|
|
67
|
+
onReceivedEvent === null || onReceivedEvent === void 0 ? void 0 : onReceivedEvent(event, local);
|
|
68
|
+
// Set the received event to our local state
|
|
69
|
+
const received = {
|
|
70
|
+
event: event,
|
|
71
|
+
local,
|
|
72
|
+
};
|
|
73
|
+
allEventsRef.current = [...allEventsRef.current, received];
|
|
74
|
+
setLatestReceived(received);
|
|
75
|
+
};
|
|
76
|
+
liveEvent.on(LiveEventEvents.received, onEventReceived);
|
|
77
|
+
if (!liveEvent.isInitialized) {
|
|
78
|
+
// Start live event
|
|
79
|
+
liveEvent.initialize(allowedRoles);
|
|
80
|
+
}
|
|
81
|
+
return () => {
|
|
82
|
+
// on unmount, remove event listeners
|
|
83
|
+
liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.off(LiveEventEvents.received, onEventReceived);
|
|
84
|
+
};
|
|
85
|
+
}, [liveEvent]);
|
|
86
|
+
return {
|
|
87
|
+
latestEvent,
|
|
88
|
+
allEvents: allEventsRef.current,
|
|
89
|
+
sendEvent,
|
|
90
|
+
liveEvent,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
86
93
|
//# sourceMappingURL=useLiveEvent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EACH,eAAe,EAEf,SAAS,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CACxB,SAAiB,EACjB,YAAgC,EAChC,eAAmD;IAEnD;;OAEG;IACH,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,GAClC,KAAK,CAAC,QAAQ,EAA6B,CAAC;IAChD;;;OAGG;IACH,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAA8B,EAAE,CAAC,CAAC;IACnE;;OAEG;IACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,aAAa,CACpC,SAAS,EACT,CAAA,SAAiB,CAAA,CACpB,CAAC;IAEF;;OAEG;IACH,MAAM,SAAS,GAAgC,KAAK,CAAC,WAAW,CAC5D,CAAO,KAAa,EAAE,EAAE;QACpB,IAAI,SAAS,KAAK,SAAS,EAAE;YACzB,MAAM,IAAI,KAAK,CACX,mDAAmD,CACtD,CAAC;SACL;QACD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,MAAM,IAAI,KAAK,CACX,sDAAsD,CACzD,CAAC;SACL;QACD,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,CAAA,EACD,CAAC,SAAS,CAAC,CACd,CAAC;IAEF;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,aAAa,MAAK,SAAS;YAAE,OAAO;QACnD,0BAA0B;QAC1B,MAAM,eAAe,GAAG,CAAC,KAAU,EAAE,KAAc,EAAE,EAAE;YACnD,gEAAgE;YAChE,WAAW;YACX,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,KAAe,EAAE,KAAK,CAAC,CAAC;YAC1C,4CAA4C;YAC5C,MAAM,QAAQ,GAA8B;gBACxC,KAAK,EAAE,KAAe;gBACtB,KAAK;aACR,CAAC;YACF,YAAY,CAAC,OAAO,GAAG,CAAC,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC3D,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC,CAAC;QACF,SAAS,CAAC,EAAE,CAAC,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACxD,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAC1B,mBAAmB;YACnB,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;SACtC;QAED,OAAO,GAAG,EAAE;YACR,qCAAqC;YACrC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC9D,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO;QACH,WAAW;QACX,SAAS,EAAE,YAAY,CAAC,OAAO;QAC/B,SAAS;QACT,SAAS;KACZ,CAAC;AACN,CAAC"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
import { PresenceState } from "@microsoft/live-share";
|
|
6
|
-
import { IUseLivePresenceResults } from "../types";
|
|
7
|
-
/**
|
|
8
|
-
* React hook for using a Live Share `LivePresence`.
|
|
9
|
-
*
|
|
10
|
-
* @remarks
|
|
11
|
-
* Use this hook if you want to track presence for who is currently using this component, such as
|
|
12
|
-
* who is online or who is viewing a specific document. With presence, you can sent along any custom
|
|
13
|
-
* user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
|
|
14
|
-
*
|
|
15
|
-
* @template TData Optional typing for the custom user presence data object. Default is `object` type.
|
|
16
|
-
|
|
17
|
-
* @param userId Optional. The unique ID for a user. If none is provided, a random UUID will be generated.
|
|
18
|
-
* @param initialData Optional. Initial presence data object for the user.
|
|
19
|
-
* @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
|
|
20
|
-
* @param
|
|
21
|
-
* will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
|
|
22
|
-
* @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
|
|
23
|
-
* to update the local user's presence and the `LivePresence` Fluid object.
|
|
24
|
-
*/
|
|
25
|
-
export declare function useLivePresence<TData extends object = object>(initialData?: TData | undefined, initialPresenceState?: PresenceState,
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { PresenceState, UserMeetingRole } from "@microsoft/live-share";
|
|
6
|
+
import { IUseLivePresenceResults } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* React hook for using a Live Share `LivePresence`.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Use this hook if you want to track presence for who is currently using this component, such as
|
|
12
|
+
* who is online or who is viewing a specific document. With presence, you can sent along any custom
|
|
13
|
+
* user data. This is useful for rendering a list of users, profile pictures, cursor positions, and more.
|
|
14
|
+
*
|
|
15
|
+
* @template TData Optional typing for the custom user presence data object. Default is `object` type.
|
|
16
|
+
* @param uniqueKey The unique key for `LivePresence`. If one does not yet exist, a new one
|
|
17
|
+
* @param userId Optional. The unique ID for a user. If none is provided, a random UUID will be generated.
|
|
18
|
+
* @param initialData Optional. Initial presence data object for the user.
|
|
19
|
+
* @param initialPresenceState Optional. Initial status of the user's presence. Default is online.
|
|
20
|
+
* @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state
|
|
21
|
+
* will be created, otherwise it will use the existing one. Default value is ":<dds-default>"
|
|
22
|
+
* @returns stateful `localUser`, `otherUsers` list, and `allUsers` list. Also returns a callback method
|
|
23
|
+
* to update the local user's presence and the `LivePresence` Fluid object.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useLivePresence<TData extends object = object>(uniqueKey: string, initialData?: TData | undefined, initialPresenceState?: PresenceState, allowedRoles?: UserMeetingRole[]): IUseLivePresenceResults<TData>;
|
|
26
26
|
//# sourceMappingURL=useLivePresence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLivePresence.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,aAAa,
|
|
1
|
+
{"version":3,"file":"useLivePresence.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLivePresence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,aAAa,EAEb,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAA8B,MAAM,UAAU,CAAC;AAG/E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACzD,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,KAAK,GAAG,SAAS,EAC/B,oBAAoB,GAAE,aAAoC,EAC1D,YAAY,CAAC,EAAE,eAAe,EAAE,GACjC,uBAAuB,CAAC,KAAK,CAAC,CA4FhC"}
|