Menu
  • HOME
  • TAGS

How do I check the version of socket.io and update it

socket.io,socket.io-1.0

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...

How to store client associated data in socket.io 1.0

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...

Socket.io connection reverts to polling, never fires the 'connection' handler

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...

Socket.io-client fires duplicate 'reconnect_failed' event

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 ...

Concurrent timers in node.js with socket.io

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...

Can't add handshake parameter when authenticating socket.io

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'...

Can I stream microphone audio from client to client using nodejs?

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...

socket.io doens't work with transports: [ 'xhr-polling' ]

node.js,socket.io-1.0

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' ] }; ...

Chat project - load balance with socket.io

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 vs Socket.io

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...

Can I use rooms in namespaces in socket.io

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:...

Connecting through xhr-polling and jsonp-polling timeout

socket.io,socket.io-1.0

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...

socket.io: socket reconnect in version 1.0

socket.io-1.0

I ended up using socket.connect()... if anyone has a solution with .reconnect(), I'm all ears.

How to best structure an Express V4.11+ project with Socket.IO?

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...

Why is the broadcast described as flag in the docs when it is actually an object?

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...

socket.IO: how can i get the socketid when i emit to a specific client in socket.io 1.0

socket.io,socket.io-1.0

Simply access id property of socket object: io.on('connection', function(socket) { console.log(socket.id); }); ...

Number of clients in the room in socket io v1

socket.io,socket.io-1.0

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...

How can I emit events to connected sockets using socket.io from within my Express 4 routes?

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:...

Why mozilla firefox log many messages from socket.io 1.2.1

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....

how to add custom data with sails.io handshake query

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];...

Socket.IO 1.0.x: Get socket by id

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]...

SocketIo.use(function(socket, next)) - Where goes next, how to catch or receive it?

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:...