This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
84 lines (71 loc) · 2.39 KB
/
server.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
var $ = require('jquery');
var func = require('./main_func');
var osc = require('node-osc');
var ip = require('ip');
var fs = require("fs");
var term = require( 'terminal-kit' ).terminal;
// Get settings from file
var contents = fs.readFileSync(__dirname+"/settings.json");
var settings = JSON.parse(contents);
var currentHogTime;
// Clear the console
term.clear();
// Print title
term.color(4);
term.bold("OSC Rewrite\n");
term.defaultColor();
term("Local IP: "+ip.address()+", Incoming port: "+settings.incomingHogPort+", Outgoing port: "+ settings.outgoingQlabPort +"\n");
term("Relays OSC data to: "+settings.touchOscHostA+" @ "+settings.touchOscPortA+" and "+settings.touchOscHostB+" @ "+settings.touchOscPortB+"\n")
term("Listning to list nr: "+ settings.listenToHogList);
// Init rest of gui
updateCue("");
updatePing("");
function startServer(properties){
// Start OSC Server
try {
var oscServer = new osc.Server(settings.incomingHogPort, '0.0.0.0');
updateStatus("Server gestart", 2);
} catch (e) {
updateStatus("Error: Kan server niet verbinden (" + e + ")", 1);
}
// Handle incoming cues
func.handleOSCMsg(oscServer, settings.listenToHogList, {
onCueIncoming: function(currentCue){
updateCue(currentCue.number);
// Send osc to qlab
func.sendOSCMsg(settings.qlabHost, settings.outgoingQlabPort, '/cue/'+currentCue.number+'/start');
},
onPing: function(hog){
updatePing(hog.time)
currentHogTime = hog.time;
//console.log("Ping");
},
onRawPacket: function(data){
// Relay unfiltered data to touchOsc device #1
func.sendOSCMsg(settings.touchOscHostA, settings.touchOscPortA, data);
func.sendOSCMsg(settings.touchOscHostB, settings.touchOscPortB, data);
}
});
}
function updateStatus(msg, colorNr){
//Red: 1, Green: 2, Yellow: 3, Blue: 4
term.moveTo( 1 , 7 ).eraseLine();
term("Status: ");
term.color(colorNr);
term(msg)
term.defaultColor()
}
function updateCue(msg){
term.moveTo( 1 , 10 ).eraseLine();
term("Latest Cue: ");
term(msg);
term(" @ ");
term(currentHogTime);
}
function updatePing(msg){
term.moveTo( 1 , 8 , "Time from Hog: ");
term(msg);
term.moveTo( 1 , 9 );
term.gray("If the time is not changing the connection is broken.");
}
startServer();