Static
defaultAdds or updates the attributes of a specified channel.
This method updates the specified channel's attributes if it finds that the attributes has/have the same keys, or adds attributes to the channel if it does not.
Note
The channel ID of the specified channel.
An array of channel attributes.
Optional
options: ChannelAttributeOptionsOptions for this attribute operation. See ChannelAttributeOptions.
Adds or updates the local user's attributes.
This method updates the local user's attributes if it finds that the attributes has/have the same keys, or adds attributes to the local user if it does not.
The Promise resolves after successfully adding or updating the local user's attributes.
The attributes to be added or updated.
Clears all attributes of a specified channel.
Note
The channel ID of the specified channel.
Optional
options: ChannelAttributeOptionsOptions for this attribute operation. See ChannelAttributeOptions.
The unique channel name of the Agora RTM channel. The string length must be less than 64 bytes with the following character scope:
Note:
The uid of the callee.
Uploads a file to the Agora server to get an RtmFileMessage instance for file messages.
// Blob from a file
const blob = <Blob>
// Upload a file to create an RtmFileMessage instance
const mediaMessage = await client.createMediaMessageByUploading(blob, { messageType: 'FILE' })
// Send a peer-to-peer file message
await client.sendMessageToPeer(mediaMessage, <peerId>)
The Promise resolves after the file is successfully uploaded. The value of the Promise is an RtmFileMessage instance for sending channel messages and peer-to-peer messages.
Content of the file in binary format. Must not exceed 32 MB in size.
Optional
params: { Contains the name of the file to upload, the description of the file message, the thumbnail, and the message type.
fileName
, description
, and thumbnail
is 32 KB.fileName
, description
, and thumbnail
is 32 KB.fileName
, description
, and thumbnail
is 32 KB.Optional
description?: stringOptional
fileOptional
messageOptional
thumbnail?: BlobOptional
transHandler: MediaTransferHandlerA MediaTransferHandler instance. You can use this parameter to cancel an upload or report the upload progress.
Uploads an image to the Agora server to get an RtmImageMessage instance for sending image messages.
// Blob from an image
const blob = <Blob>
// Upload an image to create an RtmImageMessage instance
const mediaMessage = await client.createMediaMessageByUploading(blob, {
messageType: 'IMAGE',
fileName: 'file_name',
description: 'description',
thumbnail: blob,
width: 100,
height: 200,
thumbnailWidth: 50,
thumbnailHeight: 200,
})
// Send a peer-to-peer image message
await client.sendMessageToPeer(mediaMessage, <peerId>)
The Promise resolves after the image file is successfully uploaded. The value of the Promise is an RtmImageMessage instance for sending channel messages and peer-to-peer messages.
Content of the image in binary format. Must not exceed 32 MB in size.
Optional
params: { Contains the the width, height, name of the image file to upload, the description of the image message, the thumbnail, the width and height of the thumbnail, and the message type.
fileName
, description
, and thumbnail
is 32 KB.fileName
, description
, and thumbnail
is 32 KB.fileName
, description
, and thumbnail
is 32 KB.Optional
description?: stringOptional
fileOptional
height?: numberOptional
messageOptional
thumbnail?: BlobOptional
thumbnailOptional
thumbnailOptional
width?: numberOptional
transHandler: MediaTransferHandlerA MediaTransferHandler instance. You can use this parameter to cancel an upload or report the upload progress.
Creates a message instance for sending peer-to-peer or channel messages. For file messages and image messages, if the corresponding files or image files have been uploaded and the media IDs are still valid, you can call this method to get a message instance for sending peer-to-peer or channel messages.
const mediaMessage = client.createMessage({
mediaId: <mediaId>,
mediaType: 'FILE',
}) // Create an RtmFileMessage instance
A message instance to send. You can use the message instance to send peer-to-peer or channel messages.
A RtmMessage type.
An object that includes any property of RtmMessage.
Deletes the local user's attributes using attribute keys.
Note
The channel ID of the specified channel.
A list of channel attribute keys.
Optional
options: ChannelAttributeOptionsOptions for this attribute operation. See ChannelAttributeOptions.
Deletes the local user's attributes using attribute keys.
The Promise resolves after successfully deleting the local user's attributes.
A list of the attribute keys to be deleted.
Downloads a file or image file from the Agora server by media ID.
// Download a file blob
client.on('MessageFromPeer', async message => {
if (message.messageType === 'FILE') {
const blob = await client.downloadMedia(message.mediaId)
}
})
The Promise is resolved when the download is complete. The value of the Promise is the Blob
instance that represents the downloaded file or image file.
Media ID of the uploaded file or image file. The SDK automatically returns a media ID when a file or image file is successfully uploaded to the Agora server. You can use the RtmFileMessage instance or the RtmImageMessage instance to get the media ID of a file or image file.
Optional
transHandler: MediaTransferHandlerA MediaTransferHandler instance. You can use this parameter to cancel a download or report the download progress.
Gets all attributes of a specified channel.
Note
The ID of the specified channel.
Gets the attributes of a specified channel by attribute keys.
Note
The ID of the specified channel.
An array of attribute keys.
Gets the member count of specified channels.
Note
An array of the specified channel IDs.
Gets all attributes of a specified user.
The user ID of the specified user.
Gets the attributes of a specified user by attribute keys.
The user ID of the specified user.
An array of the attribute keys.
Logs in to the Agora RTM system.
If you use the Agora RTM SDK together with the Agora RTC SDK, Agora recommends that you avoid logging in to the RTM system and joining the RTC channel at the same time.
If the user logs in with the same uid from a different instance, the user will be kicked out of your previous login and removed from previously joined channels.
The Promise resolves after the user logs in to the Agora RTM system successfully.
Optional
token?: stringAn optional token generated by the app server.
The uid of the user logging in the Agora RTM system. The string length must be less than 64 bytes with the following character scope:
Note
number
type and recommend using the toString()
method to convert your non-string uid.Allows a user to log out of the Agora RTM system.
After the user logs out of the Agora RTM system, the SDK disconnects from the Agora RTM system and destroys the corresponding event listener.
The Promises resolves after the user logs out of the Agora RTM system and disconnects from WebSocket.
Rest
...args: any[]Adds the listener
function to the channel for the event named eventName
. See the EventEmitter
API documentation for other event methods on the RtmClient
instance.
The name of the RTM client event. See the property names in the RtmClientEvents for the list of events.
The callback function of the RTM client event.
Rest
...args: ListenerType<RtmClientEvents[EventName]>Rest
...args: ListenerType<RtmClientEvents[P]>Gets a list of the peers, to whose specific status you have subscribed.
The status type, to which you have subscribed. See RtmStatusCode.PeerSubscriptionOption.
Queries the online status of the specified users.
A list of the user IDs. The number of user IDs must not exceed 256.
Optional
event: PAllows a user to send an (offline) peer-to-peer message to a specified remote user.
You can send messages, including peer-to-peer and channel messages at a maximum frequency of 180 calls every three second.
client.sendMessageToPeer(
{ text: 'test peer message' }, // An RtmMessage object.
'demoPeerId', // The uid of the remote user.
).then(sendResult => {
if (sendResult.hasPeerReceived) {
// Your code for handling the event when the remote user receives the message.
} else {
// Your code for handling the event when the message is received by the server but the remote user cannot be reached.
}
}).catch(error => {
// Your code for handling the event when the message fails to be sent.
});
The Promise resolves after the message is successfully sent. The value of the Promise indicates whether the peer user is online and receives the message.
The message to be sent.
The uid of the peer user.
Optional
options: SendMessageOptionsEnables offline messaging. See SendMessageOptions.
Note
We do not support uids of thenumber
type. We recommend using the toString()
method to convert a non-string uid.Sets the attributes of a specified channel with new ones.
Note
The channel ID of the specified channel.
An array of channel attributes.
Optional
options: ChannelAttributeOptionsOptions for this attribute operation. See ChannelAttributeOptions.
Substitutes the local user's attributes with new ones.
The Promise resolves after successfully setting the local user's attributes.
The new attributes.
Modifies the RtmClient
instance configuration. The changes take effect immediately.
This method is deprecated as of v1.4.2. Please use updateConfig instead.
Subscribes to the online status of the specified users.
Note
An array of the specified user IDs.
Generated using TypeDoc
Class that represents the RTM client. You can call the createInstance method of AgoraRTM to create an
RtmClient
instance. This class is the entry point of the Agora RTM SDK.No Inherit Doc