Options
All
  • Public
  • Public/Protected
  • All
Menu

A channel represents a remote channel of communication between multiple Programmable Chat clients.

Hierarchy

  • ReplayEventEmitter<ChannelEvents>
    • Channel

Index

Events

Static Readonly memberJoined

memberJoined: "memberJoined" = 'memberJoined'

Fired when a member has joined the channel.

Parameters:

  1. Member member - member that joined the channel

Static Readonly memberLeft

memberLeft: "memberLeft" = 'memberLeft'

Fired when a member has left the channel.

Parameters:

  1. Member member - member that left the channel

Static Readonly memberUpdated

memberUpdated: "memberUpdated" = 'memberUpdated'

Fired when data of a member has been updated.

Parameters:

  1. object data - info object provided with the event. It has the following properties:

Static Readonly messageAdded

messageAdded: "messageAdded" = 'messageAdded'

Fired when a new message has been added to the channel.

Parameters:

  1. Message message - message that has been added

Static Readonly messageRemoved

messageRemoved: "messageRemoved" = 'messageRemoved'

Fired when message is removed from the channel's message list.

Parameters:

  1. Message message - message that has been removed

Static Readonly messageUpdated

messageUpdated: "messageUpdated" = 'messageUpdated'

Fired when data of a message has been updated.

Parameters:

  1. object data - info object provided with the event. It has the following properties:

Static Readonly removed

removed: "removed" = 'removed'

Fired when the channel was destroyed or the currently-logged-in user has left private channel.

Parameters:

  1. Channel channel - channel that has been removed

Static Readonly typingEnded

typingEnded: "typingEnded" = 'typingEnded'

Fired when a member has stopped typing.

Parameters:

  1. Member member - the member that has stopped typing

Static Readonly typingStarted

typingStarted: "typingStarted" = 'typingStarted'

Fired when a member has started typing.

Parameters:

  1. Member member - the member that has started typing

Static Readonly updated

updated: "updated" = 'updated'

Fired when the data of the message has been updated.

Parameters:

  1. object data - info object provided with the event. It has the following properties:

Properties

Readonly sid

sid: string

Unique system identifier of the channel.

Accessors

attributes

  • get attributes(): Object
  • Custom attributes of the channel.

    Returns Object

createdBy

  • get createdBy(): string
  • Identity of the user that created this channel.

    Returns string

dateCreated

  • get dateCreated(): any
  • Date this channel was created on.

    Returns any

dateUpdated

  • get dateUpdated(): any
  • Date this channel was last updated on.

    Returns any

friendlyName

  • get friendlyName(): string
  • Name of the channel.

    Returns string

isPrivate

  • get isPrivate(): boolean
  • Signifies whether the channel is private.

    Returns boolean

lastConsumedMessageIndex

  • get lastConsumedMessageIndex(): number
  • Index of the last message the user has read in this channel.

    Returns number

lastMessage

  • Last message sent to this channel.

    Returns LastMessage

notificationLevel

state

status

type

uniqueName

  • get uniqueName(): string
  • Unique name of the channel.

    Returns string

Methods

add

  • add(identity: string): Promise<void>
  • Add a member to the channel by its identity.

    Parameters

    • identity: string

      Identity of the Client to add.

    Returns Promise<void>

advanceLastConsumedMessageIndex

  • advanceLastConsumedMessageIndex(index: number): Promise<number>
  • Advance the channel's last consumed message index to the current read horizon. Rejects if the user is not a member of the channel. Last consumed message index is updated only if the new index value is higher than the previous.

    Parameters

    • index: number

      Message index to advance to.

    Returns Promise<number>

    Resulting unread messages count in the channel.

decline

  • Decline an invitation to the channel and unsubscribe from its events.

    Returns Promise<Channel>

delete

  • Delete the channel and unsubscribe from its events.

    Returns Promise<Channel>

getAttributes

  • getAttributes(): Promise<any>
  • Get the custom attributes of this Channel.

    Note: Channel.attributes will be empty for public channels until this function is called.

    Returns Promise<any>

getMemberByIdentity

  • getMemberByIdentity(identity: string): Promise<Member>
  • Get a member by its identity.

    Parameters

    • identity: string

      Member identity.

    Returns Promise<Member>

getMemberBySid

  • getMemberBySid(memberSid: string): Promise<Member>
  • Get a member by its SID.

    Parameters

    • memberSid: string

      Member SID.

    Returns Promise<Member>

getMembers

  • getMembers(): Promise<Member[]>
  • Get a list of all the members who are joined to this channel.

    Returns Promise<Member[]>

getMembersCount

  • getMembersCount(): Promise<number>
  • Get channel members count.

    This method is semi-realtime. This means that this data will be eventually correct, but will also be possibly incorrect for a few seconds. The Programmable Chat system does not provide real time events for counter values changes.

    This is useful for any UI badges, but it is not recommended to build any core application logic based on these counters being accurate in real time.

    Returns Promise<number>

getMessages

  • getMessages(pageSize?: number, anchor?: number, direction?: "backwards" | "forward"): Promise<Paginator<Message>>
  • Return messages from the channel using the paginator interface.

    Parameters

    • Optional pageSize: number

      Number of messages to return in a single chunk. Default is 30.

    • Optional anchor: number

      Index of the newest message to fetch. Default is from the end.

    • Optional direction: "backwards" | "forward"

      Query direction. By default it queries backwards from newer to older. The "forward" value will query in the opposite direction.

    Returns Promise<Paginator<Message>>

    A page of messages.

getMessagesCount

  • getMessagesCount(): Promise<number>
  • Get the total message count in the channel.

    This method is semi-realtime. This means that this data will be eventually correct, but will also be possibly incorrect for a few seconds. The Programmable Chat system does not provide real time events for counter values changes.

    This is useful for any UI badges, but it is not recommended to build any core application logic based on these counters being accurate in real time.

    Returns Promise<number>

getUnconsumedMessagesCount

  • getUnconsumedMessagesCount(): Promise<number>
  • Get unread messages count for the user if they are a member of this channel. Rejects if the user is not a member of the channel.

    Use this method to obtain the number of unread messages together with Channel.updateLastConsumedMessageIndex instead of relying on the message indices which may have gaps. See Message.index for details.

    This method is semi-realtime. This means that this data will be eventually correct, but will also be possibly incorrect for a few seconds. The Programmable Chat system does not provide real time events for counter values changes.

    This is useful for any UI badges, but it is not recommended to build any core application logic based on these counters being accurate in real time.

    Returns Promise<number>

getUserDescriptors

  • Get user descriptors of this channel.

    Returns Promise<Paginator<UserDescriptor>>

invite

  • invite(identity: string): Promise<void>
  • Invite a user to the channel by their identity.

    Parameters

    • identity: string

      Identity of the user.

    Returns Promise<void>

join

  • Join the channel and subscribe to its events.

    Returns Promise<Channel>

leave

  • Leave the channel.

    Returns Promise<Channel>

removeMember

  • removeMember(member: string | Member): Promise<void>
  • Remove a member from the channel. When a string is passed as the argument, it will assume that the string is an identity.

    Parameters

    • member: string | Member

      Identity or the member object to remove.

    Returns Promise<void>

sendMessage

  • sendMessage(message: string | FormData | SendMediaOptions, messageAttributes?: any): Promise<number>
  • Send a message to the channel.

    Parameters

    • message: string | FormData | SendMediaOptions

      Message body for the text message, FormData or {@link Channel.MediaOptions) for media content. Sending FormData is supported only with the browser engine.

    • Optional messageAttributes: any

      Attributes for the message.

    Returns Promise<number>

    Index of the new message.

setAllMessagesConsumed

  • setAllMessagesConsumed(): Promise<number>
  • Set last consumed message index of the channel to the index of the last known message.

    Returns Promise<number>

    Resulting unread messages count in the channel.

setNoMessagesConsumed

  • setNoMessagesConsumed(): Promise<number>
  • Set all messages in the channel unread.

    Returns Promise<number>

    Resulting unread messages count in the channel.

setUserNotificationLevel

  • Set user notification level for this channel.

    Parameters

    Returns Promise<void>

typing

  • typing(): Promise<void>
  • 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 this method again you ensure that typing ended is not received.

    Returns Promise<void>

updateAttributes

  • updateAttributes(attributes: any): Promise<Channel>
  • Update the attributes of the channel.

    Parameters

    • attributes: any

      New attributes.

    Returns Promise<Channel>

updateFriendlyName

  • updateFriendlyName(friendlyName: string): Promise<Channel>
  • Update the friendly name of the channel.

    Parameters

    • friendlyName: string

      New friendly name.

    Returns Promise<Channel>

updateLastConsumedMessageIndex

  • updateLastConsumedMessageIndex(index: number): Promise<number>
  • Set the last consumed message index to the current read horizon.

    Parameters

    Returns Promise<number>

    Resulting unread messages count in the channel.

updateUniqueName

  • updateUniqueName(uniqueName: string): Promise<Channel>
  • Update the unique name of the channel.

    Parameters

    • uniqueName: string

      New unique name for the channel. Setting unique name to null removes it.

    Returns Promise<Channel>