From 37d107511639b8da3a742dc989944e705f90c6de Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Sun, 17 Mar 2024 02:16:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E9=9F=B3=E8=A7=86=E9=A2=91=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=8A=A0=E5=85=A5=E4=BC=9A=E8=AF=9D=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WebrtcController.java | 4 +- .../bx/implatform/service/IWebrtcService.java | 2 +- .../service/impl/WebrtcServiceImpl.java | 7 +- im-ui/src/api/enums.js | 17 +- im-ui/src/assets/iconfont/iconfont.css | 10 +- im-ui/src/assets/iconfont/iconfont.ttf | Bin 4364 -> 4836 bytes im-ui/src/components/chat/ChatBox.vue | 48 +- im-ui/src/components/chat/ChatMessageItem.vue | 640 ++++++++++-------- .../src/components/chat/ChatPrivateVideo.vue | 314 +++++---- .../src/components/chat/ChatVideoAcceptor.vue | 155 ++++- im-ui/src/store/chatStore.js | 8 + im-ui/src/store/uiStore.js | 28 - im-ui/src/store/userStore.js | 22 +- im-ui/src/view/Friend.vue | 2 +- im-ui/src/view/Home.vue | 609 +++++++++-------- im-uniapp/common/enums.js | 2 + .../chat-message-item/chat-message-item.vue | 70 +- im-uniapp/manifest.json | 20 +- im-uniapp/pages/chat/chat-box.vue | 18 +- im-uniapp/pages/chat/chat-video.vue | 113 ++++ im-uniapp/static/icon/iconfont.css | 10 +- im-uniapp/static/icon/iconfont.ttf | Bin 6224 -> 6696 bytes im-uniapp/store/chatStore.js | 10 +- 23 files changed, 1257 insertions(+), 852 deletions(-) create mode 100644 im-uniapp/pages/chat/chat-video.vue 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 79f6e9c8f2b217df04a92e4733cde861bfafd3ee..b1d7cb7f0e66038175edc55436fe539bd269dea0 100644 GIT binary patch delta 1018 zcmZ{iO=uHA6vyA2-EF>hH@j(?wA&clwArongEq-#m1?Y15D`=q@u1Siex=ZwNQ<DuqSc%f4}u3ldJw#LD56k2h=_MV#gA@>uv-a`j-+6162X2_wUSN)wnzK)?#BuWu z^HyT4`t+M^7r-mvwyidr{gn3xc(_N&F;K`O+JY_Gnw_=}+cWmOy|&c7w7Lw-&sR=v zZ2|lntz2b|l^4icNGJTS1Bf6{9R^k4+pdcw)dLa)p1x%gmggPG)Fh{b3vB`W540I< z&4rEuJMH4!);{b)M}s}%LPfx)GaaZL*lRA%g_pWroR_e)>QW{(uuQoQq>JwB;s{zf z=>h>K2q$0>JMl6*&PwbpH_S8s2LDRv5Ux{f``d62*aIr+1p`QC(l9MlyBh0JuL`1> z(VH3*RW)ijl5R|8O)DD59GYb{qYDWc!*NWfvKgK0KYDbdpM`M28}gh@Y8yZ5le)&L zwIrVLgcP4|ra{*s$_TYUUh1{T~>)K|IGak$d=neX?-xsWvB3eX> zwZ!OGb8f+{vJnz^1fV*HM%l__E$XBuS`&`!WGO3^-G>?7=s=H*J1~y>F--cabi>pw zGh^kjArg&HvW!L(WtoOpk!VYd-h%vf7rYZ!U4H9nYOOmdAZe^`G-ATpY21Q~Z5mkjaRuSgJSG5UWcVUm6`8 PD*iExqXR>gN6Nr&>ZQ`| delta 561 zcmZvXO(;ZB7>3_-?lm*a#cgb+N%Ft47?joc$&SQ=vee{n(hO59SfM0MLv(FyEZELs zqBIN1!it@e6;V1ySx{IS@0q)ha!$`V-{1MZ_dGSF>$k(pZ`o@Hkkw>hI=(d3ZzmrB za}6k6iA_c)nlDGL05FD*7z5sWW0UqNX^bTn7Q-|E@ya6{pBsG&WAsCb=webd zV2}AA{o2`RV$wd0WPu8k^QMz?^W_V7qr10&9cRJ*&S^up1woU{tInRW%E%}DEarN= z*_i#k3uzO^6n!70j&kXDmQy3Xokm$Tlq>qc5saeM!n=$`Iha^yWe_$aK2@SD6;gdF zr84U4`6G|~*~@UD0Q}83Te7ZQ@YR1C>}*hn2`^{);6VxeDCIQI;ky*eS{MO#izk?5 zdlxNAF{@z{sE~{Pmg;k1W2lr1M?hs<^vBef3&-O5!-WEnXFCn0wDM1Mh#veh?4tE? l#c?9iA|uP>fzf4Ln9`gv&yRaOeoI)+U?3>qtOmv@<_GUeeG>ox 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 @@
  • - @@ -44,8 +46,11 @@
-
+
+
+
@@ -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 @@