sails.sockets.emit( socketIds, [event], data)

Purpose

Send a message to one or more sockets by ID.

Overview

Parameters

Description Accepted Data Types Required ?
1 IDs of sockets to receive message string, array Yes
2 Event name string No
3 Message data object Yes

Example Usage

// Controller action

sayHiToFriend: function(req, res) {
    var friendId = req.param('friendId');
    sails.sockets.emit(friendId, 'privateMessage', {from: req.session.userId, msg: 'Hi!'});
    res.json({
      message: 'Message sent!'
    });
}