Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

socketio options parameter #124

Closed emilingerslev closed 13 years ago

emilingerslev commented 13 years ago

Changing the transport setting of the internal socket.io isn't possible right now since the setter takes an array like this:

socketio.set('transports', [ 'xhr-polling', 'websocket' ])

The problem is at now.js#L117:

nowUtil.extend(this.options, options);

which changes the options:

var options = { socketio: { transports: [ 'xhr-polling', 'websocket' ] };
var changedOptions = {};
nowUtil.extend(changedOptions, options);
console.log(changedOptions); // >  { socketio: { transports: { '0': 'xhr-polling', '1': 'websocket' } }

The translation of transports into some kind of object breaks socketio. A fix could be adding obj[key].constructor !== Array to nowUtil.extend ensuring that arrays are not traversed but just set.

Change nowUtil.js from

  extend: function (target, obj) {
    for (var i = 0, keys = Object.keys(obj), ii = keys.length; i < ii; i++) {
      var key = keys[i];
      if (obj[key] && typeof obj[key] === 'object') {
        target[key] = target[key] || {};
        util.extend(target[key], obj[key]);
      } else {
        target[key] = obj[key];
      }
    }
  },

to:

  extend: function (target, obj) {
    for (var i = 0, keys = Object.keys(obj), ii = keys.length; i < ii; i++) {
      var key = keys[i];
      if (obj[key] && typeof obj[key] === 'object' && obj[key].constructor !== Array) {
        target[key] = target[key] || {};
        util.extend(target[key], obj[key]);
      } else {
        target[key] = obj[key];
      }
    }
  },

Hope this makes sense and sorry for not just patching but I'm still new to github :S

steveWang commented 13 years ago

I think this was fixed a few days ago when we pushed 0.7.2 : see 432624efb03014d602f723ec09749732f93732cb.

emilingerslev commented 13 years ago

ah of cause, forgot to check updates. Checked out and it works. Sorry for the inconvenience.