headless mode : clients are now all synchronized AND independant
This commit is contained in:
parent
651c0499dc
commit
f308f50165
5 changed files with 54 additions and 29 deletions
|
|
@ -17,8 +17,9 @@ ipc.on('load',function(preset){
|
|||
setState(preset)
|
||||
})
|
||||
|
||||
|
||||
var listSessions = false
|
||||
ipc.on('listSessions',function(data){
|
||||
if (listSessions) return false
|
||||
$('#lobby').append('\
|
||||
<div class="main">\
|
||||
<div class="header">\
|
||||
|
|
@ -44,22 +45,24 @@ ipc.on('listSessions',function(data){
|
|||
e.stopPropagation()
|
||||
ipc.send('browseSessions')
|
||||
})
|
||||
ipc.off('listSession')
|
||||
listSessions = true
|
||||
})
|
||||
|
||||
var openSession = false
|
||||
ipc.on('openSession',function(data){
|
||||
if (openSession) return false
|
||||
var error = data.error,
|
||||
path = data.path,
|
||||
session = JSON.parse(data.session)
|
||||
|
||||
if (!error) {
|
||||
openSession = true
|
||||
ipc.send('addSessionToHistory',path)
|
||||
$('#lobby').hide()
|
||||
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
|
||||
setTimeout(function(){
|
||||
init(session,function(){$('#loading').hide()})
|
||||
},1)
|
||||
ipc.off('openSession')
|
||||
} else {
|
||||
createPopup(icon('warning')+' Error: invalid session file',error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,15 +58,29 @@ init = function(session,callback) {
|
|||
// or if mouse is on h-scrollbar
|
||||
var scrollbarHeight = 20
|
||||
var contentPanels = $('.content')
|
||||
$('.tab').on('mousewheel',function(e) {
|
||||
// console.log(e)
|
||||
if (e.ctrlKey) {
|
||||
e.preventDefault()
|
||||
var d = -e.originalEvent.deltaY/Math.abs(e.originalEvent.deltaY)/10,
|
||||
s = d+webFrame.getZoomFactor()
|
||||
ipc.send('setZoomFactor',s)
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if (webFrame) {
|
||||
$('.tab').on('mousewheel.zoom',function(e) {
|
||||
// console.log(e)
|
||||
if (e.ctrlKey) {
|
||||
e.preventDefault()
|
||||
var d = -e.originalEvent.deltaY/Math.abs(e.originalEvent.deltaY)/10,
|
||||
s = d+webFrame.getZoomFactor()
|
||||
webFrame.setZoomFactor(s)
|
||||
|
||||
}
|
||||
})
|
||||
$(document).on('keydown.resetzoom', function(e){
|
||||
if (e.keyCode==96||e.keyCode==48) webFrame.setZoomFactor(1)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
$('.tab').on('mousewheel.scroll',function(e) {
|
||||
if (!e.ctrlKey) {
|
||||
if ($(this).height()>$(this).get(0).scrollHeight) {
|
||||
var scroll = e.originalEvent.deltaY || e.originalEvent.deltaX
|
||||
$(this).scrollLeft($(this).scrollLeft()+scroll)
|
||||
|
|
@ -77,7 +91,8 @@ init = function(session,callback) {
|
|||
}
|
||||
}
|
||||
})
|
||||
$('.panel').on('mousewheel',function(e) {
|
||||
|
||||
$('.panel').on('mousewheel.scroll',function(e) {
|
||||
if (!e.ctrlKey) {
|
||||
|
||||
var h = $(this).parent().innerHeight()-scrollbarHeight-$(this).parents('.tab').length*5
|
||||
|
|
@ -90,10 +105,7 @@ init = function(session,callback) {
|
|||
}
|
||||
})
|
||||
|
||||
// reset zoom
|
||||
$(document).on('keydown.resetzoom', function(e){
|
||||
if (e.keyCode==96||e.keyCode==48) ipc.send('setZoomFactor',1)
|
||||
})
|
||||
|
||||
|
||||
|
||||
// sidepanel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
webFrame = false
|
||||
|
||||
// mainProcess & renderProcess communication engine
|
||||
// electron's ipc module is not available here, we use socket.io as a replacement
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
webFrame = require('web-frame')
|
||||
|
||||
// mainProcess & renderProcess communication engine
|
||||
ipc = require('ipc')
|
||||
|
|
|
|||
|
|
@ -241,10 +241,10 @@ ipc.on('fullscreen', function(event){
|
|||
// callbacks !
|
||||
|
||||
var callbacks = {}
|
||||
callbacks.ready = function() {
|
||||
callbacks.ready = function(data,clientId) {
|
||||
if (settings.read('sessionFile')) callbacks.openSession(settings.read('sessionFile'))
|
||||
var recentSessions = settings.read('recentSessions')
|
||||
ipc.send('listSessions',recentSessions)
|
||||
ipc.send('listSessions',recentSessions,clientId)
|
||||
}
|
||||
|
||||
callbacks.browseSessions = function(data) {
|
||||
|
|
@ -274,18 +274,18 @@ callbacks.removeSessionFromHistory = function(data) {
|
|||
settings.write('recentSessions',sessionlist)
|
||||
}
|
||||
|
||||
callbacks.openSession = function(path) {
|
||||
var data = fs.readFileSync(path,'utf8'),
|
||||
callbacks.openSession = function(data,clientId) {
|
||||
var file = fs.readFileSync(data,'utf8'),
|
||||
session,
|
||||
error
|
||||
|
||||
try {
|
||||
session = vm.runInNewContext(data)
|
||||
session = vm.runInNewContext(file)
|
||||
} catch(err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
ipc.send('openSession',{error:error,path:path,session:JSON.stringify(session)})
|
||||
ipc.send('openSession',{error:error,path:data,session:JSON.stringify(session)},clientId)
|
||||
}
|
||||
|
||||
callbacks.sendOsc = function(data) {
|
||||
|
|
@ -320,7 +320,7 @@ callbacks.save = function(data) {
|
|||
})
|
||||
}
|
||||
|
||||
callbacks.load = function(data) {
|
||||
callbacks.load = 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}
|
||||
|
|
@ -328,16 +328,16 @@ callbacks.load = function(data) {
|
|||
|
||||
fs.readFile(file[0],'utf-8', function read(err, data) {
|
||||
if (err) throw err
|
||||
ipc.send('load',data)
|
||||
ipc.send('load',data,clientId)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
callbacks.loadlast = function(data) {
|
||||
callbacks.loadlast = function(data,clientId) {
|
||||
if (!settings.read('presetPath')) {return}
|
||||
fs.readFile(settings.read('presetPath'),'utf-8', function read(err, data) {
|
||||
if (err) throw err
|
||||
ipc.send('load',data)
|
||||
ipc.send('load',data,clientId)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -377,7 +377,11 @@ if (settings.noGui) {
|
|||
socket.on('*', function(e){
|
||||
var name = e.data[0],
|
||||
data = e.data[1]
|
||||
if (callbacks[name]) callbacks[name](data)
|
||||
if (callbacks[name]) callbacks[name](data,socket.id)
|
||||
if (name=='sendOsc' && data.sync!==false) {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('receiveOsc',data)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -385,7 +389,11 @@ if (settings.noGui) {
|
|||
|
||||
server.listen(settings.noGui)
|
||||
|
||||
ipc.send = function(name,data) {
|
||||
io.emit(name,data)
|
||||
ipc.send = function(name,data,clientId) {
|
||||
if (clientId) {
|
||||
io.to(clientId).emit(name,data)
|
||||
} else {
|
||||
io.emit(name,data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue