diff --git a/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java b/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java index 14d5a14..d75ec6d 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/WebrtcController.java @@ -57,8 +57,8 @@ public class WebrtcController { @ApiOperation(httpMethod = "POST", value = "挂断") @PostMapping("/handup") - public Result leave(@RequestParam Long uid) { - webrtcService.leave(uid); + public Result handup(@RequestParam Long uid) { + webrtcService.handup(uid); return ResultUtils.success(); } diff --git a/im-platform/src/main/java/com/bx/implatform/service/IWebrtcService.java b/im-platform/src/main/java/com/bx/implatform/service/IWebrtcService.java index 19b2b0d..b93858f 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/IWebrtcService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/IWebrtcService.java @@ -22,7 +22,7 @@ public interface IWebrtcService { void failed(Long uid, String reason); - void leave(Long uid); + void handup(Long uid); void candidate(Long uid, String candidate); diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcServiceImpl.java index 4c3f8b5..5b2ccad 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcServiceImpl.java @@ -152,8 +152,7 @@ public class WebrtcServiceImpl implements IWebrtcService { IMPrivateMessage sendMessage = new IMPrivateMessage<>(); sendMessage.setSender(new IMUserInfo(session.getUserId(), session.getTerminal())); sendMessage.setRecvId(uid); - // 告知其他终端已经会话失败,中止呼叫 - sendMessage.setSendToSelf(true); + sendMessage.setSendToSelf(false); sendMessage.setSendResult(false); sendMessage.setRecvTerminals(Collections.singletonList(webrtcSession.getCallerTerminal())); sendMessage.setData(messageInfo); @@ -163,7 +162,7 @@ public class WebrtcServiceImpl implements IWebrtcService { } @Override - public void leave(Long uid) { + public void handup(Long uid) { UserSession session = SessionContext.getSession(); // 查询webrtc会话 WebrtcSession webrtcSession = getWebrtcSession(session.getUserId(), uid); @@ -219,7 +218,7 @@ public class WebrtcServiceImpl implements IWebrtcService { String key = getSessionKey(userId, uid); WebrtcSession webrtcSession = (WebrtcSession)redisTemplate.opsForValue().get(key); if (webrtcSession == null) { - throw new GlobalException("视频通话已结束"); + throw new GlobalException("通话已结束"); } return webrtcSession; } diff --git a/im-ui/src/api/enums.js b/im-ui/src/api/enums.js index 3206bba..0e6a1b1 100644 --- a/im-ui/src/api/enums.js +++ b/im-ui/src/api/enums.js @@ -5,13 +5,16 @@ const MESSAGE_TYPE = { FILE:2, AUDIO:3, VIDEO:4, + RT_VOICE:5, + RT_VIDEO:6, RECALL:10, READED:11, RECEIPT:12, TIP_TIME:20, TIP_TEXT:21, LOADDING:30, - RTC_CALL: 101, + RTC_CALL_VOICE: 100, + RTC_CALL_VIDEO: 101, RTC_ACCEPT: 102, RTC_REJECT: 103, RTC_CANCEL: 104, @@ -20,10 +23,12 @@ const MESSAGE_TYPE = { RTC_CANDIDATE: 107 } -const USER_STATE = { - OFFLINE: 0, - FREE: 1, - BUSY: 2 +const RTC_STATE = { + FREE: 0, //空闲,可以被呼叫 + WAIT_CALL: 1, // 呼叫后等待 + WAIT_ACCEPT: 2, // 被呼叫后等待 + ACCEPTED: 3, // 已接受聊天,等待建立连接 + CHATING:4 // 聊天中 } const TERMINAL_TYPE = { @@ -41,7 +46,7 @@ const MESSAGE_STATUS = { export { MESSAGE_TYPE, - USER_STATE, + RTC_STATE, TERMINAL_TYPE, MESSAGE_STATUS } diff --git a/im-ui/src/assets/iconfont/iconfont.css b/im-ui/src/assets/iconfont/iconfont.css index 7092657..af7aa38 100644 --- a/im-ui/src/assets/iconfont/iconfont.css +++ b/im-ui/src/assets/iconfont/iconfont.css @@ -1,6 +1,6 @@ @font-face { font-family: "iconfont"; /* Project id 3791506 */ - src: url('iconfont.ttf?t=1706022894868') format('truetype'); + src: url('iconfont.ttf?t=1710567233281') format('truetype'); } .iconfont { @@ -11,6 +11,14 @@ -moz-osx-font-smoothing: grayscale; } +.icon-chat-video:before { + content: "\e73b"; +} + +.icon-chat-voice:before { + content: "\e633"; +} + .icon-ok:before { content: "\e6ac"; } diff --git a/im-ui/src/assets/iconfont/iconfont.ttf b/im-ui/src/assets/iconfont/iconfont.ttf index 79f6e9c..b1d7cb7 100644 Binary files a/im-ui/src/assets/iconfont/iconfont.ttf and b/im-ui/src/assets/iconfont/iconfont.ttf differ diff --git a/im-ui/src/components/chat/ChatBox.vue b/im-ui/src/components/chat/ChatBox.vue index 93af571..3d74536 100644 --- a/im-ui/src/components/chat/ChatBox.vue +++ b/im-ui/src/components/chat/ChatBox.vue @@ -13,7 +13,9 @@
-
+
+
+
@@ -133,13 +138,19 @@ export default { methods: { moveChatToTop(){ let chatIdx = this.$store.getters.findChatIdx(this.chat); - console.log(chatIdx); this.$store.commit("moveTop",chatIdx); }, closeRefBox() { this.$refs.emoBox.close(); this.$refs.atBox.close(); }, + onCall(type){ + if(type == this.$enums.MESSAGE_TYPE.RT_VOICE){ + this.showChatVideo('voice'); + }else if(type == this.$enums.MESSAGE_TYPE.RT_VIDEO){ + this.showChatVideo('video'); + } + }, onKeyDown() { if (this.$refs.atBox.show) { this.$refs.atBox.moveDown() @@ -433,11 +444,17 @@ export default { closeVoiceBox() { this.showVoice = false; }, - showVideoBox() { - this.$store.commit("showChatPrivateVideoBox", { + showChatVideo(mode) { + let rtcInfo = { + mode: mode, + isHost: true, friend: this.friend, - master: true - }); + sendId: this.$store.state.userStore.userInfo.id, + recvId: this.friend.id, + offer: "", + state: this.$enums.RTC_STATE.WAIT_CALL + } + this.$store.commit("setRtcInfo",rtcInfo); }, showHistoryBox() { this.showHistory = true; @@ -686,6 +703,12 @@ export default { }, unreadCount() { return this.chat.unreadCount; + }, + messageSize() { + if (!this.chat || !this.chat.messages) { + return 0; + } + return this.chat.messages.length; } }, watch: { @@ -716,9 +739,9 @@ export default { }, immediate: true }, - unreadCount: { - handler(newCount, oldCount) { - if (newCount > 0) { + messageSize: { + handler(newSize, oldSize) { + if (newSize > oldSize) { // 拉至底部 this.scrollToBottom(); } @@ -812,7 +835,6 @@ export default { } } - .send-content-area { position: relative; display: flex; @@ -820,8 +842,6 @@ export default { height: 100%; background-color: white !important; - - .send-text-area { box-sizing: border-box; padding: 5px; diff --git a/im-ui/src/components/chat/ChatMessageItem.vue b/im-ui/src/components/chat/ChatMessageItem.vue index 22b0e6c..04ab953 100644 --- a/im-ui/src/components/chat/ChatMessageItem.vue +++ b/im-ui/src/components/chat/ChatMessageItem.vue @@ -1,6 +1,9 @@ \ No newline at end of file diff --git a/im-ui/src/components/chat/ChatPrivateVideo.vue b/im-ui/src/components/chat/ChatPrivateVideo.vue index 687bafd..445eaf7 100644 --- a/im-ui/src/components/chat/ChatPrivateVideo.vue +++ b/im-ui/src/components/chat/ChatPrivateVideo.vue @@ -1,13 +1,12 @@