Sending a chat message
As mentioned in introduction, there are 3 types of chat
messages - text messages, images, and files. There is a method in meeting.chat
to send a message of each type.
Send a text message
To send a text message, the meeting.chat.sendTextMessage()
method can be used.
This accepts a string message
and sends it to the room.
const message = 'Is this the real life?';
await meeting.chat.sendTextMessage(message);
Send an image
You can send an image with the help of meeting.chat.sendImageMessage()
. This
accepts an image of type File
, and sends it to the participants in the
meeting.
async function onSendImage() {
// Get the image uri and create an object with the following fields
const res = await DocumentPicker.pickSingle({
type: [DocumentPicker.types.images],
});
const image = {
uri: res.uri,
name: res.name,
size: res.size,
type: res.type,
};
await meeting.chat.sendImageMessage(image);
}
Send a file
Sending a file is quite similar to sending an image. The only difference is that
when you send an image, a preview will be shown in the meeting chat, which is
not the case for sending files. That being said, an image can be sent as a file
too using meeting.chat.sendFileMessage()
.
async function onSendFile() {
// Get the file uri and create an object with the following fields
const res = await DocumentPicker.pickSingle({
type: [DocumentPicker.types.allFiles],
});
const file = {
uri: res.uri,
name: res.name,
size: res.size,
type: res.type,
};
await meeting.chat.sendFileMessage(file);
}
Extra
There is also a common method called meeting.chat.sendMessage()
that can be
used to send any of the 3 types of messages displayed above. It essentially
calls one of the methods from above depending upon the type of payload you send
to the method. The sendMessage()
method accepts a parameter message
of the
following type:
async function sendMessage(
message: { type: 'text', message: string }
| { type: 'image', image: File }
| { type: 'file', file: File },
) {...}
Here's how you would use the sendMessage()
method to send a text message.
const message = 'Is this just fantasy?';
await meeting.chat.sendMessage({ type: 'text', message });