ipc: remove woker, just handle queue in a separate loop, use a better io-parser, update deps
This commit is contained in:
parent
7770d01698
commit
547f66a2a2
6 changed files with 36 additions and 84 deletions
|
|
@ -21,7 +21,7 @@ Sessions saved with this version will not be readable with older versions (old s
|
|||
- custom module
|
||||
- add access to the app's `settings` object
|
||||
- misc
|
||||
- ui performance optimizations (clients <> server communcation is now queued and threaded)
|
||||
- ui performance optimizations (queued clients <> server communcation)
|
||||
|
||||
## 0.17.8
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ var express = require('express')(),
|
|||
path = require('path'),
|
||||
http = require('http'),
|
||||
server = http.createServer(express),
|
||||
io = require('socket.io')(),
|
||||
customParser= require('socket.io-msgpack-parser'),
|
||||
io = require('socket.io')(server, {parser:customParser}),
|
||||
ipc = {},
|
||||
settings = require('./settings'),
|
||||
appAddresses = settings.read('appAddresses'),
|
||||
|
|
@ -16,9 +17,6 @@ express.get('*', function(req, res){
|
|||
res.sendFile(path.resolve(__dirname + '/../browser' + req.path))
|
||||
})
|
||||
|
||||
|
||||
io.listen(server)
|
||||
|
||||
server.listen(settings.read('httpPort'))
|
||||
|
||||
ipc.send = function(name,data,clientId) {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"vmodule":"1.0.1",
|
||||
"electron-localshortcut": "1.1.1",
|
||||
"electron-localshortcut": "2.0.0",
|
||||
"osc": "2.2.0",
|
||||
"yargs": "8.0.1",
|
||||
"socket.io": "2.0.1",
|
||||
"yargs": "8.0.2",
|
||||
"socket.io": "2.0.3",
|
||||
"socket.io-msgpack-parser": "2.1.0",
|
||||
"express": "4.15.3",
|
||||
"jquery": "3.2.1",
|
||||
"chokidar": "1.7.0",
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -2,19 +2,19 @@
|
|||
"name": "open-stage-control-builder",
|
||||
"description": "A libre desktop OSC bi-directionnal control surface application - builder package",
|
||||
"dependencies": {
|
||||
"electron": "1.6.10",
|
||||
"electron": "1.6.11",
|
||||
"mathjs": "3.13.3",
|
||||
"autolayout": "0.7.0",
|
||||
"browserify": "14.4.0",
|
||||
"webworkify": "1.4.0",
|
||||
"exorcist": "0.4.0",
|
||||
"node-sass": "^4.1.1",
|
||||
"nodemon": "^1.9.2",
|
||||
"socket.io-client": "2.0.1",
|
||||
"socket.io-client": "2.0.3",
|
||||
"socket.io-msgpack-parser": "2.1.0",
|
||||
"jquery": "3.2.1",
|
||||
"shortid": "2.2.8",
|
||||
"electron-installer-debian": "0.5.1",
|
||||
"electron-packager": "8.7.0",
|
||||
"electron-installer-debian": "0.5.2",
|
||||
"electron-packager": "8.7.1",
|
||||
"babelify": "7.3.0",
|
||||
"babel-preset-es2015": "6.24.1",
|
||||
"babel-plugin-transform-object-rest-spread": "6.23.0",
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
var io = require('socket.io-client/dist/socket.io.slim.js')
|
||||
|
||||
var IpcWorker = class IpcWorker {
|
||||
|
||||
constructor(worker) {
|
||||
|
||||
this.worker = worker
|
||||
this.queue = []
|
||||
this.socket = null
|
||||
|
||||
this.worker.addEventListener('message', (e)=>{
|
||||
|
||||
var [name, data] = e.data
|
||||
|
||||
if (name == 'on') {
|
||||
|
||||
this.socket.on(data, (message)=>{
|
||||
this.worker.postMessage([data, message])
|
||||
})
|
||||
|
||||
} else if (name == 'send'){
|
||||
|
||||
this.queue.push(data)
|
||||
|
||||
} else if (name == 'connect') {
|
||||
|
||||
this.socket = io.connect(data)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
setInterval(this.flush.bind(this), 20)
|
||||
|
||||
}
|
||||
|
||||
flush() {
|
||||
|
||||
if (this.queue.length && this.socket !== null) {
|
||||
|
||||
for (let msg of this.queue) {
|
||||
|
||||
this.socket.emit(...msg)
|
||||
}
|
||||
this.queue = []
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = (worker)=>{
|
||||
|
||||
return new IpcWorker(worker)
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +1,44 @@
|
|||
var worker = require('webworkify')
|
||||
var io = require('socket.io-client/dist/socket.io.slim.js'),
|
||||
customParser = require('socket.io-msgpack-parser')
|
||||
|
||||
|
||||
var Ipc = class Ipc {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.callbacks = {}
|
||||
this.queue = []
|
||||
this.socket = io.connect('/', {parser:customParser})
|
||||
|
||||
this.worker = worker(require('./ipc-worker'))
|
||||
this.worker.addEventListener('message', (ev)=>{
|
||||
setInterval(this.flush.bind(this), 5)
|
||||
|
||||
var [name, data] = ev.data
|
||||
|
||||
if (this.callbacks[name]) this.callbacks[name](data)
|
||||
|
||||
})
|
||||
|
||||
this.worker.postMessage(['connect', window.location.href])
|
||||
|
||||
}
|
||||
|
||||
send(name, data) {
|
||||
|
||||
this.worker.postMessage(['send', [name, data]])
|
||||
flush() {
|
||||
|
||||
if (this.queue.length) {
|
||||
|
||||
for (let msg of this.queue) {
|
||||
|
||||
this.socket.emit(...msg)
|
||||
}
|
||||
this.queue = []
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
send() {
|
||||
|
||||
this.queue.push(arguments)
|
||||
|
||||
}
|
||||
|
||||
on(name, fn) {
|
||||
|
||||
this.callbacks[name] = fn
|
||||
this.worker.postMessage(['on', name])
|
||||
|
||||
this.socket.on(name, fn)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue