// 请将 AppId 改为你自己的 AppId,否则无法本地测试
var appId = 'jrL2k7Ch5Xq1sYvAfuszevK2-gzGzoHsz';
var appKey = 'R3P55vWR0JayYC2BYIizfVLN';
AV.initialize (appId, appKey);
var roomId = 'xxx';
var user1Id = 'user1';
var user2Id = 'user2';
var room = null;
// 创建实时通信实例
var realtime = new AV.Realtime ({
appId: appId,
appKey: appKey,
// plugins: TypedMessagesPlugin,
});
async function init () {
var user1 = await realtime.createIMClient (user1Id);
var user2 = await realtime.createIMClient (user2Id);
room = await user1.getConversation (roomId);
if (!room) {
room = await user1.createConversation ({
name: 'LeanCloud-Conversation',
// 创建暂态的聊天室(暂态聊天室支持无限人员聊天)
members: [user1Id, user2Id],
});
}
await room
.join ()
.then (conversation => {
conversation.on ('MEMBER_INFO_UPDATED', function (message) {
console.log (message);
});
conversation.on ('MESSAGE', function (message) {
console.log (message);
});
conversation.on ('MESSAGE_UPDATE', function (message) {
console.log (message);
});
return conversation;
})
.catch (function (err) {
console.error (err);
});
await room.send (new AV.TextMessage ('1'));
await room.send (new AV.TextMessage ('2'));
await room.send (new AV.TextMessage ('3'));
}
init ().catch (function (err) {
console.error (err);
});
简单的创建聊天室+发送信息
但是
conversation.on ('MESSAGE', function (message) {
console.log (message);
});
conversation没有监听成功!!!!!????