Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions packages/sockethub/src/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,14 @@
SockethubClient.prototype.__handlers = {
// wrapping the `on` method in order to automatically unpack Activity Streams objects
// that come in on the 'messages' channel, so that app developers don't need to.
message: function (msg) {
console.warn(`message event received with no handler registered: `, msg);
},
completed: function (msg) {
console.warn('completed event received with no handler registered: ', msg);
},
failed: function (msg) {
console.warn('failed event received with no handler registered: ', msg);
},
reconnecting: function (msg) {
console.warn('reconnecting: ', msg);
},
reconnect_failed: function (msg) {
console.warn('reconnect failed: ', msg);
},
connect: function () {
console.warn('connected.');
},
reconnect: function (msg) {
console.warn('reconnected: ', msg);
},
disconnect: function (msg) {
console.warn('disconnected: ', msg);
}
message: [],
completed: [],
failed: [],
reconnecting: [],
reconnect_failed: [],
connect: [],
reconnect: [],
disconnect: []
};

SockethubClient.prototype.__registerSocketIOHandlers = function () {
Expand All @@ -86,7 +70,9 @@
} else if (event === 'disconnect') {
this.online = false;
}
this.__handlers[event](obj);
for (let cb of this.__handlers[event]) {
cb(obj);
}
};
};

Expand Down Expand Up @@ -149,7 +135,7 @@
this.socket.on = (event, cb) => {
if (Object.keys(this.__handlers).includes(event)) {
// store the desired message channel callback, because we use our own first
this.__handlers[event] = cb;
this.__handlers[event].push(cb);
} else {
// pass on any other handlers
this.socket._on(event, cb);
Expand All @@ -169,7 +155,9 @@
SockethubClient.prototype.__unpackAndCallHandler = function (event) {
return (obj) => {
let unpackedObject = this.ActivityStreams.Stream(obj);
this.__handlers[event](unpackedObject);
for (let cb of this.__handlers[event]) {
cb(unpackedObject);
}
};
};

Expand Down