Streams Class
Streams plugin's front end code
Item Index
Methods
- _connectSockets static
- _disconnectSockets static
- actionUrl static
- batchFunction static
- construct static
- create static
- define static
- displayType static
- followup static
- get static
- iconUrl static
- invite static
- isStream static
- key static
- refresh static
- relate
- related static
- release static
- retainedByKey static
- retainWith static
- unrelate static
- updateRelation
Properties
- ADMIN_LEVEL
- ADMIN_LEVEL.invite
- ADMIN_LEVEL.manage
- ADMIN_LEVEL.max
- ADMIN_LEVEL.none
- ADMIN_LEVEL.own
- ADMIN_LEVEL.tell
- READ_LEVEL
- READ_LEVEL.content
- READ_LEVEL.max
- READ_LEVEL.messages
- READ_LEVEL.none
- READ_LEVEL.participants
- READ_LEVEL.relations
- READ_LEVEL.see
- WRITE_LEVEL
- WRITE_LEVEL.close
- WRITE_LEVEL.closePending
- WRITE_LEVEL.edit
- WRITE_LEVEL.join
- WRITE_LEVEL.max
- WRITE_LEVEL.messages
- WRITE_LEVEL.none
- WRITE_LEVEL.postPending
- WRITE_LEVEL.relate
- WRITE_LEVEL.relations
- WRITE_LEVEL.suggest
- WRITE_LEVEL.vote
Methods
_connectSockets
-
refresh
Connects or reconnects sockets for all participating streams
Parameters:
-
refresh
Boolean
_disconnectSockets
()
private
static
Disconnects all Streams sockets which have been connected. Note that this also affects other plugins that might be listening on the sockets (maybe we should have another thing, I don't know, but for now it's ok).
actionUrl
-
publisherId
-
streamName
-
[what='stream']
A convenience method to get the URL of the streams-related action
Parameters:
Returns:
The corresponding URL
construct
-
fields
-
[extra={}]
-
[callback]
-
[updateCache=false]
This function is similar to _activateTools in Q.js That one is to create "controllers" on the front end, and this one is to create "models" on the front end. They have very similar conventions.
Parameters:
-
fields
ObjectProvide any stream fields here. Requires at least the "type" of the stream.
-
[extra={}]
Object optionalCan include "messages" and "participants"
-
[callback]
Function optionalThe function to call when all constructors and event handlers have executed The first parameter is an error, in case something went wrong. The second one is the stream object.
-
[updateCache=false]
Boolean optionalWhether to update the Streams.get cache after constructing the stream
Returns:
create
-
fields
-
callback
-
[related]
-
[options]
Create a new stream
Parameters:
-
fields
ObjectShould contain at least the publisherId and type of the stream. Fields are passed to the Streams/stream POST handler. The attributes field can be an object.
-
callback
Functionif there were errors, first parameter is the error message
otherwise, first parameter is null and second parameter is a Streams.Stream object
-
[related]
Object optionalOptional information to add a relation from the newly created stream to another one. Can include:
-
[options]
Object optionalAny extra options involved in creating the stream
-
[fields]
Object optionalUsed to override any fields passed in the request
-
[filename]
String optionalOverrides the default filename for file uploads
-
[form]
HTMLElement optionalIf you want to upload a file or an icon, pass a form element here which includes input elements of type "file", named "file" or "icon". If they have files selected in them, they will be passed along with the rest of the fields. Setting this option will cause a call to Q.formPost which will load the result in an iframe. That resulting webpage must contain javascript to call the resultFunction.
-
[resultFunction=null]
String optionalThe path to the function to handle inside the contentWindow of the resulting iframe, e.g. "Foo.result". Your document is supposed to define this function if it wants to return results to the callback's second parameter, otherwise it will be undefined
-
define
-
type
-
ctor
-
methods
Call this function to define a stream type
displayType
-
type
Try to figure out a displayable title from a stream's type
Parameters:
-
type
String
Returns:
followup
-
options
Parameters:
-
options
Object-
[show="alert"]
String optionalCan be "alert" or "confirm", or empty
-
[mobile]
Object optional -
[email]
Object optional-
[addresses]
Array optionalThe list of email addresses to send to -
[subject]
String optionalOverride template for subject -
[body]
String optionalOverride template for email body -
[alert]
String optionalOverride template for alert -
[confirm]
String optionalOverride template for confirmation dialog to continue
-
-
facebook
Object-
uids
ArrayThe facebook uids to send followup push notifications to messenger
-
-
get
-
publisherId
-
name
-
callback
-
[extra]
Streams batch getter.
Parameters:
-
publisherId
StringPublisher's user id
-
name
StringName of the stream published by this publisher
-
callback
FunctionIf there were errors, first parameter is an array of errors. Otherwise, first parameter is null and second parameter is a Streams.Stream object
-
[extra]
Object optionalOptional object which can include the following keys:
-
[participants=0]
Number | Object optionalOptionally fetch up to that many participants
-
[messages=0]
Number | Object optionalOptionally fetch up to that many latest messages
-
[messageType]
String optionaloptional String specifying the type of messages to fetch
-
[withMessageTotals]
Array optionalan array of message types to get messageTotals for in the returned stream object
-
[withRelatedToTotals]
Array optionalan array of relation types to get relatedToTotals for in the returned stream object
-
[withRelatedFromTotals]
Array optionalan array of relation types to get relatedFromTotals for in the returned stream object
-
[cacheIfMissing]
Boolean optionaldefaults to false. If true, caches the "missing stream" result.
-
[fields]
Array optionalthe stream is obtained again from the server if any fields named in this array are == null
-
["$Module_$fieldname"]
Mixed optionalany other fields you would like can be added, to be passed to your hooks on the back end
-
iconUrl
-
icon
-
[basename=40]
Calculate the url of a stream's icon
Parameters:
Returns:
the url
invite
-
publisherId
-
streamName
-
[options]
-
callback
Invite other users to a stream. Must be logged in first.
Parameters:
-
publisherId
StringThe user id of the publisher of the stream
-
streamName
StringThe name of the stream you are inviting to
-
[options]
Object optionalMore options that are passed to the API, which can include:
-
[identifier]
String | Array optionalAn email address or mobile number to invite. Might not belong to an existing user yet. Can also be an array of identifiers.
-
[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, which are called before the followup.
-
[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 to users who haven't registered yet.
-
[uri]
String optionalIf you need to hit a custom "Module/action" endpoint
-
-
callback
FunctionCalled with (err, result) . In this way you can obtain the invite token, email addresses, etc. See Streams::invite on the PHP side for the possible return values. This is called before the followup flow.
Returns:
represents the request that was made if an identifier was provided
isStream
-
value
Use this to check whether variable is a Q.Streams.Stream object
Parameters:
-
value
Mixed
Returns:
key
-
publisherId
-
streamName
Calculate the key of a stream used internally for retaining and releasing
Returns:
the key
refresh
-
callback
-
[options]
Refreshes all the streams the logged-in user is participating in If your app is using socket.io, then calling this manually is largely unnecessary.
Parameters:
-
callback
Functionoptional callback
-
[options]
Object optionalA hash of options, including:
-
[messages]
Boolean optionalIf set to true, then besides just reloading the stream, 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.
-
[duringEvents]
Array optionalStreams.refresh.options.duringEvents are the window events that can lead to an automatic refresh
-
[minSeconds]
Number optionalStreams.refresh.options.minEvents is the minimum number of seconds to wait between automatic refreshes
-
[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 the refresh occurred
relate
-
publisherId
-
streamName
-
relationType
-
fromPublisherId
-
fromStreamName
-
[callback]
Relates streams to one another
Parameters:
-
publisherId
Stringthe publisher id of the stream to relate to
-
streamName
Stringthe name of the stream to relate to
-
relationType
Stringthe type of the relation, such as "parent" or "photo"
-
fromPublisherId
Stringthe publisher id of the stream to relate from
-
fromStreamName
Stringthe name of the stream to relate from
-
[callback]
Function optionalcallback to call with the results First parameter is the error, the second will be relations data
release
-
key
Releases all retained streams under a given key. See Streams.retain() It also closes sockets corresponding to all the released streams, if they were the last streams to be retained on their respective nodes.
Parameters:
-
key
String
retainedByKey
-
publisherId
-
streamName
Detect whether stream retained
Returns:
Whether stream retained (true) or not (false)
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 Streams.get, Streams.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()
unrelate
-
publisherId
-
streamName
-
relationType
-
fromPublisherId
-
fromStreamName
-
[callback]
Removes relations from streams to one another
Parameters:
-
publisherId
Stringthe publisher id of the stream to relate to
-
streamName
Stringthe name of the stream to relate to
-
relationType
Stringthe type of the relation, such as "parent" or "photo"
-
fromPublisherId
Stringthe publisher id of the stream to relate from
-
fromStreamName
Stringthe name of the stream to relate from
-
[callback]
Function optionalcallback to call with the results First parameter is the error, the second will be relations data
updateRelation
-
toPublisherId
-
toStreamName
-
relationType
-
fromPublisherId
-
fromStreamName
-
weight
-
adjustWeights
-
callback
Later we will probably make Streams.Relation objects which will provide easier access to this functionality. For now, use this to update weights of relations, etc.
Properties
ADMIN_LEVEL.invite
Integer
final
Able to create invitations for others, granting access and permissions up to what they themselves have
Default: 20
ADMIN_LEVEL.manage
Integer
final
Can approve posts, and give people any adminLevel < 'manage'
Default: 30
ADMIN_LEVEL.max
Integer
final
Max admin level
Default: 40
ADMIN_LEVEL.none
Integer
final
Cannot do anything related to admin / users
Default: 0
ADMIN_LEVEL.own
Integer
final
Can give people any adminLevel <= 'own'
Default: 40
ADMIN_LEVEL.tell
Integer
final
Can prove things about the stream's content or participants
Default: 10
READ_LEVEL.content
Integer
final
Can see the stream's content
Default: 20
READ_LEVEL.max
Integer
final
Max read level
Default: 40
READ_LEVEL.messages
Integer
final
Can play stream in a player
Default: 40
READ_LEVEL.none
Integer
final
Can't see the stream
Default: 0
READ_LEVEL.participants
Integer
final
Can see participants in the stream
Default: 30
READ_LEVEL.relations
Integer
final
Can see relations to other streams
Default: 25
READ_LEVEL.see
Integer
final
Can see icon and title
Default: 10
WRITE_LEVEL.close
Integer
final
Don't delete, just prevent any new changes to stream however, joining and leaving is still ok
Default: 40
WRITE_LEVEL.closePending
Integer
final
Can post a message requesting to close the stream
Default: 35
WRITE_LEVEL.edit
Integer
final
Can post messages to edit stream content immediately
Default: 30
WRITE_LEVEL.join
Integer
final
Can become a participant, chat, and leave
Default: 10
WRITE_LEVEL.max
Integer
final
Max write level
Default: 40
WRITE_LEVEL.messages
Integer
final
Can post messages which appear immediately
Default: 20
WRITE_LEVEL.none
Integer
final
Cannot affect stream or participants list
Default: 0
WRITE_LEVEL.postPending
Integer
final
Can post messages, but manager must approve
Default: 15
WRITE_LEVEL.relate
Integer
final
Can post messages relating other streams to this one
Default: 23
WRITE_LEVEL.relations
Integer
final
Can update properties of relations directly
Default: 25
WRITE_LEVEL.suggest
Integer
final
Can post messages requesting edits of stream
Default: 28
WRITE_LEVEL.vote
Integer
final
Can vote for a relation message posted to the stream.
Default: 13
Events
create.onError
Occurs when Streams.create encounters an error trying to create a stream on the server
get.onError
Occurs when Streams.get encounters an error loading a stream from the server
get.onStream
Occurs when Streams.get constructs a stream loaded from the server
onAvatar
Returns Q.Event that occurs when an avatar has been returned, possibly because it was refreshed. Any tools displaying an avatar should add a handler to this event, and refresh their avatar displays.
Event Payload:
-
userId
Stringthe id of the user whose avatar it is
onConstruct
Returns Q.Event that occurs after a stream is constructed on the client side
Event Payload:
-
type
Stringtype of the stream being constructed on the client side
onError
This event is fired if an error occurs in any Streams function
onInviteComplete
Event occurs when the user enters their full name after following an invite, completing their registration
onInvitedDialog
This event is fired when a dialog is presented to a newly invited user.
onInvitedUserAction
This event is fired when the invited user takes the first action after entering their name. It is a good time to start playing any audio, 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.
onMessageUnseen
Returns Q.Event that occurs on a message coming in that hasn't been seen yet. You can call .seen() on the message to mark it as seen, otherwise if no handlers mark it seen, some other code might show a badge for "unseen" messages.
Event Payload:
-
stream
Streams.Stream -
message
Streams.Message
onRefresh
Returns Q.Event that occurs when a stream is obtained via Streams.get() and gets pulled from the server again (whether it changed or not). If you just want to take some action whenever any field in the stream changes (via Stream.update() method, which is called for most standard Streams/ messages) then use the Streams.Stream.onFieldChanged event factory instead.
Event Payload:
-
type
Stringtype of the stream being refreshed on the client side