Class: Channel

Channel

A Channel represents a remote channel of communication between multiple Programmable Chat Clients

Properties:
Name Type Description
attributes Object The Channel's custom attributes
createdBy String The identity of the User that created this Channel
dateCreated Date The Date this Channel was created
dateUpdated Date The Date this Channel was last updated
friendlyName String The Channel's name
isPrivate Boolean Whether the channel is private (as opposed to public)
lastConsumedMessageIndex Number Index of the last Message the User has consumed in this Channel
sid String The Channel's unique system identifier
status 'unknown' | 'known' | 'invited' | 'joined' | 'failed' Whether the Channel is 'known' to local Client, Client is 'invited' to or is 'joined' to this Channel
type 'public' | 'private' The Channel's type as a String: ['private', 'public']
uniqueName String The Channel's unique name (tag)
Fires:

Methods


add(identity)

Add a participant to the Channel by its Identity.
Parameters:
Name Type Description
identity String Identity of the Client to add
Returns:
Type
Promise.<(void|Error|SessionError)>

advanceLastConsumedMessageIndex(index)

Advance last consumed Channel's Message index to current consumption horizon. Rejects if User is not Member of Channel. Last consumed Message index is updated only if new index value is higher than previous.
Parameters:
Name Type Description
index Number Message index to advance to as last read
Returns:
Type
Promise.<(void|Error|SessionError)>

decline()

Decline an invitation to the Channel and unsubscribe from its events.
Returns:
Type
Promise.<(Channel|SessionError)>

delete()

Delete the Channel and unsubscribe from its events.
Returns:
Type
Promise.<(Channel|SessionError)>

getAttributes()

Get the custom attributes of this Channel.
NOTE: Channel's attributes property will be empty for public channels until this function is called.
Returns:
Type
Promise.<Object>

getMembers()

Get a list of all Members joined to this Channel.
Returns:
Type
Promise.<Array.<Member>>

getMembersCount()

Get channel members count.
Returns:
Type
Promise.<number>

getMessages( [pageSize] [, anchor] [, direction])

Returns messages from channel using paginator interface.
Parameters:
Name Type Argument Default Description
pageSize Number <optional>
30 Number of messages to return in single chunk
anchor Number <optional>
Index of newest Message to fetch. From the end by default
direction String <optional>
backwards Query direction. By default it query backwards from newer to older. 'forward' will query in opposite direction
Returns:
page of messages
Type
Promise.<Paginator.<Message>>

getMessagesCount()

Get total message count in a channel.
Returns:
Type
Promise.<number>

getUnconsumedMessagesCount()

Get unconsumed messages count for User if he is Member of this Channel. Rejects if User is not Member of Channel.
Returns:
Type
Promise.<number>

getUserDescriptors()

Gets User Descriptors for this channel.
Returns:
Type
Promise.<Paginator.<UserDescriptor>>

invite(identity)

Invite a user to the Channel by their Identity.
Parameters:
Name Type Description
identity String Identity of the user to invite
Returns:
Type
Promise.<(void|Error|SessionError)>

join()

Join the Channel and subscribe to its events.
Returns:
Type
Promise.<(Channel|SessionError)>

leave()

Leave the Channel.
Returns:
Type
Promise.<(Channel|SessionError)>

removeMember(member)

Remove a Member from the Channel.
Parameters:
Name Type Description
member String identity of member to remove
Returns:
Type
Promise.<(void|Error|SessionError)>

sendMessage(messageBody, messageAttributes)

Send a Message in the Channel.
Parameters:
Name Type Description
messageBody String The message body
messageAttributes Object attributes for the message
Returns:
Type
Promise.<String>

setAllMessagesConsumed()

Set last consumed Channel's Message index to last known Message's index in this Channel.
Returns:
Type
Promise.<Channel>

setNoMessagesConsumed()

Set all messages in the channel unread.
Returns:
Type
Promise.<Channel>

typing()

Send a notification to the server indicating that this Client is currently typing in this Channel. Typing ended notification is sent after a while automatically, but by calling again this method you ensure typing ended is not received.
Returns:
Type
Promise.<(void|SessionError)>

updateAttributes(attributes)

Update the Channel's attributes.
Parameters:
Name Type Description
attributes Object The new attributes object
Returns:
Type
Promise.<(Channel|Error|SessionError)>

updateFriendlyName(name)

Update the Channel's friendlyName.
Parameters:
Name Type Description
name String The new Channel friendlyName
Returns:
Type
Promise.<(Channel|SessionError)>

updateLastConsumedMessageIndex(index)

Set last consumed Channel's Message index to current consumption horizon.
Parameters:
Name Type Description
index Number | null Message index to set as last read. Null if no messages have been read
Returns:
Type
Promise.<(void|Error|SessionError)>

updateUniqueName(uniqueName)

Update the Channel's unique name.
Parameters:
Name Type Description
uniqueName String The new Channel uniqueName
Returns:
Type
Promise.<(Channel|SessionError)>

Events


memberJoined

Fired when a Member has joined the Channel.
Type: Member

memberLeft

Fired when a Member has left the Channel.
Type: Member

memberUpdated

Fired when a Member's fields has been updated.
Type: Member

messageAdded

Fired when a new Message has been added to the Channel.
Type: Message

messageRemoved

Fired when Message is removed from Channel's message list.
Type: Message

messageUpdated

Fired when an existing Message's fields are updated with new values.
Type: Message

typingEnded

Fired when a Member has stopped typing.
Type: Member

typingStarted

Fired when a Member has started typing.
Type: Member

updated

Fired when a Channel's attributes or metadata have been updated. During Channel's creation and initialization this event might be fired multiple times for same joined or created Channel as new data is arriving from different sources.
Type: Channel