From 0760d28d3623ba58ede381ed05f14da3f17d8064 Mon Sep 17 00:00:00 2001 From: rowger Date: Thu, 7 Dec 2023 14:23:26 +0800 Subject: [PATCH] bak --- hd-glasses-app/public/srs/srs.sdk.js | 5 + hd-glasses-app/src/pages/call_room.vue | 97 +++++++++++++++++-- .../controller/ImCallHistoryController.java | 18 ++++ .../service/call/dao/ImCallHistoryEntity.java | 1 + .../call/service/ImCallHistoryService.java | 67 ++++++++++++- .../com/lld/im/service/config/WebConfig.java | 1 + .../taskScheduler/CallHistoryTask.java | 28 +++--- .../service/taskScheduler/SRSStreamTask.java | 3 +- im-uniapp/wx/chatWindow/index.vue | 7 +- lim-ts-sdk-master/lim-ts-sdk/README.md | 3 + lim-ts-sdk-master/lim-ts-sdk/package.json | 3 +- .../lim-ts-sdk/src/lim/core/ImClient.ts | 27 ++---- .../src/lim/model/dto/MessageContent.ts | 2 +- 13 files changed, 213 insertions(+), 49 deletions(-) diff --git a/hd-glasses-app/public/srs/srs.sdk.js b/hd-glasses-app/public/srs/srs.sdk.js index c495b0b..7edebe9 100644 --- a/hd-glasses-app/public/srs/srs.sdk.js +++ b/hd-glasses-app/public/srs/srs.sdk.js @@ -371,6 +371,11 @@ function SrsRtcPlayerAsync() { await self.pc.setLocalDescription(offer); var session = await new Promise(function (resolve, reject) { // @see https://github.com/rtcdn/rtcdn-draft + + conf.apiUrl = conf.apiUrl.replace('172.16.3.17', '172.16.3.18'); + conf.streamUrl = conf.streamUrl.replace('172.16.3.17', '172.16.3.18'); + + var data = { api: conf.apiUrl, tid: conf.tid, streamurl: conf.streamUrl, clientip: null, sdp: offer.sdp diff --git a/hd-glasses-app/src/pages/call_room.vue b/hd-glasses-app/src/pages/call_room.vue index ed7cd86..1753dd2 100644 --- a/hd-glasses-app/src/pages/call_room.vue +++ b/hd-glasses-app/src/pages/call_room.vue @@ -92,7 +92,7 @@ export default { isForce: "0", hasVideo: "1", callSessionId: "", - callStatus: "watting",//房间状态 + callStatus: "0",//房间状态 1 未开始等待 2已开始 3已关闭 callRoomInfoRequetTimes:0,//房间拉取次数 }; }, @@ -141,8 +141,8 @@ export default { message: `${this.inviteName}邀请你加入${this.videoTitle}聊天`, }) .then(() => { - this.callBegin(); this.init(); + this.callStatus=1 // on confirm }) .catch(() => { @@ -160,6 +160,7 @@ export default { this.callSessionId = uuidv4(); this.sendInvite(); this.init(); + this.callStatus=1 } catch (e) { console.log(e) } @@ -435,6 +436,19 @@ export default { }, }).then(res => { if (res.status == 200) { + if(this.isPublish==1){ + if(res.data.data.length==2){ + this.callStatus=2 + this.callBegin(); + } + }else { + if(res.data.data.length==1){ + this.callStatus=2 + this.callBegin(); + } + } + + this.generateVideoRoomStream(res.data.data) }else { this.generateVideoRoomStream([]) @@ -459,12 +473,13 @@ export default { }) }, callBegin() { + let passiveId=this.roomId==this.uid?this.tuid:this.tuid let roomInfo = { id:uuidv4(), inviteId: this.roomId,//后面改成发起人的手机号或者id roomId: this.roomId, - passiveId: this.uid, + passiveId: passiveId, isForce: this.isForce, type: this.hasVideo == 1 ? "video" : "voice", } @@ -533,12 +548,80 @@ export default { }, generateVideoRoomStream(videoList) { this.callRoomInfoRequetTimes=this.callRoomInfoRequetTimes+1; - if(this.callRoomInfoRequetTimes>5){ - if(videoList.length==0){ + //如果电话一直未拨通 + if(this.callStatus==1){ + if(this.callRoomInfoRequetTimes>12){ + if(videoList.length==0){ // 拉取5次房间列表之后,如果房间里面视频流的数量为0,则关掉房间 - this.videoDownAction() - } + Notify({ + message: '通讯异常,即将挂断', + duration: 2, + type: 'primary' + }); + setTimeout(()=>{ + this.videoDownAction() + },1500) + } + if(videoList.length==1){ + // 拉取5次房间列表之后,如果房间里面视频流的数量为1,并且是自己的流,则关闭房间 + if(videoList[0].publishId==this.uid){ + Notify({ + message: '通讯异常,即将挂断', + duration: 2, + type: 'primary' + }); + setTimeout(()=>{ + this.videoDownAction() + },1500) + } + //如果房间里面只有一路流,并且是查岗模式,则表示正常 + if(this.isPublish==0){ + this.callRoomInfoRequetTimes=0; + } + } + if(videoList.length==2){ + this.callRoomInfoRequetTimes=0; + } + } } + //如果电话打通过一次 + if(this.callStatus==2){ + if(this.callRoomInfoRequetTimes>2){ + if(videoList.length==0){ + // 拉取5次房间列表之后,如果房间里面视频流的数量为0,则关掉房间 + Notify({ + message: '通讯异常,即将挂断', + duration: 2, + type: 'primary' + }); + setTimeout(()=>{ + this.videoDownAction() + },1500) + } + if(videoList.length==1){ + // 拉取5次房间列表之后,如果房间里面视频流的数量为1,并且是自己的流,则关闭房间 + if(videoList[0].publishId==this.uid){ + Notify({ + message: '通讯异常,即将挂断', + duration: 2, + type: 'primary' + }); + setTimeout(()=>{ + this.videoDownAction() + },1500) + } + //如果房间里面只有一路流,并且是查岗模式,则表示正常 + if(this.isPublish==0){ + this.callRoomInfoRequetTimes=0; + } + } + if(videoList.length==2){ + this.callRoomInfoRequetTimes=0; + } + } + } + + let hasUpdate = false; if (this.oldVideoStreamList == null) { diff --git a/hs-im-server/im-service/src/main/java/com/lld/im/service/call/controller/ImCallHistoryController.java b/hs-im-server/im-service/src/main/java/com/lld/im/service/call/controller/ImCallHistoryController.java index 02a4b12..fac261e 100644 --- a/hs-im-server/im-service/src/main/java/com/lld/im/service/call/controller/ImCallHistoryController.java +++ b/hs-im-server/im-service/src/main/java/com/lld/im/service/call/controller/ImCallHistoryController.java @@ -2,6 +2,7 @@ package com.lld.im.service.call.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.lld.im.common.ResponseVO; @@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Date; +import java.util.List; @Slf4j @RestController @@ -61,9 +63,25 @@ public class ImCallHistoryController { @PostMapping("/callBegin") public ResponseVO callBegin(@RequestBody ImCallHistoryEntity imCallHistoryEntity) { + + //判断当前房间是否有通话 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("session_id",imCallHistoryEntity.getSessionId()); + queryWrapper.eq("status",1); + + List imCallHistoryEntityList = callHistoryMapper.selectList(queryWrapper); + + //如果存在则直接返回旧的记录 + if(imCallHistoryEntityList.size()>0){ + return ResponseVO.successResponse(imCallHistoryEntityList.get(0)); + } + + // 如果不存在则插入新的记录 imCallHistoryEntity.setCreateTime(new Date()); imCallHistoryEntity.setStatus("1"); + + ResponseVO inviteUserInfo = imUserService.getSingleUserInfo(imCallHistoryEntity.getRoomId(), 10000); ResponseVO passiveUserInfo = imUserService.getSingleUserInfo(imCallHistoryEntity.getPassiveId(), 10000); diff --git a/hs-im-server/im-service/src/main/java/com/lld/im/service/call/dao/ImCallHistoryEntity.java b/hs-im-server/im-service/src/main/java/com/lld/im/service/call/dao/ImCallHistoryEntity.java index 01235ae..0ffd787 100644 --- a/hs-im-server/im-service/src/main/java/com/lld/im/service/call/dao/ImCallHistoryEntity.java +++ b/hs-im-server/im-service/src/main/java/com/lld/im/service/call/dao/ImCallHistoryEntity.java @@ -28,5 +28,6 @@ public class ImCallHistoryEntity { // 持续时间(秒) private Integer continueSecond; + private Integer checkTimes; } diff --git a/hs-im-server/im-service/src/main/java/com/lld/im/service/call/service/ImCallHistoryService.java b/hs-im-server/im-service/src/main/java/com/lld/im/service/call/service/ImCallHistoryService.java index 6b01dfb..cd45aaf 100644 --- a/hs-im-server/im-service/src/main/java/com/lld/im/service/call/service/ImCallHistoryService.java +++ b/hs-im-server/im-service/src/main/java/com/lld/im/service/call/service/ImCallHistoryService.java @@ -39,12 +39,15 @@ public class ImCallHistoryService { List imCallHistoryEntityList = callHistoryMapper.selectList(queryWrapper); - for(ImCallHistoryEntity imCallHistory: imCallHistoryEntityList){ - imCallHistory.setStatus("2"); - callHistoryMapper.updateById(imCallHistory); + if(imCallHistoryEntityList.size()>0){ + for(ImCallHistoryEntity imCallHistory: imCallHistoryEntityList){ + imCallHistory.setStatus("1"); + callHistoryMapper.updateById(imCallHistory); + } + }else { + callHistoryMapper.insert(callHistory); } - callHistoryMapper.insert(callHistory); } public List queryListByStatus(String status){ @@ -55,6 +58,62 @@ public class ImCallHistoryService { } + public void updateCallHistory(ImCallHistoryEntity callHistory){ + callHistoryMapper.updateById(callHistory); + } + + + public void closeCallRoomWithError(ImCallHistoryEntity callHistory){ + Date _now=new Date(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("session_id",callHistory.getSessionId()); + queryWrapper.eq("status",1); + + // end_time + ImCallHistoryEntity imCallHistory = callHistoryMapper.selectOne(queryWrapper); + + if(!ObjectUtils.isEmpty(imCallHistory)){ + imCallHistory.setEndTime(_now); + imCallHistory.setStatus("3"); + Duration duration = Duration.between(imCallHistory.getCreateTime().toInstant(),_now.toInstant()); + long seconds = TimeUnit.MILLISECONDS.toSeconds(duration.toMillis()); + Integer i = Long.valueOf(seconds).intValue(); + imCallHistory.setContinueSecond(i); + + + //TODO 结束之后通知客户端 + SendMessageReq req= new SendMessageReq(); + req.setAppId(10000); + req.setFromId(imCallHistory.getInviteId()); + req.setToId(imCallHistory.getPassiveId()); + req.setMessageTime(System.currentTimeMillis()); + // req.setMessageRandom(); + + req.setMessageId(UUID.randomUUID().toString().replace("-", "")); + req.setImei("uniapp"); + req.setClientType(1); + + + Map data = new HashMap(); + data.put("userId", imCallHistory.getInviteId()); + data.put("msgType", "CALL_"+imCallHistory.getType()); + data.put("content", JSONObject.toJSONString(imCallHistory)); + + req.setMessageBody(JSONObject.toJSONString(data)); + + p2PMessageService.send(req); + + + callHistoryMapper.updateById(imCallHistory); + + + + } + + + } + + public void updateBySessionId(ImCallHistoryEntity callHistory){ Date _now=new Date(); QueryWrapper queryWrapper = new QueryWrapper<>(); diff --git a/hs-im-server/im-service/src/main/java/com/lld/im/service/config/WebConfig.java b/hs-im-server/im-service/src/main/java/com/lld/im/service/config/WebConfig.java index e1e7adb..445053b 100644 --- a/hs-im-server/im-service/src/main/java/com/lld/im/service/config/WebConfig.java +++ b/hs-im-server/im-service/src/main/java/com/lld/im/service/config/WebConfig.java @@ -26,6 +26,7 @@ public class WebConfig implements WebMvcConfigurer { .excludePathPatterns("/v1/file/**") .excludePathPatterns("/v1/room/**") .excludePathPatterns("/v1/im_call_history/**") + .excludePathPatterns("/v1/message/listMessage") .excludePathPatterns("/v1/message/checkSend"); } diff --git a/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/CallHistoryTask.java b/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/CallHistoryTask.java index b583d57..a1bbd91 100644 --- a/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/CallHistoryTask.java +++ b/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/CallHistoryTask.java @@ -30,29 +30,29 @@ public class CallHistoryTask { ImRoomService roomService; - @Scheduled(cron="0/10 * * * * ? ") + @Scheduled(cron="0/2 * * * * ? ") public void executeTask(){ List callHistoryEntities = callHistoryService.queryListByStatus("1"); for(ImCallHistoryEntity callHistoryEntity: callHistoryEntities){ - ImRoomEntity imRoomEntity = new ImRoomEntity(); - imRoomEntity.setRoomId(callHistoryEntity.getRoomId()); - List serviceRoomInfo = roomService.getRoomInfo(imRoomEntity); - if(serviceRoomInfo.size()<2){ - log.info("{}房间里面的流少于2路,关掉全部视频流并且判断异常中断",callHistoryEntity.getSessionId()); - //房间里面的流少于2路,关掉全部视频流并且判断异常中断 - closeAll(callHistoryEntity,serviceRoomInfo); + if(callHistoryEntity.getCheckTimes()>2){ + ImRoomEntity imRoomEntity = new ImRoomEntity(); + imRoomEntity.setRoomId(callHistoryEntity.getRoomId()); + List serviceRoomInfo = roomService.getRoomInfo(imRoomEntity); + if(serviceRoomInfo.size()==0){ + log.info("{}房间里面没有流,关掉全部视频流并且设置状态为异常中断",callHistoryEntity.getSessionId()); + //房间里面没有流,关掉全部视频流并且判断异常中断 + // closeAll(callHistoryEntity,serviceRoomInfo); + } + }else { + callHistoryEntity.setCheckTimes(callHistoryEntity.getCheckTimes()+1); } + } } @Transactional(rollbackFor = Exception.class) public void closeAll(ImCallHistoryEntity callHistoryEntity,List roomList){ - callHistoryEntity.setStatus("3"); - callHistoryService.updateBySessionId(callHistoryEntity); - - if(roomList.size()>0){ - roomService.deleteAllUserFromRoom(roomList.get(0).getRoomId()); - } + callHistoryService.closeCallRoomWithError(callHistoryEntity); } diff --git a/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/SRSStreamTask.java b/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/SRSStreamTask.java index f5567e5..eb6854e 100644 --- a/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/SRSStreamTask.java +++ b/hs-im-server/im-service/src/main/java/com/lld/im/service/taskScheduler/SRSStreamTask.java @@ -59,6 +59,7 @@ public class SRSStreamTask { List streamEntityList = response.getStreams(); for (StreamEntity streamEntity:streamEntityList){ String webRTCUrl=streamEntity.getTcUrl()+"/"+streamEntity.getName(); + //如果流存在,则 if(StringUtils.equals(roomEntity.getWebrtcUrl(),webRTCUrl)){ hasStream=true; break; @@ -71,7 +72,7 @@ public class SRSStreamTask { if(!hasStream){ roomService.addCheckTimes(roomEntity,roomEntity.getCheckTimes()+1); if(roomEntity.getCheckTimes()>4){ - roomService.deleteRoomById(roomEntity.getId()); + // roomService.deleteRoomById(roomEntity.getId()); } }else { roomService.addCheckTimes(roomEntity,0); diff --git a/im-uniapp/wx/chatWindow/index.vue b/im-uniapp/wx/chatWindow/index.vue index 961698f..8306319 100644 --- a/im-uniapp/wx/chatWindow/index.vue +++ b/im-uniapp/wx/chatWindow/index.vue @@ -28,10 +28,10 @@ - + - 按住说话 +