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 2bd4d5d..14d5a14 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 @@ -21,8 +21,8 @@ public class WebrtcController { @ApiOperation(httpMethod = "POST", value = "呼叫视频通话") @PostMapping("/call") - public Result call(@RequestParam Long uid, @RequestBody String offer) { - webrtcService.call(uid, offer); + public Result call(@RequestParam Long uid, @RequestParam(defaultValue = "video") String mode, @RequestBody String offer) { + webrtcService.call(uid, mode, offer); return ResultUtils.success(); } @@ -65,7 +65,7 @@ public class WebrtcController { @PostMapping("/candidate") @ApiOperation(httpMethod = "POST", value = "同步candidate") - public Result forwardCandidate(@RequestParam Long uid, @RequestBody String candidate) { + public Result candidate(@RequestParam Long uid, @RequestBody String candidate) { webrtcService.candidate(uid, candidate); return ResultUtils.success(); } diff --git a/im-platform/src/main/java/com/bx/implatform/enums/MessageType.java b/im-platform/src/main/java/com/bx/implatform/enums/MessageType.java index 1ca0784..2200387 100644 --- a/im-platform/src/main/java/com/bx/implatform/enums/MessageType.java +++ b/im-platform/src/main/java/com/bx/implatform/enums/MessageType.java @@ -53,10 +53,15 @@ public enum MessageType { * 消息加载标记 */ LOADDING(30,"加载中"), + + /** + * 语音呼叫 + */ + RTC_CALL_VOICE(100, "语音呼叫"), /** - * 呼叫 + * 视频呼叫 */ - RTC_CALL(101, "呼叫"), + RTC_CALL_VIDEO(101, "视频呼叫"), /** * 接受 */ 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 4e98a79..19b2b0d 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 @@ -12,9 +12,9 @@ import java.util.List; */ public interface IWebrtcService { - void call(Long uid, String offer); + void call(Long uid, String mode,String offer); - void accept(Long uid, @RequestBody String answer); + void accept(Long uid, String answer); void reject(Long uid); 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 bf7f020..4c3f8b5 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 @@ -33,7 +33,7 @@ public class WebrtcServiceImpl implements IWebrtcService { private final ICEServerConfig iceServerConfig; @Override - public void call(Long uid, String offer) { + public void call(Long uid, String mode, String offer) { UserSession session = SessionContext.getSession(); if (!imClient.isOnline(uid)) { throw new GlobalException("对方目前不在线"); @@ -46,7 +46,8 @@ public class WebrtcServiceImpl implements IWebrtcService { redisTemplate.opsForValue().set(key, webrtcSession, 12, TimeUnit.HOURS); // 向对方所有终端发起呼叫 PrivateMessageVO messageInfo = new PrivateMessageVO(); - messageInfo.setType(MessageType.RTC_CALL.code()); + MessageType messageType = mode.equals("video") ? MessageType.RTC_CALL_VIDEO : MessageType.RTC_CALL_VOICE; + messageInfo.setType(messageType.code()); messageInfo.setRecvId(uid); messageInfo.setSendId(session.getUserId()); messageInfo.setContent(offer); @@ -146,6 +147,7 @@ public class WebrtcServiceImpl implements IWebrtcService { messageInfo.setType(MessageType.RTC_FAILED.code()); messageInfo.setRecvId(uid); messageInfo.setSendId(session.getUserId()); + messageInfo.setContent(reason); IMPrivateMessage sendMessage = new IMPrivateMessage<>(); sendMessage.setSender(new IMUserInfo(session.getUserId(), session.getTerminal())); @@ -215,7 +217,7 @@ public class WebrtcServiceImpl implements IWebrtcService { private WebrtcSession getWebrtcSession(Long userId, Long uid) { String key = getSessionKey(userId, uid); - WebrtcSession webrtcSession = (WebrtcSession) redisTemplate.opsForValue().get(key); + WebrtcSession webrtcSession = (WebrtcSession)redisTemplate.opsForValue().get(key); if (webrtcSession == null) { throw new GlobalException("视频通话已结束"); } diff --git a/im-ui/src/assets/audio/call.wav b/im-ui/src/assets/audio/call.wav index 754e33c..8eae87f 100644 Binary files a/im-ui/src/assets/audio/call.wav and b/im-ui/src/assets/audio/call.wav differ diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 3984a47..49665dd 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -104,8 +104,26 @@ }, insertPrivateMessage(friend, msg) { // webrtc 信令 - if (msg.type >= enums.MESSAGE_TYPE.RTC_CALL && - msg.type <= enums.MESSAGE_TYPE.RTC_CANDIDATE) {} + if (msg.type >= enums.MESSAGE_TYPE.RTC_CALL_VOICE && + msg.type <= enums.MESSAGE_TYPE.RTC_CANDIDATE) { + // 被呼叫,弹出视频页面 + if(msg.type == enums.MESSAGE_TYPE.RTC_CALL_VOICE + || msg.type == enums.MESSAGE_TYPE.RTC_CALL_VIDEO){ + let mode = msg.type == enums.MESSAGE_TYPE.RTC_CALL_VIDEO? "video":"voice"; + let pages = getCurrentPages(); + let curPage = pages[pages.length-1].route; + if(curPage != "pages/chat/chat-video"){ + const friendInfo = encodeURIComponent(JSON.stringify(friend)); + uni.navigateTo({ + url: `/pages/chat/chat-video?mode=${mode}&friend=${friendInfo}&isHost=false` + }) + } + } + setTimeout(() => { + uni.$emit('WS_RTC',msg); + },500) + return; + } let chatInfo = { type: 'PRIVATE', diff --git a/im-uniapp/common/enums.js b/im-uniapp/common/enums.js index caad425..133983e 100644 --- a/im-uniapp/common/enums.js +++ b/im-uniapp/common/enums.js @@ -11,7 +11,8 @@ const MESSAGE_TYPE = { 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, diff --git a/im-uniapp/hybrid/html/index.html b/im-uniapp/hybrid/html/index.html new file mode 100644 index 0000000..6733f82 --- /dev/null +++ b/im-uniapp/hybrid/html/index.html @@ -0,0 +1,13 @@ + + + + + + + + 视频通话 + + +
音视频通话为付费功能,有需要请联系作者...
+ + \ No newline at end of file diff --git a/im-uniapp/pages.json b/im-uniapp/pages.json index 32b6119..520b23c 100644 --- a/im-uniapp/pages.json +++ b/im-uniapp/pages.json @@ -1,5 +1,5 @@ { - "lazyCodeLoading":"requiredComponents", + "pages": [{ "path": "pages/login/login" }, { @@ -16,6 +16,8 @@ "path": "pages/common/user-info" }, { "path": "pages/chat/chat-box" + },{ + "path": "pages/chat/chat-video" }, { "path": "pages/friend/friend-add" }, { @@ -30,7 +32,8 @@ "path": "pages/mine/mine-edit" },{ "path": "pages/mine/mine-password" - }], + } + ], "globalStyle": { "navigationBarTitleText": "盒子IM", "navigationBarTextStyle": "black", diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 9b6e154..580c74e 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -30,9 +30,9 @@ + :placeholder="isReceipt?'[回执消息]':''" :adjust-position="false" @confirm="sendTextMessage()" + @keyboardheightchange="onKeyboardheightchange" @input="onTextInput" confirm-type="send" confirm-hold + :hold-keyboard="true"> @@ -71,14 +71,18 @@ 语音输入 - + 回执消息 - + + + 视频通话 + + - 呼叫 + 语音通话 @@ -116,17 +120,28 @@ }, methods: { showTip() { - uni.showToast({ title: "暂未支持...", icon: "none" }) }, - moveChatToTop(){ + onVideoCall(){ + const friendInfo = encodeURIComponent(JSON.stringify(this.friend)); + uni.navigateTo({ + url: `/pages/chat/chat-video?mode=video&friend=${friendInfo}&isHost=true` + }) + }, + onVoiceCall(){ + const friendInfo = encodeURIComponent(JSON.stringify(this.friend)); + uni.navigateTo({ + url: `/pages/chat/chat-video?mode=voice&friend=${friendInfo}&isHost=true` + }) + }, + moveChatToTop() { let chatIdx = this.$store.getters.findChatIdx(this.chat); - this.$store.commit("moveTop",chatIdx); + this.$store.commit("moveTop", chatIdx); }, - switchReceipt(){ + switchReceipt() { this.isReceipt = !this.isReceipt; }, openAtBox() { @@ -164,12 +179,12 @@ icon: "none" }); } - let receiptText = this.isReceipt? "【回执消息】":""; + let receiptText = this.isReceipt ? "【回执消息】" : ""; let atText = this.createAtText(); let msgInfo = { content: receiptText + this.sendText + atText, atUserIds: this.atUserIds, - receipt : this.isReceipt, + receipt: this.isReceipt, type: 0 } // 填充对方id @@ -185,7 +200,7 @@ msgInfo.sendId = this.$store.state.userStore.userInfo.id; msgInfo.selfSend = true; msgInfo.readedCount = 0, - msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND; + msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND; this.$store.commit("insertMessage", msgInfo); // 会话置顶 this.moveChatToTop(); @@ -727,7 +742,7 @@ .chat-tools { display: flex; flex-wrap: wrap; - + .chat-tools-item { width: 140rpx; padding: 16rpx; @@ -736,12 +751,12 @@ align-items: center; .tool-icon { - padding: 18rpx; - font-size: 80rpx; + padding: 28rpx; + font-size: 60rpx; background-color: white; border-radius: 20%; - - &.active{ + + &.active { background-color: #ddd; } } diff --git a/im-uniapp/static/icon/iconfont.css b/im-uniapp/static/icon/iconfont.css index 911f651..f8a1629 100644 --- a/im-uniapp/static/icon/iconfont.css +++ b/im-uniapp/static/icon/iconfont.css @@ -1,6 +1,6 @@ @font-face { font-family: "iconfont"; /* Project id 4272106 */ - src: url('iconfont.ttf?t=1706027587101') format('truetype'); + src: url('iconfont.ttf?t=1710059877142') format('truetype'); } .iconfont { @@ -11,6 +11,10 @@ -moz-osx-font-smoothing: grayscale; } +.icon-video:before { + content: "\e685"; +} + .icon-receipt:before { content: "\e61a"; } diff --git a/im-uniapp/static/icon/iconfont.ttf b/im-uniapp/static/icon/iconfont.ttf index 45f0474..4ee439c 100644 Binary files a/im-uniapp/static/icon/iconfont.ttf and b/im-uniapp/static/icon/iconfont.ttf differ