|
@@ -15,6 +15,7 @@ const formatMessageExt = (message, ext) => {
|
|
|
...message,
|
|
|
content:ext.content,
|
|
|
msgId: ext.msgId,
|
|
|
+ // fromUuids: ext.fromUuid,
|
|
|
cc : ext.cc, // @群成员 0:全部
|
|
|
id : ext.id, // 真实消息id
|
|
|
quote : ext.quote, //引用的消息id
|
|
@@ -68,7 +69,7 @@ export const setMessageHook = (message, wsStore) => {
|
|
|
// console.log('消息撤回',message)
|
|
|
// 更新消息
|
|
|
if (msg && msg.isTemp) {
|
|
|
- wsStore.modifyMessage({isTemp: true}, msg.id, message.to)
|
|
|
+ wsStore.modifyMessageId({isTemp: true}, msg, message.to)
|
|
|
} else {
|
|
|
wsStore.deleteMessage(message, msg.id, message.to);
|
|
|
}
|
|
@@ -89,14 +90,14 @@ export const setMessageHook = (message, wsStore) => {
|
|
|
|
|
|
// 语音和视频挂断/拒接消息处理
|
|
|
if (Constant.MSG_AUDIO_GROUP.includes(message.contentType)) {
|
|
|
- let sender = wsStore.toUserInfo.sender || {
|
|
|
+ let sender = wsStore.toUserAudioInfo.sender || {
|
|
|
uuid: walletStore.account,
|
|
|
nickname: walletStore.username,
|
|
|
avatar: walletStore.avatar,
|
|
|
}
|
|
|
wsStore.pushMessage({
|
|
|
...message,
|
|
|
- align: sender.uuid != wsStore.toUserInfo.uuid ? 'right' : 'left',
|
|
|
+ align: sender.uuid == message.from ? 'right' : 'left',
|
|
|
fromAvatar: message.avatar,
|
|
|
toUuid: message.to,
|
|
|
fromUuid: message.from,
|
|
@@ -106,16 +107,18 @@ export const setMessageHook = (message, wsStore) => {
|
|
|
}
|
|
|
// 文本消息
|
|
|
if (message.contentType == MsgType.MSG_TYPE.TEXT) {
|
|
|
+ msg.isTemp=false;
|
|
|
wsStore.pushMessage(formatMessageExt({
|
|
|
...message,
|
|
|
align: 'right',
|
|
|
fromAvatar: message.avatar,
|
|
|
toUuid:message.to,
|
|
|
- fromUuid:message.from
|
|
|
+ fromUuid:message.from,
|
|
|
}, msg), message.to);
|
|
|
}
|
|
|
// 音频消息
|
|
|
if (message.contentType === MsgType.MSG_TYPE.AUDIO) {
|
|
|
+ msg.isTemp = false;
|
|
|
const blob = new Blob([message.file], { type: message.fileSuffix });
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
wsStore.pushMessage(formatMessageExt({
|
|
@@ -191,7 +194,7 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
// 处理消息回执, 更新消息id
|
|
|
if (message.messageType === MsgType.MESSAGE_RECEIPT) {
|
|
|
// 检测是否在群内或是好友
|
|
|
- wsStore.modifyMessageId(message, msg)
|
|
|
+ wsStore.modifyMessageId(message, { id: msg.id, uniqueId: msg.uniqueId, msgId: msg.msgId }, message.from)
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -201,7 +204,7 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
wsStore.systemReceiptMessage(message, msg)
|
|
|
// 更新消息
|
|
|
if (msg && msg.isTemp) {
|
|
|
- wsStore.modifyMessage({isTemp: true}, msg.id)
|
|
|
+ wsStore.modifyMessageId({isTemp: true}, msg,message.from)
|
|
|
} else {
|
|
|
wsStore.deleteMessage(message, msg.id);
|
|
|
}
|
|
@@ -212,8 +215,9 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
else {
|
|
|
wsStore.pushMessage({
|
|
|
...message,
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ toUuid: wsStore.toUserInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : message.to,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
align: 'left',
|
|
|
content: `${(msg.fromUsername || '对方')}撤回了一条消息`,
|
|
|
fromAvatar: message.avatar,
|
|
@@ -263,8 +267,9 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
contentType,
|
|
|
messageType: MsgType.MESSAGE_TYPE_GROUP,
|
|
|
fromAvatar: message.avatar,
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ toUuid: wsStore.toUserInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : message.to,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
});
|
|
|
notifications(wsStore);
|
|
|
return;
|
|
@@ -274,7 +279,7 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
if (Constant.MSG_AUDIO_GROUP.includes(message.contentType)) {
|
|
|
// 消息送达回执发送
|
|
|
wsStore.systemReceiptMessage(message, msg)
|
|
|
- let sender = wsStore.toUserInfo.sender || {
|
|
|
+ let sender = wsStore.toUserAudioInfo.sender || {
|
|
|
uuid: walletStore.account,
|
|
|
nickname: walletStore.username,
|
|
|
avatar: walletStore.avatar,
|
|
@@ -282,9 +287,10 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
// 语音消息
|
|
|
wsStore.pushMessage({
|
|
|
...message,
|
|
|
- align: sender.uuid != wsStore.toUserInfo.uuid?'right':'left',
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ align: sender.uuid != message.from?'right':'left',
|
|
|
+ toUuid: wsStore.toUserAudioInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : msg.fromUuid,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
content: message.contentType === Constant.REJECT_AUDIO_ONLINE || message.contentType === Constant.REJECT_VIDEO_ONLINE ? '[对方拒绝]' : '[通话结束]',
|
|
|
sender,
|
|
|
fromAvatar: message.avatar,
|
|
@@ -297,8 +303,9 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
wsStore.systemReceiptMessage(message, msg)
|
|
|
wsStore.pushMessage(formatMessageExt({
|
|
|
...message,
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ toUuid: wsStore.toUserInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : msg.fromUuid,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
align: 'left',
|
|
|
fromAvatar: message.avatar,
|
|
|
}, msg));
|
|
@@ -317,8 +324,9 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
wsStore.pushMessage(formatMessageExt({
|
|
|
...message,
|
|
|
file: audioUrl,
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ toUuid: wsStore.toUserInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : msg.fromUuid,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
align: 'left',
|
|
|
fromAvatar: message.avatar,
|
|
|
}, msg));
|
|
@@ -334,8 +342,9 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
wsStore.pushMessage(formatMessageExt({
|
|
|
...message,
|
|
|
file: url,
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ toUuid: wsStore.toUserInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : msg.fromUuid,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
align: 'left',
|
|
|
fromAvatar: message.avatar,
|
|
|
}, msg));
|
|
@@ -351,8 +360,9 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
wsStore.pushMessage(formatMessageExt({
|
|
|
...message,
|
|
|
file: url,
|
|
|
- toUuid: message.to,
|
|
|
- fromUuid: message.from,
|
|
|
+ toUuid: wsStore.toUserInfo.type == 'user' ? message.to : message.from,
|
|
|
+ fromUuid: wsStore.toUserInfo.type == 'user' ? message.from : msg.fromUuid,
|
|
|
+ // fromUuids: msg?.fromUuid,
|
|
|
align: 'left',
|
|
|
fromAvatar: message.avatar,
|
|
|
}, msg));
|
|
@@ -372,10 +382,14 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
wsStore.toUserAudioInfo = {
|
|
|
uuid: message.from,
|
|
|
type: "user",
|
|
|
- // 接收到来自谁的拨号请求
|
|
|
- fromUuid: message.from,
|
|
|
- fromAvatar: message.avatar,
|
|
|
- fromUsername: message.fromUsername,
|
|
|
+ // 接收到来自谁的拨号请求信息
|
|
|
+ toUuid: message.from,
|
|
|
+ toAvatar: message.avatar,
|
|
|
+ toUsername: message.fromUsername,
|
|
|
+ // 自己的信息
|
|
|
+ fromUuid: message.to,
|
|
|
+ fromAvatar: walletStore.avatar,
|
|
|
+ fromUsername: wsStore.toUserInfo.nickname,
|
|
|
// 发送者信息
|
|
|
sender: {
|
|
|
uuid: message.from,
|
|
@@ -383,17 +397,17 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
nickname: message.fromUsername,
|
|
|
},
|
|
|
};
|
|
|
- wsStore.toUserInfo = {
|
|
|
- ...wsStore.toUserInfo,
|
|
|
- uuid: message.from,
|
|
|
- type: "user",
|
|
|
- unReadNum: 1,
|
|
|
- sender: {
|
|
|
- uuid: message.from,
|
|
|
- avatar: message.avatar,
|
|
|
- nickname: message.fromUsername,
|
|
|
- },
|
|
|
- };
|
|
|
+ // wsStore.toUserInfo = {
|
|
|
+ // ...wsStore.toUserInfo,
|
|
|
+ // uuid: message.from,
|
|
|
+ // type: "user",
|
|
|
+ // unReadNum: 1,
|
|
|
+ // sender: {
|
|
|
+ // uuid: message.from,
|
|
|
+ // avatar: message.avatar,
|
|
|
+ // nickname: message.fromUsername,
|
|
|
+ // },
|
|
|
+ // };
|
|
|
// 调起通话界面
|
|
|
const rtcStore = useWebRTCStore();
|
|
|
rtcStore.streamType = message.contentType == Constant.DIAL_AUDIO_ONLINE ? 'audio' :'video'
|
|
@@ -529,11 +543,15 @@ export const handleMessageHook = async (payload, wsStore) => {
|
|
|
.then(() => rtcStore.createAnswer())
|
|
|
.then((answer) => {
|
|
|
console.log('发送answer给呼叫者', answer)
|
|
|
- // 发送给呼叫者
|
|
|
+ // 发送给被呼叫者(拨打者)
|
|
|
wsStore.sendMessage({
|
|
|
content: JSON.stringify(answer),
|
|
|
type: Constant.MESSAGE_TRANS_TYPE,
|
|
|
messageType: message.contentType,
|
|
|
+ fromUsername: wsStore.toUserAudioInfo.fromUsername,
|
|
|
+ avatar: wsStore.toUserAudioInfo.fromAvatar,
|
|
|
+ to: wsStore.toUserAudioInfo.toUuid,
|
|
|
+ from: wsStore.toUserAudioInfo.fromUuid,
|
|
|
});
|
|
|
})
|
|
|
.catch((error) => {
|
|
@@ -556,6 +574,7 @@ const messageCallback = (contentType, state)=>{
|
|
|
// 创建呼叫:开启语音电话
|
|
|
const startAudioOnline = (video, state) => {
|
|
|
const rtcStore = useWebRTCStore();
|
|
|
+ const wsStore = useWebSocketStore();
|
|
|
// 初始化webrtc连接
|
|
|
rtcStore.initConnection(true, video);
|
|
|
// 获取音视频数据流
|
|
@@ -571,11 +590,15 @@ const startAudioOnline = (video, state) => {
|
|
|
})
|
|
|
.then((offer) => {
|
|
|
console.log('caller', offer)
|
|
|
- // 发送offer给被呼叫者
|
|
|
+ // 发送offer给被呼叫者(接听者)
|
|
|
state.sendMessage({
|
|
|
contentType: video? Constant.VIDEO_ONLINE: Constant.AUDIO_ONLINE, // 消息内容类型
|
|
|
content: JSON.stringify(offer),
|
|
|
type: Constant.MESSAGE_TRANS_TYPE,
|
|
|
+ fromUsername: wsStore.toUserAudioInfo.fromUsername,
|
|
|
+ avatar: wsStore.toUserAudioInfo.fromAvatar,
|
|
|
+ to: wsStore.toUserAudioInfo.toUuid,
|
|
|
+ from: wsStore.toUserAudioInfo.fromUuid,
|
|
|
});
|
|
|
})
|
|
|
.catch((error) => {
|