experimenting with peer protocol/api...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-24 19:47:04 +03:00
parent f1a23fda6d
commit 5f610ca091

View File

@ -16,6 +16,18 @@ var core = require('features/core')
/*********************************************************************/
// helpers...
// XXX should this parse out the protocol???
// ...technically we no longer need it....
var makeProtocolHandiler = function(protocol, func){
return function(id){
return id.startsWith(protocol + ':')
&& func.apply(this, arguments) } }
/*********************************************************************/ /*********************************************************************/
// XXX this is a generic API, add ability to define protocols... // XXX this is a generic API, add ability to define protocols...
@ -154,25 +166,54 @@ module.Peer = core.ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX all the return values here will be ignored -- need a way to figure
// out a cooperative mechanic to return promises...
var ChildProcessPeerActions = actions.Actions({ var ChildProcessPeerActions = actions.Actions({
peerConnect: ['- Peer/', peerConnect: ['- Peer/',
function(id, options){ makeProtocolHandiler('child', function(id, options){
// XXX // XXX need a cooperative way to pass this to the root method return...
}], return new Promise((function(resolve, reject){
// already connected...
if(id in this.__peers){
return resolve(id)
}
// XXX run ig.js in child_process + add peer feature to setup...
// XXX
}).bind(this))
})],
peerDisconnect: ['- Peer/', peerDisconnect: ['- Peer/',
function(id){ makeProtocolHandiler('child', function(id){
// XXX // XXX need a cooperative way to pass this to the root method return...
}], return new Promise((function(resolve, reject){
// already disconnected...
if(this.__peers[id] == null){
return resolve(id)
}
// trigger stop...
this.peerCall(id, 'stop')
.then(function(){
// XXX terminate child...
// XXX
})
}).bind(this))
})],
peerCall: ['- Peer/', peerCall: ['- Peer/',
function(id, action){ makeProtocolHandiler('child', function(id, action){
// XXX // XXX need a cooperative way to pass this to the root method return...
}], return new Promise((function(resolve, reject){
// XXX
}).bind(this))
})],
peerApply: ['- Peer/', peerApply: ['- Peer/',
function(id, action, args){ makeProtocolHandiler('child', function(id, action, args){
// XXX // XXX need a cooperative way to pass this to the root method return...
}], return new Promise((function(resolve, reject){
// XXX
}).bind(this))
})],
}) })
@ -186,6 +227,9 @@ module.ChildProcessPeer = core.ImageGridFeatures.Feature({
'peer', 'peer',
], ],
isApplicable: function(){
return this.runtime == 'nw' || this.runtime == 'node' },
actions: ChildProcessPeerActions, actions: ChildProcessPeerActions,
}) })