@clockworkdog/cogs-client-react 1.5.7 → 2.0.0
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 +29 -5
- package/dist/components/Hint.d.ts +2 -2
- package/dist/components/Hint.js +3 -3
- package/dist/components/Images.d.ts +1 -1
- package/dist/components/Images.js +3 -3
- package/dist/components/RtspVideo.js +11 -7
- package/dist/components/Timer.d.ts +1 -1
- package/dist/components/Timer.js +14 -10
- package/dist/components/VideoContainer.js +8 -4
- package/dist/hooks/useAudioClips.js +2 -2
- package/dist/hooks/useCogsConfig.d.ts +1 -3
- package/dist/hooks/useCogsConfig.js +3 -4
- package/dist/hooks/useCogsEvent.d.ts +5 -4
- package/dist/hooks/useCogsEvent.js +5 -6
- package/dist/hooks/useCogsEvents.d.ts +3 -4
- package/dist/hooks/useCogsEvents.js +2 -3
- package/dist/hooks/useCogsMessage.d.ts +1 -1
- package/dist/hooks/useCogsMessage.js +2 -2
- package/dist/hooks/useCogsStateValue.d.ts +3 -0
- package/dist/hooks/useCogsStateValue.js +18 -0
- package/dist/hooks/useCogsStateValues.d.ts +2 -0
- package/dist/hooks/useCogsStateValues.js +14 -0
- package/dist/hooks/useHint.d.ts +1 -1
- package/dist/hooks/useHint.js +2 -2
- package/dist/hooks/useImages.d.ts +2 -2
- package/dist/hooks/useImages.js +2 -2
- package/dist/hooks/useIsAudioPlaying.js +2 -2
- package/dist/hooks/useIsConnected.d.ts +1 -1
- package/dist/hooks/useIsConnected.js +2 -2
- package/dist/hooks/usePageVisibility.js +3 -3
- package/dist/hooks/usePreloadedUrl.js +3 -3
- package/dist/hooks/useShowPhase.d.ts +1 -1
- package/dist/hooks/useShowPhase.js +2 -2
- package/dist/hooks/useWhenShowReset.d.ts +1 -1
- package/dist/hooks/useWhenShowReset.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -5
- package/dist/providers/CogsConnectionProvider.d.ts +12 -13
- package/dist/providers/CogsConnectionProvider.js +33 -23
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.js +2 -0
- package/package.json +4 -3
- package/dist/hooks/useCogsInputPortValue.d.ts +0 -4
- package/dist/hooks/useCogsInputPortValue.js +0 -17
- package/dist/hooks/useCogsInputPortValues.d.ts +0 -4
- package/dist/hooks/useCogsInputPortValues.js +0 -14
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# COGS Client React library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use this library to create custom content for your COGS Media Master or COGS Plugin
|
|
4
|
+
|
|
5
|
+
We recommend using the [`cogs-client` Create React App template](https://github.com/clockwork-dog/cra-template-cogs-client) to get started or follow this guide to add `@clockworkdog/cogs-client-react` to your existing project.
|
|
4
6
|
|
|
5
7
|
## [Documentation](https://clockwork-dog.github.io/cogs-client-react-lib/)
|
|
6
8
|
|
|
@@ -18,7 +20,27 @@ yarn add @clockworkdog/cogs-client-react
|
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
1. Create a `cogs-plugin-manifest.js` file in the public folder of your project.
|
|
24
|
+
|
|
25
|
+
See the [CogsPluginManifestJson documentation](https://clockwork-dog.github.io/cogs-client-lib/interfaces/CogsPluginManifestJson.html) for more information on the manifest format.
|
|
26
|
+
|
|
27
|
+
e.g.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
module.exports =
|
|
31
|
+
/**
|
|
32
|
+
* @type {const}
|
|
33
|
+
* @satisfies {import("@clockworkdog/cogs-client").CogsPluginManifest}
|
|
34
|
+
*/
|
|
35
|
+
({
|
|
36
|
+
name: 'My Plugin',
|
|
37
|
+
description: 'My Plugin description',
|
|
38
|
+
version: '1.0.0',
|
|
39
|
+
// etc.
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
2. Import the library
|
|
22
44
|
|
|
23
45
|
```ts
|
|
24
46
|
import {
|
|
@@ -46,19 +68,21 @@ const {
|
|
|
46
68
|
} = require('@clockworkdog/cogs-client-react');
|
|
47
69
|
```
|
|
48
70
|
|
|
49
|
-
|
|
71
|
+
3. Instantiate `<CogsConnectionProvider>` with the manifest
|
|
50
72
|
|
|
51
73
|
```tsx
|
|
74
|
+
import manifest from './public/cogs-plugin-manifest.js'; // For Typescript requires `"allowJs": true` in `tsconfig.json`
|
|
75
|
+
|
|
52
76
|
function App() {
|
|
53
77
|
return (
|
|
54
|
-
<CogsConnectionProvider audioPlayer videoPlayer>
|
|
78
|
+
<CogsConnectionProvider manifest={manifest} audioPlayer videoPlayer>
|
|
55
79
|
<MyComponent />
|
|
56
80
|
</CogsConnectionProvider>
|
|
57
81
|
);
|
|
58
82
|
}
|
|
59
83
|
|
|
60
84
|
function MyComponent() {
|
|
61
|
-
const cogsConnection = useCogsConnection();
|
|
85
|
+
const cogsConnection = useCogsConnection<typeof manifest>();
|
|
62
86
|
const isConnected = useIsConnected(cogsConnection);
|
|
63
87
|
|
|
64
88
|
const audioPlayer = useAudioPlayer();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
3
|
-
export default function Hint({ connection: customConnection }: {
|
|
4
|
-
connection: CogsConnection
|
|
3
|
+
export default function Hint({ connection: customConnection, }: {
|
|
4
|
+
connection: CogsConnection<any>;
|
|
5
5
|
}): JSX.Element | null;
|
package/dist/components/Hint.js
CHANGED
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
7
|
const useHint_1 = __importDefault(require("../hooks/useHint"));
|
|
8
8
|
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
9
|
-
function Hint({ connection: customConnection }) {
|
|
10
|
-
const providerConnection = CogsConnectionProvider_1.useCogsConnection();
|
|
9
|
+
function Hint({ connection: customConnection, }) {
|
|
10
|
+
const providerConnection = (0, CogsConnectionProvider_1.useCogsConnection)();
|
|
11
11
|
const connection = customConnection !== null && customConnection !== void 0 ? customConnection : providerConnection;
|
|
12
|
-
const hint = useHint_1.default(connection);
|
|
12
|
+
const hint = (0, useHint_1.default)(connection);
|
|
13
13
|
return hint ? react_1.default.createElement(react_1.default.Fragment, null, hint) : null;
|
|
14
14
|
}
|
|
15
15
|
exports.default = Hint;
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
export default function Images({ className, style, connection: customConnection, fullscreen, }: {
|
|
4
4
|
className?: string;
|
|
5
5
|
style?: React.CSSProperties;
|
|
6
|
-
connection: CogsConnection
|
|
6
|
+
connection: CogsConnection<any>;
|
|
7
7
|
fullscreen?: boolean | {
|
|
8
8
|
style: React.CSSProperties;
|
|
9
9
|
};
|
|
@@ -8,11 +8,11 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const useImages_1 = __importDefault(require("../hooks/useImages"));
|
|
9
9
|
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
10
10
|
function Images({ className, style, connection: customConnection, fullscreen, }) {
|
|
11
|
-
const providerConnection = CogsConnectionProvider_1.useCogsConnection();
|
|
11
|
+
const providerConnection = (0, CogsConnectionProvider_1.useCogsConnection)();
|
|
12
12
|
const connection = customConnection !== null && customConnection !== void 0 ? customConnection : providerConnection;
|
|
13
|
-
const images = useImages_1.default(connection);
|
|
13
|
+
const images = (0, useImages_1.default)(connection);
|
|
14
14
|
const fullscreenCustomStyle = typeof fullscreen === 'object' ? fullscreen.style : undefined;
|
|
15
|
-
const imageElements = images.map((image, index) => (react_1.default.createElement("img", { className: className, key: index, src: cogs_client_1.assetUrl(image.file), alt: image.file, style: {
|
|
15
|
+
const imageElements = images.map((image, index) => (react_1.default.createElement("img", { className: className, key: index, src: (0, cogs_client_1.assetUrl)(image.file), alt: image.file, style: {
|
|
16
16
|
objectFit: image.fit,
|
|
17
17
|
...(fullscreen ? { width: '100%', height: '100%', position: 'absolute', top: 0, left: 0 } : {}),
|
|
18
18
|
...style,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -35,19 +39,19 @@ function RtspVideo({ uri, websocketHostname, websocketPort, websocketPath, live,
|
|
|
35
39
|
// This is needed because the stream will "pause" when the page looses focus and start playback when it
|
|
36
40
|
// becomes visible again. This will essentially cause a delay to be introduced into the stream when loosing
|
|
37
41
|
// page focus. To fix this, we simply stop and restart the stream when the page visibility changes.
|
|
38
|
-
const isVisible = usePageVisibility_1.default();
|
|
42
|
+
const isVisible = (0, usePageVisibility_1.default)();
|
|
39
43
|
// For the video ref we actually use state so useEffect runs when the video ref changes
|
|
40
|
-
const [videoRef, setVideoRef] = react_1.useState(null);
|
|
41
|
-
const videoRefCallback = react_1.useCallback((newRef) => setVideoRef(newRef), []);
|
|
44
|
+
const [videoRef, setVideoRef] = (0, react_1.useState)(null);
|
|
45
|
+
const videoRefCallback = (0, react_1.useCallback)((newRef) => setVideoRef(newRef), []);
|
|
42
46
|
// Get the RTSP streamer from the COGS provider
|
|
43
|
-
const rtspStreamer = react_1.useMemo(() => new cogs_client_1.CogsRtspStreamer({
|
|
47
|
+
const rtspStreamer = (0, react_1.useMemo)(() => new cogs_client_1.CogsRtspStreamer({
|
|
44
48
|
hostname: websocketHostname,
|
|
45
49
|
port: websocketPort,
|
|
46
50
|
path: websocketPath,
|
|
47
51
|
}), [websocketHostname, websocketPath, websocketPort]);
|
|
48
52
|
// An effect which runs when the video element, page visibility, or URIs change
|
|
49
53
|
// This will start playback of the camera stream in the given element
|
|
50
|
-
react_1.useEffect(() => {
|
|
54
|
+
(0, react_1.useEffect)(() => {
|
|
51
55
|
// Nothing to do if we don't yet have a video element yet or if the page isn't visible
|
|
52
56
|
if (!videoRef || !rtspStreamer || !isVisible) {
|
|
53
57
|
return;
|
|
@@ -62,6 +66,6 @@ function RtspVideo({ uri, websocketHostname, websocketPort, websocketPath, live,
|
|
|
62
66
|
pipeline.close();
|
|
63
67
|
};
|
|
64
68
|
}, [uri, isVisible, rtspStreamer, videoRef, live]);
|
|
65
|
-
return react_1.default.createElement("video",
|
|
69
|
+
return react_1.default.createElement("video", { ref: videoRefCallback, autoPlay: true, ...rest });
|
|
66
70
|
}
|
|
67
71
|
exports.default = RtspVideo;
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
export default function Timer({ className, style, connection: customConnection, separator, center, }: {
|
|
4
4
|
className?: string;
|
|
5
5
|
style?: React.CSSProperties;
|
|
6
|
-
connection: CogsConnection
|
|
6
|
+
connection: CogsConnection<any>;
|
|
7
7
|
separator?: string;
|
|
8
8
|
center?: boolean;
|
|
9
9
|
}): JSX.Element;
|
package/dist/components/Timer.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -40,17 +44,17 @@ function formatTime(time, countingUp) {
|
|
|
40
44
|
}
|
|
41
45
|
function Timer({ className, style, connection: customConnection, separator = ':', center, }) {
|
|
42
46
|
var _a, _b, _c, _d, _e, _f;
|
|
43
|
-
const providerConnection = CogsConnectionProvider_1.useCogsConnection();
|
|
47
|
+
const providerConnection = (0, CogsConnectionProvider_1.useCogsConnection)();
|
|
44
48
|
const connection = customConnection !== null && customConnection !== void 0 ? customConnection : providerConnection;
|
|
45
|
-
const [timerElapsed, setTimerElapsed] = react_1.useState(0);
|
|
46
|
-
const [timerStartedAt, setTimerStartedAt] = react_1.useState((_b = (_a = connection.timerState) === null || _a === void 0 ? void 0 : _a.startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
47
|
-
const [timerTotalMillis, setTimerTotalMillis] = react_1.useState((_d = (_c = connection.timerState) === null || _c === void 0 ? void 0 : _c.durationMillis) !== null && _d !== void 0 ? _d : 0);
|
|
48
|
-
const [timerTicking, setTimerTicking] = react_1.useState((_f = (_e = connection.timerState) === null || _e === void 0 ? void 0 : _e.ticking) !== null && _f !== void 0 ? _f : false);
|
|
49
|
-
const updateTimerElapsed = react_1.useCallback(() => {
|
|
49
|
+
const [timerElapsed, setTimerElapsed] = (0, react_1.useState)(0);
|
|
50
|
+
const [timerStartedAt, setTimerStartedAt] = (0, react_1.useState)((_b = (_a = connection.timerState) === null || _a === void 0 ? void 0 : _a.startedAt) !== null && _b !== void 0 ? _b : 0);
|
|
51
|
+
const [timerTotalMillis, setTimerTotalMillis] = (0, react_1.useState)((_d = (_c = connection.timerState) === null || _c === void 0 ? void 0 : _c.durationMillis) !== null && _d !== void 0 ? _d : 0);
|
|
52
|
+
const [timerTicking, setTimerTicking] = (0, react_1.useState)((_f = (_e = connection.timerState) === null || _e === void 0 ? void 0 : _e.ticking) !== null && _f !== void 0 ? _f : false);
|
|
53
|
+
const updateTimerElapsed = (0, react_1.useCallback)(() => {
|
|
50
54
|
const timerElapsed = timerTicking ? Date.now() - timerStartedAt : 0;
|
|
51
55
|
setTimerElapsed(timerElapsed);
|
|
52
56
|
}, [timerTicking, timerStartedAt]);
|
|
53
|
-
const updateTimerState = react_1.useCallback((timerState) => {
|
|
57
|
+
const updateTimerState = (0, react_1.useCallback)((timerState) => {
|
|
54
58
|
setTimerTotalMillis(timerState.durationMillis);
|
|
55
59
|
setTimerTicking(timerState.ticking);
|
|
56
60
|
if (timerState.ticking) {
|
|
@@ -59,7 +63,7 @@ function Timer({ className, style, connection: customConnection, separator = ':'
|
|
|
59
63
|
}
|
|
60
64
|
}, []);
|
|
61
65
|
// Deal with starting/stopping the visual ticking of the timer
|
|
62
|
-
react_1.useEffect(() => {
|
|
66
|
+
(0, react_1.useEffect)(() => {
|
|
63
67
|
if (timerTicking) {
|
|
64
68
|
updateTimerElapsed();
|
|
65
69
|
const ticker = setInterval(updateTimerElapsed, 100);
|
|
@@ -69,7 +73,7 @@ function Timer({ className, style, connection: customConnection, separator = ':'
|
|
|
69
73
|
}
|
|
70
74
|
return;
|
|
71
75
|
}, [timerTicking, updateTimerElapsed]);
|
|
72
|
-
useCogsMessage_1.default(connection, react_1.useCallback((message) => {
|
|
76
|
+
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
73
77
|
if (message.type === 'adjustable_timer_update') {
|
|
74
78
|
updateTimerState({ startedAt: Date.now(), ticking: message.ticking, durationMillis: message.durationMillis });
|
|
75
79
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,10 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
26
|
const react_1 = __importStar(require("react"));
|
|
23
27
|
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
24
28
|
function VideoContainer({ className, style, videoPlayer: customVideoPlayer, fullscreen, }) {
|
|
25
|
-
const containerRef = react_1.useRef(null);
|
|
26
|
-
const providerVideoPlayer = CogsConnectionProvider_1.useVideoPlayer();
|
|
29
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
30
|
+
const providerVideoPlayer = (0, CogsConnectionProvider_1.useVideoPlayer)();
|
|
27
31
|
const videoPlayer = customVideoPlayer !== null && customVideoPlayer !== void 0 ? customVideoPlayer : providerVideoPlayer;
|
|
28
|
-
react_1.useEffect(() => {
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
29
33
|
if (videoPlayer && containerRef.current) {
|
|
30
34
|
videoPlayer.setParentElement(containerRef.current);
|
|
31
35
|
return () => videoPlayer.resetParentElement();
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
function useAudioClips(audioPlayer) {
|
|
5
|
-
const [audioClips, setAudioClips] = react_1.useState({});
|
|
6
|
-
react_1.useEffect(() => {
|
|
5
|
+
const [audioClips, setAudioClips] = (0, react_1.useState)({});
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
7
|
const listener = (event) => setAudioClips(event.detail.clips);
|
|
8
8
|
audioPlayer.addEventListener('state', listener);
|
|
9
9
|
return () => audioPlayer.removeEventListener('state', listener);
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
|
|
3
|
-
export default function useCogsConfig<Connection extends CogsConnection<any>>(connection: Connection): ConfigType<Connection>;
|
|
4
|
-
export {};
|
|
2
|
+
export default function useCogsConfig<Connection extends CogsConnection<any>>(connection: Connection): Connection['config'];
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
4
|
function useCogsConfig(connection) {
|
|
6
|
-
const [config, setConfig] = react_1.useState(connection.config);
|
|
7
|
-
react_1.useEffect(() => {
|
|
8
|
-
const listener = (event) => setConfig(event.
|
|
5
|
+
const [config, setConfig] = (0, react_1.useState)(connection.config);
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
|
+
const listener = (event) => setConfig(event.config);
|
|
9
8
|
connection.addEventListener('config', listener);
|
|
10
9
|
setConfig(connection.config); // Use the latest config in case is has changed before this useEffect ran
|
|
11
10
|
return () => connection.removeEventListener('config', listener);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CogsConnection,
|
|
2
|
-
|
|
3
|
-
export default function useCogsEvent<Connection extends CogsConnection<any>,
|
|
4
|
-
|
|
1
|
+
import { CogsConnection, CogsIncomingEventTypes, ManifestTypes } from '@clockworkdog/cogs-client';
|
|
2
|
+
import { ManifestFromConnection } from '../utils/types';
|
|
3
|
+
export default function useCogsEvent<Connection extends CogsConnection<any>, EventName extends string & ManifestTypes.EventNameFromCogs<ManifestFromConnection<Connection>>>(connection: Connection, eventName: EventName, handleEvent: (event: Extract<CogsIncomingEventTypes<ManifestTypes.EventFromCogs<ManifestFromConnection<Connection>>>, {
|
|
4
|
+
name: EventName;
|
|
5
|
+
}>) => void): void;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
react_1.useEffect(() => {
|
|
4
|
+
function useCogsEvent(connection, eventName, handleEvent) {
|
|
5
|
+
(0, react_1.useEffect)(() => {
|
|
7
6
|
const listener = (event) => {
|
|
8
|
-
if (event.
|
|
9
|
-
handleEvent(event.
|
|
7
|
+
if (event.name === eventName) {
|
|
8
|
+
handleEvent(event.value);
|
|
10
9
|
}
|
|
11
10
|
};
|
|
12
11
|
connection.addEventListener('event', listener);
|
|
13
12
|
return () => connection.removeEventListener('event', listener);
|
|
14
|
-
}, [connection,
|
|
13
|
+
}, [connection, eventName, handleEvent]);
|
|
15
14
|
}
|
|
16
15
|
exports.default = useCogsEvent;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CogsConnection,
|
|
2
|
-
|
|
3
|
-
export default function useCogsEvents<Connection extends CogsConnection<any
|
|
4
|
-
export {};
|
|
1
|
+
import { CogsConnection, CogsIncomingEvent, ManifestTypes } from '@clockworkdog/cogs-client';
|
|
2
|
+
import { ManifestFromConnection } from '../utils/types';
|
|
3
|
+
export default function useCogsEvents<Connection extends CogsConnection<any>>(connection: Connection, handleEvent: (event: CogsIncomingEvent<ManifestTypes.EventFromCogs<ManifestFromConnection<Connection>>>) => void): void;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
4
|
function useCogsEvents(connection, handleEvent) {
|
|
6
|
-
react_1.useEffect(() => {
|
|
7
|
-
const listener = (event) => handleEvent(event
|
|
5
|
+
(0, react_1.useEffect)(() => {
|
|
6
|
+
const listener = (event) => handleEvent(event);
|
|
8
7
|
connection.addEventListener('event', listener);
|
|
9
8
|
return () => connection.removeEventListener('event', listener);
|
|
10
9
|
}, [connection, handleEvent]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CogsClientMessage, CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
export default function useCogsMessage<
|
|
2
|
+
export default function useCogsMessage<Connection extends CogsConnection<any>>(connection: Connection, handleMessage: (message: CogsClientMessage) => void): void;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
function useCogsMessage(connection, handleMessage) {
|
|
5
|
-
react_1.useEffect(() => {
|
|
5
|
+
(0, react_1.useEffect)(() => {
|
|
6
6
|
const listener = (event) => {
|
|
7
|
-
handleMessage(event.
|
|
7
|
+
handleMessage(event.message);
|
|
8
8
|
};
|
|
9
9
|
connection.addEventListener('message', listener);
|
|
10
10
|
return () => connection.removeEventListener('message', listener);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CogsConnection, ManifestTypes } from '@clockworkdog/cogs-client';
|
|
2
|
+
import { ManifestFromConnection } from '../utils/types';
|
|
3
|
+
export default function useCogsStateValue<Connection extends CogsConnection<any>, Name extends string & ManifestTypes.StateName<ManifestFromConnection<Connection>>>(connection: Connection, stateName: Name): ManifestTypes.StateValue<ManifestFromConnection<Connection>, Name>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
function useCogsStateValue(connection, stateName) {
|
|
5
|
+
const [value, setValue] = (0, react_1.useState)(connection.state[stateName]);
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
|
+
const listener = ({ state }) => {
|
|
8
|
+
const value = state[stateName];
|
|
9
|
+
if (value !== undefined) {
|
|
10
|
+
setValue(value);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
connection.addEventListener('state', listener);
|
|
14
|
+
return () => connection.removeEventListener('state', listener);
|
|
15
|
+
}, [connection, stateName]);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
exports.default = useCogsStateValue;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
function useCogsInputPortValues(connection) {
|
|
5
|
+
const [value, setValue] = (0, react_1.useState)(connection.state);
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
|
+
setValue(connection.state);
|
|
8
|
+
const listener = () => setValue(connection.state);
|
|
9
|
+
connection.addEventListener('state', listener);
|
|
10
|
+
return () => connection.removeEventListener('state', listener);
|
|
11
|
+
}, [connection]);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
exports.default = useCogsInputPortValues;
|
package/dist/hooks/useHint.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
export default function useHint(connection:
|
|
2
|
+
export default function useHint<Connection extends CogsConnection<any>>(connection: Connection): string | null;
|
package/dist/hooks/useHint.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
8
8
|
function useHint(connection) {
|
|
9
|
-
const [hint, setHint] = react_1.useState('');
|
|
10
|
-
useCogsMessage_1.default(connection, react_1.useCallback((message) => {
|
|
9
|
+
const [hint, setHint] = (0, react_1.useState)('');
|
|
10
|
+
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
11
11
|
message.type === 'text_hints_update' && setHint(message.lastSentHint);
|
|
12
12
|
}, []));
|
|
13
13
|
return hint || null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CogsConnection, MediaObjectFit } from '@clockworkdog/cogs-client';
|
|
2
|
-
export
|
|
2
|
+
export type Image = {
|
|
3
3
|
file: string;
|
|
4
4
|
fit: MediaObjectFit;
|
|
5
5
|
};
|
|
6
|
-
export default function useImages(connection:
|
|
6
|
+
export default function useImages<Connection extends CogsConnection<any>>(connection: Connection): Image[];
|
package/dist/hooks/useImages.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
8
8
|
function useImages(connection) {
|
|
9
|
-
const [images, setImages] = react_1.useState([]);
|
|
10
|
-
useCogsMessage_1.default(connection, react_1.useCallback((message) => {
|
|
9
|
+
const [images, setImages] = (0, react_1.useState)([]);
|
|
10
|
+
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
11
11
|
switch (message.type) {
|
|
12
12
|
case 'image_show':
|
|
13
13
|
{
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
function useIsAudioPlaying(audioPlayer) {
|
|
5
|
-
const [isAudioPlaying, setAudioPlaying] = react_1.useState(false);
|
|
6
|
-
react_1.useEffect(() => {
|
|
5
|
+
const [isAudioPlaying, setAudioPlaying] = (0, react_1.useState)(false);
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
7
|
const listener = (event) => setAudioPlaying(event.detail.isPlaying);
|
|
8
8
|
audioPlayer.addEventListener('state', listener);
|
|
9
9
|
return () => audioPlayer.removeEventListener('state', listener);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
export default function useIsConnected(connection:
|
|
2
|
+
export default function useIsConnected<Connection extends CogsConnection<any>>(connection: Connection): boolean;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
function useIsConnected(connection) {
|
|
5
|
-
const [isConnected, setConnected] = react_1.useState(connection.isConnected);
|
|
6
|
-
react_1.useEffect(() => {
|
|
5
|
+
const [isConnected, setConnected] = (0, react_1.useState)(connection.isConnected);
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
7
|
// The connection may have opened in between the useState initialization above
|
|
8
8
|
// and this useEffect logic running so use the latest state from the connection
|
|
9
9
|
setConnected(connection.isConnected);
|
|
@@ -5,9 +5,9 @@ const react_1 = require("react");
|
|
|
5
5
|
* Uses the Page Visibility API to detect if the page is currently visible to the user.
|
|
6
6
|
*/
|
|
7
7
|
function usePageVisibility() {
|
|
8
|
-
const [isVisible, setIsVisible] = react_1.useState(() => !document.hidden);
|
|
9
|
-
const onVisibilityChange = react_1.useCallback(() => setIsVisible(!document.hidden), []);
|
|
10
|
-
react_1.useEffect(() => {
|
|
8
|
+
const [isVisible, setIsVisible] = (0, react_1.useState)(() => !document.hidden);
|
|
9
|
+
const onVisibilityChange = (0, react_1.useCallback)(() => setIsVisible(!document.hidden), []);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
11
|
document.addEventListener('visibilitychange', onVisibilityChange, false);
|
|
12
12
|
return () => {
|
|
13
13
|
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const cogs_client_1 = require("@clockworkdog/cogs-client");
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
function usePreloadedUrl(url) {
|
|
6
|
-
const [preloadedUrl, setPreloadedUrl] = react_1.useState();
|
|
7
|
-
react_1.useEffect(() => {
|
|
8
|
-
cogs_client_1.preloadUrl(url).then((url) => setPreloadedUrl(url));
|
|
6
|
+
const [preloadedUrl, setPreloadedUrl] = (0, react_1.useState)();
|
|
7
|
+
(0, react_1.useEffect)(() => {
|
|
8
|
+
(0, cogs_client_1.preloadUrl)(url).then((url) => setPreloadedUrl(url));
|
|
9
9
|
}, [url]);
|
|
10
10
|
return preloadedUrl;
|
|
11
11
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CogsConnection, ShowPhase } from '@clockworkdog/cogs-client';
|
|
2
|
-
export default function useShowPhase(connection:
|
|
2
|
+
export default function useShowPhase<Connection extends CogsConnection<any>>(connection: Connection): ShowPhase;
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
8
8
|
function useShowPhase(connection) {
|
|
9
|
-
const [status, setStatus] = react_1.useState(connection.showPhase);
|
|
10
|
-
useCogsMessage_1.default(connection, react_1.useCallback((message) => {
|
|
9
|
+
const [status, setStatus] = (0, react_1.useState)(connection.showPhase);
|
|
10
|
+
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
11
11
|
if (message.type === 'show_phase') {
|
|
12
12
|
setStatus(message.phase);
|
|
13
13
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
export default function useWhenShowReset(connection:
|
|
2
|
+
export default function useWhenShowReset<Connection extends CogsConnection<any>>(connection: Connection, whenReset: () => void): void;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
8
8
|
function useWhenShowReset(connection, whenReset) {
|
|
9
|
-
useCogsMessage_1.default(connection, react_1.useCallback((message) => {
|
|
9
|
+
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
10
10
|
if (message.type === 'show_reset') {
|
|
11
11
|
whenReset();
|
|
12
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export { default as CogsConnectionProvider, useCogsConnection, useAudioPlayer, u
|
|
|
2
2
|
export { default as useIsConnected } from './hooks/useIsConnected';
|
|
3
3
|
export { default as useCogsConfig } from './hooks/useCogsConfig';
|
|
4
4
|
export { default as useCogsEvent } from './hooks/useCogsEvent';
|
|
5
|
-
export { default as
|
|
6
|
-
export { default as
|
|
5
|
+
export { default as useCogsEvents } from './hooks/useCogsEvents';
|
|
6
|
+
export { default as useCogsStateValue } from './hooks/useCogsStateValue';
|
|
7
|
+
export { default as useCogsStateValues } from './hooks/useCogsStateValues';
|
|
7
8
|
export { default as useCogsMessage } from './hooks/useCogsMessage';
|
|
8
9
|
export { default as usePreloadedUrl } from './hooks/usePreloadedUrl';
|
|
9
10
|
export { default as useShowPhase } from './hooks/useShowPhase';
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Images = exports.useImages = exports.Timer = exports.Hint = exports.useHint = exports.VideoContainer = exports.RtspVideo = exports.useIsAudioPlaying = exports.useAudioClips = exports.useWhenShowReset = exports.useShowPhase = exports.usePreloadedUrl = exports.useCogsMessage = exports.
|
|
6
|
+
exports.Images = exports.useImages = exports.Timer = exports.Hint = exports.useHint = exports.VideoContainer = exports.RtspVideo = exports.useIsAudioPlaying = exports.useAudioClips = exports.useWhenShowReset = exports.useShowPhase = exports.usePreloadedUrl = exports.useCogsMessage = exports.useCogsStateValues = exports.useCogsStateValue = exports.useCogsEvents = exports.useCogsEvent = exports.useCogsConfig = exports.useIsConnected = exports.useVideoPlayer = exports.useAudioPlayer = exports.useCogsConnection = exports.CogsConnectionProvider = void 0;
|
|
7
7
|
// Utilities
|
|
8
8
|
var CogsConnectionProvider_1 = require("./providers/CogsConnectionProvider");
|
|
9
9
|
Object.defineProperty(exports, "CogsConnectionProvider", { enumerable: true, get: function () { return __importDefault(CogsConnectionProvider_1).default; } });
|
|
@@ -16,10 +16,12 @@ var useCogsConfig_1 = require("./hooks/useCogsConfig");
|
|
|
16
16
|
Object.defineProperty(exports, "useCogsConfig", { enumerable: true, get: function () { return __importDefault(useCogsConfig_1).default; } });
|
|
17
17
|
var useCogsEvent_1 = require("./hooks/useCogsEvent");
|
|
18
18
|
Object.defineProperty(exports, "useCogsEvent", { enumerable: true, get: function () { return __importDefault(useCogsEvent_1).default; } });
|
|
19
|
-
var
|
|
20
|
-
Object.defineProperty(exports, "
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "
|
|
19
|
+
var useCogsEvents_1 = require("./hooks/useCogsEvents");
|
|
20
|
+
Object.defineProperty(exports, "useCogsEvents", { enumerable: true, get: function () { return __importDefault(useCogsEvents_1).default; } });
|
|
21
|
+
var useCogsStateValue_1 = require("./hooks/useCogsStateValue");
|
|
22
|
+
Object.defineProperty(exports, "useCogsStateValue", { enumerable: true, get: function () { return __importDefault(useCogsStateValue_1).default; } });
|
|
23
|
+
var useCogsStateValues_1 = require("./hooks/useCogsStateValues");
|
|
24
|
+
Object.defineProperty(exports, "useCogsStateValues", { enumerable: true, get: function () { return __importDefault(useCogsStateValues_1).default; } });
|
|
23
25
|
var useCogsMessage_1 = require("./hooks/useCogsMessage");
|
|
24
26
|
Object.defineProperty(exports, "useCogsMessage", { enumerable: true, get: function () { return __importDefault(useCogsMessage_1).default; } });
|
|
25
27
|
var usePreloadedUrl_1 = require("./hooks/usePreloadedUrl");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CogsAudioPlayer, CogsConnection, CogsVideoPlayer } from '@clockworkdog/cogs-client';
|
|
1
|
+
import { CogsAudioPlayer, CogsConnection, CogsPluginManifest, CogsVideoPlayer } from '@clockworkdog/cogs-client';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
declare type CogsConnectionCustomTypes<Connection> = Connection extends CogsConnection<infer T> ? T : never;
|
|
4
3
|
/**
|
|
5
4
|
* Create a persistent connection to COGS which can be accessed with `useCogsConnection()`
|
|
6
5
|
* @param audioPlayer Creates a `CogsAudioPlayer` than can be accessed with `useAudioPlayer()`
|
|
@@ -14,6 +13,8 @@ declare type CogsConnectionCustomTypes<Connection> = Connection extends CogsConn
|
|
|
14
13
|
* *Example:*
|
|
15
14
|
*
|
|
16
15
|
* ```jsx
|
|
16
|
+
* import manifest from './cogs-plugin-manifest.js';
|
|
17
|
+
*
|
|
17
18
|
* function MyComponent() {
|
|
18
19
|
* const cogsConnection = useCogsConnection();
|
|
19
20
|
* const numberOfPlayers = useCogsConfig(cogsConnection)['Number of players'];
|
|
@@ -22,7 +23,7 @@ declare type CogsConnectionCustomTypes<Connection> = Connection extends CogsConn
|
|
|
22
23
|
* }
|
|
23
24
|
*
|
|
24
25
|
* function App() {
|
|
25
|
-
* return <CogsConnectionProvider audioPlayer videoPlayer>
|
|
26
|
+
* return <CogsConnectionProvider manifest={manifest} audioPlayer videoPlayer>
|
|
26
27
|
* <MyComponent />
|
|
27
28
|
* <CogsConnectionProvider/>;
|
|
28
29
|
* }
|
|
@@ -31,25 +32,24 @@ declare type CogsConnectionCustomTypes<Connection> = Connection extends CogsConn
|
|
|
31
32
|
* or with Typescript:
|
|
32
33
|
*
|
|
33
34
|
* ```tsx
|
|
34
|
-
*
|
|
35
|
-
* config: { 'Number of players': number }
|
|
36
|
-
* };
|
|
35
|
+
* import manifest from './cogs-plugin-manifest.js'; // Requires `"allowJs": true` in `tsconfig.json`
|
|
37
36
|
*
|
|
38
37
|
* function MyComponent() {
|
|
39
|
-
* const cogsConnection = useCogsConnection<
|
|
38
|
+
* const cogsConnection = useCogsConnection<typeof manifest>();
|
|
40
39
|
* const numberOfPlayers = useCogsConfig(cogsConnection)['Number of players'];
|
|
41
40
|
*
|
|
42
41
|
* return <div>Players: {numberOfPlayers}</div>;
|
|
43
42
|
* }
|
|
44
43
|
*
|
|
45
44
|
* function App() {
|
|
46
|
-
* return <CogsConnectionProvider audioPlayer videoPlayer>
|
|
45
|
+
* return <CogsConnectionProvider manifest={manifest} audioPlayer videoPlayer>
|
|
47
46
|
* <MyComponent />
|
|
48
47
|
* <CogsConnectionProvider/>;
|
|
49
48
|
* }
|
|
50
49
|
* ```
|
|
51
50
|
*/
|
|
52
|
-
export default function CogsConnectionProvider({ hostname, port, children, audioPlayer, videoPlayer, }: {
|
|
51
|
+
export default function CogsConnectionProvider<Manifest extends CogsPluginManifest>({ manifest, hostname, port, children, audioPlayer, videoPlayer, }: {
|
|
52
|
+
manifest: Manifest;
|
|
53
53
|
hostname?: string;
|
|
54
54
|
port?: number;
|
|
55
55
|
children: React.ReactNode;
|
|
@@ -59,13 +59,12 @@ export default function CogsConnectionProvider({ hostname, port, children, audio
|
|
|
59
59
|
/**
|
|
60
60
|
* Get the connection from `<CogsConnectionProvider>`
|
|
61
61
|
*/
|
|
62
|
-
export declare function useCogsConnection<
|
|
62
|
+
export declare function useCogsConnection<Manifest extends CogsPluginManifest>(): CogsConnection<Manifest>;
|
|
63
63
|
/**
|
|
64
64
|
* Get the audio player from `<CogsConnectionProvider audioPlayer>`
|
|
65
65
|
*/
|
|
66
|
-
export declare function useAudioPlayer(): CogsAudioPlayer | null;
|
|
66
|
+
export declare function useAudioPlayer<Manifest extends CogsPluginManifest>(): CogsAudioPlayer | null;
|
|
67
67
|
/**
|
|
68
68
|
* Get the video player from `<CogsConnectionProvider audioPlayer>`
|
|
69
69
|
*/
|
|
70
|
-
export declare function useVideoPlayer(): CogsVideoPlayer | null;
|
|
71
|
-
export {};
|
|
70
|
+
export declare function useVideoPlayer<Manifest extends CogsPluginManifest>(): CogsVideoPlayer | null;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -23,9 +27,15 @@ exports.useVideoPlayer = exports.useAudioPlayer = exports.useCogsConnection = vo
|
|
|
23
27
|
const cogs_client_1 = require("@clockworkdog/cogs-client");
|
|
24
28
|
const react_1 = __importStar(require("react"));
|
|
25
29
|
const CogsConnectionContext = react_1.default.createContext({
|
|
26
|
-
useCogsConnection: () =>
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
useCogsConnection: () => {
|
|
31
|
+
throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
|
|
32
|
+
},
|
|
33
|
+
useAudioPlayer: () => {
|
|
34
|
+
throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
|
|
35
|
+
},
|
|
36
|
+
useVideoPlayer: () => {
|
|
37
|
+
throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
|
|
38
|
+
},
|
|
29
39
|
});
|
|
30
40
|
/**
|
|
31
41
|
* Create a persistent connection to COGS which can be accessed with `useCogsConnection()`
|
|
@@ -40,6 +50,8 @@ const CogsConnectionContext = react_1.default.createContext({
|
|
|
40
50
|
* *Example:*
|
|
41
51
|
*
|
|
42
52
|
* ```jsx
|
|
53
|
+
* import manifest from './cogs-plugin-manifest.js';
|
|
54
|
+
*
|
|
43
55
|
* function MyComponent() {
|
|
44
56
|
* const cogsConnection = useCogsConnection();
|
|
45
57
|
* const numberOfPlayers = useCogsConfig(cogsConnection)['Number of players'];
|
|
@@ -48,7 +60,7 @@ const CogsConnectionContext = react_1.default.createContext({
|
|
|
48
60
|
* }
|
|
49
61
|
*
|
|
50
62
|
* function App() {
|
|
51
|
-
* return <CogsConnectionProvider audioPlayer videoPlayer>
|
|
63
|
+
* return <CogsConnectionProvider manifest={manifest} audioPlayer videoPlayer>
|
|
52
64
|
* <MyComponent />
|
|
53
65
|
* <CogsConnectionProvider/>;
|
|
54
66
|
* }
|
|
@@ -57,44 +69,42 @@ const CogsConnectionContext = react_1.default.createContext({
|
|
|
57
69
|
* or with Typescript:
|
|
58
70
|
*
|
|
59
71
|
* ```tsx
|
|
60
|
-
*
|
|
61
|
-
* config: { 'Number of players': number }
|
|
62
|
-
* };
|
|
72
|
+
* import manifest from './cogs-plugin-manifest.js'; // Requires `"allowJs": true` in `tsconfig.json`
|
|
63
73
|
*
|
|
64
74
|
* function MyComponent() {
|
|
65
|
-
* const cogsConnection = useCogsConnection<
|
|
75
|
+
* const cogsConnection = useCogsConnection<typeof manifest>();
|
|
66
76
|
* const numberOfPlayers = useCogsConfig(cogsConnection)['Number of players'];
|
|
67
77
|
*
|
|
68
78
|
* return <div>Players: {numberOfPlayers}</div>;
|
|
69
79
|
* }
|
|
70
80
|
*
|
|
71
81
|
* function App() {
|
|
72
|
-
* return <CogsConnectionProvider audioPlayer videoPlayer>
|
|
82
|
+
* return <CogsConnectionProvider manifest={manifest} audioPlayer videoPlayer>
|
|
73
83
|
* <MyComponent />
|
|
74
84
|
* <CogsConnectionProvider/>;
|
|
75
85
|
* }
|
|
76
86
|
* ```
|
|
77
87
|
*/
|
|
78
|
-
function CogsConnectionProvider({ hostname, port, children, audioPlayer, videoPlayer, }) {
|
|
79
|
-
const connectionRef = react_1.useRef();
|
|
80
|
-
const [, forceRender] = react_1.useState({});
|
|
81
|
-
react_1.useEffect(() => {
|
|
82
|
-
const connection = new cogs_client_1.CogsConnection({ hostname, port });
|
|
88
|
+
function CogsConnectionProvider({ manifest, hostname, port, children, audioPlayer, videoPlayer, }) {
|
|
89
|
+
const connectionRef = (0, react_1.useRef)();
|
|
90
|
+
const [, forceRender] = (0, react_1.useState)({});
|
|
91
|
+
(0, react_1.useEffect)(() => {
|
|
92
|
+
const connection = new cogs_client_1.CogsConnection(manifest, { hostname, port });
|
|
83
93
|
connectionRef.current = connection;
|
|
84
94
|
forceRender({});
|
|
85
95
|
return () => {
|
|
86
96
|
connectionRef.current = undefined;
|
|
87
97
|
connection.close();
|
|
88
98
|
};
|
|
89
|
-
}, [hostname, port]);
|
|
90
|
-
const audioPlayerRef = react_1.useRef();
|
|
91
|
-
react_1.useEffect(() => {
|
|
99
|
+
}, [manifest, hostname, port]);
|
|
100
|
+
const audioPlayerRef = (0, react_1.useRef)();
|
|
101
|
+
(0, react_1.useEffect)(() => {
|
|
92
102
|
if (audioPlayer && !audioPlayerRef.current && connectionRef.current) {
|
|
93
103
|
audioPlayerRef.current = new cogs_client_1.CogsAudioPlayer(connectionRef.current);
|
|
94
104
|
}
|
|
95
105
|
}, [audioPlayer]);
|
|
96
|
-
const videoPlayerRef = react_1.useRef();
|
|
97
|
-
react_1.useEffect(() => {
|
|
106
|
+
const videoPlayerRef = (0, react_1.useRef)();
|
|
107
|
+
(0, react_1.useEffect)(() => {
|
|
98
108
|
if (videoPlayer && !videoPlayerRef.current && connectionRef.current) {
|
|
99
109
|
videoPlayerRef.current = new cogs_client_1.CogsVideoPlayer(connectionRef.current);
|
|
100
110
|
}
|
|
@@ -116,20 +126,20 @@ exports.default = CogsConnectionProvider;
|
|
|
116
126
|
* Get the connection from `<CogsConnectionProvider>`
|
|
117
127
|
*/
|
|
118
128
|
function useCogsConnection() {
|
|
119
|
-
return react_1.useContext(CogsConnectionContext).useCogsConnection();
|
|
129
|
+
return (0, react_1.useContext)(CogsConnectionContext).useCogsConnection();
|
|
120
130
|
}
|
|
121
131
|
exports.useCogsConnection = useCogsConnection;
|
|
122
132
|
/**
|
|
123
133
|
* Get the audio player from `<CogsConnectionProvider audioPlayer>`
|
|
124
134
|
*/
|
|
125
135
|
function useAudioPlayer() {
|
|
126
|
-
return react_1.useContext(CogsConnectionContext).useAudioPlayer();
|
|
136
|
+
return (0, react_1.useContext)(CogsConnectionContext).useAudioPlayer();
|
|
127
137
|
}
|
|
128
138
|
exports.useAudioPlayer = useAudioPlayer;
|
|
129
139
|
/**
|
|
130
140
|
* Get the video player from `<CogsConnectionProvider audioPlayer>`
|
|
131
141
|
*/
|
|
132
142
|
function useVideoPlayer() {
|
|
133
|
-
return react_1.useContext(CogsConnectionContext).useVideoPlayer();
|
|
143
|
+
return (0, react_1.useContext)(CogsConnectionContext).useVideoPlayer();
|
|
134
144
|
}
|
|
135
145
|
exports.useVideoPlayer = useVideoPlayer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clockworkdog/cogs-client-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"author": "Clockwork Dog <info@clockwork.dog>",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/node": "18",
|
|
19
20
|
"@types/react": "^17.0.0",
|
|
20
21
|
"@types/react-dom": "^17.0.0",
|
|
21
22
|
"@typescript-eslint/eslint-plugin": "^4.12.0",
|
|
@@ -27,10 +28,10 @@
|
|
|
27
28
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
28
29
|
"prettier": "^2.2.1",
|
|
29
30
|
"typedoc": "^0.21.4",
|
|
30
|
-
"typescript": "^
|
|
31
|
+
"typescript": "^5.1.6"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@clockworkdog/cogs-client": "^
|
|
34
|
+
"@clockworkdog/cogs-client": "^2.0.0"
|
|
34
35
|
},
|
|
35
36
|
"description": "React components and hooks to connect to COGS to build a custom Media Master",
|
|
36
37
|
"repository": {
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
declare type InputPortsType<Connection> = Connection extends CogsConnection<infer Types> ? Types['inputPorts'] : never;
|
|
3
|
-
export default function useCogsInputPortValue<Connection extends CogsConnection<any>, PortName extends keyof NonNullable<InputPortsType<Connection>>>(connection: Connection, portName: PortName): NonNullable<InputPortsType<Connection>>[PortName];
|
|
4
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_1 = require("react");
|
|
4
|
-
function useCogsInputPortValue(connection, portName) {
|
|
5
|
-
const [value, setValue] = react_1.useState(connection.inputPortValues[portName]);
|
|
6
|
-
react_1.useEffect(() => {
|
|
7
|
-
const listener = (event) => {
|
|
8
|
-
if (event.detail[portName] !== undefined) {
|
|
9
|
-
setValue(event.detail[portName]);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
connection.addEventListener('updates', listener);
|
|
13
|
-
return () => connection.removeEventListener('updates', listener);
|
|
14
|
-
}, [connection, portName]);
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
exports.default = useCogsInputPortValue;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { CogsConnection } from '@clockworkdog/cogs-client';
|
|
2
|
-
declare type InputPortsType<Connection> = Connection extends CogsConnection<infer Types> ? Types['inputPorts'] : never;
|
|
3
|
-
export default function useCogsInputPortValues<Connection extends CogsConnection<any>>(connection: Connection): InputPortsType<Connection>;
|
|
4
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_1 = require("react");
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
function useCogsInputPortValues(connection) {
|
|
6
|
-
const [value, setValue] = react_1.useState(connection.inputPortValues);
|
|
7
|
-
react_1.useEffect(() => {
|
|
8
|
-
const listener = () => setValue(connection.inputPortValues);
|
|
9
|
-
connection.addEventListener('updates', listener);
|
|
10
|
-
return () => connection.removeEventListener('updates', listener);
|
|
11
|
-
}, [connection]);
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
exports.default = useCogsInputPortValues;
|