发送接收文本消息
发送文本消息
当加入房间之后,可以使用 TrackModeSession
提供的方法 sendCustomMessage
向房间内的其他人发送文本消息。
例如,下面向 userId
为 user1
的用户发送了一条消息。
myRoom.sendCustomMessage("Hi!", ["user1"]);
下面向 userId
为 user1
和 user2
的两个用户各发送了一条消息。
myRoom.sendCustomMessage("Hi!", ["user1", "user2"]);
下面是向房间内所有人广播了一条消息。
myRoom.sendCustomMessage("Hi!");
接收文本消息
当加入房间之后,可以通过监听 messages-received
事件,来获取房间内其他人发给自己的消息。例如:
myRoom.on("messages-received", msgData => {
console.log(msgData);
})