Page({
data: {
messages: [],
},
createARoom() {
// const { userId } = store.getState().global;
// LeanCloud.createChatClient(userId).then(client => client.createChatRoom({ name: roomName })).then(r => console.log("r", r)).catch(e => console.error("e", e));
},
sendMessage() {
const message = new TextMessage("test" + (new Date()));
this.chatRoom.send(message).then(console.log).catch(console.error);
},
onLoad() {
// LeanCloud.joinAChatRoom(roomName);
// LeanCloud.findAChatRoom(roomId);
LeanCloud.findConversationById(roomId)
.then(chatRoom => chatRoom.join())
.then(chatRoom => {
this.chatRoom = chatRoom;
// listen on message
chatRoom.on(Event.MESSAGE, message => {
console.log("message", message);
});
// fetch messages
LeanCloud.fetchMessages(chatRoom.id)
.then(messages => this.setData({ messages }));
const message = new TextMessage("test" + (new Date()));
this.chatRoom.send(message).then(message => console.log(message));
});
},
});
onLoad里面消息能发出去,sendMessage就发不出去, 20秒后超时, Error: Command Timeout [cmd:2 op:null]