@clockworkdog/cogs-client 1.4.3 → 1.5.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 +17 -5
- package/dist/AudioPlayer.js +4 -2
- package/dist/RtspStreamer.d.ts +6 -3
- package/dist/RtspStreamer.js +74 -22
- package/dist/VideoPlayer.js +3 -1
- package/dist/browser/index.js +84 -27
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,21 +6,33 @@ Create content for your COGS Media Master
|
|
|
6
6
|
|
|
7
7
|
## Add to your project
|
|
8
8
|
|
|
9
|
-
###
|
|
9
|
+
### Static HTML
|
|
10
|
+
|
|
11
|
+
Download `cogs-client.js` from https://unpkg.com/@clockworkdog/cogs-client and save it to your project.
|
|
12
|
+
|
|
13
|
+
Include the script in your HTML page:
|
|
10
14
|
|
|
11
15
|
```html
|
|
12
|
-
<script src="
|
|
16
|
+
<script src="./cogs-client.js"></script>
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
(Avoid `<script>` tags with `http...` so your content works without an internet connection.)
|
|
20
|
+
|
|
21
|
+
### NPM / Yarn
|
|
22
|
+
|
|
23
|
+
If you haven't yet created a web project we recommend using Vite with Typescript:
|
|
16
24
|
|
|
17
25
|
```shell
|
|
18
|
-
|
|
26
|
+
yarn create vite my-custom-content --template vanilla-ts
|
|
27
|
+
cd my-custom-content
|
|
28
|
+
yarn
|
|
19
29
|
```
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
Then add `cogs-client` with NPM or Yarn:
|
|
22
32
|
|
|
23
33
|
```shell
|
|
34
|
+
npm install --save @clockworkdog/cogs-client
|
|
35
|
+
# OR
|
|
24
36
|
yarn add @clockworkdog/cogs-client
|
|
25
37
|
```
|
|
26
38
|
|
package/dist/AudioPlayer.js
CHANGED
|
@@ -405,12 +405,14 @@ function isFadeValid(fade) {
|
|
|
405
405
|
return typeof fade === 'number' && !isNaN(fade) && fade > 0;
|
|
406
406
|
}
|
|
407
407
|
function setPlayerSinkId(player, sinkId) {
|
|
408
|
+
var _a;
|
|
408
409
|
if (sinkId === undefined) {
|
|
409
410
|
return;
|
|
410
411
|
}
|
|
411
412
|
if (player._html5) {
|
|
412
|
-
player._sounds.forEach((sound) => {
|
|
413
|
-
|
|
413
|
+
(_a = player._sounds) === null || _a === void 0 ? void 0 : _a.forEach((sound) => {
|
|
414
|
+
var _a, _b;
|
|
415
|
+
(_b = (_a = sound._node) === null || _a === void 0 ? void 0 : _a.setSinkId) === null || _b === void 0 ? void 0 : _b.call(_a, sinkId);
|
|
414
416
|
});
|
|
415
417
|
}
|
|
416
418
|
else {
|
package/dist/RtspStreamer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export declare const LIVE_VIDEO_PLAYBACK_RATE = 1.1;
|
|
2
2
|
/**
|
|
3
3
|
* Manages a websocket connection to the COGS TCP relay which can be used to send RTSP video
|
|
4
4
|
* feeds to the web.
|
|
@@ -12,11 +12,14 @@ export default class RtspStreamer {
|
|
|
12
12
|
});
|
|
13
13
|
/**
|
|
14
14
|
* Start an RTSP video stream on with the given URI on the given video element.
|
|
15
|
-
* @returns
|
|
15
|
+
* @returns An object with a function to close the pipeline
|
|
16
16
|
*/
|
|
17
17
|
play(params: {
|
|
18
18
|
uri: string;
|
|
19
19
|
videoElement: HTMLVideoElement;
|
|
20
20
|
playbackRate?: number;
|
|
21
|
-
|
|
21
|
+
restartIfStopped?: boolean;
|
|
22
|
+
}): {
|
|
23
|
+
close: () => void;
|
|
24
|
+
};
|
|
22
25
|
}
|
package/dist/RtspStreamer.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LIVE_VIDEO_PLAYBACK_RATE = void 0;
|
|
3
4
|
const media_stream_library_browser_1 = require("@clockworkdog/media-stream-library-browser");
|
|
4
5
|
const urls_1 = require("./helpers/urls");
|
|
6
|
+
const DEFAULT_VIDEO_PLAYBACK_RATE = 1;
|
|
5
7
|
// Use a faster-than-realtime playback rate by default
|
|
6
8
|
// so that it keeps up with a realtime stream in case of video buffering
|
|
7
|
-
|
|
9
|
+
exports.LIVE_VIDEO_PLAYBACK_RATE = 1.1;
|
|
8
10
|
/**
|
|
9
11
|
* Manages a websocket connection to the COGS TCP relay which can be used to send RTSP video
|
|
10
12
|
* feeds to the web.
|
|
@@ -15,32 +17,82 @@ class RtspStreamer {
|
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Start an RTSP video stream on with the given URI on the given video element.
|
|
18
|
-
* @returns
|
|
20
|
+
* @returns An object with a function to close the pipeline
|
|
19
21
|
*/
|
|
20
22
|
play(params) {
|
|
21
23
|
var _a;
|
|
22
24
|
const { uri, videoElement } = params;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
let pipeline;
|
|
26
|
+
const startPipeline = () => {
|
|
27
|
+
pipeline === null || pipeline === void 0 ? void 0 : pipeline.close();
|
|
28
|
+
pipeline = new media_stream_library_browser_1.Html5VideoPipeline({
|
|
29
|
+
ws: { uri: this._websocketUri },
|
|
30
|
+
rtsp: { uri: uri },
|
|
31
|
+
mediaElement: videoElement,
|
|
32
|
+
});
|
|
33
|
+
// Restart stream on RTCP BYE (stream ended)
|
|
34
|
+
pipeline.rtsp.onRtcp = (rtcp) => {
|
|
35
|
+
if (media_stream_library_browser_1.isRtcpBye(rtcp)) {
|
|
36
|
+
console.log('Video stream ended. Restarting.');
|
|
37
|
+
videoElement.pause();
|
|
38
|
+
setTimeout(startPipeline, 0);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
// Start playback when ready
|
|
42
|
+
pipeline.ready.then(() => {
|
|
43
|
+
pipeline.rtsp.play();
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
startPipeline();
|
|
47
|
+
if (params.playbackRate) {
|
|
48
|
+
const playbackRate = (_a = params.playbackRate) !== null && _a !== void 0 ? _a : DEFAULT_VIDEO_PLAYBACK_RATE;
|
|
49
|
+
videoElement.playbackRate = playbackRate;
|
|
50
|
+
videoElement.addEventListener('play', () => {
|
|
51
|
+
videoElement.playbackRate = playbackRate;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
let removeRestartListeners = null;
|
|
55
|
+
if (params.restartIfStopped) {
|
|
56
|
+
let playing = false;
|
|
57
|
+
let interval = null;
|
|
58
|
+
const handleTimeUpdate = () => {
|
|
59
|
+
playing = true;
|
|
60
|
+
};
|
|
61
|
+
const handlePlay = () => {
|
|
62
|
+
playing = true;
|
|
63
|
+
videoElement.addEventListener('timeupdate', handleTimeUpdate);
|
|
64
|
+
if (!interval) {
|
|
65
|
+
interval = setInterval(() => {
|
|
66
|
+
if (!playing) {
|
|
67
|
+
console.log('Video stopped playing. Restarting.');
|
|
68
|
+
videoElement.pause();
|
|
69
|
+
setTimeout(startPipeline, 0);
|
|
70
|
+
}
|
|
71
|
+
playing = false;
|
|
72
|
+
}, 2000);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const handlePause = () => {
|
|
76
|
+
videoElement.removeEventListener('timeupdate', handleTimeUpdate);
|
|
77
|
+
if (interval) {
|
|
78
|
+
clearInterval(interval);
|
|
79
|
+
interval = null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
videoElement.addEventListener('play', handlePlay);
|
|
83
|
+
videoElement.addEventListener('pause', handlePause);
|
|
84
|
+
removeRestartListeners = () => {
|
|
85
|
+
handlePause();
|
|
86
|
+
videoElement.removeEventListener('play', handlePlay);
|
|
87
|
+
videoElement.removeEventListener('pause', handlePause);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
close: () => {
|
|
92
|
+
pipeline === null || pipeline === void 0 ? void 0 : pipeline.close();
|
|
93
|
+
removeRestartListeners === null || removeRestartListeners === void 0 ? void 0 : removeRestartListeners();
|
|
94
|
+
},
|
|
33
95
|
};
|
|
34
|
-
// Start playback when ready
|
|
35
|
-
pipeline.ready.then(() => {
|
|
36
|
-
pipeline.rtsp.play();
|
|
37
|
-
});
|
|
38
|
-
videoElement.playbackRate = (_a = params.playbackRate) !== null && _a !== void 0 ? _a : DEFAULT_VIDEO_PLAYBACK_RATE;
|
|
39
|
-
videoElement.addEventListener('play', () => {
|
|
40
|
-
var _a;
|
|
41
|
-
videoElement.playbackRate = (_a = params.playbackRate) !== null && _a !== void 0 ? _a : DEFAULT_VIDEO_PLAYBACK_RATE;
|
|
42
|
-
});
|
|
43
|
-
return pipeline;
|
|
44
96
|
}
|
|
45
97
|
}
|
|
46
98
|
exports.default = RtspStreamer;
|
package/dist/VideoPlayer.js
CHANGED