@microsoft/live-share-react 2.0.0-internal.10 → 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/README.md +4 -4
- package/bin/index.d.ts +7 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +7 -0
- package/bin/index.js.map +1 -0
- package/bin/interfaces/LiveInterfaceExtensions.d.ts +26 -0
- package/bin/interfaces/LiveInterfaceExtensions.d.ts.map +1 -0
- package/bin/interfaces/LiveInterfaceExtensions.js +6 -0
- package/bin/interfaces/LiveInterfaceExtensions.js.map +1 -0
- package/bin/interfaces/index.d.ts +2 -0
- package/bin/interfaces/index.d.ts.map +1 -0
- package/bin/interfaces/index.js +2 -0
- package/bin/interfaces/index.js.map +1 -0
- package/bin/internal/errors.d.ts +41 -0
- package/bin/internal/errors.d.ts.map +1 -0
- package/bin/internal/errors.js +42 -0
- package/bin/internal/errors.js.map +1 -0
- package/bin/internal/index.d.ts +3 -0
- package/bin/internal/index.d.ts.map +1 -0
- package/bin/internal/index.js +3 -0
- package/bin/internal/index.js.map +1 -0
- package/bin/internal/type-guards.d.ts +11 -0
- package/bin/internal/type-guards.d.ts.map +1 -0
- package/bin/internal/type-guards.js +20 -0
- package/bin/internal/type-guards.js.map +1 -0
- package/bin/live-hooks/index.d.ts +8 -0
- package/bin/live-hooks/index.d.ts.map +1 -0
- package/bin/live-hooks/index.js +8 -0
- package/bin/live-hooks/index.js.map +1 -0
- package/bin/live-hooks/useLiveCanvas.d.ts +29 -0
- package/bin/live-hooks/useLiveCanvas.d.ts.map +1 -0
- package/bin/live-hooks/useLiveCanvas.js +160 -0
- package/bin/live-hooks/useLiveCanvas.js.map +1 -0
- package/bin/live-hooks/useLiveEvent.d.ts +23 -0
- package/bin/live-hooks/useLiveEvent.d.ts.map +1 -0
- package/bin/live-hooks/useLiveEvent.js +108 -0
- package/bin/live-hooks/useLiveEvent.js.map +1 -0
- package/bin/live-hooks/useLiveFollowMode.d.ts +24 -0
- package/bin/live-hooks/useLiveFollowMode.d.ts.map +1 -0
- package/bin/live-hooks/useLiveFollowMode.js +211 -0
- package/bin/live-hooks/useLiveFollowMode.js.map +1 -0
- package/bin/live-hooks/useLivePresence.d.ts +26 -0
- package/bin/live-hooks/useLivePresence.d.ts.map +1 -0
- package/bin/live-hooks/useLivePresence.js +106 -0
- package/bin/live-hooks/useLivePresence.js.map +1 -0
- package/bin/live-hooks/useLiveState.d.ts +21 -0
- package/bin/live-hooks/useLiveState.d.ts.map +1 -0
- package/bin/live-hooks/useLiveState.js +83 -0
- package/bin/live-hooks/useLiveState.js.map +1 -0
- package/bin/live-hooks/useLiveTimer.d.ts +25 -0
- package/bin/live-hooks/useLiveTimer.d.ts.map +1 -0
- package/bin/live-hooks/useLiveTimer.js +172 -0
- package/bin/live-hooks/useLiveTimer.js.map +1 -0
- package/bin/live-hooks/useMediaSynchronizer.d.ts +25 -0
- package/bin/live-hooks/useMediaSynchronizer.d.ts.map +1 -0
- package/bin/live-hooks/useMediaSynchronizer.js +234 -0
- package/bin/live-hooks/useMediaSynchronizer.js.map +1 -0
- package/bin/providers/AzureProvider.d.ts +113 -0
- package/bin/providers/AzureProvider.d.ts.map +1 -0
- package/bin/providers/AzureProvider.js +119 -0
- package/bin/providers/AzureProvider.js.map +1 -0
- package/bin/providers/LiveShareProvider.d.ts +91 -0
- package/bin/providers/LiveShareProvider.d.ts.map +1 -0
- package/bin/providers/LiveShareProvider.js +95 -0
- package/bin/providers/LiveShareProvider.js.map +1 -0
- package/bin/providers/index.d.ts +3 -0
- package/bin/providers/index.d.ts.map +1 -0
- package/bin/providers/index.js +3 -0
- package/bin/providers/index.js.map +1 -0
- package/bin/shared-hooks/index.d.ts +5 -0
- package/bin/shared-hooks/index.d.ts.map +1 -0
- package/bin/shared-hooks/index.js +5 -0
- package/bin/shared-hooks/index.js.map +1 -0
- package/bin/shared-hooks/useDynamicDDS.d.ts +23 -0
- package/bin/shared-hooks/useDynamicDDS.d.ts.map +1 -0
- package/bin/shared-hooks/useDynamicDDS.js +72 -0
- package/bin/shared-hooks/useDynamicDDS.js.map +1 -0
- package/bin/shared-hooks/useSharedMap.d.ts +23 -0
- package/bin/shared-hooks/useSharedMap.d.ts.map +1 -0
- package/bin/shared-hooks/useSharedMap.js +114 -0
- package/bin/shared-hooks/useSharedMap.js.map +1 -0
- package/bin/shared-hooks/useSharedState.d.ts +22 -0
- package/bin/shared-hooks/useSharedState.d.ts.map +1 -0
- package/bin/shared-hooks/useSharedState.js +74 -0
- package/bin/shared-hooks/useSharedState.js.map +1 -0
- package/bin/shared-hooks/useSharedStateRegistry.d.ts +37 -0
- package/bin/shared-hooks/useSharedStateRegistry.d.ts.map +1 -0
- package/bin/shared-hooks/useSharedStateRegistry.js +105 -0
- package/bin/shared-hooks/useSharedStateRegistry.js.map +1 -0
- package/bin/types/ActionTypes.d.ts +112 -0
- package/bin/types/ActionTypes.d.ts.map +1 -0
- package/bin/types/ActionTypes.js +6 -0
- package/bin/types/ActionTypes.js.map +1 -0
- package/bin/types/PropTypes.d.ts +8 -0
- package/bin/types/PropTypes.d.ts.map +1 -0
- package/bin/types/PropTypes.js +6 -0
- package/bin/types/PropTypes.js.map +1 -0
- package/bin/types/ResultTypes.d.ts +302 -0
- package/bin/types/ResultTypes.d.ts.map +1 -0
- package/bin/types/ResultTypes.js +6 -0
- package/bin/types/ResultTypes.js.map +1 -0
- package/bin/types/index.d.ts +4 -0
- package/bin/types/index.d.ts.map +1 -0
- package/bin/types/index.js +4 -0
- package/bin/types/index.js.map +1 -0
- package/bin/utils/index.d.ts +2 -0
- package/bin/utils/index.d.ts.map +1 -0
- package/bin/utils/index.js +2 -0
- package/bin/utils/index.js.map +1 -0
- package/bin/utils/type-check.d.ts +15 -0
- package/bin/utils/type-check.d.ts.map +1 -0
- package/bin/utils/type-check.js +54 -0
- package/bin/utils/type-check.js.map +1 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -597,10 +597,10 @@ The Live Share SDK contains dependencies for [@microsoft/teams-js](https://www.n
|
|
|
597
597
|
|
|
598
598
|
There are several ways you can [contribute](../../CONTRIBUTING.md) to this project:
|
|
599
599
|
|
|
600
|
-
-
|
|
601
|
-
-
|
|
602
|
-
-
|
|
603
|
-
-
|
|
600
|
+
- [Submit bugs](https://github.com/microsoft/live-share-sdk/issues) and help us verify fixes as they are checked in.
|
|
601
|
+
- Review the source code changes.
|
|
602
|
+
- Engage with other Live Share developers on [StackOverflow](https://stackoverflow.com/questions/tagged/live-share).
|
|
603
|
+
- [Contribute bug fixes](../../CONTRIBUTING.md).
|
|
604
604
|
|
|
605
605
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact <opencode@microsoft.com> with any additional questions or comments.
|
|
606
606
|
|
package/bin/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
package/bin/index.js
ADDED
package/bin/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Object response for a received event
|
|
7
|
+
*/
|
|
8
|
+
export interface IReceiveLiveEvent<TEvent = any> {
|
|
9
|
+
/**
|
|
10
|
+
* The value of the event that was sent
|
|
11
|
+
*/
|
|
12
|
+
value: TEvent;
|
|
13
|
+
/**
|
|
14
|
+
* True if the local client was the one to send this event
|
|
15
|
+
*/
|
|
16
|
+
local: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Client ID of the user that sent the event
|
|
19
|
+
*/
|
|
20
|
+
clientId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Server timestamp at which the event was sent
|
|
23
|
+
*/
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=LiveInterfaceExtensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveInterfaceExtensions.d.ts","sourceRoot":"","sources":["../../src/interfaces/LiveInterfaceExtensions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,GAAG;IAC3C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveInterfaceExtensions.js","sourceRoot":"","sources":["../../src/interfaces/LiveInterfaceExtensions.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
*/
|
|
4
|
+
declare class UseLiveDataObjectActionError extends Error {
|
|
5
|
+
constructor(ddsName: string, functionName: string, message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
export declare class ActionContainerNotJoinedError extends UseLiveDataObjectActionError {
|
|
11
|
+
constructor(ddsName: string, functionName: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
export declare class ActionLiveDataObjectUndefinedError extends UseLiveDataObjectActionError {
|
|
17
|
+
constructor(ddsName: string, functionName: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @hidden
|
|
21
|
+
*/
|
|
22
|
+
export declare class ActionLiveDataObjectInitializedError extends UseLiveDataObjectActionError {
|
|
23
|
+
constructor(ddsName: string, functionName: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @hidden
|
|
27
|
+
*/
|
|
28
|
+
export interface ITeamsJsSdkError {
|
|
29
|
+
/**
|
|
30
|
+
* error code
|
|
31
|
+
*/
|
|
32
|
+
errorCode: number;
|
|
33
|
+
/**
|
|
34
|
+
* Optional description for the error. This may contain useful information for web-app developers.
|
|
35
|
+
* This string will not be localized and is not for end-user consumption.
|
|
36
|
+
* App should not depend on the string content. The exact value may change. This is only for debugging purposes.
|
|
37
|
+
*/
|
|
38
|
+
message?: string;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAM,4BAA6B,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAIrE;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,4BAA4B;gBAC/D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAOpD;AAED;;GAEG;AACH,qBAAa,kCAAmC,SAAQ,4BAA4B;gBACpE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAQpD;AAED;;GAEG;AACH,qBAAa,oCAAqC,SAAQ,4BAA4B;gBACtE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAQpD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
*/
|
|
4
|
+
class UseLiveDataObjectActionError extends Error {
|
|
5
|
+
constructor(ddsName, functionName, message) {
|
|
6
|
+
const hookName = `use${toFirstLetterUppercase(ddsName)}`;
|
|
7
|
+
super(`${hookName} ${functionName}: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @hidden
|
|
12
|
+
*/
|
|
13
|
+
export class ActionContainerNotJoinedError extends UseLiveDataObjectActionError {
|
|
14
|
+
constructor(ddsName, functionName) {
|
|
15
|
+
super(ddsName, functionName, "container has not yet been joined.\nTo fix this error, ensure `container` from `useFluidObjectsContext()` is defined before calling this function.\nIf using `<LiveShareProvider>`, you can instead check the `joined` response is true from `useLiveShareContext()` before calling this function.");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
export class ActionLiveDataObjectUndefinedError extends UseLiveDataObjectActionError {
|
|
22
|
+
constructor(ddsName, functionName) {
|
|
23
|
+
const hookName = `use${toFirstLetterUppercase(ddsName)}`;
|
|
24
|
+
super(ddsName, functionName, `${ddsName} is undefined, which means it is still being dynamically created.\nTo fix this error, ensure that \`${ddsName}\` (found in the response of \`${hookName}\`) is defined before calling this function.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @hidden
|
|
29
|
+
*/
|
|
30
|
+
export class ActionLiveDataObjectInitializedError extends UseLiveDataObjectActionError {
|
|
31
|
+
constructor(ddsName, functionName) {
|
|
32
|
+
const hookName = `use${toFirstLetterUppercase(ddsName)}`;
|
|
33
|
+
super(ddsName, functionName, `${ddsName} is not yet initialized.\nTo fix this error, ensure that \`${ddsName}?.isInitialized\` is true (found in the response of \`${hookName}\`) before calling this function.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @hidden
|
|
38
|
+
*/
|
|
39
|
+
function toFirstLetterUppercase(word) {
|
|
40
|
+
return word[0].toUpperCase() + word.substring(1);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,4BAA6B,SAAQ,KAAK;IAC5C,YAAY,OAAe,EAAE,YAAoB,EAAE,OAAe;QAC9D,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,KAAK,CAAC,GAAG,QAAQ,IAAI,YAAY,KAAK,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,4BAA4B;IAC3E,YAAY,OAAe,EAAE,YAAoB;QAC7C,KAAK,CACD,OAAO,EACP,YAAY,EACZ,oSAAoS,CACvS,CAAC;IACN,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,kCAAmC,SAAQ,4BAA4B;IAChF,YAAY,OAAe,EAAE,YAAoB;QAC7C,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,KAAK,CACD,OAAO,EACP,YAAY,EACZ,GAAG,OAAO,uGAAuG,OAAO,kCAAkC,QAAQ,8CAA8C,CACnN,CAAC;IACN,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,oCAAqC,SAAQ,4BAA4B;IAClF,YAAY,OAAe,EAAE,YAAoB;QAC7C,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,KAAK,CACD,OAAO,EACP,YAAY,EACZ,GAAG,OAAO,8DAA8D,OAAO,yDAAyD,QAAQ,mCAAmC,CACtL,CAAC;IACN,CAAC;CACJ;AAkBD;;GAEG;AACH,SAAS,sBAAsB,CAAC,IAAY;IACxC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ITeamsJsSdkError } from "./errors";
|
|
2
|
+
/**
|
|
3
|
+
* @hidden
|
|
4
|
+
* Used for useLiveState and useSharedState for checking if a value is a prevState callback
|
|
5
|
+
*/
|
|
6
|
+
export declare function isPrevStateCallback<TState>(value: any): value is (value: TState) => TState;
|
|
7
|
+
/**
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
export declare function isITeamsJsSdkError(value: any): value is ITeamsJsSdkError;
|
|
11
|
+
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/internal/type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EACtC,KAAK,EAAE,GAAG,GACX,KAAK,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAEpC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,gBAAgB,CAKxE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
* Used for useLiveState and useSharedState for checking if a value is a prevState callback
|
|
4
|
+
*/
|
|
5
|
+
export function isPrevStateCallback(value) {
|
|
6
|
+
return typeof value === "function";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export function isITeamsJsSdkError(value) {
|
|
12
|
+
if (!value)
|
|
13
|
+
return false;
|
|
14
|
+
if (typeof value.errorCode !== "number")
|
|
15
|
+
return false;
|
|
16
|
+
if (value.message === undefined)
|
|
17
|
+
return true;
|
|
18
|
+
return typeof value.message === "string";
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=type-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/internal/type-guards.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAAU;IAEV,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAU;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./useLivePresence";
|
|
2
|
+
export * from "./useLiveFollowMode";
|
|
3
|
+
export * from "./useLiveState";
|
|
4
|
+
export * from "./useMediaSynchronizer";
|
|
5
|
+
export * from "./useLiveEvent";
|
|
6
|
+
export * from "./useLiveCanvas";
|
|
7
|
+
export * from "./useLiveTimer";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/live-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./useLivePresence";
|
|
2
|
+
export * from "./useLiveFollowMode";
|
|
3
|
+
export * from "./useLiveState";
|
|
4
|
+
export * from "./useMediaSynchronizer";
|
|
5
|
+
export * from "./useLiveEvent";
|
|
6
|
+
export * from "./useLiveCanvas";
|
|
7
|
+
export * from "./useLiveTimer";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/live-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { CanvasReferencePoint, IBrush, InkingTool, IPoint } from "@microsoft/live-share-canvas";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { IUseLiveCanvasResults } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* React hook for using a Live Share Canvas `LiveCanvas` and `InkingManager`.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Use this hook to set up an `LiveCanvas` object, which is used for collaborative inking. It takes several input parameters, including a unique key,
|
|
13
|
+
* a reference to a canvas element, and various settings for the inking tool, brush, and canvas offset and scale.
|
|
14
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
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 declare function useLiveCanvas(uniqueKey: string, canvasElementRef: React.RefObject<HTMLElement | null> | string, active?: boolean, tool?: InkingTool, lineBrush?: IBrush, offset?: IPoint, scale?: number, referencePoint?: CanvasReferencePoint, isCursorShared?: boolean, localUserPictureUrl?: string): IUseLiveCanvasResults;
|
|
29
|
+
//# sourceMappingURL=useLiveCanvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveCanvas.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveCanvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,oBAAoB,EACpB,MAAM,EAEN,UAAU,EACV,MAAM,EAET,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,MAAM,EAC9D,MAAM,CAAC,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,UAAU,EACjB,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,oBAAoB,EACrC,cAAc,CAAC,EAAE,OAAO,EACxB,mBAAmB,CAAC,EAAE,MAAM,GAC7B,qBAAqB,CA6IvB"}
|
|
@@ -0,0 +1,160 @@
|
|
|
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
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
16
|
+
*
|
|
17
|
+
* @param uniqueKey the unique key for the `LiveCanvas`. If one does not yet exist, a new one.
|
|
18
|
+
* @param canvasElementRef the HTML div element ref or document ID that `InkingManager` will use for canvas-based collaboration.
|
|
19
|
+
* @param active Optional. Stateful boolean that will activate/de-activate `InkingManager` accordingly.
|
|
20
|
+
* @param tool Optional. Stateful enum for what tool to use in the `InkingManager`.
|
|
21
|
+
* @param lineBrush Optional. Stateful lineBrush object for the selected lineBrush options to use in `InkingManager`.
|
|
22
|
+
* @param offset Optional. Stateful offset point to use in the `InkingManager`. Gets the viewport offset. Defaults to 0,0.
|
|
23
|
+
* @param scale Optional. Stateful scale number to use in the `InkingManager`. Defaults to 1 and must be greater than 0.
|
|
24
|
+
* @param referencePoint Optional. Stateful reference point enum to use in the `InkingManger`. Defaults to "center".
|
|
25
|
+
* @param isCursorShared Optional. Stateful boolean flag for whether cursor should be shared in `LiveCanvas`. Defaults to false.
|
|
26
|
+
* @param localUserPictureUrl Optional. url string for the local user to display alongside their cursor. Defaults to undefined.
|
|
27
|
+
* @returns IUseLiveCanvasResults object that contains the `liveCanvas` data object and `inkingManager`.
|
|
28
|
+
*/
|
|
29
|
+
export function useLiveCanvas(uniqueKey, canvasElementRef, active, tool, lineBrush, offset, scale, referencePoint, isCursorShared, localUserPictureUrl) {
|
|
30
|
+
/**
|
|
31
|
+
* User facing: inking manager instance
|
|
32
|
+
*/
|
|
33
|
+
const [inkingManager, setInkingManager] = React.useState();
|
|
34
|
+
/**
|
|
35
|
+
* User facing: dynamically load the DDS for the given unique key.
|
|
36
|
+
*/
|
|
37
|
+
const { dds: liveCanvas } = useDynamicDDS(uniqueKey, LiveCanvas);
|
|
38
|
+
/**
|
|
39
|
+
* Setup the InkingManager and LiveCanvas
|
|
40
|
+
*/
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
// if the component is already listening or liveCanvas is not yet initialized, return
|
|
43
|
+
if (!liveCanvas)
|
|
44
|
+
return;
|
|
45
|
+
// get the canvas element from the ref or document
|
|
46
|
+
let htmlElement;
|
|
47
|
+
if (isRefObject(canvasElementRef)) {
|
|
48
|
+
htmlElement = canvasElementRef.current;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
htmlElement = document.getElementById(canvasElementRef);
|
|
52
|
+
}
|
|
53
|
+
if (htmlElement === null)
|
|
54
|
+
return;
|
|
55
|
+
// Create the InkingManager and initialize the liveCanvas with it
|
|
56
|
+
const inkingManager = new InkingManager(htmlElement);
|
|
57
|
+
setInkingManager(inkingManager);
|
|
58
|
+
liveCanvas.initialize(inkingManager);
|
|
59
|
+
// cleanup function to be called when the component is unmount
|
|
60
|
+
return () => {
|
|
61
|
+
liveCanvas.dispose();
|
|
62
|
+
inkingManager.removeAllListeners();
|
|
63
|
+
};
|
|
64
|
+
}, [liveCanvas]);
|
|
65
|
+
/**
|
|
66
|
+
* Activate or deactivate the inkingManager based on the 'active' prop
|
|
67
|
+
*/
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
if (inkingManager && active !== undefined) {
|
|
70
|
+
if (active) {
|
|
71
|
+
inkingManager.activate();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
inkingManager.deactivate();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}, [active, inkingManager]);
|
|
78
|
+
/**
|
|
79
|
+
* Sets the tool of the inkingManager based on the 'tool' prop
|
|
80
|
+
*/
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
if (inkingManager && tool !== undefined) {
|
|
83
|
+
inkingManager.tool = tool;
|
|
84
|
+
}
|
|
85
|
+
}, [tool, inkingManager]);
|
|
86
|
+
/**
|
|
87
|
+
* Sets the offset of the inkingManager based on the 'offset' prop
|
|
88
|
+
*/
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
if (inkingManager && offset !== undefined) {
|
|
91
|
+
inkingManager.offset = {
|
|
92
|
+
x: offset.x,
|
|
93
|
+
y: offset.y,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}, [offset === null || offset === void 0 ? void 0 : offset.x, offset === null || offset === void 0 ? void 0 : offset.y, inkingManager]);
|
|
97
|
+
/**
|
|
98
|
+
* Sets the scale of the inkingManager based on the 'scale' prop
|
|
99
|
+
*/
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
if (inkingManager && scale !== undefined) {
|
|
102
|
+
inkingManager.scale = scale;
|
|
103
|
+
}
|
|
104
|
+
}, [scale, inkingManager]);
|
|
105
|
+
/**
|
|
106
|
+
* Sets the referencePoint of the inkingManager based on the 'referencePoint' prop
|
|
107
|
+
*/
|
|
108
|
+
React.useEffect(() => {
|
|
109
|
+
if (inkingManager && referencePoint !== undefined) {
|
|
110
|
+
inkingManager.referencePoint = referencePoint;
|
|
111
|
+
}
|
|
112
|
+
}, [referencePoint, inkingManager]);
|
|
113
|
+
/**
|
|
114
|
+
* Sets the lineBrush of the inkingManager based on the 'lineBrush' prop
|
|
115
|
+
*/
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
if (inkingManager && lineBrush) {
|
|
118
|
+
inkingManager.lineBrush = {
|
|
119
|
+
color: lineBrush.color,
|
|
120
|
+
tip: lineBrush.tip,
|
|
121
|
+
tipSize: lineBrush.tipSize,
|
|
122
|
+
type: lineBrush.type,
|
|
123
|
+
endArrow: lineBrush.endArrow,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}, [
|
|
127
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.color,
|
|
128
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tip,
|
|
129
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.tipSize,
|
|
130
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.type,
|
|
131
|
+
lineBrush === null || lineBrush === void 0 ? void 0 : lineBrush.endArrow,
|
|
132
|
+
inkingManager,
|
|
133
|
+
]);
|
|
134
|
+
/**
|
|
135
|
+
* Sets the isCursorShared of the liveCanvas based on the 'isCursorShared' prop
|
|
136
|
+
*/
|
|
137
|
+
React.useEffect(() => {
|
|
138
|
+
if (liveCanvas && isCursorShared !== undefined) {
|
|
139
|
+
liveCanvas.isCursorShared = isCursorShared;
|
|
140
|
+
}
|
|
141
|
+
}, [isCursorShared, liveCanvas]);
|
|
142
|
+
/**
|
|
143
|
+
* Sets the onGetLocalUserInfo method of the liveCanvas based on the 'localUserCursor' prop
|
|
144
|
+
*/
|
|
145
|
+
React.useEffect(() => {
|
|
146
|
+
if (liveCanvas && localUserPictureUrl) {
|
|
147
|
+
liveCanvas.onGetLocalUserPictureUrl = () => {
|
|
148
|
+
return localUserPictureUrl;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}, [localUserPictureUrl, liveCanvas]);
|
|
152
|
+
/**
|
|
153
|
+
* Return hook response
|
|
154
|
+
*/
|
|
155
|
+
return {
|
|
156
|
+
inkingManager,
|
|
157
|
+
liveCanvas,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=useLiveCanvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveCanvas.js","sourceRoot":"","sources":["../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U,CAAC,CAAC,CAAC;IAEtC;;OAEG;IACH,OAAO;QACH,aAAa;QACb,UAAU;KACb,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
14
|
+
*
|
|
15
|
+
* @template TEvent Optional typing for events sent & received. Default is `object` type.
|
|
16
|
+
* @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
|
|
17
|
+
* will be created, otherwise it will use the existing one.
|
|
18
|
+
* @param allowedRoles Optional. The meeting roles eligible to send events through this object.
|
|
19
|
+
* @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
|
|
20
|
+
* @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useLiveEvent<TEvent = any>(uniqueKey: string, allowedRoles?: UserMeetingRole[], onReceivedEvent?: OnReceivedLiveEventAction<TEvent>): IUseLiveEventResults<TEvent>;
|
|
23
|
+
//# sourceMappingURL=useLiveEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveEvent.d.ts","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEH,eAAe,EAGlB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,oBAAoB,EACpB,yBAAyB,EAE5B,MAAM,UAAU,CAAC;AAUlB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAG,GAAG,EACrC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,eAAe,CAAC,EAAE,yBAAyB,CAAC,MAAM,CAAC,GACpD,oBAAoB,CAAC,MAAM,CAAC,CAoG9B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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, LiveDataObjectInitializeState, } from "@microsoft/live-share";
|
|
15
|
+
import React from "react";
|
|
16
|
+
import { useDynamicDDS } from "../shared-hooks";
|
|
17
|
+
import { ActionContainerNotJoinedError, ActionLiveDataObjectInitializedError, ActionLiveDataObjectUndefinedError, } from "../internal";
|
|
18
|
+
import { useFluidObjectsContext } from "../providers";
|
|
19
|
+
/**
|
|
20
|
+
* React hook for using a Live Share `LiveEvent`.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* Use this hook if you want to send transient JSON objects to everyone connected to the Fluid container,
|
|
24
|
+
* such as when sending push notifications or reactions.
|
|
25
|
+
* This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
|
|
26
|
+
*
|
|
27
|
+
* @template TEvent Optional typing for events sent & received. Default is `object` type.
|
|
28
|
+
* @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one
|
|
29
|
+
* will be created, otherwise it will use the existing one.
|
|
30
|
+
* @param allowedRoles Optional. The meeting roles eligible to send events through this object.
|
|
31
|
+
* @param onReceivedEvent Optional. Callback method to be called when a new notification is received.
|
|
32
|
+
* @returns stateful `latestEvent` & `allEvents` list, `sendEvent` callback, and the `liveEvent` object.
|
|
33
|
+
*/
|
|
34
|
+
export function useLiveEvent(uniqueKey, allowedRoles, onReceivedEvent) {
|
|
35
|
+
/**
|
|
36
|
+
* Stateful latest event (user facing) and its non-user-facing setter method.
|
|
37
|
+
*/
|
|
38
|
+
const [latestEvent, setLatestReceived] = React.useState();
|
|
39
|
+
/**
|
|
40
|
+
* Reference for all received/sent events. The current value of this is user-facing. Because
|
|
41
|
+
* this is always set at the same time as latestEvent, it is effectively a stateful value.
|
|
42
|
+
*/
|
|
43
|
+
const allEventsRef = React.useRef([]);
|
|
44
|
+
/**
|
|
45
|
+
* User facing: dynamically load the DDS for the given unique key.
|
|
46
|
+
*/
|
|
47
|
+
const { dds: liveEvent } = useDynamicDDS(uniqueKey, (LiveEvent));
|
|
48
|
+
const { container } = useFluidObjectsContext();
|
|
49
|
+
/**
|
|
50
|
+
* User facing: callback to send event through `LiveEvent`
|
|
51
|
+
*/
|
|
52
|
+
const sendEvent = React.useCallback((event) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
if (!container) {
|
|
54
|
+
throw new ActionContainerNotJoinedError("liveEvent", "sendEvent");
|
|
55
|
+
}
|
|
56
|
+
if (liveEvent === undefined) {
|
|
57
|
+
throw new ActionLiveDataObjectUndefinedError("liveEvent", "sendEvent");
|
|
58
|
+
}
|
|
59
|
+
if (!liveEvent.isInitialized) {
|
|
60
|
+
throw new ActionLiveDataObjectInitializedError("liveEvent", "sendEvent");
|
|
61
|
+
}
|
|
62
|
+
return yield liveEvent.send(event);
|
|
63
|
+
}), [container, liveEvent]);
|
|
64
|
+
/**
|
|
65
|
+
* Setup change listeners and start `LiveEvent` if needed
|
|
66
|
+
*/
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
if ((liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.isInitialized) === undefined)
|
|
69
|
+
return;
|
|
70
|
+
// Register event listener
|
|
71
|
+
const onEventReceived = (event, local, clientId, timestamp) => {
|
|
72
|
+
// If developer passed the optional onReceivedEvent callback, we
|
|
73
|
+
// call it.
|
|
74
|
+
onReceivedEvent === null || onReceivedEvent === void 0 ? void 0 : onReceivedEvent(event, local);
|
|
75
|
+
// Set the received event to our local state
|
|
76
|
+
const received = {
|
|
77
|
+
value: event,
|
|
78
|
+
local,
|
|
79
|
+
clientId,
|
|
80
|
+
timestamp,
|
|
81
|
+
};
|
|
82
|
+
allEventsRef.current = [...allEventsRef.current, received];
|
|
83
|
+
setLatestReceived(received);
|
|
84
|
+
};
|
|
85
|
+
// Reset the events list if it allEventRef.current is non-empty.
|
|
86
|
+
// This happens when the `id` a developer provides changes on the fly.
|
|
87
|
+
if (allEventsRef.current.length > 0) {
|
|
88
|
+
allEventsRef.current = [];
|
|
89
|
+
setLatestReceived(undefined);
|
|
90
|
+
}
|
|
91
|
+
liveEvent.on(LiveEventEvents.received, onEventReceived);
|
|
92
|
+
if (liveEvent.initializeState === LiveDataObjectInitializeState.needed) {
|
|
93
|
+
// Start live event
|
|
94
|
+
liveEvent.initialize(allowedRoles);
|
|
95
|
+
}
|
|
96
|
+
return () => {
|
|
97
|
+
// on unmount, remove event listeners
|
|
98
|
+
liveEvent === null || liveEvent === void 0 ? void 0 : liveEvent.off(LiveEventEvents.received, onEventReceived);
|
|
99
|
+
};
|
|
100
|
+
}, [liveEvent]);
|
|
101
|
+
return {
|
|
102
|
+
latestEvent,
|
|
103
|
+
allEvents: allEventsRef.current,
|
|
104
|
+
sendEvent,
|
|
105
|
+
liveEvent,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=useLiveEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveEvent.js","sourceRoot":"","sources":["../../src/live-hooks/useLiveEvent.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;AAEH,OAAO,EACH,eAAe,EAEf,SAAS,EACT,6BAA6B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACH,6BAA6B,EAC7B,oCAAoC,EACpC,kCAAkC,GACrC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;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,MAAM,EAAE,SAAS,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAE/C;;OAEG;IACH,MAAM,SAAS,GAAgC,KAAK,CAAC,WAAW,CAC5D,CAAO,KAAa,EAAE,EAAE;QACpB,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,6BAA6B,CACnC,WAAW,EACX,WAAW,CACd,CAAC;SACL;QACD,IAAI,SAAS,KAAK,SAAS,EA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