diff --git a/cf.js b/cf.js index 536779940b66fd958c810f9aa959344e42f80965..8c223b542ad1f1558060c596f4659f29470133c5 100644 --- a/cf.js +++ b/cf.js @@ -49,7 +49,7 @@ app.get('/fileList', (req, res) => { }) let unfjson = (program) => { - + } // we also handle file-saving this way, @@ -83,6 +83,7 @@ app.post('/save/systems/:file', (req, res) => { // we also want to institute some pipes: this is a holdover for a better system // more akin to nautilus, where server-side graphs are manipulated // for now, we just want to dive down to a usb port, probably, so this shallow link is OK +let processes = [] app.get('/spawnProcess/:file', (req, res) => { // launches another node instance at this file w/ these args, let args = '' @@ -93,7 +94,8 @@ app.get('/spawnProcess/:file', (req, res) => { const process = child_process.fork(`processes/${req.params.file}`) process.on('message', (data) => { console.log('process msg', data) - res.send({startup: true, ip: ownIp, port: data.port}) + processes.push(process) + res.send({startup: true, pid: process.pid, ip: ownIp, port: data.port}) }) process.on('error', (data) => { console.log('process errs', data) @@ -106,6 +108,19 @@ app.get('/spawnProcess/:file', (req, res) => { }) }) +app.get('/killProcess', (req, res) => { + console.log('kill cm for ', req.query.pid) + for(proc of processes){ + if(proc.pid == req.query.pid){ + // a local listener, + proc.on('exit', (err) => { + res.send({success: true}) + }) + proc.kill() + } + } +}) + // finally, we tell the thing to listen here: let port = 8080 app.listen(port) diff --git a/hunks/pipes/vfptc.js b/hunks/pipes/vfptc.js index 04067ec962b70905fe9269cd79c86816f56c6bbe..f80e54064152806d2702ef4b6558c6e96ce368cd 100644 --- a/hunks/pipes/vfptc.js +++ b/hunks/pipes/vfptc.js @@ -38,15 +38,22 @@ export default function VFPTC() { // and serialport, let serialStatusMessage = new State('string', 'serialport status', 'unknown') let usbPidSelect = new State('string', 'usb PID', '8022') - let serialRetryButton = new State('boolean', 'serial reset', false) - this.states.push(pipeStatusMessage, portSelect, pipeRetryButton, serialStatusMessage, serialRetryButton) + let remoteProcessId = '' + let shutdownRemote = () => { + return new Promise((resolve, reject) => { + jQuery.get(`/killProcess?pid=${remoteProcessId}`, (res) => { + resolve() + }) + }) + } + + this.states.push(pipeStatusMessage, portSelect, pipeRetryButton, serialStatusMessage) // for simplicity, joy, just reset everything ? pipeRetryButton.onChange = (value) => { - startWsConnection() - } - serialRetryButton.onChange = (value) => { - console.error('yet-2-write') + shutdownRemote().then((res) => { + startWsConnection() + }) } // coming merge of init and onload, however: @@ -66,7 +73,8 @@ export default function VFPTC() { pipeStatusMessage.set(STATUS_OPENING) jQuery.get(`spawnProcess/vfpts.js?args=${portSelect.value},${usbPidSelect.value}`, (data) => { if (data.startup) { - console.log('serverside launched, starting client') + console.log(`serverside launched with pid ${data.pid}, starting client`) + remoteProcessId = data.pid console.log(data) // have data.ip and data.port ws = new WebSocket(`ws://${data.ip}:${data.port}`)