-
-
Save mikermcneil/6598661 to your computer and use it in GitHub Desktop.
module.exports = { | |
/** | |
* | |
* Using raw socket.io functionality from a Sails.js controller | |
* | |
*/ | |
index: function (req,res) { | |
var socket = req.socket; | |
var io = sails.io; | |
// emit to all sockets (aka publish) | |
// including yourself | |
io.sockets.emit('messageName', {thisIs: 'theMessage'}); | |
// broadcast to a room (aka publish) | |
// excluding yourself, if you're in it | |
socket.broadcast.to('roomName').emit('messageName', {thisIs: 'theMessage'}); | |
// emit to a room (aka publish) | |
// including yourself | |
io.sockets.in('roomName').emit('messageName', {thisIs: 'theMessage'}); | |
// Join a room (aka subscribe) | |
// If you're in the room already, no problem, do nothing | |
// If the room doesn't exist yet, it gets created | |
socket.join('roomName'); | |
// Leave a room (aka unsubscribe) | |
// If you're not in the room, no problem, do nothing | |
// If the room doesn't exist yet, no problem, do nothing | |
socket.leave('roomName'); | |
// Get all connected sockets in the app | |
sails.io.sockets.clients(); | |
// Get all conneted sockets in the room, "roomName" | |
sails.io.sockets.clients('roomName'); | |
} | |
}; |
this is awesome if someone update the video on Youtube ~~~ , the version on Youtube was still 0.9.7~
Documentation can now be found here
Thanks everyone for the links! We're in the middle of some major documentation improvements (particularly in relation to sockets) which will be deployed here. In the mean time, if you're interested in contributing, you can use http://next.sailsjs.org/documentation/reference/web-sockets/sails-sockets for previewing purposes. More info on contributing to Sails docs here.
do you have an example on how to connect regular nodejs client, and swift or android clients to sails js socket io server also? I'd like to see if I could connect my mobile phones to get push notification from sailsjs socket io server, thank you!
Hi,
Please help me, I want to use sails socket with android. any library for android or how to use socket.io directly with sails.js
hi guys, i implemented socket.io but have an issue, can you look at my code and help?
https://stackoverflow.com/questions/56963376/angular-8-using-sails-js-websokcet-sokcet-io
how would anyone implement this in routes ?
'GET /is/it/micky': {action: 'validate-micky', isSocket: true}
< in routes.js ?
Try: http://sailsjs.org/#!/documentation/reference/websockets/sails.sockets