Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Fix SocketIO client iteration for all cases (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 6, 2016
1 parent 305811b commit 9bc5a01
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea/
test/
!lib/
src/
2 changes: 1 addition & 1 deletion src/sockets/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function setupEventHandlers(info, service, path) {
service[ev] : defaultDispatcher;
let eventName = `${path} ${ev}`;

Object.keys(info.clients()).forEach(function (socket) {
each(info.clients(), function (socket) {
dispatcher.call(service, data, info.params(socket), function (error, dispatchData) {
if (error) {
socket[info.method]('error', error);
Expand Down
2 changes: 1 addition & 1 deletion src/sockets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function service(path, obj) {
// Set up event handlers for this new service
_setupEventHandlers(protoService, location);
// For any existing connection add method handlers
Object.keys(info.clients()).forEach(socket => _setupMethodHandlers(socket, location, protoService));
each(info.clients(), socket => _setupMethodHandlers(socket, location, protoService));
}

return protoService;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function stripSlashes(name) {
}

export function each(obj, callback) {
if(Array.isArray(obj)) {
if(obj && typeof obj.forEach === 'function') {
obj.forEach(callback);
} else if(typeof obj === 'object') {
Object.keys(obj).forEach(key => callback(obj[key], key));
Expand Down

0 comments on commit 9bc5a01

Please sign in to comment.