Download npm, the NodeJS Package Manager Install npm Open the terminal and execute the following command to install socket.io npm install socket.io When you want to update it, execute the following command on the terminal npm update socket.io Alternatively you can execute npm update -g in order to update...
node.js,socket.io,socket.io-1.0,socket.io-redis
Yes, it is OK to add properties to the socket.io socket object. You should be careful to not use names that could conflict with built-in properties or methods (I'd suggest adding a leading underscore or namescoping them with some sort of name prefix). But a socket is just a Javascript...
node.js,sockets,socket.io,socket.io-1.0
I had the same problem and the way how I solved it was by replacing this // Start server app.listen(config.port, function () { console.log('Express server listening on port %d in %s mode', config.port, app.get('env')); }); with this: // Start server http.listen(config.port, function () { console.log('Express server listening on port %d...
javascript,sockets,socket.io,socket.io-1.0
This will be fixed in next version. See reply on Github: https://github.com/Automattic/socket.io-client/issues/705 ...
node.js,settimeout,socket.io-1.0
As you noted, lastRoom is a global variable and might/will change between the time you set it and the timeout You can create a closure on the timeout function to keep the room as a locale variable: var lastRoom = 'default'; //this has to be set in the same function...
node.js,express,socket.io,socket.io-1.0
Based on the migration notes from 0.9 to 1.x, authorization shouldn't depend on the set function anymore, but instead should be a normal express middleware, so it should be like this: liveTopicIo.use (socket, next)-> # doing some authentication logic here based on the info # from socket.handshake & reading 'currentUser'...
javascript,node.js,socket.io,web-audio,socket.io-1.0
I build something like this on my own a few weeks ago without socket.io only with the ws module. Problems I ran into (you will at some point): To much Data without reducing bitrate and samplerate (over internet) bad audio quallity without interpolation or a better audio compression Even if...
I popped open the source and found that socket.io.js is now checking for the string polling instead of xhr-polling. So this works: var options = { transports: [ 'polling' ] }; ...
node.js,mongodb,nginx,socket.io,socket.io-1.0
To ensure that we can scale to multiple nodes but keep up interconnectivity between different clients and different servers, I use redis. It's actually very simple to use and set up. What this does is creates a pub/sub system between your servers to keep track of your different socket clients....
ajax,node.js,websocket,socket.io-1.0
Many of the generic tradeoffs between webSocket and Ajax are discussed here: websocket vs rest API for real time data? Some tradeoff issues for mobile devices are discussed here: Cordova: Sockets, PushNotifications, or repeatedly polling server? In a nutshell, if your data is primarily server-driven and then needs to be...
node.js,socket.io,socket.io-1.0,node.js-connect
I have had no problem doing this. I have a few multiplayer games that I built (see here), and they all run on the same socket.io instance. The namespacing keeps the different games separated, and the rooms keep individual game rooms within a single game separated. Full code example here:...
I found out that this is because the Socket.IO version 1.0+ does not, in fact, allow setting a transport aside from [websocket and polling]. Setting polling as your transport defaults to polling-xhr unless you set the properties forceJSONP and/or jsonp to true in your options. In other words, the code...
I ended up using socket.connect()... if anyone has a solution with .reconnect(), I'm all ears.
node.js,express,socket.io,socket.io-1.0,express-4
A lot of info about socket.io and express are out of date due to their popularity and fast changing pace. This is what I ended up doing, by no means it's the best. I would create a sockets.js at the same level as app.js, so you can separate all socket.io...
javascript,socket.io,socket.io-1.0
Internally in the socket.io implementation, broadcast is a flag that is sent with an emit that tells the underlying infrastructure what to do. See the source for that flag here and you can see here in the source where it tests for that flag on a socket to decide if...
Simply access id property of socket object: io.on('connection', function(socket) { console.log(socket.id); }); ...
This occurs because clients array stores sockets not with index keys, but with string keys (like an object). To demonstrate this take a look at the following code: var clients = []; clients.somekey1 = true; clients.somekey2 = true; console.log(clients.length); console.log(clients); Here is the output: 0 [ somekey1: true, somekey2: true...
javascript,node.js,express,socket.io-1.0
I was able to ultimately get things working using this example: https://github.com/expressjs/generator/issues/45#issuecomment-53719435 I created a new file called server/io.js: var io = require('socket.io')(); io.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); module.exports = io; Then I updated server/bin/www to this:...
javascript,node.js,firefox,socket.io,socket.io-1.0
socket.io uses the debug module for its output. In node this means you toggle debug output via an environment variable called DEBUG. In the browser however, debug output is toggled by setting localStorage.debug. If you open up the console and do console.log(localStorage.debug); you should see it output some non-empty string....
socket.io,sails.js,socket.io-1.0,sails.io.js
I intercepted the window.io() function call to inject my query parameter to the .query property of the options object (second param to .io()) <script> (function () { var io; Object.defineProperty(window, 'io', { get: function get() { return io; }, set: function set(iofunc) { io = function(){ var opts = arguments[1];...
node.js,socket.io,socket.io-1.0
For socket.io 1.0 use: io.sockets.connected[socketId] For 0.9 its io.sockets.sockets[socketId] and not io.sockets.socket[socketId]...
node.js,sockets,socket.io,socket.io-1.0
It goes to the client. http://socket.io/docs/server-api/#namespace#use(fn:function):namespace var io = require('socket.io')(); io.use(function(socket, next){ if (socket.request.headers.cookie) return next(); next(new Error('Authentication error')); }); Errors passed to middleware callbacks are sent as special error packets to clients. Note that any middlewares following it aren't invoked. On the client-side you can handle then like so:...