Show:

Streams.Stream Class

Extends Base.Streams.Stream
Module: Streams

Class representing 'Stream' rows in the 'Streams' database
stored primarily on publisherId's fm server

Constructor

Streams.Stream

(
  • fields
)

Parameters:

  • fields Object

    The fields values to initialize table row as an associative array of {column: value} pairs

Methods

addPermission

(
  • permission
)

Parameters:

calculateAccess

(
  • $asUserId=''
  • callback=null
)

Set access data for the stream. Acces data is calculated:

  1. from read/write/admin level fields of the stream
  2. from labels. Streams_Access record may contain <publisherId>, <streamName> (allowed exact match or generic name "<streamType>/") and <ofContactLabel>. If <publisherId> is recorded in Users_Contact to have either current user or <ofContactLabel> as contact, access claculation is considering such record.
  3. from user. Stream_Access record may contain <publisherId>, <streamName> (allowed exact match or generic name "<streamType>/") and <ofUserId>. Such record is considered in access calculation.

Parameters:

  • $asUserId='' String
  • callback=null Function
    Callback receives "error" as argument

clear

(
  • [key=null]
)

Clears the value of an extra field

Parameters:

  • [key=null] String optional

    A key to clear. If null, clears all keys.

clearAttribute

(
  • attributeName
)

Parameters:

  • attributeName String

    The name of the attribute to remove

get

(
  • key
  • [def=null]
)
Mixed

Gets the value of an extra field

Parameters:

  • key String
  • [def=null] Mixed optional

    The value to return if the field is not found. Defaults to undefined.

Returns:

Mixed:

The field if it is found, otherwise def or undefined.

getAllAttributes

() Object

Returns:

Object:

The object of all attributes set in the stream

getAllPermissions

() Array

Returns:

getAttribute

(
  • attributeName
  • def
)
Mixed

Parameters:

  • attributeName String

    The name of the attribute to get

  • def Mixed

    The value to return if the attribute is missing

Returns:

Mixed:

The value of the attribute, or the default value, or null

getConfigField

(
  • type
  • field
  • def
  • [merge=true]
)
static

Gets a value from the config corresponding to this stream type and a field name, using defaults from "Streams"/"types"/"*" and merging the value under "Streams"/"types"/$stream->type, if any.

Parameters:

  • type String

    The type of the stream

  • field String | Array

    The name of the field, or array of path keys

  • def Mixed

    The value to return if the config field isn't specified

  • [merge=true] Boolean optional

    if objects are found in both places, merge them

Returns:

mixed

getSubscriptionTemplate

(
  • className
  • ofUserId
  • [templateType=null]
)
Streams.Subscription | Array

Parameters:

  • className String

    The class extending Db_Row to fetch from the database

  • ofUserId String

    The id of the possible subscriber

  • [templateType=null] &integer optional

    Gets filled with the template type 0-4. Set to true to return all templates.

Returns:

Streams.Subscription | Array:

Returns the template subscription, or an array if $templateType is true

hasPermission

(
  • permission
  • UNKNOWN
)

Parameters:

iconUrl

(
  • [size=40]
)
String

Calculate the url of a stream's icon

Parameters:

  • [size=40] Number optional

    the size of the icon to render. Defaults to 40.

Returns:

String:

the url

inheritAccess

(
  • callback=null
)

Inherits access from any streams specified in the inheritAccess field.

Parameters:

  • callback=null Function
    Callback receives "error" and boolean as arguments - whether the access potentially changed.

join

(
  • options=
  • callback
)

If the user is not participating in the stream yet, inserts a participant record and posts a "Streams/join" type message to the stream. Otherwise update timestamp

Parameters:

  • options= Object

    {object} An associative array of options. 'userId' is mandatory. The keys can be:
    "subscribed" => boolean
    "posted" => boolean
    "reputation" => integer
    "reason" => string
    "enthusiasm" => decimal
    "userId" => The user who is joining the stream.

  • callback Function

    receives error if any and participant object as arguments

notify

(
  • participant
  • event
  • userId
  • message
  • [callback]
)

Notify participants of the stream depending on user status. Set the "Streams/notifications/onlyIfAllClientsOffline" config field to false to send offline notifications whenever all clients related to device sessions are offline, even if other clients are online.

Parameters:

  • participant Streams_Participant

    The stream participant to notify

  • event String

    The type of Streams event, such as "post" or "remove"

  • userId String

    The user who initiated the message

  • message Streams_Message

    Message on 'post' event or stream on other events

  • [callback] Function optional

    This would be called after all the notifying was done

notifyObservers

(
  • event
  • userId
  • message
)

Sends a message to all observers of a stream, i.e. socket clients besides the ones which are associated to participants. This can include socket clients that are not associated to any user.

Parameters:

  • event String

    The type of Streams event, such as "Streams/post" or "Streams/remove"

  • userId String

    User who initiated the event

  • message Streams_Message

notifyParticipants

(
  • event
  • userId
  • message
  • dontNotifyObservers
)

Sends a message to all participants of a stream. Also sends it to observers unless dontNotifyObservers is true.

Parameters:

  • event String

    The type of Streams event, such as "Streams/post" or "Streams/remove"

  • userId String

    User who initiated the event

  • message Streams_Message
  • dontNotifyObservers Boolean

post Currently this is not nearly as robust as the PHP method, and doesn't perform any access checks, so it is only meant to be called internally.

(
  • asUserId
  • fields
  • callback=null
)

Posts a message to the stream.

Parameters:

removePermission

(
  • permission
  • UNKNOWN
)

Parameters:

restrictedFromClient

(
  • streamType
  • fieldName
  • [whenCreating=false]
)
Boolean static

Find out whether a certain field is restricted from being edited by clients via the regular Streams REST API.

Parameters:

Returns:

set

(
  • key
  • value
)

Sets some extra data

Parameters:

  • key String
  • value Mixed

    The value to set for that extra data

setAttribute

(
  • attributeName
  • value
)

Parameters:

  • attributeName String

    The name of the attribute to set, or an array of {attributeName: attributeValue} pairs

  • value Mixed

    The value to set the attribute to

setUp

()

The setUp() method is called the first time an object of this class is constructed.

subscribe

(
  • [options={}]
)
Streams_Subscription | False

Subscribe to the stream's messages
If options are not given check the subscription templates:

  1. exact stream name and exact user id
  2. generic stream name and exact user id
  3. exact stream name and generic user
  4. generic stream name and generic user
default is to subscribe to ALL messages.
If options supplied - skip templates and use options

Using subscribe if subscription is already active will modify existing subscription - change type(s) or modify notifications

Parameters:

  • [options={}] Object optional
    • [filter] Array optional

      optional array with two keys

      • [types] Array optional
        array of message types, if this is empty then subscribes to all types
      • [notifications=0] Integer optional
        limit number of notifications, 0 means no limit
    • [untilTime=null] Datetime optional

      time limit, if any for subscription

    • [readyTime] Datetime optional

      time from which user is ready to receive notifications again

    • [userId] String optional

      the user subscribing to the stream. Defaults to the logged in user.

    • [rule=array()] Array optional

      optionally override the rule for new subscriptions

      • [deliver=array('to'] Array optional
        under "to" key, named the field under Streams/rules/deliver config, which will contain the names of destinations, which can include "email", "mobile", "email+pending", "mobile+pending"
      • [readyTime] Datetime optional
        time from which user is ready to receive notifications again
      • [filter] Array optional
        optionally set a filter for the rules to add
    • [skipRules] Boolean optional

      if true, do not attempt to create rules for new subscriptions

Returns:

Streams_Subscription | False:

testAdminLevel

(
  • level
  • callback=null
)
Boolean

Verifies wheather Stream can be administered. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check

Parameters:

  • level String | Integer

    String describing the level (see Streams.ADMIN_LEVEL) or integer

  • callback=null Function
    Callback receives "error" and boolean as arguments - whether the access is granted.

Returns:

testLevel

(
  • type
  • values
  • level
  • callback=null
)
private

Verifies wheather Stream can be handled. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check

Parameters:

  • type String
  • values String
  • level String | Integer
  • callback=null Function
    Callback receives "error" and boolean as arguments - whether the access is granted.

testPermission

(
  • permission
  • callback=null
)
Boolean

Verifies whether the user has at least the given permission

Parameters:

  • permission String | Array

    The name of the permission

  • callback=null Function
    Callback receives "error" and boolean as arguments - whether the access is granted.

Returns:

testReadLevel

(
  • level
  • callback=null
)
Boolean

Verifies wheather Stream can be read. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check

Parameters:

  • level String | Integer

    String describing the level (see Streams.READ_LEVEL) or integer

  • callback=null Function
    Callback receives "error" and boolean as arguments - whether the access is granted.

Returns:

testWriteLevel

(
  • level
  • callback=null
)
Boolean

Verifies wheather Stream can be written. Can be called syncronously and in such case skips verification of inherited access or asyncronously to make ful check

Parameters:

  • level String | Integer

    String describing the level (see Streams.WRITE_LEVEL) or integer

  • callback=null Function
    Callback receives "error" and boolean as arguments - whether the access is granted.

Returns:

updateParticipantCounts

(
  • newState
  • prevState
  • [callback=null]
)

Update the participant counts

Parameters:

  • newState String
  • prevState String
  • [callback=null] Function optional

    Callback receives "error" and "result" as arguments