-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoscServer.js
83 lines (62 loc) · 1.52 KB
/
oscServer.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
const fs = require('fs');
const path = require('path');
const OSC = require('osc-js');
const express = require('express');
const ip = require('ip');
class Server {
constructor(options) {
this.options = options;
this.osc = new OSC({
plugin: new OSC.BridgePlugin(this.options)
});
this.osc.on('error', (error) => {
console.error('osc error');
})
this.osc.on('open', () => {
console.log('osc open');
});
this.httpServer = undefined;
}
start() {
this.osc.open();
}
startHttp() {
const { port, host } = this.options.httpServer;
const staticPath = path.resolve(__dirname, this.options.staticFolderName);
this.httpServer = express();
fs.access(staticPath, err => {
if (!err) {
console.log('static folder found');
} else {
console.log('static folder not found');
}
});
this.httpServer.use(express.static(staticPath));
this.httpServer.listen(port, host, () => {
console.log('http server ready');
});
}
stop() {
this.osc.close();
}
hello() {
const ipAddress = ip.address();
const { options } = this;
// Clear terminal
// process.stdout.write('\x1Bc');
if (this.httpServer) {
// console.log('server');
}
}
}
function startStaticServer() {
const options = require('./options.json');
const server = new Server(options);
server.start();
server.startHttp();
server.hello();
}
if (require.main === module) {
startStaticServer();
}
module.exports = Server;