node.jssocketsherokusocket.iodeployd

Transport Settings in Socket.IO 1.4.x


I have been tinkering with deployd on Heroku using this gist as a starting point:

Line 20 of that server.js tries to set transports for socket.io like so:

server.sockets.manager.settings.transports = ["xhr-polling"];

But encounters this error:

Cannot read property 'settings' of undefined.

From research so far it seems this approach is deprecated in socket.io 1.4.5. However, if that's so I am not clear on how I should address this setting.

My question is similar to this one. But differs in that I seek to change the settings once socket.io is already constructed by and attached to an instance of deployd.


Solution

  • Set it on creation:

    var server = deployd({
        socketIo: {
            options: { transports : ['xhr-polling'] }
        }
    });
    

    Or if you can't do that, change it runtime (this is a hack):

    server.sockets.server.eio.transports = ['xhr-polling'];
    

    (This is still supported for backwards compatibility:)

    server.sockets.server.set('transports', ['xhr-polling']);