From 3c01f2fa0d844a1e9ebc692e9d97e2e8d01530a0 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Wed, 6 Jan 2016 12:51:57 -0800 Subject: [PATCH] Fix SocketIO client iteration for all cases (#10) --- .npmignore | 1 + src/sockets/helpers.js | 2 +- src/sockets/index.js | 2 +- src/utils.js | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.npmignore b/.npmignore index 80acb5d..367114d 100644 --- a/.npmignore +++ b/.npmignore @@ -2,3 +2,4 @@ .idea/ test/ !lib/ +src/ diff --git a/src/sockets/helpers.js b/src/sockets/helpers.js index 10e97ad..34f9ff9 100644 --- a/src/sockets/helpers.js +++ b/src/sockets/helpers.js @@ -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); diff --git a/src/sockets/index.js b/src/sockets/index.js index 4aeea63..03a52c9 100644 --- a/src/sockets/index.js +++ b/src/sockets/index.js @@ -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; diff --git a/src/utils.js b/src/utils.js index 54dd157..5b46809 100644 --- a/src/utils.js +++ b/src/utils.js @@ -3,7 +3,7 @@ export function stripSlashes(name) { } export function each(obj, callback) { - if(Array.isArray(obj)) { + if(typeof obj.forEach === 'function') { obj.forEach(callback); } else if(typeof obj === 'object') { Object.keys(obj).forEach(key => callback(obj[key], key));