1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| const conversation = { conversationType: RongIMLib.ConversationType.PRIVATE, targetId: "userID", };
function sendTextMsg() { const message = new RongIMLib.TextMessage({ content: "这里是发送的文本消息内容", }); RongIMLib.sendMessage(conversation, message) .then((res) => { console.log("发送回调", res); }) .catch((err) => { console.log(err); }); }
function sendImgMsg() { const msgBody = { file, user: { id: "", name: "", portraitUri: "", extra: "" }, extra: "连同图片一起发送的文本", }; const hooks = { onProgress(progress) { console.log("progress", progress); }, onComplete(fileInfo) { console.log(fileInfo.url); }, }; const options = { contentDisposition: "inline", }; RongIMLib.sendImageMessage(conversation, msgBody, hooks, options).then( ({ code, data }) => { console.log(data); if (code === 0) { console.log("发送成功"); } return alert("图片发送失败"); } ); }
|