Streams.Stream Class
Constructs a stream from fields, which are typically returned from the server.
Constructor
Item Index
Methods
- actionUrl
- addPermission
- clearAttribute
- fileUrl
- get
- getAll
- getAllAttributes
- getAllPermissions
- getAttribute
- getMessage
- getParticipant
- hasPermission
- iconUrl
- invite
- join
- join static
- leave static
- leave
- neglect static
- neglect
- observe
- observe static
- post
- refresh
- refresh static
- relate
- relatedFrom
- relatedTo
- relateTo
- release
- release static
- remove static
- remove
- removePermission
- reopen static
- retain static
- retain
- retainedByKey
- retainWith
- save
- set
- setAttribute
- subscribe
- subscribe static
- testAdminLevel
- testReadLevel
- testWriteLevel
- unrelateFrom
- unrelateTo
- unsubscribe static
- unsubscribe
Events
- beforeSet static
- beforeSet static
- beforeSet
- beforeSetAttribute
- close.onError
- join.onError
- leave.onError
- onAttribute
- onAttribute static
- onClosed static
- onClosed
- onConstruct
- onConstruct
- onFieldChanged static
- onFieldChanged
- onMessage static
- onMessage
- onRelatedFrom
- onRelatedFrom static
- onRelatedTo static
- onRelatedTo
- onUnrelatedFrom static
- onUnrelatedFrom
- onUnrelatedFrom
- onUnrelatedTo static
- onUnrelatedTo
- onUnrelatedTo
- onUpdated
- onUpdated static
- onUpdatedRelateFrom static
- onUpdatedRelateTo static
- subscribe.onError
- unsubscribe.onError
Methods
actionUrl
-
[what='stream']
A convenience method to get the URL of the streams-related action
Parameters:
-
[what='stream']
String optionalCan be one of 'stream', 'message', 'relation', etc.
Returns:
The corresponding URL
clearAttribute
-
attributeName
Remove an attribute from the stream, pending to be saved to the server
Parameters:
-
attributeName
String
get
-
fieldName
-
usePending
Get the value of a field
Parameters:
Returns:
getAllAttributes
-
usePending
Get all stream attributes
Parameters:
-
usePending
Boolean
Returns:
getAttribute
-
attributeName
-
usePending
Get the value of an attribute
Parameters:
Returns:
getMessage
-
ordinal
-
callback
Retrieves a Streams.Message object, by using Message.get
getParticipant
-
userId
-
callback
Retrieves a Streams.Participant object, by using Participant.get
iconUrl
-
[size=40]
Calculate the url of a stream's icon
Parameters:
-
[size=40]
Number optionalthe size of the icon to render. Defaults to 40.
Returns:
the url
invite
-
[options]
-
callback
Invite other users to this stream. Must be logged in first.
Parameters:
-
[options]
Object optionalMore options that are passed to the API, which can include:
-
[identifier]
String optionalAn email address or mobile number to invite. Might not belong to an existing user yet.
-
[token=false]
Boolean optionalPass true here to generate an invite which you can then send to anyone however you like. When they show up with the token and presents it via "Q.Streams.token" querystring parameter, the Streams plugin will accept this invite either right away, or as soon as they log in. They will then be added to the list of Streams_Invited for this stream, thus keeping track of who accepted whose invite.
-
[appUrl]
String optionalCan be used to override the URL to which the invited user will be redirected and receive "Q.Streams.token" in the querystring.
-
[userId]
String optionaluser id or an array of user ids to invite
-
[platform]
String optionalplatform for which uids are passed
-
[uid]
String optionaluid or arary of uids to invite
-
[label]
String optionallabel or an array of labels to invite, or tab-delimited string
-
[addLabel]
String | Array optionallabel or an array of labels for adding publisher's contacts
-
[addMyLabel]
String | Array optionallabel or an array of labels for adding logged-in user's contacts
-
[readLevel]
String optionalthe read level to grant those who are invited
-
[writeLevel]
String optionalthe write level to grant those who are invited
-
[adminLevel]
String optionalthe admin level to grant those who are invited
-
[displayName]
String optionalOptionally override the name to display in the invitation for the inviting user
-
[callback]
String optionalAlso can be used to provide callbacks.
-
[followup="future"]
Boolean optionalWhether to set up a followup email or sms for the user to send. Set to true to always send followup, or false to never send it. Set to "future" to send followups only when the invited user hasn't registered yet.
-
[uri]
String optionalIf you need to hit a custom "Module/action" endpoint
-
-
callback
FunctionCalled with (err, result)
Returns:
represents the request that was made if an identifier was provided
join
-
callback
Join a stream as a participant, so you get realtime messages through socket events.
Parameters:
-
callback
Functionreceives (err, participant) as parameters
join
-
publisherId
-
streamName
-
[callback]
Join a stream as a participant, so messages start arriving in real time via sockets. May call Streams.join.onError if an error occurs.
leave
-
publisherId
-
streamName
-
callback
Leave a stream that you previously joined, so that you don't get realtime socket messages for that stream anymore. May call Stream.leave.onError if an error occurs.
leave
-
callback
Leave a stream that you previously joined, so that you don't get realtime messages anymore.
Parameters:
-
callback
FunctionReceives (err, participant) as parameters
neglect
-
publisherId
-
streamName
-
[callback]
Stop observing a stream which you previously started observing, so that you don't get realtime messages anymore.
neglect
-
callback
Stop observing a stream which you previously started observing, so that you don't get realtime messages anymore.
Parameters:
-
callback
FunctionReceives (err, participant) as parameters
observe
-
callback
Start observing a stream as an anonymous observer, so you get realtime messages through socket events but you don't join as a participant.
Parameters:
-
callback
Functionreceives (err, participant) as parameters
observe
-
publisherId
-
streamName
-
[callback]
Start observing a stream as an anonymous observer, so you get realtime messages through socket events but you don't join as a participant.
post
-
[data]
-
callback
Post a message to this stream.
refresh
-
callback
-
[options]
Waits for the latest messages to be posted to a given stream. If your app is using socket.io, then calling this manually is largely unnecessary.
Parameters:
-
callback
FunctionThis is called when the stream has been refreshed, or if Streams has determined it won't send a refresh request, it will get null as the first parameter.
-
[options]
Object optionalA hash of options, including:
-
[messages]
Boolean optionalIf set to true, then besides just reloading the fields, attempt to catch up on the latest messages
-
[max]
Number optionalThe maximum number of messages to wait and hope they will arrive via sockets. Any more and we just request them again.
-
[timeout]
Number optionalThe maximum amount of time to wait and hope the messages will arrive via sockets. After this we just request them again.
-
[unlessSocket]
Number optionalWhether to avoid doing any requests when a socket is attached
-
[changed]
Array optionalAn array of {fieldName: true} pairs naming fields to trigger change events for, even if their values stayed the same
-
[evenIfNotRetained]
Boolean optionalIf the stream wasn't retained (for example because it was missing last time), then refresh anyway
-
[extra]
Object optionalAny extra parameters to pass to the callback
-
Returns:
whether the refresh occurred
refresh
-
callback
-
[options]
Refreshes a stream, to show the latest content and possibly process the latest messages posted to the stream. If your app server script is running, then calling this manually is largely unnecessary because messages arrive via push using socket.io .
Parameters:
-
callback
FunctionThis is called when the stream has been refreshed. If the first argument is not false or null, then "this" is the stream. The arguments are different depending on the options. If options.messages is true, then it receives (err, ordinals).
-
[options]
Object optionalA hash of options, including:
-
[messages]
Boolean optionalIf set to true, then besides just reloading the fields, attempt to catch up on the latest messages
-
[max]
Number optionalThe maximum number of messages to wait and hope they will arrive via sockets. Any more and we just request them again.
-
[timeout]
Number optionalThe maximum amount of time to wait and hope the messages will arrive via sockets. After this we just request them again.
-
[unlessSocket]
Number optionalWhether to avoid doing any requests when a socket is attached
-
[changed=null]
Object optionalAn Object of {fieldName: true} pairs naming fields to trigger change events for, even if their values stayed the same.
-
[evenIfNotRetained]
Boolean optionalIf the stream wasn't retained (for example because it was missing last time), then refresh anyway
-
[extra]
Object optionalAny extra parameters to pass to the callback
-
Returns:
Whether callback will be called, or false if the refresh has been canceled
relate
-
type
-
fromPublisherId
-
fromStreamName
-
[callback]
Relates another stream to this stream
Parameters:
-
type
Stringthe type of the relation
-
fromPublisherId
Stringid of publisher of the stream
-
fromStreamName
Stringname of stream which is being related to this stream
-
[callback]
Function optionalcallback to call with the results First parameter is the error, the second one is an object of Streams.RelatedTo objects you can iterate over with Q.each
relateTo
-
type
-
toPublisherId
-
toStreamName
-
[callback]
Relates this stream to another stream
Parameters:
-
type
Stringthe type of the relation
-
toPublisherId
Stringd of publisher of the stream
-
toStreamName
Stringname of stream to which this stream is being related
-
[callback]
Function optionalcallback to call with the results First parameter is the error, the second one is an object of Streams.RelatedTo objects you can iterate over with Q.each
release
()
Q.Streams.Stream
Release the stream in the client retained under a certain key. When the stream is released under all the keys it was retained under, it is no longer refreshed during Streams.refresh() This method also closes a socket to the stream's node, if it was the last stream released on that node.
Returns:
release
-
publisherId
-
streamName
Releases a stream from being retained. See Streams.Stream.retain() This method also closes a socket to the stream's node, if it was the last stream released on that node.
remove
-
publisherId
-
streamName
-
callback
Closes a stream in the database, and marks it for removal unless it is required.
remove
-
callback
Closes a stream in the database, and marks it for removal unless it is required.
Parameters:
-
callback
Function
reopen
()
static
Reopens a stream in the database that was previously closed, but not yet removed.
retain
-
publisherId
-
streamName
-
key
-
callback
Call this function to retain a particular stream. When a stream is retained, it is refreshed when Streams.refresh() or stream.refresh() are called. You can release the stream with stream.release(). This method also opens a socket to the stream's node, if one isn't already open.
Parameters:
Returns:
returns Streams object for chaining with .get() or .related()
retain
-
key
Retain the stream in the client under a certain key. Retained streams are refreshed during Streams.refresh()
Parameters:
-
key
String
Returns:
retainWith
-
key
When a stream is retained, it is refreshed when Streams.refresh() or stream.refresh() are called. You can release it with stream.release(). Call this function in a chain before calling stream.related, etc. in order to set the key for retaining the streams those functions obtain.
Parameters:
-
key
String
Returns:
returns Streams object for chaining with .get() or .related()
save
-
[options]
Save a stream to the server
Parameters:
-
[options]
Object optionalA hash of options for the subsequent refresh. See Q.Streams.Stream.refresh
-
[onSave]
Q.Event optionalWhen the result of the server request comes back. The first parameter is any error that may have occurred. Note: the steam may not be refreshed yet by that point. You can return false from the handler to prevent the refresh, for whatever reason.
-
[onRefresh]
Q.Event optionalWhen the stream has been saved and refrshed.
-
set
-
fieldName
-
value
Set the value of a field, pending to be saved to the server with the stream May cause some validators to run and throw a validation exception on the value.
Parameters:
-
fieldName
String -
value
Mixed
setAttribute
-
attributeName
-
value
Set the value of an attribute, pending to be saved to the server with the stream
Parameters:
-
attributeName
String -
value
Mixed
subscribe
-
callback
Subscribe to a stream, so you get realtime messages and offline notifications.
Parameters:
-
callback
Functionreceives (err, participant) as parameters
subscribe
-
publisherId
-
streamName
-
[callback]
-
[options]
Subscribe to a stream, to start getting offline notifications May call Streams.subscribe.onError if an error occurs.
Parameters:
-
publisherId
Stringid of publisher which is publishing the stream
-
streamName
Stringname of stream to join
-
[callback]
Function optionalreceives (err, participant) as parameters
-
[options]
Object optionaloptional object that can include:
-
[device]
Bool optionalWhether to subscribe device when user subscribed to some stream
-
testAdminLevel
-
level
Test whether the user has enough access rights when it comes to administering the stream
Parameters:
-
level
StringOne of the values in Streams.ADMIN_LEVEL
Returns:
Returns true if the user has at least this level of access
testReadLevel
-
level
Test whether the user has enough access rights when it comes to reading from the stream
Parameters:
-
level
StringOne of the values in Streams.READ_LEVEL
Returns:
Returns true if the user has at least this level of access
testWriteLevel
-
level
Test whether the user has enough access rights when it comes to writing to the stream
Parameters:
-
level
StringOne of the values in Streams.WRITE_LEVEL
Returns:
Returns true if the user has at least this level of access
unrelateFrom
-
fromPublisherId
-
fromStreamName
-
relationType
-
[callback]
Removes a relation from another stream to this stream
Parameters:
-
fromPublisherId
Stringid of publisher which is publishing the stream
-
fromStreamName
Stringname of stream which is being unrelated
-
relationType
Stringthe type of the relation, such as "parent" or "photo"
-
[callback]
Function optionalcallback to call with the results First parameter is the error, the second one is an object of Streams.RelatedTo objects you can iterate over with Q.each
unrelateTo
-
toPublisherId
-
toStreamName
-
relationType
-
[callback]
Removes a relation from this stream to another stream
Parameters:
-
toPublisherId
Stringid of publisher which is publishing the stream
-
toStreamName
Stringname of stream which the being unrelated
-
relationType
Stringthe type of the relation, such as "parent" or "photo"
-
[callback]
Function optionalcallback to call with the results First parameter is the error, the second one is an object of Streams.RelatedTo objects you can iterate over with Q.each
unsubscribe
-
publisherId
-
streamName
-
callback
Unsubscribe from a stream you previously subscribed to May call Stream.unsubscribe.onError if an error occurs.
unsubscribe
-
callback
Unsubscribe from a stream that you previously subscribed to
Parameters:
-
callback
FunctionReceives (err, participant) as parameters
Events
beforeSet
static
Event factory for validation hooks that run when setting stream fields. Have the hooks throw a Q.Error on validation errors.
beforeSet
static
Event factory for validation hooks that run when setting stream attributes. Have the hooks throw a Q.Error on validation errors.
beforeSet
Event factory for validation hooks that run when setting stream fields. Have the hooks throw a Q.Error on validation errors.
beforeSetAttribute
Event factory for validation hooks that run when setting stream attributes Have the hooks throw a Q.Error on validation errors.
close.onError
Occurs when Stream.close encounters an error trying to close a stream
join.onError
Occurs when Stream.join encounters an error trying to join the stream
leave.onError
Occurs when Stream.leave encounters an error leave a stream
onAttribute
Returns Q.Event which occurs when attributes of the stream officially updated
Event Payload:
-
[attributeName]
String optionalname of the attribute to listen for, or "" for all
onAttribute
static
Returns Q.Event which occurs when attributes of the stream officially updated
onClosed
static
Returns Q.Event which occurs when a stream has been closed (and perhaps has been marked for removal)
onClosed
Event factory for listening for changed stream fields based on name.
onConstruct
Returns Q.Event which occurs after a stream is constructed on the client side Generic callbacks can be assigend by setting type or mtype or both to ""
onConstruct
Returns Q.Event that you can use update any of your stream representations. If you are already handling the Streams.Stream.onFieldChanged and Streams.Stream.onAttribute events, however, then you don't need to also add a handler to this event, because they are called during the refresh anyway.
onFieldChanged
static
Returns Q.Event which occurs when fields of the stream officially changed on the server, or was simulated by the client. Either way, you can use this opportunity to update your tools and other visual representations of the stream. Note that this event occurs before the stream object is finally updated, so you can compare the old values of the fields to the new ones. If you need to use the updated stream object, use setTimeout(callback, 0). Finally, if the field which changed is an "extend" field for that stream type, then its value will be null even if the real value is probably something else. You will need to call stream.refresh(callback) to load the stream from the server and in the callback you'll finally have the stream object you've been looking for.
onFieldChanged
Event factory for listening for changed stream fields based on name.
Event Payload:
-
field
Stringcan be "" to get triggered for on all fields
onMessage
static
Returns Q.Event that occurs after the system learns of a new message that was posted. The platform makes sure the ordinals come in the right order, for each stream. So you just have to handle the messages to update your tools, pages, etc. By the time this event happens, the platform has already taken any default actions for standard events such as "Streams/join", etc. so the stream and all caches are up-to-date, e.g. the participants include the newly joined participant, etc.
onMessage
Returns Q.Event that occurs after the system learns of a new message that was posted. The platform makes sure the ordinals come in the right order, for each stream. So you just have to handle the messages to update your tools, pages, etc. By the time this event happens, the platform has already taken any default actions for standard events such as "Streams/join", etc. so the stream and all caches are up-to-date, e.g. the participants include the newly joined participant, etc.
Event Payload:
-
[messageType]
String optionaltype of the message, or its ordinal, pass "" for all types
onRelatedFrom
Event factory for listening to this stream being related to other streams
onRelatedFrom
static
Returns Q.Event which occurs when this stream was related to a category stream. You may want to retain that category stream on the client.
onRelatedTo
static
Returns Q.Event which occurs when another stream has been related to this stream. You may want to retain this stream on the client.
onRelatedTo
Event factory for listening to streams being related to this stream
onUpdated
Alias for onAttribute for backward compatibility
onUpdated
static
Alias for onAttribute for backward compatibility
onUpdatedRelateFrom
static
Returns Q.Event which occurs when this stream was related to a category stream
onUpdatedRelateTo
static
Returns Q.Event which occurs when another stream has been related to this stream
subscribe.onError
Occurs when Stream.subscribe encounters an error trying to subscribe to a stream
unsubscribe.onError
Occurs when Stream.unsubscribe encounters an error trying to unsubscribe from a stream