-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
116 lines (100 loc) · 3.2 KB
/
app.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// connects two ProPresenter 6 instances using stage display and remote control protocols
// treats one as master and one as slave
// whatever signal is sent by the master is duplicated and sent to the slave
"use strict";
// ----- SETUP HAPPENS HERE ----------------
// general configuration
const config = require( "./config.js" );
// modules
const { ProControlClient } = require( "propresenter" );
// prepare to get user input
const prompt = require( 'prompt' );
let masterPC, slavePC;
let slavePlaylistPath = '';
let slavePlaylistName = '';
let starting = true;
let pauseOutput = false;
async function selectPlaylist( playlists ) {
if ( playlists ) {
console.log( '\n\n-- SELECT THE SLAVE PLAYLIST TO CONTROL --' );
console.log( 'If blank, the master will control slave playlists based on playlist location.' );
console.log( '' );
let selected = '';
let selectedPath = [];
prompt.start();
prompt.message = 'Select a playlist';
while ( true ) {
// output only one layer of playlist items
let index = 1;
for ( let item of playlists ) {
console.log( `${index++}. ${item.playlistName}` )
}
console.log( '===============================' );
let answer = await prompt.get( [ 'number' ] );
if ( answer.number == '' ) {
console.log( 'nothing selected' );
console.log( 'master will control matching playlists' )
return '';
}
index = parseInt( answer.number ) - 1;
selected = playlists[ index ];
selectedPath.push( selected.playlistName );
if ( selected.playlistType == 'playlistTypePlaylist' ) {
slavePlaylistName = selectedPath.join( '/' );
console.log( `SLAVE PLAYLIST SET TO: ${slavePlaylistName}` );
return selected.playlistLocation;
} else {
playlists = selected.playlist;
}
}
}
}
function print( s ) {
if ( pauseOutput ) return;
console.log( s );
}
slavePC = new ProControlClient(
config.slave.host,
config.slave.control.password,
{
version: config.slave.version,
onupdate: async ( data, procc ) => {
// print( "--------- SLAVE CONTROL UPDATE -------------" );
// print(data);
if ( data.action == 'playlistRequestAll' && starting ) {
if ( procc.playlists && procc.playlists.length > 1 ) {
pauseOutput = true;
slavePlaylistPath = await selectPlaylist( procc.playlists );
pauseOutput = false;
}
starting == false;
}
}
} );
masterPC = new ProControlClient(
config.master.host,
config.master.control.password,
{
version: config.master.version,
ondata: ( data ) => {
switch ( data.action ) {
case 'presentationTriggerIndex':
print( "--------- MASTER CONTROL DATA -------------" );
print( data );
// pro7 needs the request to only be strings for some reason
data.slideIndex = data.slideIndex.toString();
// if we are specifying a custom target playlist use it here
if ( slavePlaylistPath != '' ) {
let presentationIndex = data.presentationPath.split( ':' ).slice( -1 );
data.presentationPath = `${slavePlaylistPath}:${presentationIndex}`
};
print( `sending to slave playlist: ${slavePlaylistName}` )
print( data );
if ( slavePC.connected ) slavePC.send( data );
break;
default:
return;
}
},
} );
console.log( 'STARTING...' );