Question

I added socket.io-client.js to my front end application. Because backend is driven by sails.js I added a socket.io wrapper provided by sails:

https://raw.githubusercontent.com/balderdashy/sails.io.js/master/sails.io.js

When I refresh site I get an error in this line:

Socket.prototype.get = function(url, data, cb)

Console:

Uncaught TypeError: Cannot read property 'prototype' of undefined sails.io.js:311 SailsIOClient sails.io.js:311 (anonymous function) sails.io.js:724 (anonymous function) sails.io.js:726

Is this some bug in the sails.io.js script? I am not using the script right now, just included it.

Was it helpful?

Solution

The version of sails.io.js in that repo is under active development. To safely implement socket.io in your Sails project, you can use the sails.io.js that is provided with new Sails projects created by the sails new command.

That having been said, the issue here is that you need to include the dist version of the repo's sails.io.js file, which includes the code for the socket.io client inline. So don't include a separate copy of socket.io.js in your project if you go that route. The new sails.io.js has a few key benefits:

  1. Automatically connects to socket server
  2. Provides a response argument to request callbacks with the response status, headers, etc.
  3. Sails will automatically detect the new version of sails.io.js and respond accordingly

Again, it's under development so read the doc page carefully and use at your own risk!

OTHER TIPS

I managed to have it working using the version 0.9.17 of socket.io-client

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top