You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A class that handles the interactions with a specific channel.
Usage
letchannel=this.props.channel// specify channel specific eventschannel.onMessageAdded=(message)=>console.log(message.author+": "+message.body);channel.onTypingStarted=(member)=>console.log(member.identity+" started typing...");channel.onTypingEnded=(member)=>console.log(member.identity+" stopped typing...");channel.onMemberAdded=(member)=>console.log(member.identity+" joined "+channel.friendlyName);channel.getMessages(20).then((messages)=>{// array of message instancesconsole.log(messages)}// mark all messages as read, etcchannel.setAllMessagesConsumed()// sending a message<TextInputonChangeText={(body)=>{this.setState({body});channel.typing();}}onSubmitEditing={()=>channel.sendMessage(this.state.body)}/>
Properties
Name
Type
Description
sid
String
The sid of the channel (shouldn't need this in an instance, all methods are pre-bound)
friendlyName
String
Friendly name of the channel
uniqueName
String
Unique name of the channel
attributes
Object
Any custom attributes added to the channel
synchronizationStatus
Constants.TCHChannelSynchronizationStatus
Current synchronization status of the channel
status
Constants.TCHChannelStatus
The user's association with the channel
type
Constants.TCHChannelType
Whether the channel is public or private
dateCreated
Date
When the channel was created
dateUpdated
Date
When the channel was last updated
createdBy
String
The identity of the channel creator
On public channels accessed through getPublicChannels, you will have these additional properties
Name
Type
Description
messagesCount
Number
Count of messages
membersCount
Number
Count of members
Methods
advanceLastConsumedMessageIndex(index)
Name
Type
Description
index
Number
The index of the message consumed (should be greater than last consumed index)
add(identity) : Promise
Name
Type
Description
identity
String
The identity of the user to add (without inviting)
close()
Close the channel and remove all listeners (call in componentWillUnmount).
declineInvitation() : Promise
Decline joining the channel, in reply to an invitation.
destroy() : Promise
Delete a channel.
getLastConsumedMessageIndex() : Promise
Returns Number index.
getMember(identity) : Promise
Name
Type
Description
identity
String
The identity of the user to return
Returns a Member instance.
getMembers() : Promise
Returns an Array<Member> instances.
getMembersCount() : Promise
Returns the number of members for this channel.
getMessage(index) : Promise
Name
Type
Description
index
Number
The index of the message to get
getMessages(count = 10) : Promise
Name
Type
Description
count
Number
Default 10. The number of most recent messages to get
The index of the last message reported as read (may refer to a deleted message)
getMessagesCount() : Promise
Returns the number of messages for this channel.
getUnconsumedMessagesCount() : Promise
Returns the number of unread messages for this channel.
initialize() : Promise
Synchronize the channel with the server. May not be needed depending on if you set synchronizationStrategy to All during the client initialization. Otherwise, without calling initialize you won't get notificed when any events pertaining to this channel occur.
invite(identity) : Promise
Name
Type
Description
identity
String
The identity of the user to invite
join() : Promise
Join the channel (if not a member or in reply to an invitation).
leave() : Promise
Leave a channel.
remove(identity) : Promise
Name
Type
Description
identity
String
The identity of the user to remove
removeMessage(index) : Promise
Name
Type
Description
index
Number
The index of the message to delete
sendMessage(body, attributes) : Promise
Name
Type
Description
body
String
The message body
attributes
Object
Any properties you want associated with the message (Optional)
setAllMessagesConsumed()
Update the last consumed index for this Member and Channel to the max message currently on this device.
setAttributes(attributes) : Promise
Name
Type
Description
attributes
Object
Any properties you want associated with the channel
setFriendlyName(friendlyName) : Promise
Name
Type
Description
friendlyName
String
Specify a friendly name for the channel
setLastConsumedMessageIndex(index)
Name
Type
Description
index
Number
The index of the consumed message
Returns a Message instance.
setUniqueName(uniqueName) : Promise
Name
Type
Description
uniqueName
String
Specify a unique name for the channel
typing()
Invoke whenever the user is typing a message.
Events
onChanged()
onDeleted()
onMemberChanged(member)
Name
Type
Description
member
Member
The changed member instance
onMemberJoined(member)
Name
Type
Description
member
Member
The instance of the new member
onMemberLeft(member)
Name
Type
Description
member
Member
The member instance who left
onMemberUserInfoUpdated({updated, userInfo})iOS Only