This repository has been archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
99 lines (88 loc) · 3.06 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const {OBSUtility} = require('nodecg-utility-obs');
module.exports = function (nodecg) {
const nowPlayingReplicant = nodecg.Replicant("now-playing");
const recordingState = nodecg.Replicant('recording');
nodecg.listenFor('obs:transitioning', data => {
nowPlayingReplicant.value = data.sceneName.toLowerCase().includes("holding");
});
const obs = new OBSUtility(nodecg);
nodecg.listenFor('obs:startRecording', async (_data, callback) => {
try {
await obs.send('StartRecording');
if (callback && !callback.handled) {
callback();
}
} catch (error) {
console.log('Error starting recording:', error);
if (callback && !callback.handled) {
callback(error);
}
}
});
nodecg.listenFor('obs:stopRecording', async (_data, callback) => {
try {
await obs.send('StopRecording');
if (callback && !callback.handled) {
callback();
}
} catch (error) {
console.log('Error stopping recording:', error);
if (callback && !callback.handled) {
callback(error);
}
}
});
obs.on("ConnectionOpened", () => {
obs.send('SetHeartbeat', {enable: true});
})
obs.on('Heartbeat', data => {
recordingState.value = data.recording;
});
obs.on('PreviewSceneChanged', data => {
data.sources.forEach(source => {
if (source.type == 'vlc_source') {
obs.send('GetSourceSettings', {sourceName: source.name, sourceType: 'vlc_source'}).then(data => {
data.sourceSettings.playlist.forEach(item => {
if(item.value.startsWith('rtmp://')) {
reloadStream(source.name, item.value)
}
})
})
}
});
});
function delay(t, v) {
return new Promise(function(resolve) {
setTimeout(resolve.bind(null, v), t)
});
}
function reloadStream(sourceName, streamURL) {
const stopSettings = {
loop: false,
playback_behaviour: 'stop_restart',
playlist: [
{
hidden: false,
selected: false,
value: streamURL
}
]
};
const startSettings = {
loop: false,
playback_behaviour: 'always_play',
playlist: [
{
hidden: false,
selected: false,
value: streamURL
}
]
}
return obs.send('SetSourceSettings', {sourceName: sourceName, sourceType: 'vlc_source', sourceSettings: stopSettings}).then(data => {
return delay(50).then(function() {
return obs.send('SetSourceSettings', {sourceName: sourceName, sourceType: 'vlc_source', sourceSettings: startSettings});
});
})
}
}