@clockworkdog/cogs-client 1.5.5 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +90 -21
- package/dist/AudioPlayer.d.ts +2 -2
- package/dist/AudioPlayer.js +22 -21
- package/dist/CogsConnection.d.ts +62 -55
- package/dist/CogsConnection.js +88 -42
- package/dist/RtspStreamer.js +1 -1
- package/dist/VideoPlayer.d.ts +2 -2
- package/dist/VideoPlayer.js +4 -4
- package/dist/browser/index.js +139 -87
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -2
- package/dist/types/AllMediaClipStatesMessage.d.ts +1 -1
- package/dist/types/AudioState.d.ts +1 -1
- package/dist/types/CogsClientMessage.d.ts +4 -4
- package/dist/types/ManifestTypes.d.ts +33 -0
- package/dist/types/ManifestTypes.js +2 -0
- package/dist/types/MediaClipStateMessage.d.ts +1 -1
- package/dist/types/MediaObjectFit.d.ts +1 -1
- package/dist/types/PluginManifestJson.d.ts +27 -14
- package/dist/types/ShowPhase.d.ts +7 -0
- package/dist/types/{valueTypes.js → ShowPhase.js} +2 -2
- package/dist/types/VideoState.js +1 -1
- package/dist/types/utils.d.ts +9 -0
- package/dist/types/utils.js +2 -0
- package/package.json +4 -3
- package/dist/types/valueTypes.d.ts +0 -18
package/dist/CogsConnection.js
CHANGED
|
@@ -3,35 +3,51 @@ 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
|
-
|
|
6
|
+
exports.CogsIncomingEvent = exports.CogsStateChangedEvent = exports.CogsConfigChangedEvent = exports.CogsMessageEvent = exports.CogsConnectionCloseEvent = exports.CogsConnectionOpenEvent = void 0;
|
|
7
|
+
const ShowPhase_1 = __importDefault(require("./types/ShowPhase"));
|
|
7
8
|
const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
|
|
8
9
|
const urls_1 = require("./helpers/urls");
|
|
9
10
|
class CogsConnection {
|
|
10
|
-
|
|
11
|
+
get config() {
|
|
12
|
+
return { ...this.currentConfig };
|
|
13
|
+
}
|
|
14
|
+
get state() {
|
|
15
|
+
return { ...this.currentState };
|
|
16
|
+
}
|
|
17
|
+
get showPhase() {
|
|
18
|
+
return this._showPhase;
|
|
19
|
+
}
|
|
20
|
+
get timerState() {
|
|
21
|
+
return this._timerState ? { ...this._timerState } : null;
|
|
22
|
+
}
|
|
23
|
+
get selectedAudioOutput() {
|
|
24
|
+
return this._selectedAudioOutput;
|
|
25
|
+
}
|
|
26
|
+
constructor(manifest, { hostname = document.location.hostname, port = urls_1.COGS_SERVER_PORT } = {}, initialClientState = undefined) {
|
|
11
27
|
var _a;
|
|
28
|
+
this.manifest = manifest;
|
|
12
29
|
this.eventTarget = new EventTarget();
|
|
13
30
|
this.currentConfig = {}; // Received on open connection
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this._showPhase = valueTypes_1.ShowPhase.Setup;
|
|
31
|
+
this.currentState = {}; // Received on open connection - TODO: set initial state from manifest?
|
|
32
|
+
this._showPhase = ShowPhase_1.default.Setup;
|
|
17
33
|
this._timerState = null;
|
|
18
34
|
/**
|
|
19
35
|
* Cached audio outputs use to look up the device/sink ID when a different device label is requested
|
|
20
36
|
*/
|
|
21
37
|
this.audioOutputs = undefined;
|
|
22
38
|
this._selectedAudioOutput = '';
|
|
23
|
-
this.
|
|
39
|
+
this.currentState = { ...initialClientState };
|
|
24
40
|
const { useReconnectingWebsocket, path, pathParams } = websocketParametersFromUrl(document.location.href);
|
|
25
41
|
const socketUrl = `ws://${hostname}:${port}${path}${pathParams ? '?' + pathParams : ''}`;
|
|
26
42
|
this.websocket = useReconnectingWebsocket ? new reconnecting_websocket_1.default(socketUrl) : new WebSocket(socketUrl);
|
|
27
43
|
this.websocket.onopen = () => {
|
|
28
44
|
this.currentConfig = {}; // Received on open connection
|
|
29
|
-
this.
|
|
30
|
-
this.dispatchEvent(
|
|
31
|
-
this.
|
|
45
|
+
this.currentState = {}; // Received on open connection
|
|
46
|
+
this.dispatchEvent(new CogsConnectionOpenEvent());
|
|
47
|
+
this.setState(this.currentState); // TODO: Remove this because you should set it manually...??
|
|
32
48
|
};
|
|
33
49
|
this.websocket.onclose = () => {
|
|
34
|
-
this.dispatchEvent(
|
|
50
|
+
this.dispatchEvent(new CogsConnectionCloseEvent());
|
|
35
51
|
};
|
|
36
52
|
this.websocket.onmessage = ({ data }) => {
|
|
37
53
|
try {
|
|
@@ -39,29 +55,30 @@ class CogsConnection {
|
|
|
39
55
|
try {
|
|
40
56
|
if (parsed.config) {
|
|
41
57
|
this.currentConfig = parsed.config;
|
|
42
|
-
this.dispatchEvent(
|
|
58
|
+
this.dispatchEvent(new CogsConfigChangedEvent(this.currentConfig));
|
|
43
59
|
}
|
|
44
60
|
else if (parsed.updates) {
|
|
45
|
-
this.
|
|
46
|
-
this.dispatchEvent(
|
|
61
|
+
this.currentState = { ...this.currentState, ...parsed.updates };
|
|
62
|
+
this.dispatchEvent(new CogsStateChangedEvent(parsed.updates));
|
|
47
63
|
}
|
|
48
64
|
else if (parsed.event && parsed.event.key) {
|
|
49
|
-
this.dispatchEvent(
|
|
65
|
+
this.dispatchEvent(new CogsIncomingEvent(parsed.event.key, parsed.event.value));
|
|
50
66
|
}
|
|
51
67
|
else if (typeof parsed.message === 'object') {
|
|
52
|
-
|
|
68
|
+
const message = parsed.message;
|
|
69
|
+
switch (message.type) {
|
|
53
70
|
case 'adjustable_timer_update':
|
|
54
71
|
this._timerState = {
|
|
55
72
|
startedAt: Date.now(),
|
|
56
|
-
durationMillis:
|
|
57
|
-
ticking:
|
|
73
|
+
durationMillis: message.durationMillis,
|
|
74
|
+
ticking: message.ticking,
|
|
58
75
|
};
|
|
59
76
|
break;
|
|
60
77
|
case 'show_phase':
|
|
61
|
-
this._showPhase =
|
|
78
|
+
this._showPhase = message.phase;
|
|
62
79
|
break;
|
|
63
80
|
}
|
|
64
|
-
this.dispatchEvent(
|
|
81
|
+
this.dispatchEvent(new CogsMessageEvent(message));
|
|
65
82
|
}
|
|
66
83
|
}
|
|
67
84
|
catch (e) {
|
|
@@ -82,29 +99,11 @@ class CogsConnection {
|
|
|
82
99
|
this.audioOutputs = audioOutputs;
|
|
83
100
|
}
|
|
84
101
|
};
|
|
85
|
-
this.addEventListener('open', refreshAudioOutputs);
|
|
102
|
+
this.eventTarget.addEventListener('open', refreshAudioOutputs);
|
|
86
103
|
(_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.addEventListener('devicechange', refreshAudioOutputs);
|
|
87
104
|
refreshAudioOutputs();
|
|
88
105
|
}
|
|
89
106
|
}
|
|
90
|
-
get config() {
|
|
91
|
-
return { ...this.currentConfig };
|
|
92
|
-
}
|
|
93
|
-
get inputPortValues() {
|
|
94
|
-
return { ...this.currentInputPortValues };
|
|
95
|
-
}
|
|
96
|
-
get outputPortValues() {
|
|
97
|
-
return { ...this.currentOutputPortValues };
|
|
98
|
-
}
|
|
99
|
-
get showPhase() {
|
|
100
|
-
return this._showPhase;
|
|
101
|
-
}
|
|
102
|
-
get timerState() {
|
|
103
|
-
return this._timerState ? { ...this._timerState } : null;
|
|
104
|
-
}
|
|
105
|
-
get selectedAudioOutput() {
|
|
106
|
-
return this._selectedAudioOutput;
|
|
107
|
-
}
|
|
108
107
|
get isConnected() {
|
|
109
108
|
return this.websocket.readyState === WebSocket.OPEN;
|
|
110
109
|
}
|
|
@@ -121,8 +120,8 @@ class CogsConnection {
|
|
|
121
120
|
}));
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
|
-
|
|
125
|
-
this.
|
|
123
|
+
setState(values) {
|
|
124
|
+
this.currentState = { ...this.currentState, ...values };
|
|
126
125
|
if (this.isConnected) {
|
|
127
126
|
this.websocket.send(JSON.stringify({ updates: values }));
|
|
128
127
|
}
|
|
@@ -163,8 +162,8 @@ class CogsConnection {
|
|
|
163
162
|
removeEventListener(type, listener, options) {
|
|
164
163
|
this.eventTarget.removeEventListener(type, listener, options);
|
|
165
164
|
}
|
|
166
|
-
dispatchEvent(
|
|
167
|
-
this.eventTarget.dispatchEvent(
|
|
165
|
+
dispatchEvent(event) {
|
|
166
|
+
this.eventTarget.dispatchEvent(event);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
exports.default = CogsConnection;
|
|
@@ -206,3 +205,50 @@ function websocketParametersFromUrl(url) {
|
|
|
206
205
|
return { path: `/client/${encodeURIComponent(serial)}`, pathParams };
|
|
207
206
|
}
|
|
208
207
|
}
|
|
208
|
+
class CogsConnectionOpenEvent extends Event {
|
|
209
|
+
constructor() {
|
|
210
|
+
super('open');
|
|
211
|
+
this.type = 'open';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.CogsConnectionOpenEvent = CogsConnectionOpenEvent;
|
|
215
|
+
class CogsConnectionCloseEvent extends Event {
|
|
216
|
+
constructor() {
|
|
217
|
+
super('close');
|
|
218
|
+
this.type = 'close';
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.CogsConnectionCloseEvent = CogsConnectionCloseEvent;
|
|
222
|
+
class CogsMessageEvent extends Event {
|
|
223
|
+
constructor(message) {
|
|
224
|
+
super('message');
|
|
225
|
+
this.message = message;
|
|
226
|
+
this.type = 'message';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.CogsMessageEvent = CogsMessageEvent;
|
|
230
|
+
class CogsConfigChangedEvent extends Event {
|
|
231
|
+
constructor(config) {
|
|
232
|
+
super('config');
|
|
233
|
+
this.config = config;
|
|
234
|
+
this.type = 'config';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.CogsConfigChangedEvent = CogsConfigChangedEvent;
|
|
238
|
+
class CogsStateChangedEvent extends Event {
|
|
239
|
+
constructor(state) {
|
|
240
|
+
super('state');
|
|
241
|
+
this.state = state;
|
|
242
|
+
this.type = 'state';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.CogsStateChangedEvent = CogsStateChangedEvent;
|
|
246
|
+
class CogsIncomingEvent extends Event {
|
|
247
|
+
constructor(name, value) {
|
|
248
|
+
super('event');
|
|
249
|
+
this.name = name;
|
|
250
|
+
this.value = value;
|
|
251
|
+
this.type = 'event';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.CogsIncomingEvent = CogsIncomingEvent;
|
package/dist/RtspStreamer.js
CHANGED
|
@@ -33,7 +33,7 @@ class RtspStreamer {
|
|
|
33
33
|
});
|
|
34
34
|
// Restart stream on RTCP BYE (stream ended)
|
|
35
35
|
pipeline.rtsp.onRtcp = (rtcp) => {
|
|
36
|
-
if (media_stream_library_browser_1.isRtcpBye(rtcp)) {
|
|
36
|
+
if ((0, media_stream_library_browser_1.isRtcpBye)(rtcp)) {
|
|
37
37
|
console.log('Video stream ended. Restarting.');
|
|
38
38
|
videoElement.pause();
|
|
39
39
|
setTimeout(startPipeline, 0);
|
package/dist/VideoPlayer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import CogsConnection from './CogsConnection';
|
|
|
2
2
|
import { VideoState } from './types/VideoState';
|
|
3
3
|
import MediaClipStateMessage from './types/MediaClipStateMessage';
|
|
4
4
|
import { MediaObjectFit } from '.';
|
|
5
|
-
|
|
5
|
+
type EventTypes = {
|
|
6
6
|
state: VideoState;
|
|
7
7
|
videoClipState: MediaClipStateMessage;
|
|
8
8
|
};
|
|
@@ -14,7 +14,7 @@ export default class VideoPlayer {
|
|
|
14
14
|
private pendingClip?;
|
|
15
15
|
private parentElement;
|
|
16
16
|
private sinkId;
|
|
17
|
-
constructor(cogsConnection: CogsConnection
|
|
17
|
+
constructor(cogsConnection: CogsConnection<any>, parentElement?: HTMLElement);
|
|
18
18
|
setParentElement(parentElement: HTMLElement): void;
|
|
19
19
|
resetParentElement(): void;
|
|
20
20
|
setGlobalVolume(globalVolume: number): void;
|
package/dist/VideoPlayer.js
CHANGED
|
@@ -15,8 +15,7 @@ class VideoPlayer {
|
|
|
15
15
|
cogsConnection.sendMediaClipState(detail);
|
|
16
16
|
});
|
|
17
17
|
// Listen for video control messages
|
|
18
|
-
cogsConnection.addEventListener('message', (
|
|
19
|
-
const message = event.detail;
|
|
18
|
+
cogsConnection.addEventListener('message', ({ message }) => {
|
|
20
19
|
switch (message.type) {
|
|
21
20
|
case 'media_config_update':
|
|
22
21
|
this.setGlobalVolume(message.globalVolume);
|
|
@@ -261,7 +260,8 @@ class VideoPlayer {
|
|
|
261
260
|
path: this.activeClip.path,
|
|
262
261
|
state: !((_b = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _b === void 0 ? void 0 : _b.paused) ? VideoState_1.ActiveVideoClipState.Playing : VideoState_1.ActiveVideoClipState.Paused,
|
|
263
262
|
loop: (_d = (_c = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _c === void 0 ? void 0 : _c.loop) !== null && _d !== void 0 ? _d : false,
|
|
264
|
-
volume: ((_e = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _e === void 0 ? void 0 : _e.muted)
|
|
263
|
+
volume: ((_e = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _e === void 0 ? void 0 : _e.muted)
|
|
264
|
+
? 0
|
|
265
265
|
: (_g = (_f = this.videoClipPlayers[this.activeClip.path].videoElement) === null || _f === void 0 ? void 0 : _f.volume) !== null && _g !== void 0 ? _g : 0,
|
|
266
266
|
}
|
|
267
267
|
: undefined,
|
|
@@ -284,7 +284,7 @@ class VideoPlayer {
|
|
|
284
284
|
createVideoElement(path, config, { volume }) {
|
|
285
285
|
const videoElement = document.createElement('video');
|
|
286
286
|
videoElement.playsInline = true; // Required for iOS
|
|
287
|
-
videoElement.src = urls_1.assetUrl(path);
|
|
287
|
+
videoElement.src = (0, urls_1.assetUrl)(path);
|
|
288
288
|
videoElement.autoplay = false;
|
|
289
289
|
videoElement.loop = false;
|
|
290
290
|
setVideoElementVolume(videoElement, volume * this.globalVolume);
|