Streams.Message Class
Constructs a message from fields, which are typically returned from the server.
Constructor
Item Index
Methods
- construct static
- define static
- get static
- getAllInstructions
- getInstruction
- latestOrdinal static
- post static
- seen
- shouldRefreshStream
- wait static
Events
Methods
construct
-
fields
-
[updateCache=false]
Constructs a Streams.Message from fields. If the Streams.Message.define() function was not called, uses a default constructor for the message, which simply copies the fields.
Parameters:
Returns:
define
-
type
-
ctor
-
methods
Call this function to set a constructor for a message type
get
-
publisherId
-
streamName
-
ordinal
-
callback
Get one or more messages, which may result in batch requests to the server. May call Message.get.onError if an error occurs.
Parameters:
-
publisherId
String -
streamName
String -
ordinal
Number | ObjectCan be the ordinal, or an object containing one or more of:
-
[withMessageTotals]
Array optionalHighly encouraged if ordinal is an object. All the possible message types to automatically update messageTotals for.
-
[min]
Number optionalThe minimum ordinal in the range. If omitted, uses limit.
-
[max]
Number optionalThe maximum ordinal in the range. If omitted, gets the latest messages.
-
[limit]
Number optionalChange the max number of messages to retrieve. If only max and limit are specified, messages are sorted by decreasing ordinal.
-
-
callback
FunctionThis receives two parameters. The first is the error. If ordinal was a Number, then the second parameter is the Streams.Message, as well as the "this" object. If ordinal was an Object, then the second parameter is a hash of { ordinal: Streams.Message } pairs
getInstruction
-
instructionName
Get the value of an instruction in the message
Parameters:
-
instructionName
String
latestOrdinal
-
publisherId
-
streamName
-
[checkMessageCache=false]
Gets the latest ordinal as long as there is a cache for that stream or that stream's messages. Otherwise it returns 0.
Parameters:
Returns:
post
-
msg
-
callback
Post a message to a stream, so it can be broadcast to all participants, sent to all subscribers, etc. May call Message.post.onError if an error occurs.
seen
-
[messageTotal]
Mark the message as seen, updating the messageTotals
Parameters:
Returns:
shouldRefreshStream
-
The
-
should
This affects how the Streams plugin handles the posting of this message on the front end. If true for a particular message type, the stream is refreshed (if it was cached before) after all the message handlers have run. You can, of course, implement more complex functionality in message handlers.
Parameters:
-
The
Typetype of the message
-
should
BooleanWhether the stream should be refreshed. Defaults to false.
wait
-
publisherId
-
streamName
-
ordinal
-
callback
-
[options]
Wait until a particular message is posted. Used by Streams plugin to make sure messages arrive in order. Call this with ordinal = -1 to load the latest messages.
Parameters:
-
publisherId
String -
streamName
String -
ordinal
NumberThe ordinal of the message to wait for, or -1 to load latest messages
-
callback
FunctionCalled whenever all the previous messages have been processed. The first parameter is [arrayOfOrdinals] that were processed, where latest < ordinals <= ordinal.
-
[options]
Object optionalA hash of options which can include:
-
[max=5]
Number optionalThe maximum number of messages to wait and hope they will arrive via sockets. Any more and we just request them again.
-
[timeout=1000]
Number optionalThe maximum amount of time to wait and hope the messages will arrive via sockets. After this we just request them again.
-
[unlessSocket=true]
Number optionalWhether to avoid doing any requests when a socket is attached and user is a participant in the stream
-
[evenIfNotRetained]
Boolean optionalSet this to true to wait for messages posted to the stream, in the event that it wasn't cached or retained.
-
Returns:
Returns false if the cached stream already got this message. Returns true if we decided to send a request for the messages. Returns new Q.Pipe if we decided to wait for messages to arrive via socket. Returns null if no attempt was made because ordinal=-1 and stream wasn't cached. In this last case, the callback is not called.
Events
get.onError
Occurs when Message.get encounters an error loading a message from the server
post.onError
Occurs when Message.post encounters an error posting a message to the server