@clockworkdog/cogs-client-react 2.11.1 → 2.11.2
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/dist/components/Hint.js +7 -13
- package/dist/components/Images.js +12 -21
- package/dist/components/Timer.js +17 -57
- package/dist/components/VideoContainer.js +7 -43
- package/dist/hooks/useAudioClips.js +6 -9
- package/dist/hooks/useCogsConfig.js +4 -7
- package/dist/hooks/useCogsEvent.js +3 -6
- package/dist/hooks/useCogsEvents.js +3 -6
- package/dist/hooks/useCogsMediaConfig.js +4 -7
- package/dist/hooks/useCogsMessage.js +3 -6
- package/dist/hooks/useCogsStateValue.js +4 -7
- package/dist/hooks/useCogsStateValues.js +4 -7
- package/dist/hooks/useHint.js +5 -11
- package/dist/hooks/useImages.js +5 -11
- package/dist/hooks/useIsAudioPlaying.js +8 -11
- package/dist/hooks/useIsConnected.js +4 -7
- package/dist/hooks/usePreloadedUrl.js +6 -9
- package/dist/hooks/useShowPhase.js +4 -7
- package/dist/hooks/useWhenShowReset.js +4 -10
- package/dist/index.js +21 -64
- package/dist/providers/CogsConnectionProvider.js +24 -63
- package/dist/utils/types.js +1 -2
- package/package.json +2 -2
package/dist/components/Hint.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const useHint_1 = __importDefault(require("../hooks/useHint"));
|
|
9
|
-
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
10
|
-
function Hint({ connection: customConnection, }) {
|
|
11
|
-
const connection = (0, CogsConnectionProvider_1.useCogsConnection)(customConnection);
|
|
12
|
-
const hint = (0, useHint_1.default)(connection);
|
|
13
|
-
return hint ? react_1.default.createElement(react_1.default.Fragment, null, hint) : null;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import useHint from '../hooks/useHint';
|
|
3
|
+
import { useCogsConnection } from '../providers/CogsConnectionProvider';
|
|
4
|
+
export default function Hint({ connection: customConnection, }) {
|
|
5
|
+
const connection = useCogsConnection(customConnection);
|
|
6
|
+
const hint = useHint(connection);
|
|
7
|
+
return hint ? React.createElement(React.Fragment, null, hint) : null;
|
|
14
8
|
}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const useImages_1 = __importDefault(require("../hooks/useImages"));
|
|
9
|
-
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
10
|
-
function Images({ className, style, connection: customConnection, fullscreen, }) {
|
|
11
|
-
const connection = (0, CogsConnectionProvider_1.useCogsConnection)(customConnection);
|
|
12
|
-
const images = (0, useImages_1.default)(connection);
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import useImages from '../hooks/useImages';
|
|
3
|
+
import { useCogsConnection } from '../providers/CogsConnectionProvider';
|
|
4
|
+
export default function Images({ className, style, connection: customConnection, fullscreen, }) {
|
|
5
|
+
const connection = useCogsConnection(customConnection);
|
|
6
|
+
const images = useImages(connection);
|
|
13
7
|
const fullscreenCustomStyle = typeof fullscreen === 'object' ? fullscreen.style : undefined;
|
|
14
|
-
const imageElements = images.map((image, index) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} }));
|
|
21
|
-
});
|
|
22
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, fullscreen ? (react_1.default.createElement("div", { style: { position: 'absolute', zIndex: 2, top: 0, left: 0, width: '100vw', height: '100vh', ...fullscreenCustomStyle } }, imageElements)) : (imageElements)));
|
|
8
|
+
const imageElements = images.map((image, index) => (React.createElement("img", { className: className, key: index, src: connection.getAssetUrl?.(image.file), alt: image.file, style: {
|
|
9
|
+
objectFit: image.fit,
|
|
10
|
+
...(fullscreen ? { width: '100%', height: '100%', position: 'absolute', top: 0, left: 0 } : {}),
|
|
11
|
+
...style,
|
|
12
|
+
} })));
|
|
13
|
+
return (React.createElement(React.Fragment, null, fullscreen ? (React.createElement("div", { style: { position: 'absolute', zIndex: 2, top: 0, left: 0, width: '100vw', height: '100vh', ...fullscreenCustomStyle } }, imageElements)) : (imageElements)));
|
|
23
14
|
}
|
package/dist/components/Timer.js
CHANGED
|
@@ -1,45 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.default = Timer;
|
|
40
|
-
const react_1 = __importStar(require("react"));
|
|
41
|
-
const useCogsMessage_1 = __importDefault(require("../hooks/useCogsMessage"));
|
|
42
|
-
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import useCogsMessage from '../hooks/useCogsMessage';
|
|
3
|
+
import { useCogsConnection } from '../providers/CogsConnectionProvider';
|
|
43
4
|
function formatTime(time, countingUp) {
|
|
44
5
|
const negative = time < 0;
|
|
45
6
|
// Flip things for negative times
|
|
@@ -53,18 +14,17 @@ function formatTime(time, countingUp) {
|
|
|
53
14
|
const seconds = String((roundedTime / 1000) % 60).padStart(2, '0');
|
|
54
15
|
return { minutes, seconds };
|
|
55
16
|
}
|
|
56
|
-
function Timer({ className, style, connection: customConnection, separator = ':', center, }) {
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const [
|
|
60
|
-
const [
|
|
61
|
-
const [
|
|
62
|
-
const
|
|
63
|
-
const updateTimerElapsed = (0, react_1.useCallback)(() => {
|
|
17
|
+
export default function Timer({ className, style, connection: customConnection, separator = ':', center, }) {
|
|
18
|
+
const connection = useCogsConnection(customConnection);
|
|
19
|
+
const [timerElapsed, setTimerElapsed] = useState(0);
|
|
20
|
+
const [timerStartedAt, setTimerStartedAt] = useState(connection.timerState?.startedAt ?? 0);
|
|
21
|
+
const [timerTotalMillis, setTimerTotalMillis] = useState(connection.timerState?.durationMillis ?? 0);
|
|
22
|
+
const [timerTicking, setTimerTicking] = useState(connection.timerState?.ticking ?? false);
|
|
23
|
+
const updateTimerElapsed = useCallback(() => {
|
|
64
24
|
const timerElapsed = timerTicking ? Date.now() - timerStartedAt : 0;
|
|
65
25
|
setTimerElapsed(timerElapsed);
|
|
66
26
|
}, [timerTicking, timerStartedAt]);
|
|
67
|
-
const updateTimerState =
|
|
27
|
+
const updateTimerState = useCallback((timerState) => {
|
|
68
28
|
setTimerTotalMillis(timerState.durationMillis);
|
|
69
29
|
setTimerTicking(timerState.ticking);
|
|
70
30
|
if (timerState.ticking) {
|
|
@@ -73,7 +33,7 @@ function Timer({ className, style, connection: customConnection, separator = ':'
|
|
|
73
33
|
}
|
|
74
34
|
}, []);
|
|
75
35
|
// Deal with starting/stopping the visual ticking of the timer
|
|
76
|
-
|
|
36
|
+
useEffect(() => {
|
|
77
37
|
if (timerTicking) {
|
|
78
38
|
updateTimerElapsed();
|
|
79
39
|
const ticker = setInterval(updateTimerElapsed, 100);
|
|
@@ -83,15 +43,15 @@ function Timer({ className, style, connection: customConnection, separator = ':'
|
|
|
83
43
|
}
|
|
84
44
|
return;
|
|
85
45
|
}, [timerTicking, updateTimerElapsed]);
|
|
86
|
-
(
|
|
46
|
+
useCogsMessage(connection, useCallback((message) => {
|
|
87
47
|
if (message.type === 'adjustable_timer_update') {
|
|
88
48
|
updateTimerState({ startedAt: Date.now(), ticking: message.ticking, durationMillis: message.durationMillis });
|
|
89
49
|
}
|
|
90
50
|
}, [updateTimerState]));
|
|
91
51
|
const time = timerTicking ? timerTotalMillis - timerElapsed : timerTotalMillis;
|
|
92
52
|
const { minutes, seconds } = formatTime(time, false);
|
|
93
|
-
return (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
53
|
+
return (React.createElement("div", { className: className, style: center ? { display: 'flex', justifyContent: 'center', ...style } : style },
|
|
54
|
+
React.createElement("span", { style: center ? { flexBasis: 0, flexGrow: 1, textAlign: 'right' } : undefined }, minutes),
|
|
55
|
+
React.createElement("span", null, separator),
|
|
56
|
+
React.createElement("span", { style: center ? { flexBasis: 0, flexGrow: 1, textAlign: 'left' } : undefined }, seconds)));
|
|
97
57
|
}
|
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = VideoContainer;
|
|
37
|
-
const react_1 = __importStar(require("react"));
|
|
38
|
-
const CogsConnectionProvider_1 = require("../providers/CogsConnectionProvider");
|
|
39
|
-
function VideoContainer({ className, style, videoPlayer: customVideoPlayer, fullscreen, }) {
|
|
40
|
-
const containerRef = (0, react_1.useRef)(null);
|
|
41
|
-
const videoPlayer = (0, CogsConnectionProvider_1.useVideoPlayer)(customVideoPlayer !== null && customVideoPlayer !== void 0 ? customVideoPlayer : undefined);
|
|
42
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { useVideoPlayer } from '../providers/CogsConnectionProvider';
|
|
3
|
+
export default function VideoContainer({ className, style, videoPlayer: customVideoPlayer, fullscreen, }) {
|
|
4
|
+
const containerRef = useRef(null);
|
|
5
|
+
const videoPlayer = useVideoPlayer(customVideoPlayer ?? undefined);
|
|
6
|
+
useEffect(() => {
|
|
43
7
|
if (videoPlayer && containerRef.current) {
|
|
44
8
|
videoPlayer.setParentElement(containerRef.current);
|
|
45
9
|
return () => videoPlayer.resetParentElement();
|
|
46
10
|
}
|
|
47
11
|
}, [videoPlayer]);
|
|
48
12
|
const fullscreenCustomStyle = typeof fullscreen === 'object' ? fullscreen.style : style;
|
|
49
|
-
return (
|
|
13
|
+
return (React.createElement("div", { ref: containerRef, className: className, style: fullscreen
|
|
50
14
|
? { position: 'absolute', zIndex: 1, top: 0, left: 0, width: '100vw', height: '100vh', ...fullscreenCustomStyle }
|
|
51
15
|
: { position: 'relative', ...style } }));
|
|
52
16
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useAudioClips(audioPlayer) {
|
|
6
|
-
const [audioClips, setAudioClips] = (0, react_1.useState)({});
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useAudioClips(audioPlayer) {
|
|
3
|
+
const [audioClips, setAudioClips] = useState({});
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
const listener = (event) => setAudioClips(event.detail.clips);
|
|
9
|
-
audioPlayer
|
|
10
|
-
return () => audioPlayer
|
|
6
|
+
audioPlayer?.addEventListener('state', listener);
|
|
7
|
+
return () => audioPlayer?.removeEventListener('state', listener);
|
|
11
8
|
}, [audioPlayer]);
|
|
12
9
|
return audioClips;
|
|
13
10
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useCogsConfig(connection) {
|
|
6
|
-
const [config, setConfig] = (0, react_1.useState)(connection.config);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useCogsConfig(connection) {
|
|
3
|
+
const [config, setConfig] = useState(connection.config);
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
// Use the latest config in case it has changed before this useEffect ran
|
|
9
6
|
setConfig(connection.config);
|
|
10
7
|
const listener = (event) => setConfig(event.config);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
function useCogsEvent(connection, eventName, handleEvent) {
|
|
6
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export default function useCogsEvent(connection, eventName, handleEvent) {
|
|
3
|
+
useEffect(() => {
|
|
7
4
|
const listener = (event) => {
|
|
8
5
|
if (event.name === eventName) {
|
|
9
6
|
handleEvent(event.value, eventName);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = useCogsEvents;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect } from 'react';
|
|
5
2
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
function useCogsEvents(connection, handleEvent) {
|
|
7
|
-
|
|
3
|
+
export default function useCogsEvents(connection, handleEvent) {
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
const listener = (event) => handleEvent(event);
|
|
9
6
|
connection.addEventListener('event', listener);
|
|
10
7
|
return () => connection.removeEventListener('event', listener);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useCogsMediaConfig(connection) {
|
|
6
|
-
const [mediaConfig, setMediaConfig] = (0, react_1.useState)(null);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useCogsMediaConfig(connection) {
|
|
3
|
+
const [mediaConfig, setMediaConfig] = useState(null);
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
// Use the latest config in case it has changed before this useEffect ran
|
|
9
6
|
setMediaConfig(connection.mediaConfig);
|
|
10
7
|
const listener = ({ mediaConfig }) => {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
function useCogsMessage(connection, handleMessage) {
|
|
6
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export default function useCogsMessage(connection, handleMessage) {
|
|
3
|
+
useEffect(() => {
|
|
7
4
|
const listener = (event) => {
|
|
8
5
|
handleMessage(event.message);
|
|
9
6
|
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useCogsStateValue(connection, stateName) {
|
|
6
|
-
const [value, setValue] = (0, react_1.useState)(connection.state[stateName]);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useCogsStateValue(connection, stateName) {
|
|
3
|
+
const [value, setValue] = useState(connection.state[stateName]);
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
// Use the latest state in case it has changed before this useEffect ran
|
|
9
6
|
setValue(connection.state[stateName]);
|
|
10
7
|
const listener = ({ state }) => {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useCogsInputPortValues(connection) {
|
|
6
|
-
const [value, setValue] = (0, react_1.useState)(connection.state);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useCogsInputPortValues(connection) {
|
|
3
|
+
const [value, setValue] = useState(connection.state);
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
// Use the latest state in case it has changed before this useEffect ran
|
|
9
6
|
setValue(connection.state);
|
|
10
7
|
const listener = () => setValue(connection.state);
|
package/dist/hooks/useHint.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.default = useHint;
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
9
|
-
function useHint(connection) {
|
|
10
|
-
const [hint, setHint] = (0, react_1.useState)('');
|
|
11
|
-
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import useCogsMessage from './useCogsMessage';
|
|
3
|
+
export default function useHint(connection) {
|
|
4
|
+
const [hint, setHint] = useState('');
|
|
5
|
+
useCogsMessage(connection, useCallback((message) => {
|
|
12
6
|
if (message.type === 'text_hints_update') {
|
|
13
7
|
setHint(message.lastSentHint);
|
|
14
8
|
}
|
package/dist/hooks/useImages.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.default = useImages;
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
9
|
-
function useImages(connection) {
|
|
10
|
-
const [images, setImages] = (0, react_1.useState)([]);
|
|
11
|
-
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import useCogsMessage from './useCogsMessage';
|
|
3
|
+
export default function useImages(connection) {
|
|
4
|
+
const [images, setImages] = useState([]);
|
|
5
|
+
useCogsMessage(connection, useCallback((message) => {
|
|
12
6
|
switch (message.type) {
|
|
13
7
|
case 'image_show':
|
|
14
8
|
{
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const [isAudioPlaying, setAudioPlaying] = (0, react_1.useState)(false);
|
|
8
|
-
const audioPlayer = (0, CogsConnectionProvider_1.useAudioPlayer)(customAudioPlayer !== null && customAudioPlayer !== void 0 ? customAudioPlayer : undefined);
|
|
9
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useAudioPlayer } from '../providers/CogsConnectionProvider';
|
|
3
|
+
export default function useIsAudioPlaying(customAudioPlayer) {
|
|
4
|
+
const [isAudioPlaying, setAudioPlaying] = useState(false);
|
|
5
|
+
const audioPlayer = useAudioPlayer(customAudioPlayer ?? undefined);
|
|
6
|
+
useEffect(() => {
|
|
10
7
|
const listener = (event) => setAudioPlaying(event.detail.isPlaying);
|
|
11
|
-
audioPlayer
|
|
12
|
-
return () => audioPlayer
|
|
8
|
+
audioPlayer?.addEventListener('state', listener);
|
|
9
|
+
return () => audioPlayer?.removeEventListener('state', listener);
|
|
13
10
|
}, [audioPlayer]);
|
|
14
11
|
return isAudioPlaying;
|
|
15
12
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useIsConnected(connection) {
|
|
6
|
-
const [isConnected, setConnected] = (0, react_1.useState)(connection.isConnected);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useIsConnected(connection) {
|
|
3
|
+
const [isConnected, setConnected] = useState(connection.isConnected);
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
// The connection may have opened in between the useState initialization above
|
|
9
6
|
// and this useEffect logic running so use the latest state from the connection
|
|
10
7
|
setConnected(connection.isConnected);
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const [preloadedUrl, setPreloadedUrl] = (0, react_1.useState)();
|
|
8
|
-
(0, react_1.useEffect)(() => {
|
|
9
|
-
(0, cogs_client_1.preloadUrl)(url).then((url) => setPreloadedUrl(url));
|
|
1
|
+
import { preloadUrl } from '@clockworkdog/cogs-client';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
export default function usePreloadedUrl(url) {
|
|
4
|
+
const [preloadedUrl, setPreloadedUrl] = useState();
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
preloadUrl(url).then((url) => setPreloadedUrl(url));
|
|
10
7
|
}, [url]);
|
|
11
8
|
return preloadedUrl;
|
|
12
9
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function useShowPhase(connection) {
|
|
6
|
-
const [status, setStatus] = (0, react_1.useState)(connection.showPhase);
|
|
7
|
-
(0, react_1.useEffect)(() => {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export default function useShowPhase(connection) {
|
|
3
|
+
const [status, setStatus] = useState(connection.showPhase);
|
|
4
|
+
useEffect(() => {
|
|
8
5
|
// Use the latest show phase in case it has changed before this useEffect ran
|
|
9
6
|
setStatus(connection.showPhase);
|
|
10
7
|
const listener = () => setStatus(connection.showPhase);
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = useWhenShowReset;
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const useCogsMessage_1 = __importDefault(require("./useCogsMessage"));
|
|
9
|
-
function useWhenShowReset(connection, whenReset) {
|
|
10
|
-
(0, useCogsMessage_1.default)(connection, (0, react_1.useCallback)((message) => {
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import useCogsMessage from './useCogsMessage';
|
|
3
|
+
export default function useWhenShowReset(connection, whenReset) {
|
|
4
|
+
useCogsMessage(connection, useCallback((message) => {
|
|
11
5
|
if (message.type === 'show_reset') {
|
|
12
6
|
whenReset();
|
|
13
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,70 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Images = exports.useImages = exports.Timer = exports.Hint = exports.useHint = exports.VideoContainer = exports.useIsAudioPlaying = exports.useAudioClips = exports.useWhenShowReset = exports.useShowPhase = exports.usePreloadedUrl = exports.useCogsMessage = exports.useCogsStateValues = exports.useCogsStateValue = exports.useCogsMediaConfig = exports.useCogsEvents = exports.useCogsEvent = exports.useCogsConfig = exports.useIsConnected = exports.useVideoPlayer = exports.useAudioPlayer = exports.useCogsConnection = exports.CogsConnectionProvider = void 0;
|
|
21
1
|
// Utilities
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var useCogsMediaConfig_1 = require("./hooks/useCogsMediaConfig");
|
|
36
|
-
Object.defineProperty(exports, "useCogsMediaConfig", { enumerable: true, get: function () { return __importDefault(useCogsMediaConfig_1).default; } });
|
|
37
|
-
var useCogsStateValue_1 = require("./hooks/useCogsStateValue");
|
|
38
|
-
Object.defineProperty(exports, "useCogsStateValue", { enumerable: true, get: function () { return __importDefault(useCogsStateValue_1).default; } });
|
|
39
|
-
var useCogsStateValues_1 = require("./hooks/useCogsStateValues");
|
|
40
|
-
Object.defineProperty(exports, "useCogsStateValues", { enumerable: true, get: function () { return __importDefault(useCogsStateValues_1).default; } });
|
|
41
|
-
var useCogsMessage_1 = require("./hooks/useCogsMessage");
|
|
42
|
-
Object.defineProperty(exports, "useCogsMessage", { enumerable: true, get: function () { return __importDefault(useCogsMessage_1).default; } });
|
|
43
|
-
var usePreloadedUrl_1 = require("./hooks/usePreloadedUrl");
|
|
44
|
-
Object.defineProperty(exports, "usePreloadedUrl", { enumerable: true, get: function () { return __importDefault(usePreloadedUrl_1).default; } });
|
|
45
|
-
var useShowPhase_1 = require("./hooks/useShowPhase");
|
|
46
|
-
Object.defineProperty(exports, "useShowPhase", { enumerable: true, get: function () { return __importDefault(useShowPhase_1).default; } });
|
|
47
|
-
var useWhenShowReset_1 = require("./hooks/useWhenShowReset");
|
|
48
|
-
Object.defineProperty(exports, "useWhenShowReset", { enumerable: true, get: function () { return __importDefault(useWhenShowReset_1).default; } });
|
|
49
|
-
__exportStar(require("./utils/types"), exports);
|
|
2
|
+
export { default as CogsConnectionProvider, useCogsConnection, useAudioPlayer, useVideoPlayer } from './providers/CogsConnectionProvider';
|
|
3
|
+
export { default as useIsConnected } from './hooks/useIsConnected';
|
|
4
|
+
export { default as useCogsConfig } from './hooks/useCogsConfig';
|
|
5
|
+
export { default as useCogsEvent } from './hooks/useCogsEvent';
|
|
6
|
+
export { default as useCogsEvents } from './hooks/useCogsEvents';
|
|
7
|
+
export { default as useCogsMediaConfig } from './hooks/useCogsMediaConfig';
|
|
8
|
+
export { default as useCogsStateValue } from './hooks/useCogsStateValue';
|
|
9
|
+
export { default as useCogsStateValues } from './hooks/useCogsStateValues';
|
|
10
|
+
export { default as useCogsMessage } from './hooks/useCogsMessage';
|
|
11
|
+
export { default as usePreloadedUrl } from './hooks/usePreloadedUrl';
|
|
12
|
+
export { default as useShowPhase } from './hooks/useShowPhase';
|
|
13
|
+
export { default as useWhenShowReset } from './hooks/useWhenShowReset';
|
|
14
|
+
export * from './utils/types';
|
|
50
15
|
// Audio
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var useIsAudioPlaying_1 = require("./hooks/useIsAudioPlaying");
|
|
54
|
-
Object.defineProperty(exports, "useIsAudioPlaying", { enumerable: true, get: function () { return __importDefault(useIsAudioPlaying_1).default; } });
|
|
16
|
+
export { default as useAudioClips } from './hooks/useAudioClips';
|
|
17
|
+
export { default as useIsAudioPlaying } from './hooks/useIsAudioPlaying';
|
|
55
18
|
// Video
|
|
56
|
-
|
|
57
|
-
Object.defineProperty(exports, "VideoContainer", { enumerable: true, get: function () { return __importDefault(VideoContainer_1).default; } });
|
|
19
|
+
export { default as VideoContainer } from './components/VideoContainer';
|
|
58
20
|
// Hints
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var Hint_1 = require("./components/Hint");
|
|
62
|
-
Object.defineProperty(exports, "Hint", { enumerable: true, get: function () { return __importDefault(Hint_1).default; } });
|
|
21
|
+
export { default as useHint } from './hooks/useHint';
|
|
22
|
+
export { default as Hint } from './components/Hint';
|
|
63
23
|
// Timer
|
|
64
|
-
|
|
65
|
-
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return __importDefault(Timer_1).default; } });
|
|
24
|
+
export { default as Timer } from './components/Timer';
|
|
66
25
|
// Images
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var Images_1 = require("./components/Images");
|
|
70
|
-
Object.defineProperty(exports, "Images", { enumerable: true, get: function () { return __importDefault(Images_1).default; } });
|
|
26
|
+
export { default as useImages } from './hooks/useImages';
|
|
27
|
+
export { default as Images } from './components/Images';
|
|
@@ -1,46 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = CogsConnectionProvider;
|
|
37
|
-
exports.useCogsConnection = useCogsConnection;
|
|
38
|
-
exports.useAudioPlayer = useAudioPlayer;
|
|
39
|
-
exports.useVideoPlayer = useVideoPlayer;
|
|
40
|
-
const cogs_client_1 = require("@clockworkdog/cogs-client");
|
|
41
|
-
const react_1 = __importStar(require("react"));
|
|
1
|
+
import { CogsAudioPlayer, CogsConnection, CogsVideoPlayer } from '@clockworkdog/cogs-client';
|
|
2
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
42
3
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
const CogsConnectionContext =
|
|
4
|
+
const CogsConnectionContext = React.createContext({
|
|
44
5
|
useCogsConnection: (customConnection) => {
|
|
45
6
|
if (!customConnection) {
|
|
46
7
|
throw new Error('Ensure <CogsConnectionProvider> has been added to your React app');
|
|
@@ -108,11 +69,11 @@ const CogsConnectionContext = react_1.default.createContext({
|
|
|
108
69
|
* }
|
|
109
70
|
* ```
|
|
110
71
|
*/
|
|
111
|
-
function CogsConnectionProvider({ manifest, hostname, port, children, audioPlayer, videoPlayer, initialClientState, initialDataStoreData, }) {
|
|
112
|
-
const connectionRef =
|
|
113
|
-
const [, forceRender] =
|
|
114
|
-
|
|
115
|
-
const connection = new
|
|
72
|
+
export default function CogsConnectionProvider({ manifest, hostname, port, children, audioPlayer, videoPlayer, initialClientState, initialDataStoreData, }) {
|
|
73
|
+
const connectionRef = useRef(undefined);
|
|
74
|
+
const [, forceRender] = useState({});
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const connection = new CogsConnection(manifest, { hostname, port }, initialClientState, initialDataStoreData);
|
|
116
77
|
connectionRef.current = connection;
|
|
117
78
|
forceRender({});
|
|
118
79
|
return () => {
|
|
@@ -120,16 +81,16 @@ function CogsConnectionProvider({ manifest, hostname, port, children, audioPlaye
|
|
|
120
81
|
connection.close();
|
|
121
82
|
};
|
|
122
83
|
}, [manifest, hostname, port, initialClientState, initialDataStoreData]);
|
|
123
|
-
const audioPlayerRef =
|
|
124
|
-
|
|
84
|
+
const audioPlayerRef = useRef(undefined);
|
|
85
|
+
useEffect(() => {
|
|
125
86
|
if (audioPlayer && !audioPlayerRef.current && connectionRef.current) {
|
|
126
|
-
audioPlayerRef.current = new
|
|
87
|
+
audioPlayerRef.current = new CogsAudioPlayer(connectionRef.current);
|
|
127
88
|
}
|
|
128
89
|
}, [audioPlayer]);
|
|
129
|
-
const videoPlayerRef =
|
|
130
|
-
|
|
90
|
+
const videoPlayerRef = useRef(undefined);
|
|
91
|
+
useEffect(() => {
|
|
131
92
|
if (videoPlayer && !videoPlayerRef.current && connectionRef.current) {
|
|
132
|
-
videoPlayerRef.current = new
|
|
93
|
+
videoPlayerRef.current = new CogsVideoPlayer(connectionRef.current);
|
|
133
94
|
}
|
|
134
95
|
}, [videoPlayer]);
|
|
135
96
|
if (!connectionRef.current) {
|
|
@@ -137,27 +98,27 @@ function CogsConnectionProvider({ manifest, hostname, port, children, audioPlaye
|
|
|
137
98
|
return null;
|
|
138
99
|
}
|
|
139
100
|
const value = {
|
|
140
|
-
useCogsConnection: (customConnection) => customConnection
|
|
141
|
-
useAudioPlayer: (customAudioPlayer) =>
|
|
142
|
-
useVideoPlayer: (customVideoPlayer) =>
|
|
101
|
+
useCogsConnection: (customConnection) => customConnection ?? connectionRef.current,
|
|
102
|
+
useAudioPlayer: (customAudioPlayer) => customAudioPlayer ?? audioPlayerRef.current ?? null,
|
|
103
|
+
useVideoPlayer: (customVideoPlayer) => customVideoPlayer ?? videoPlayerRef.current ?? null,
|
|
143
104
|
};
|
|
144
|
-
return
|
|
105
|
+
return React.createElement(CogsConnectionContext.Provider, { value: value }, children);
|
|
145
106
|
}
|
|
146
107
|
/**
|
|
147
108
|
* Get the connection from `<CogsConnectionProvider>`
|
|
148
109
|
*/
|
|
149
|
-
function useCogsConnection(customConnection) {
|
|
150
|
-
return
|
|
110
|
+
export function useCogsConnection(customConnection) {
|
|
111
|
+
return useContext(CogsConnectionContext).useCogsConnection(customConnection);
|
|
151
112
|
}
|
|
152
113
|
/**
|
|
153
114
|
* Get the audio player from `<CogsConnectionProvider audioPlayer>`
|
|
154
115
|
*/
|
|
155
|
-
function useAudioPlayer(customAudioPlayer) {
|
|
156
|
-
return
|
|
116
|
+
export function useAudioPlayer(customAudioPlayer) {
|
|
117
|
+
return useContext(CogsConnectionContext).useAudioPlayer(customAudioPlayer);
|
|
157
118
|
}
|
|
158
119
|
/**
|
|
159
120
|
* Get the video player from `<CogsConnectionProvider videoPlayer>`
|
|
160
121
|
*/
|
|
161
|
-
function useVideoPlayer(customVideoPlayer) {
|
|
162
|
-
return
|
|
122
|
+
export function useVideoPlayer(customVideoPlayer) {
|
|
123
|
+
return useContext(CogsConnectionContext).useVideoPlayer(customVideoPlayer);
|
|
163
124
|
}
|
package/dist/utils/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "React components and hooks to connect to COGS to build a custom Media Master",
|
|
4
4
|
"author": "Clockwork Dog <info@clockwork.dog>",
|
|
5
5
|
"homepage": "https://github.com/clockwork-dog/cogs-sdk/tree/main/packages/react",
|
|
6
|
-
"version": "2.11.
|
|
6
|
+
"version": "2.11.2",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"release": "yarn npm publish --access public"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@clockworkdog/cogs-client": "^2.11.
|
|
30
|
+
"@clockworkdog/cogs-client": "^2.11.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": "^18.0.0 || ^19.0.0",
|