-
Notifications
You must be signed in to change notification settings - Fork 11
/
n4m-handpose.js
37 lines (29 loc) · 1.05 KB
/
n4m-handpose.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
// This file is the single-entrypoint for the Max patch.
// When this file is executed via `node.script start` in the Max patch,
// this program will launch an Electron app as a child process, and connect to it by socket.io
const MaxAPI = require("max-api");
const io = require("socket.io")();
const electron = require("electron");
const proc = require("child_process");
const child = proc.spawn(electron, ["."]);
io.on("connection", (socket) => {
console.log("Socket is connected with Electron App");
socket.on("dispatch", (data) =>
{
MaxAPI.outlet(data);
// uncomment only when debugging max api
// console.log("dispatch: ", data);
});
socket.on('disconnect', () =>
{
MaxAPI.outlet("disconnected", 0);
// uncomment only when debugging max api
// console.log('user disconnected');
});
});
io.listen(3000);
// This will ensure that when this parent process is killed in maxpat (either by `node.script stop` or Max is shutdown for some reason),
// it will terminate the child process, the Electron app.
process.on("exit", () => {
child.kill();
});