ipc: modularize ipc manager
This commit is contained in:
parent
8bf834750f
commit
87d5aac477
5 changed files with 40 additions and 20 deletions
|
|
@ -35,20 +35,13 @@ require('./jquery/jquery.fake-input')
|
|||
|
||||
///////////////////////
|
||||
|
||||
var callbacks = require('./app/callbacks')
|
||||
var callbacks = require('./app/callbacks'),
|
||||
ipc = require('./app/ipc')
|
||||
|
||||
var bindCallback = function(i) {
|
||||
IPC.on(i,function(event,data){
|
||||
callbacks[i](event,data)
|
||||
})
|
||||
}
|
||||
|
||||
for (i in callbacks) {
|
||||
bindCallback(i)
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
$(document).ready(function(){
|
||||
LOADING = require('./app/utils').loading('Connecting server...')
|
||||
IPC.send('ready')
|
||||
ipc.send('ready')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var {WidgetManager} = require('./managers')
|
||||
var {WidgetManager} = require('./managers'),
|
||||
ipc = require('./ipc')
|
||||
|
||||
module.exports = {
|
||||
|
||||
|
|
@ -98,7 +99,7 @@ module.exports = {
|
|||
|
||||
reader.onloadend = function(e) {
|
||||
var session = e.target.result
|
||||
IPC.send('sessionOpen',{file:session,path:file.path})
|
||||
ipc.send('sessionOpen',{file:session,path:file.path})
|
||||
}
|
||||
reader.readAsText(file, 'utf-8');
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ var init = require('./init'),
|
|||
icon = utils.icon,
|
||||
remoteExec = require('./remote-exec'),
|
||||
{WidgetManager} = require('./managers'),
|
||||
ipc = require('./ipc'),
|
||||
osc = require('./osc')
|
||||
|
||||
module.exports = {
|
||||
var callbacks = module.exports = {
|
||||
|
||||
receiveOsc: function(event,data){
|
||||
var data = data || event
|
||||
|
|
@ -92,11 +93,11 @@ module.exports = {
|
|||
footer.append('<a class="btn new">'+icon('file-o')+' New</a>')
|
||||
lobby.find('.load').click(function(e){
|
||||
e.stopPropagation()
|
||||
IPC.send('sessionOpen',{path:$(this).data('session')})
|
||||
ipc.send('sessionOpen',{path:$(this).data('session')})
|
||||
})
|
||||
lobby.find('a span').click(function(e){
|
||||
e.stopPropagation()
|
||||
IPC.send('sessionRemoveFromHistory',$(this).parent().data('session'))
|
||||
ipc.send('sessionRemoveFromHistory',$(this).parent().data('session'))
|
||||
$(this).parents('a').remove()
|
||||
})
|
||||
lobby.find('.browse').click(function(e){
|
||||
|
|
@ -117,7 +118,7 @@ module.exports = {
|
|||
var data = data || event
|
||||
var session = JSON.parse(data)
|
||||
init(session,function(){
|
||||
IPC.send('sessionOpened')
|
||||
ipc.send('sessionOpened')
|
||||
})
|
||||
|
||||
},
|
||||
|
|
@ -170,3 +171,13 @@ module.exports = {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
var bindCallback = function(i) {
|
||||
ipc.on(i,function(event,data){
|
||||
callbacks[i](event,data)
|
||||
})
|
||||
}
|
||||
|
||||
for (i in callbacks) {
|
||||
bindCallback(i)
|
||||
}
|
||||
|
|
|
|||
19
src/browser/js/app/ipc.js
Normal file
19
src/browser/js/app/ipc.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
var socket = require('socket.io-client')
|
||||
|
||||
var Ipc = function(){
|
||||
|
||||
this.socket = socket.connect()
|
||||
|
||||
}
|
||||
|
||||
Ipc.prototype.send = function(){
|
||||
return this.socket.emit(...arguments)
|
||||
}
|
||||
|
||||
Ipc.prototype.on = function(){
|
||||
return this.socket.on(...arguments)
|
||||
}
|
||||
|
||||
var ipc = new Ipc()
|
||||
|
||||
module.exports = ipc
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
// mainProcess & renderProcess communication engine
|
||||
// electron's ipc module is not available here, we use socket.io as a replacement
|
||||
var socket = require('socket.io-client')
|
||||
|
||||
IPC = socket.connect()
|
||||
IPC.send = IPC.emit
|
||||
|
||||
require('./app')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue