prepwork for handling off (issue #1)
This commit is contained in:
parent
9113b7d46e
commit
062fc23ebb
22
client.js
22
client.js
@ -112,11 +112,6 @@ function create(opts) {
|
|||||||
promise = getConnection(opts);
|
promise = getConnection(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (opts.connect) {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO maybe use HTTP POST instead?
|
// TODO maybe use HTTP POST instead?
|
||||||
return promise.then(function (ws) {
|
return promise.then(function (ws) {
|
||||||
if (ws.masterClient) {
|
if (ws.masterClient) {
|
||||||
@ -130,6 +125,7 @@ function create(opts) {
|
|||||||
var cb;
|
var cb;
|
||||||
|
|
||||||
if ('function' === typeof args[args.length - 1]) {
|
if ('function' === typeof args[args.length - 1]) {
|
||||||
|
// TODO if off, search for cb and derive id from previous onMessage
|
||||||
id = Math.random();
|
id = Math.random();
|
||||||
cb = args.pop();
|
cb = args.pop();
|
||||||
}
|
}
|
||||||
@ -138,6 +134,7 @@ function create(opts) {
|
|||||||
type: 'rpc'
|
type: 'rpc'
|
||||||
, func: fname
|
, func: fname
|
||||||
, args: args
|
, args: args
|
||||||
|
, hasCallback: !!cb
|
||||||
, filename: opts.filename
|
, filename: opts.filename
|
||||||
, id: id
|
, id: id
|
||||||
}));
|
}));
|
||||||
@ -165,7 +162,16 @@ function create(opts) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('on' !== fname) {
|
/*
|
||||||
|
// TODO not sure how to handle 'emit' or 'off'...
|
||||||
|
// it'll just be broken for now
|
||||||
|
if ('off' === fname || 'remove.*Listener'.test(fname)) {
|
||||||
|
var index = ws.___listeners.indexOf(onMessage);
|
||||||
|
ws.___listeners.splice(index, 1);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ('on' !== fname && ! /add.*Listener/.test(fname)) {
|
||||||
var index = ws.___listeners.indexOf(onMessage);
|
var index = ws.___listeners.indexOf(onMessage);
|
||||||
ws.___listeners.splice(index, 1);
|
ws.___listeners.splice(index, 1);
|
||||||
}
|
}
|
||||||
@ -173,6 +179,10 @@ function create(opts) {
|
|||||||
cb.apply(cmd.this, cmd.args);
|
cb.apply(cmd.this, cmd.args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO search index by cb for 'off'
|
||||||
|
// and pass it along to the rpc with the original id
|
||||||
|
onMessage.__cb = cb;
|
||||||
|
onMessage.__id = id;
|
||||||
ws.___listeners.push(onMessage);
|
ws.___listeners.push(onMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,9 @@ function createApp(server, options) {
|
|||||||
return [
|
return [
|
||||||
'set', 'get', 'touch', 'destroy'
|
'set', 'get', 'touch', 'destroy'
|
||||||
, 'all', 'length', 'clear'
|
, 'all', 'length', 'clear'
|
||||||
, 'on', 'off', 'removeEventListener', 'addEventListener'
|
, 'emit', 'on', 'off', 'once'
|
||||||
|
, 'removeListener', 'addListener'
|
||||||
|
, 'removeEventListener', 'addEventListener'
|
||||||
].filter(function (key) {
|
].filter(function (key) {
|
||||||
if ('function' === typeof db[key]) {
|
if ('function' === typeof db[key]) {
|
||||||
return true;
|
return true;
|
||||||
@ -83,6 +85,7 @@ function createApp(server, options) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'rpc':
|
case 'rpc':
|
||||||
|
if (cmd.hasCallback) {
|
||||||
cmd.args.push(function () {
|
cmd.args.push(function () {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
|
||||||
@ -93,6 +96,10 @@ function createApp(server, options) {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO handle 'off' by id
|
||||||
|
cmd.args[cmd.args.length - 1].__id = cmd.id;
|
||||||
|
}
|
||||||
|
|
||||||
db[cmd.func].apply(db, cmd.args);
|
db[cmd.func].apply(db, cmd.args);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user