Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Latest commit

 

History

History
39 lines (27 loc) · 1.4 KB

File metadata and controls

39 lines (27 loc) · 1.4 KB

.message( models,data, [request] )

Purpose

Publishes a custom message to a model’s subscribers.

Description Accepted Data Types Required ?
1 Record (or ID of record) to send message to int, string, object Yes
2 Message payload object Yes
3 Request request object No

message() emits a socket message using the model identity as the event name. The message is broadcast to all sockets subscribed to the model instance via the .subscribe model method.

The socket message is an object with the following properties:

  • id - the id attribute of the model instance
  • verb - "messaged" (a string)
  • data - the message payload

data

Arbitrary data to send to the subscribed sockets.

request

If this argument is included then the socket attached to that request will not receive the notification.

Example

Find a user in the sails controller by name and send a socket message back to the client. This object can contain any data you want.

User.findOne({name: 'Bob'}).then(function(foundUser){
  User.message(foundUser, {count: 12, hairColor: 'red'});
});