-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
191 lines (175 loc) · 6.48 KB
/
index.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!doctype html>
<html>
<head>
<title>ProPresenter-vMix Bridge</title>
<style media="screen">
body {margin:10px auto;width:600px;background: black;color:ivory;border:1px solid ivory; border-radius: 10px;font-family:Muli,sans-serif;;padding:10px;box-sizing:border-box;}
clock{position:absolute;bottom:10px;right:10px;text-align:right;}
h1 {margin-top:0;}
li {margin-bottom:3px;list-style: none;}
label {width:250px;display:inline-block;}
input {display:inline-block;vertical-align:middle;border:1px solid #333;border-radius:2px;background:none;padding:6px;color:white;font-family:Muli;}
#cs {border:1px solid #eee;border-color:white;border-radius:3px;background:#222;padding:20px;font-size:1.2em;font-family:Muli;font-weight:600;}
.disconnected {border-color:red;}
.disconnected #cs {border-color:red;}
.connected #cs {border-color:green;}
status {position:absolute;bottom:10px;left:10px;color:white;}
.connected status {color:green;}
.disconnected status {color:red;}
.vmix.sending {color:blue;}
.vmix.failed {color:red;}
</style>
<meta charset="UTF-8">
<script type="text/javascript" src="lib/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="lib/jquery.json.min.js"></script>
<script type="text/javascript" src="lib/jquery.simple.websocket.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
var webSocket;
var slideText = '';
var lastMessageTime;
var reconnectTime = 20000;
var reconnectTimer = 0;
var vMixResendTimer = 0;
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
function check_propresenter() {
setTimeout(check_propresenter, 2000)
if (!webSocket) return connect_propresenter();
if (! webSocket.isConnected() ) {
// if (reconnectTimer != 0) clearTimeout(reconnectTimer);
// reconnectTimer = setTimeout(reconnect_propresenter, reconnectTime);
reconnect_propresenter();
$('body').addClass('disconnected');
$('body').removeClass('connected');
$('status .pp').html('DISCONNECTED')
return;
}
else if (Date.now() - lastMessageTime > 60000) {
auth_propresenter();
}
}
function set_slide(lyric) {
$("#cs").html(lyric.replaceAll("\r\n", "%0A").replaceAll("\n","<br>").replaceAll("\r","<br>"));
send_vmix(lyric.replaceAll("\r\n", "%0A").replaceAll("\n", "%0A").replaceAll("\r", "%0A"));
}
function resend_vmix() {
send_vmix(lastVmixMessage);
}
function send_vmix(text) {
$('status .vmix').addClass('sending')
$('status .vmix').html('SENDING...')
console.log('Sending to vmix:\n' + text)
lastVmixMessage = text;
$.ajax(
"http://"+config.vmix_ip+":"+config.vmix_port+"/api/?Function=SetText&SelectedIndex=0&Input="+config.vmix_input+"&Value="+text,
{
timeout: 500,
success: function() {
$('status .vmix').removeClass('failed')
$('status .vmix').html('SENT')
},
error: function(xhr, status, error){
$('status .vmix').addClass('failed')
$('status .vmix').html('FAILED')
console.log('vmix connection error, is it running?');
if (vMixResendTimer!=0) clearTimeout(vMixResendTimer);
vMixResendTimer = setTimeout(resend_vmix, 3000)
},
complete: function() {
$('status .vmix').removeClass('sending');
}
}
);
}
function reconnect_propresenter() {
webSocket.removeAll();
webSocket.close();
connect_propresenter();
}
function connect_propresenter() {
//Connect to ProPresenter Remote Stage Display
webSocket = $.simpleWebSocket({ attempts:1, url: 'ws://'+config.propresenter_ip+':'+config.propresenter_port+'/stagedisplay' });
webSocket.isConnected(auth_propresenter)
// reconnected listening
webSocket.listen(function(message) {
console.log(message);
lastMessageTime = Date.now()
$('body').removeClass('disconnected')
$('body').addClass('connected');
$('status .pp').html('CONNECTED')
if (message['acn'] != "vid") {
// console.log(message);
}
if (message['acn'] == 'sys') {
$('clock').html(message['txt'])
}
if (message['acn'] == "fv") {
if (message['ary'][0]['txt'] != undefined && message['ary'][0]['acn'] == 'cs') {
// console.log(message['ary']);
//set_slide(message['ary'][0]['txt']);
if (typeof message['ary'][2] == 'undefined' || (typeof message['ary'][2] !== 'undefined' && message['ary'][2]['txt'] != 'novmix')) {
set_slide(message['ary'][0]['txt']);
}
if (typeof message['ary'][2] !== 'undefined' && message['ary'][2]['txt'] == 'novmix') {
set_slide('');
}
}
}
});
}
function auth_propresenter() {
//Connect and send the password
webSocket.send({"pwd":config.propresenter_password,"ptl":610,"acn":"ath"}).done(function() {
// message send
console.log("SENT AUTH");
}).fail(function(e) {
// error sending
});
}
function check_vmix() {
//Replace 127.0.0.1:8088 with the IP and Port of your vMix system
$.get("http://127.0.0.1:8088/api", function(d) {
console.log(d);
});
}
function update_prop_address(address) {
data = address.split(':');
config.propresenter_ip = data[0];
config.propresenter_port = data[1];
webSocket.close();
connect_propresenter();
}
function update_vmix_address(address) {
data = address.split(':');
config.vmix_ip = data[0];
config.vmix_port = data[1];
}
$(document).ready(function() {
// $('#propresenter_ip').text("ProPresenter at "+ config['propresenter_ip'] +':'+config['propresenter_port']);
// $('#vmix_ip').text("vMix at "+ config['vmix_ip'] +":"+ config['vmix_port']);
// $('#vmix_input').text("Controlling vMix Input #"+ config['vmix_input']);
$('#prop_ip_input').val(config.propresenter_ip +':'+config.propresenter_port);
$('#vmix_ip_input').val(config.vmix_ip +":"+ config.vmix_port);
$('#vmix_input_input').val(config.vmix_input);
check_propresenter();
// check_vmix();
});
</script>
</head>
<body>
<clock></clock>
<status>PP: <span class='pp'>CONNECTING...</span> | VMIX: <span class='vmix'>WAITING</span></status>
<h1>ProPresenter vMix Bridge</h1>
<h3>Configuration</h3>
<ul>
<li id="propresenter_ip"><label>ProPresenter Address (IP:Port): </label><input id="prop_ip_input" onchange="update_prop_address(this.value);"/></li>
<li id="vmix_ip"><label>vMix Address (IP:Port): </label><input id="vmix_ip_input" onchange="update_vmix_address(this.value)"/></li>
<li id="vmix_input"><label>vMix Input: </label><input id="vmix_input_input" onchange="config.vmix_input = this.value;"/></li>
</ul>
<h3>Current Slide</h3>
<div id="cs"></div>
</body>
</html>