main: stop using electron-specific api : always use express server and use electron as a normal browser/client
This commit is contained in:
parent
d2791758f7
commit
bde96d5d3b
7 changed files with 359 additions and 400 deletions
|
|
@ -1,142 +1,142 @@
|
|||
var vm = require('vm'),
|
||||
path = require('path')
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
settings = require('./settings'),
|
||||
osc = require('./osc'),
|
||||
ipc = require('./server-express').ipc
|
||||
|
||||
module.exports = function(settings,fs,ipc,osc,dialog) {
|
||||
module.exports = {
|
||||
|
||||
return {
|
||||
ready: function(data,clientId) {
|
||||
if (settings.read('theme')) ipc.send('applyStyle',settings.read('theme'),clientId)
|
||||
if (settings.read('sessionFile')) this.sessionOpen({path:settings.read('sessionFile')},clientId)
|
||||
var recentSessions = settings.read('recentSessions')
|
||||
|
||||
ready: function(data,clientId) {
|
||||
if (settings.read('theme')) ipc.send('applyStyle',settings.read('theme'),clientId)
|
||||
if (settings.read('sessionFile')) this.sessionOpen({path:settings.read('sessionFile')},clientId)
|
||||
var recentSessions = settings.read('recentSessions')
|
||||
|
||||
if (settings.read('examples')) {
|
||||
var dir = path.resolve(__dirname + '/../examples')
|
||||
recentSessions = fs.readdirSync(dir)
|
||||
recentSessions = recentSessions.map(function(file){return 'examples/' + file})
|
||||
}
|
||||
|
||||
ipc.send('sessionList',recentSessions,clientId)
|
||||
},
|
||||
|
||||
sessionBrowse: function(data) {
|
||||
var sessionlist = settings.read('recentSessions'),
|
||||
self = this
|
||||
dialog.showOpenDialog(window,{title:'Load session file',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
|
||||
if (file==undefined) {return}
|
||||
settings.write('sessionPath',file[0].replace(file[0].split('/').pop(),''))
|
||||
self.sessionOpen({path:file[0]})
|
||||
})
|
||||
},
|
||||
|
||||
sessionSave: function(data) {
|
||||
var self = this
|
||||
dialog.showSaveDialog(window,{title:'Save current session',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('sessionPath',file.replace(file.split('/').pop(),''))
|
||||
|
||||
if (file.indexOf('.js')==-1){file+='.js'}
|
||||
fs.writeFile(file,data, function (err, data) {
|
||||
if (err) throw err
|
||||
self.sessionAddToHistory(file)
|
||||
console.log('The session was saved in '+file)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
sessionAddToHistory: function(data) {
|
||||
var sessionlist = settings.read('recentSessions')
|
||||
// add session to history
|
||||
sessionlist.unshift(data)
|
||||
// remove doubles from history
|
||||
sessionlist = sessionlist.filter(function(elem, index, self) {
|
||||
return index == self.indexOf(elem)
|
||||
})
|
||||
// save history
|
||||
settings.write('recentSessions',sessionlist)
|
||||
},
|
||||
|
||||
sessionRemoveFromHistory: function(data) {
|
||||
var sessionlist = settings.read('recentSessions')
|
||||
sessionlist.splice(data,1)
|
||||
settings.write('recentSessions',sessionlist)
|
||||
},
|
||||
|
||||
sessionOpen: function(data,clientId) {
|
||||
var file = data.file || (function(){try {return fs.readFileSync(data.path,'utf8')} catch(err) {return false}})(),
|
||||
error = file===false&&data.path?'Session file "' + data.path + '" not found.':false,
|
||||
session
|
||||
|
||||
try {
|
||||
session = vm.runInNewContext(file)
|
||||
} catch(err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
if (!session) error= 'No session object returned'
|
||||
|
||||
if (!error) {
|
||||
if (data.path) this.sessionAddToHistory(data.path)
|
||||
ipc.send('sessionOpen',JSON.stringify(session),clientId)
|
||||
} else {
|
||||
ipc.send('error',{title:'Error: invalid session file',text:'<p>'+error+'</p>'})
|
||||
}
|
||||
},
|
||||
|
||||
sendOsc: function(data) {
|
||||
|
||||
var targets = []
|
||||
|
||||
if (settings.read('syncTargets') && data.sync!==false) Array.prototype.push.apply(targets, settings.read('syncTargets'))
|
||||
if (data.target) Array.prototype.push.apply(targets, data.target)
|
||||
|
||||
|
||||
for (i in targets) {
|
||||
|
||||
var host = targets[i].split(':')[0],
|
||||
port = targets[i].split(':')[1]
|
||||
|
||||
if (port) osc.send(host,port,data.path,data.args,data.precision)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
stateSave: function(data) {
|
||||
dialog.showSaveDialog(window,{title:'Save current state to preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('presetPath',file)
|
||||
|
||||
if (file.indexOf('.preset')==-1){file+='.preset'}
|
||||
fs.writeFile(file,data, function (err, data) {
|
||||
if (err) throw err
|
||||
console.log('The current state was saved in '+file)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
stateLoad: function(data,clientId) {
|
||||
dialog.showOpenDialog(window,{title:'Load preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('presetPath',file[0])
|
||||
|
||||
fs.readFile(file[0],'utf-8', function read(err, data) {
|
||||
if (err) throw err
|
||||
ipc.send('stateLoad',data,clientId)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fullscreen: function(data) {
|
||||
window.setFullScreen(!window.isFullScreen())
|
||||
},
|
||||
|
||||
log: function(data) {
|
||||
console.log(data)
|
||||
if (settings.read('examples')) {
|
||||
var dir = path.resolve(__dirname + '/../examples')
|
||||
recentSessions = fs.readdirSync(dir)
|
||||
recentSessions = recentSessions.map(function(file){return 'examples/' + file})
|
||||
}
|
||||
}
|
||||
|
||||
ipc.send('sessionList',recentSessions,clientId)
|
||||
},
|
||||
|
||||
sessionBrowse: function(data) {
|
||||
var sessionlist = settings.read('recentSessions'),
|
||||
self = this
|
||||
dialog.showOpenDialog(window,{title:'Load session file',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
|
||||
if (file==undefined) {return}
|
||||
settings.write('sessionPath',file[0].replace(file[0].split('/').pop(),''))
|
||||
self.sessionOpen({path:file[0]})
|
||||
})
|
||||
},
|
||||
|
||||
sessionSave: function(data) {
|
||||
var self = this
|
||||
dialog.showSaveDialog(window,{title:'Save current session',defaultPath:settings.read('sessionPath'),filters: [ { name: 'OSC Session file', extensions: ['js'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('sessionPath',file.replace(file.split('/').pop(),''))
|
||||
|
||||
if (file.indexOf('.js')==-1){file+='.js'}
|
||||
fs.writeFile(file,data, function (err, data) {
|
||||
if (err) throw err
|
||||
self.sessionAddToHistory(file)
|
||||
console.log('The session was saved in '+file)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
sessionAddToHistory: function(data) {
|
||||
var sessionlist = settings.read('recentSessions')
|
||||
// add session to history
|
||||
sessionlist.unshift(data)
|
||||
// remove doubles from history
|
||||
sessionlist = sessionlist.filter(function(elem, index, self) {
|
||||
return index == self.indexOf(elem)
|
||||
})
|
||||
// save history
|
||||
settings.write('recentSessions',sessionlist)
|
||||
},
|
||||
|
||||
sessionRemoveFromHistory: function(data) {
|
||||
var sessionlist = settings.read('recentSessions')
|
||||
sessionlist.splice(data,1)
|
||||
settings.write('recentSessions',sessionlist)
|
||||
},
|
||||
|
||||
sessionOpen: function(data,clientId) {
|
||||
var file = data.file || (function(){try {return fs.readFileSync(data.path,'utf8')} catch(err) {return false}})(),
|
||||
error = file===false&&data.path?'Session file "' + data.path + '" not found.':false,
|
||||
session
|
||||
|
||||
try {
|
||||
session = vm.runInNewContext(file)
|
||||
} catch(err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
if (!session) error= 'No session object returned'
|
||||
|
||||
if (!error) {
|
||||
if (data.path) this.sessionAddToHistory(data.path)
|
||||
ipc.send('sessionOpen',JSON.stringify(session),clientId)
|
||||
} else {
|
||||
ipc.send('error',{title:'Error: invalid session file',text:'<p>'+error+'</p>'})
|
||||
}
|
||||
},
|
||||
|
||||
sendOsc: function(data) {
|
||||
|
||||
var targets = []
|
||||
|
||||
if (settings.read('syncTargets') && data.sync!==false) Array.prototype.push.apply(targets, settings.read('syncTargets'))
|
||||
if (data.target) Array.prototype.push.apply(targets, data.target)
|
||||
|
||||
|
||||
for (i in targets) {
|
||||
|
||||
var host = targets[i].split(':')[0],
|
||||
port = targets[i].split(':')[1]
|
||||
|
||||
if (port) osc.send(host,port,data.path,data.args,data.precision)
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
stateSave: function(data) {
|
||||
dialog.showSaveDialog(window,{title:'Save current state to preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('presetPath',file)
|
||||
|
||||
if (file.indexOf('.preset')==-1){file+='.preset'}
|
||||
fs.writeFile(file,data, function (err, data) {
|
||||
if (err) throw err
|
||||
console.log('The current state was saved in '+file)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
stateLoad: function(data,clientId) {
|
||||
dialog.showOpenDialog(window,{title:'Load preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
if (file==undefined) {return}
|
||||
settings.write('presetPath',file[0])
|
||||
|
||||
fs.readFile(file[0],'utf-8', function read(err, data) {
|
||||
if (err) throw err
|
||||
ipc.send('stateLoad',data,clientId)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fullscreen: function(data) {
|
||||
window.setFullScreen(!window.isFullScreen())
|
||||
},
|
||||
|
||||
log: function(data) {
|
||||
console.log(data)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
app/main/gui.js
Normal file
47
app/main/gui.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
var path = require('path'),
|
||||
shortcut = require('electron-localshortcut'),
|
||||
{app, BrowserWindow, dialog} = require('electron'),
|
||||
settings = require('./settings')
|
||||
|
||||
dialog.showErrorBox = function(title,err) {
|
||||
console.log(title + ': ' + err)
|
||||
}
|
||||
|
||||
app.commandLine.appendSwitch('--enable-touch-events')
|
||||
|
||||
app.on('window-all-closed', function() {
|
||||
if (process.platform != 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('ready',function(){
|
||||
window = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
icon: path.resolve(__dirname + '/../resources/images/logo.png'),
|
||||
title:settings.read('appName'),
|
||||
backgroundColor:'#1a1d22'
|
||||
})
|
||||
|
||||
window.loadURL('http://127.0.0.1:' + settings.read('httpPort'))
|
||||
|
||||
window.on('closed', function() {
|
||||
window = null
|
||||
})
|
||||
|
||||
window.setMenuBarVisibility(false)
|
||||
|
||||
shortcut.register(window,'CmdOrCtrl+R',function(){
|
||||
window.reload()
|
||||
})
|
||||
|
||||
shortcut.register(window,'F11',function(){
|
||||
window.setFullScreen(!window.isFullScreen())
|
||||
})
|
||||
|
||||
shortcut.register(window,'F12',function(){
|
||||
window.toggleDevTools();
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -1,41 +1,17 @@
|
|||
var fs = require('fs'),
|
||||
settings = require('./settings')(fs)
|
||||
|
||||
if (!settings.read('noGui')) {
|
||||
|
||||
var electron = require('electron'),
|
||||
app = electron.app,
|
||||
browserWindow = electron.BrowserWindow,
|
||||
dialog = electron.dialog,
|
||||
ipc = electron.ipcMain
|
||||
|
||||
dialog.showErrorBox = function(title,err) {
|
||||
console.log(title + ': ' + err)
|
||||
}
|
||||
|
||||
app.commandLine.appendSwitch('--enable-touch-events')
|
||||
app.on('window-all-closed', function() {
|
||||
if (process.platform != 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('ready',function(){
|
||||
var server = require('./server-electron')(settings,app,ipc,browserWindow),
|
||||
osc = require('./osc')(ipc,settings),
|
||||
callbacks = require('./callbacks')(settings,fs,ipc,osc,dialog)
|
||||
var settings = require('./settings')
|
||||
|
||||
|
||||
server.bindCallbacks(callbacks)
|
||||
})
|
||||
if (!settings.read('guiOnly')) {
|
||||
|
||||
} else {
|
||||
|
||||
var server = require('./server-express')(settings),
|
||||
ipc = server.ipc,
|
||||
osc = require('./osc')(ipc,settings),
|
||||
callbacks = require('./callbacks')(settings,fs,ipc,osc,dialog)
|
||||
var server = require('./server-express'),
|
||||
osc = require('./osc'),
|
||||
callbacks = require('./callbacks')
|
||||
|
||||
server.bindCallbacks(callbacks)
|
||||
|
||||
}
|
||||
|
||||
if (!settings.read('noGui')) {
|
||||
require('./gui')
|
||||
}
|
||||
|
|
|
|||
120
app/main/osc.js
120
app/main/osc.js
|
|
@ -1,64 +1,64 @@
|
|||
var osc = require('node-osc')
|
||||
var osc = require('node-osc'),
|
||||
ipc = require('./server-express').ipc,
|
||||
settings = require('./settings'),
|
||||
oscInPort = settings.read('oscInPort'),
|
||||
debug = settings.read('debug')
|
||||
|
||||
module.exports = function(ipc, settings) {
|
||||
if (oscInPort) {
|
||||
|
||||
var inPort = settings.read('oscInPort'),
|
||||
debug = settings.read('debug')
|
||||
|
||||
if (inPort) {
|
||||
var oscServer = new osc.Server(inPort, '127.0.0.1')
|
||||
|
||||
oscServer.on('message', function (msg, rinfo) {
|
||||
var data = {path:msg.shift(),args:msg}
|
||||
if (data.args.length==1) data.args = data.args[0]
|
||||
ipc.send('receiveOsc',data)
|
||||
if (debug) console.log('OSC received: ',data, 'From : ' + rinfo.address + ':' + rinfo.port)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
send: function(host,port,path,args,precision) {
|
||||
|
||||
var client = new osc.Client(host, port)
|
||||
|
||||
client._sock.bind({exclusive:false,reuseAddr:true,port:inPort},function(){
|
||||
|
||||
|
||||
var message = new osc.Message(path)
|
||||
|
||||
var numberType = precision==0?'integer':'float'
|
||||
|
||||
if (typeof args=='object' && args!==null) {
|
||||
for (i in args) {
|
||||
var arg = args[i]
|
||||
|
||||
if (typeof arg == 'number' && arg!==null && typeof arg != 'object') {
|
||||
message.append({type:numberType,value:arg})
|
||||
} else if (arg!==null && typeof arg != 'object'){
|
||||
message.append({type:'string',value:String(arg)})
|
||||
} else if (arg!==null && typeof arg == 'object' && arg.type && arg.value!=undefined) {
|
||||
message.append({type:arg.type,value:arg.value})
|
||||
}
|
||||
}
|
||||
} else if (args!==null){
|
||||
if (typeof args == 'number') {
|
||||
message.append({type:numberType,value:args})
|
||||
} else if (typeof args == 'object' && arg.type && arg.value!=undefined) {
|
||||
message.append({type:args.type,value:args.value})
|
||||
} else {
|
||||
message.append({type:'string',value:String(args)})
|
||||
}
|
||||
}
|
||||
|
||||
client.send(message, function () {
|
||||
client.kill()
|
||||
})
|
||||
|
||||
if (debug) console.log('OSC sent: ',{path:path,args:message.args}, 'To : ' + host + ':' + port)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
var oscServer = new osc.Server(oscInPort, '127.0.0.1')
|
||||
|
||||
oscServer.on('message', function (msg, rinfo) {
|
||||
var data = {path:msg.shift(),args:msg}
|
||||
if (data.args.length==1) data.args = data.args[0]
|
||||
ipc.send('receiveOsc',data)
|
||||
if (debug) console.log('OSC received: ',data, 'From : ' + rinfo.address + ':' + rinfo.port)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
send: function(host,port,path,args,precision) {
|
||||
|
||||
var client = new osc.Client(host, port)
|
||||
|
||||
client._sock.bind({exclusive:false,reuseAddr:true,port:oscInPort},function(){
|
||||
|
||||
|
||||
var message = new osc.Message(path)
|
||||
|
||||
var numberType = precision==0?'integer':'float'
|
||||
|
||||
if (typeof args=='object' && args!==null) {
|
||||
for (i in args) {
|
||||
var arg = args[i]
|
||||
|
||||
if (typeof arg == 'number' && arg!==null && typeof arg != 'object') {
|
||||
message.append({type:numberType,value:arg})
|
||||
} else if (arg!==null && typeof arg != 'object'){
|
||||
message.append({type:'string',value:String(arg)})
|
||||
} else if (arg!==null && typeof arg == 'object' && arg.type && arg.value!=undefined) {
|
||||
message.append({type:arg.type,value:arg.value})
|
||||
}
|
||||
}
|
||||
} else if (args!==null){
|
||||
if (typeof args == 'number') {
|
||||
message.append({type:numberType,value:args})
|
||||
} else if (typeof args == 'object' && arg.type && arg.value!=undefined) {
|
||||
message.append({type:args.type,value:args.value})
|
||||
} else {
|
||||
message.append({type:'string',value:String(args)})
|
||||
}
|
||||
}
|
||||
|
||||
client.send(message, function () {
|
||||
client.kill()
|
||||
})
|
||||
|
||||
if (debug) console.log('OSC sent: ',{path:path,args:message.args}, 'To : ' + host + ':' + port)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
var path = require('path'),
|
||||
shortcut = require('electron-localshortcut')
|
||||
|
||||
module.exports = function(settings,app,ipc,browserWindow) {
|
||||
|
||||
window = new browserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
icon: path.resolve(__dirname + '/../resources/images/logo.png'),
|
||||
title:settings.read('appName'),
|
||||
backgroundColor:'#1a1d22'
|
||||
})
|
||||
|
||||
window.loadURL('file://' + __dirname + '/../browser/index.html')
|
||||
|
||||
window.on('closed', function() {
|
||||
window = null
|
||||
})
|
||||
|
||||
window.setMenuBarVisibility(false)
|
||||
|
||||
shortcut.register(window,'CmdOrCtrl+R',function(){
|
||||
window.reload()
|
||||
})
|
||||
|
||||
shortcut.register(window,'F11',function(){
|
||||
window.setFullScreen(!window.isFullScreen())
|
||||
})
|
||||
|
||||
shortcut.register(window,'F12',function(){
|
||||
window.toggleDevTools();
|
||||
})
|
||||
|
||||
|
||||
// mainProcess > renderProcess ipc shorthand
|
||||
ipc.send = function(name,data) {
|
||||
window.webContents.send(name,data)
|
||||
}
|
||||
|
||||
|
||||
// ipc bindings
|
||||
|
||||
var bindCallbacks = function(callbacks) {
|
||||
|
||||
var bindCallback = function(i) {
|
||||
ipc.on(i,function(event,data){
|
||||
callbacks[i](data)
|
||||
})
|
||||
}
|
||||
|
||||
for (i in callbacks) {
|
||||
bindCallback(i)
|
||||
}
|
||||
|
||||
ipc.on('ready',function(){
|
||||
window.show()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
ipc:ipc,
|
||||
bindCallbacks:bindCallbacks
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,74 +1,71 @@
|
|||
module.exports = function(settings) {
|
||||
|
||||
// Headless (noGui) mode
|
||||
var express = require('express')(),
|
||||
path = require('path'),
|
||||
http = require('http'),
|
||||
server = http.createServer(express),
|
||||
io = require('socket.io')(),
|
||||
ioWildcard = require('socketio-wildcard')(),
|
||||
ifaces = require('os').networkInterfaces(),
|
||||
ipc = {},
|
||||
settings = require('./settings')
|
||||
|
||||
var express = require('express')(),
|
||||
path = require('path'),
|
||||
http = require('http'),
|
||||
server = http.createServer(express),
|
||||
io = require('socket.io')(),
|
||||
ioWildcard = require('socketio-wildcard')(),
|
||||
ifaces = require('os').networkInterfaces(),
|
||||
ipc = {}
|
||||
|
||||
express.get('/', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser/index-headless.html'))
|
||||
})
|
||||
express.get('*', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser' + req.path))
|
||||
})
|
||||
express.get('/', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser/index-headless.html'))
|
||||
})
|
||||
express.get('*', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser' + req.path))
|
||||
})
|
||||
|
||||
|
||||
io.use(ioWildcard)
|
||||
io.use(ioWildcard)
|
||||
|
||||
|
||||
io.listen(server);
|
||||
io.listen(server);
|
||||
|
||||
server.listen(settings.read('noGui'))
|
||||
|
||||
ipc.send = function(name,data,clientId) {
|
||||
if (clientId) {
|
||||
io.to(clientId).emit(name,data)
|
||||
} else {
|
||||
io.emit(name,data)
|
||||
}
|
||||
}
|
||||
|
||||
var bindCallbacks = function(callbacks) {
|
||||
io.on('connection', function(socket) {
|
||||
socket.on('*', function(e){
|
||||
var name = e.data[0],
|
||||
data = e.data[1]
|
||||
|
||||
if ((name=='sendOsc' && data.sync!==false) || name=='syncOsc') {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('receiveOsc',data)
|
||||
}
|
||||
if (name=='sessionOpened') {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('stateSend',data)
|
||||
}
|
||||
|
||||
if (callbacks[name]) callbacks[name](data,socket.id)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var appAddresses = []
|
||||
Object.keys(ifaces).forEach(function (ifname) {
|
||||
for (i=0;i<ifaces[ifname].length;i++) {
|
||||
if (ifaces[ifname][i].family == 'IPv4') {
|
||||
appAddresses.push('http://' + ifaces[ifname][i].address + ':' + settings.read('noGui'))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
console.log('Headless mode: app available at ' + appAddresses.join(' & '))
|
||||
|
||||
return {
|
||||
ipc:ipc,
|
||||
bindCallbacks:bindCallbacks
|
||||
}
|
||||
server.listen(settings.read('httpPort'))
|
||||
|
||||
ipc.send = function(name,data,clientId) {
|
||||
if (clientId) {
|
||||
io.to(clientId).emit(name,data)
|
||||
} else {
|
||||
io.emit(name,data)
|
||||
}
|
||||
}
|
||||
|
||||
var bindCallbacks = function(callbacks) {
|
||||
io.on('connection', function(socket) {
|
||||
socket.on('*', function(e){
|
||||
var name = e.data[0],
|
||||
data = e.data[1]
|
||||
|
||||
if ((name=='sendOsc' && data.sync!==false) || name=='syncOsc') {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('receiveOsc',data)
|
||||
}
|
||||
if (name=='sessionOpened') {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('stateSend',data)
|
||||
}
|
||||
|
||||
if (callbacks[name]) callbacks[name](data,socket.id)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var appAddresses = []
|
||||
|
||||
Object.keys(ifaces).forEach(function (ifname) {
|
||||
for (i=0;i<ifaces[ifname].length;i++) {
|
||||
if (ifaces[ifname][i].family == 'IPv4') {
|
||||
appAddresses.push('http://' + ifaces[ifname][i].address + ':' + settings.read('httpPort'))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
console.log('App available at ' + appAddresses.join(' & '))
|
||||
|
||||
module.exports = {
|
||||
ipc:ipc,
|
||||
bindCallbacks:bindCallbacks
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,65 +2,70 @@
|
|||
if (process.argv[1]&&process.argv[1].indexOf('-')==0) process.argv.unshift('')
|
||||
|
||||
var baseDir = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'],
|
||||
configFile = require('path').join(baseDir, '.open-stage-control')
|
||||
configFile = require('path').join(baseDir, '.open-stage-control'),
|
||||
fs = require('fs')
|
||||
|
||||
var argv = require('yargs')
|
||||
.help('help').usage(`\nUsage:\n $0 [options]`).alias('h', 'help')
|
||||
.options({
|
||||
's':{alias:'sync',type:'array',describe:'synchronized hosts (ip:port pairs)'},
|
||||
'l':{alias:'load',type:'string',describe:'session file to load'},
|
||||
'p':{alias:'port',describe:'osc input port (for synchronization)'},
|
||||
'p':{alias:'port',describe:'http port of the app\'s server'},
|
||||
'i':{alias:'input-port',describe:'osc input port (for synchronization)'},
|
||||
'd':{alias:'debug',describe:'log received osc messages in the console'},
|
||||
'n':{alias:'nogui',describe:'disable default gui and makes the app availabe through http on specified port'},
|
||||
'n':{alias:'no-gui',describe:'disable default gui and makes the app availabe through http on specified port'},
|
||||
'g':{alias:'gui-only',describe:'only launch the gui (a server instance must be running) '},
|
||||
't':{alias:'theme',type:'array',describe:'theme name or path (mutliple values allowed)'},
|
||||
'examples':{describe:'list examples instead of recent sessions'}
|
||||
})
|
||||
.check(function(a,x){if(a.i==undefined || !isNaN(a.i)&&a.i>1023&&parseInt(a.i)===a.i){return true}else{throw 'Error: Port must be an integer >= 1024'}})
|
||||
.check(function(a,x){if(a.p==undefined || !isNaN(a.p)&&a.p>1023&&parseInt(a.p)===a.p){return true}else{throw 'Error: Port must be an integer >= 1024'}})
|
||||
.check(function(a,x){if(a.n==undefined || !isNaN(a.n)&&a.n>1023&&parseInt(a.n)===a.n){return true}else{throw 'Error: Port must be an integer >= 1024'}})
|
||||
.check(function(a,x){if(a.s==undefined || a.s.join(' ').match('^([^:\s]*:[0-9]{4,5}[\s]*)*$')!=null){return true}else{throw 'Error: Sync hosts must be ip:port pairs & port must be >= 1024'}})
|
||||
.strict()
|
||||
.argv
|
||||
|
||||
module.exports = function(fs) {
|
||||
var config = function(){try {return JSON.parse(fs.readFileSync(configFile,'utf-8'))} catch(err) {return {}}}(),
|
||||
defaultConfig = {
|
||||
presetPath : process.cwd(),
|
||||
sessionPath: process.cwd(),
|
||||
recentSessions: [],
|
||||
var config = function(){try {return JSON.parse(fs.readFileSync(configFile,'utf-8'))} catch(err) {return {}}}(),
|
||||
defaultConfig = {
|
||||
presetPath : process.cwd(),
|
||||
sessionPath: process.cwd(),
|
||||
recentSessions: [],
|
||||
|
||||
appName: 'Open Stage Control',
|
||||
syncTargets: argv.s || false,
|
||||
oscInPort: argv.p || 0,
|
||||
debug: argv.d || false,
|
||||
sessionFile: argv.l || false,
|
||||
noGui: argv.n || false,
|
||||
examples: argv.examples,
|
||||
theme: function(){
|
||||
if (!argv.t) return
|
||||
var style = []
|
||||
for (i in argv.t) {
|
||||
try {style.push(fs.readFileSync(__dirname + '/themes/' + argv.t[i] + '.css','utf-8'))}
|
||||
appName: 'Open Stage Control',
|
||||
syncTargets: argv.s || false,
|
||||
oscInPort: argv.i || 0,
|
||||
httpPort: argv.p || 8080,
|
||||
debug: argv.d || false,
|
||||
sessionFile: argv.l || false,
|
||||
noGui: argv.n || false,
|
||||
guiOnly: argv.g || false,
|
||||
examples: argv.examples,
|
||||
theme: function(){
|
||||
if (!argv.t) return
|
||||
var style = []
|
||||
for (i in argv.t) {
|
||||
try {style.push(fs.readFileSync(__dirname + '/themes/' + argv.t[i] + '.css','utf-8'))}
|
||||
catch(err) {
|
||||
try {style.push(fs.readFileSync(argv.t[i],'utf-8'))}
|
||||
catch(err) {
|
||||
try {style.push(fs.readFileSync(argv.t[i],'utf-8'))}
|
||||
catch(err) {
|
||||
console.log('Theme "' + argv.t[i] + '" not found.')
|
||||
}
|
||||
console.log('Theme "' + argv.t[i] + '" not found.')
|
||||
}
|
||||
}
|
||||
return style
|
||||
}()
|
||||
}
|
||||
return {
|
||||
}
|
||||
return style
|
||||
}()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
read:function(key){
|
||||
var x = config[key] || defaultConfig[key]
|
||||
return x
|
||||
},
|
||||
write:function(key,value) {
|
||||
config[key] = value
|
||||
fs.writeFile(configFile,JSON.stringify(config,null,4), function (err, data) {
|
||||
if (err) throw err
|
||||
})
|
||||
}
|
||||
|
||||
read:function(key){
|
||||
var x = config[key] || defaultConfig[key]
|
||||
return x
|
||||
},
|
||||
write:function(key,value) {
|
||||
config[key] = value
|
||||
fs.writeFile(configFile,JSON.stringify(config,null,4), function (err, data) {
|
||||
if (err) throw err
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue