Browse Source

!103 合并到master

Merge pull request !103 from blue/v_3.0.0
master
blue 2 years ago
committed by Gitee
parent
commit
fefcb2eaf4
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
  1. 2
      im-client/src/main/java/com/bx/imclient/IMAutoConfiguration.java
  2. 13
      im-platform/Dockerfile
  3. 2
      im-platform/src/main/java/com/bx/implatform/controller/WebrtcGroupController.java
  4. 4
      im-platform/src/main/java/com/bx/implatform/controller/WebrtcPrivateController.java
  5. 8
      im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcGroupServiceImpl.java
  6. 26
      im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcPrivateServiceImpl.java
  7. 2
      im-platform/src/main/java/com/bx/implatform/vo/PrivateMessageVO.java
  8. 13
      im-server/Dockerfile
  9. 2
      im-server/src/main/java/com/bx/imserver/constant/ChannelAttrKey.java
  10. 2
      im-server/src/main/java/com/bx/imserver/netty/processor/LoginProcessor.java
  11. 4
      im-uniapp/common/messageType.js
  12. 2
      im-uniapp/store/chatStore.js
  13. 4
      im-web/src/api/messageType.js
  14. 4
      im-web/src/components/chat/ChatBox.vue
  15. 15
      im-web/src/store/chatStore.js

2
im-client/src/main/java/com/bx/imclient/IMAutoConfiguration.java

@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration;
@Slf4j
@Configuration
@ComponentScan(basePackages = "com.bx.imclient,com.bx.imcommon")
@ComponentScan(basePackages = {"com.bx.imclient", "com.bx.imcommon"})
public class IMAutoConfiguration {
}

13
im-platform/Dockerfile

@ -1,13 +0,0 @@
FROM openjdk:8-jdk-alpine
ENV APP_FILE im-platform.jar
ENV APP_HOME /data/boxim
WORKDIR $APP_HOME
COPY ./dist/$APP_FILE $APP_HOME/
EXPOSE 8888
EXPOSE 9001
CMD java -jar $APP_HOME/$APP_FILE --spring.profiles.active=prod

2
im-platform/src/main/java/com/bx/implatform/controller/WebrtcGroupController.java

@ -114,7 +114,7 @@ public class WebrtcGroupController {
return ResultUtils.success(webrtcGroupService.info(groupId));
}
@Operation(summary = "获取通话信息")
@Operation(summary = "心跳")
@PostMapping("/heartbeat")
public Result heartbeat(@RequestParam("groupId") Long groupId) {
webrtcGroupService.heartbeat(groupId);

4
im-platform/src/main/java/com/bx/implatform/controller/WebrtcPrivateController.java

@ -17,7 +17,7 @@ public class WebrtcPrivateController {
private final WebrtcPrivateService webrtcPrivateService;
@OnlineCheck
@Operation(summary = "呼叫视频通话")
@PostMapping("/call")
public Result call(@RequestParam Long uid, @RequestParam(defaultValue = "video") String mode,
@ -68,7 +68,7 @@ public class WebrtcPrivateController {
return ResultUtils.success();
}
@Operation(summary = "获取通话信息")
@Operation(summary = "心跳")
@PostMapping("/heartbeat")
public Result heartbeat(@RequestParam Long uid) {
webrtcPrivateService.heartbeat(uid);

8
im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcGroupServiceImpl.java

@ -323,7 +323,7 @@ public class WebrtcGroupServiceImpl implements WebrtcGroupService {
sendRtcMessage1(MessageType.RTC_GROUP_CANCEL, groupId, recvIds, "", false);
// 发送文字提示信息
sendTipMessage(groupId, "通话结束");
log.info("发起人取消群通话,userId:{},groupId:{}", userSession.getUserId(), groupId);
log.info("取消群通话,userId:{},groupId:{}", userSession.getUserId(), groupId);
}
@RedisLock(prefixKey = RedisKey.IM_LOCK_RTC_GROUP, key = "#groupId")
@ -372,7 +372,7 @@ public class WebrtcGroupServiceImpl implements WebrtcGroupService {
WebrtcGroupSession webrtcSession = getWebrtcSession(dto.getGroupId());
IMUserInfo userInfo = findInChatUser(webrtcSession, dto.getUserId());
if (Objects.isNull(userInfo)) {
log.info("对方未加入群通话,userId:{},对方id:{},groupId:{}", userSession.getUserId(), dto.getUserId(),
log.warn("对方未加入群通话,userId:{},对方id:{},groupId:{}", userSession.getUserId(), dto.getUserId(),
dto.getGroupId());
return;
}
@ -389,7 +389,7 @@ public class WebrtcGroupServiceImpl implements WebrtcGroupService {
IMUserInfo userInfo = findInChatUser(webrtcSession, dto.getUserId());
if (Objects.isNull(userInfo)) {
// 对方未加入群通话
log.info("对方未加入群通话,userId:{},对方id:{},groupId:{}", userSession.getUserId(), dto.getUserId(),
log.warn("对方未加入群通话,userId:{},对方id:{},groupId:{}", userSession.getUserId(), dto.getUserId(),
dto.getGroupId());
return;
}
@ -406,7 +406,7 @@ public class WebrtcGroupServiceImpl implements WebrtcGroupService {
IMUserInfo userInfo = findInChatUser(webrtcSession, dto.getUserId());
if (Objects.isNull(userInfo)) {
// 对方未加入群通话
log.info("对方未加入群通话,无法同步candidate,userId:{},remoteUserId:{},groupId:{}", userSession.getUserId(),
log.warn("对方未加入群通话,无法同步candidate,userId:{},remoteUserId:{},groupId:{}", userSession.getUserId(),
dto.getUserId(), dto.getGroupId());
return;
}

26
im-platform/src/main/java/com/bx/implatform/service/impl/WebrtcPrivateServiceImpl.java

@ -3,6 +3,7 @@ package com.bx.implatform.service.impl;
import com.bx.imclient.IMClient;
import com.bx.imcommon.model.IMPrivateMessage;
import com.bx.imcommon.model.IMUserInfo;
import com.bx.implatform.annotation.OnlineCheck;
import com.bx.implatform.contant.RedisKey;
import com.bx.implatform.entity.PrivateMessage;
import com.bx.implatform.enums.MessageStatus;
@ -37,9 +38,11 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
private final PrivateMessageService privateMessageService;
private final UserStateUtils userStateUtils;
@OnlineCheck
@Override
public void call(Long uid, String mode, String offer) {
UserSession session = SessionContext.getSession();
log.info("发起呼叫,sid:{},uid:{}", session.getUserId(), uid);
// 创建webrtc会话
WebrtcPrivateSession webrtcSession = new WebrtcPrivateSession();
webrtcSession.setCallerId(session.getUserId());
@ -48,11 +51,13 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
webrtcSession.setMode(mode);
// 校验
if (!imClient.isOnline(uid)) {
this.sendActMessage(webrtcSession,MessageStatus.UNSEND,"未接通");
this.sendActMessage(webrtcSession, MessageStatus.UNSEND, "未接通");
log.info("对方不在线,uid:{}", uid);
throw new GlobalException("对方目前不在线");
}
if (userStateUtils.isBusy(uid)) {
this.sendActMessage(webrtcSession,MessageStatus.UNSEND,"未接通");
this.sendActMessage(webrtcSession, MessageStatus.UNSEND, "未接通");
log.info("对方正忙,uid:{}", uid);
throw new GlobalException("对方正忙");
}
// 保存rtc session
@ -83,6 +88,7 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
@Override
public void accept(Long uid, @RequestBody String answer) {
UserSession session = SessionContext.getSession();
log.info("接受通话,sid:{},uid:{}", session.getUserId(), uid);
// 查询webrtc会话
WebrtcPrivateSession webrtcSession = getWebrtcSession(session.getUserId(), uid);
// 更新接受者信息
@ -112,6 +118,7 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
@Override
public void reject(Long uid) {
UserSession session = SessionContext.getSession();
log.info("拒绝通话,sid:{},uid:{}", session.getUserId(), uid);
// 查询webrtc会话
WebrtcPrivateSession webrtcSession = getWebrtcSession(session.getUserId(), uid);
// 删除会话信息
@ -135,12 +142,13 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
sendMessage.setData(messageInfo);
imClient.sendPrivateMessage(sendMessage);
// 生成通话消息
sendActMessage(webrtcSession, MessageStatus.READED,"已拒绝");
sendActMessage(webrtcSession, MessageStatus.READED, "已拒绝");
}
@Override
public void cancel(Long uid) {
UserSession session = SessionContext.getSession();
log.info("取消通话,sid:{},uid:{}", session.getUserId(), uid);
// 查询webrtc会话
WebrtcPrivateSession webrtcSession = getWebrtcSession(session.getUserId(), uid);
// 删除会话信息
@ -163,12 +171,13 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
// 通知对方取消会话
imClient.sendPrivateMessage(sendMessage);
// 生成通话消息
sendActMessage(webrtcSession, MessageStatus.UNSEND,"已取消");
sendActMessage(webrtcSession, MessageStatus.UNSEND, "已取消");
}
@Override
public void failed(Long uid, String reason) {
UserSession session = SessionContext.getSession();
log.info("通话失败,sid:{},uid:{},reason:{}", session.getUserId(), uid, reason);
// 查询webrtc会话
WebrtcPrivateSession webrtcSession = getWebrtcSession(session.getUserId(), uid);
// 删除会话信息
@ -193,12 +202,13 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
// 通知对方取消会话
imClient.sendPrivateMessage(sendMessage);
// 生成消息
sendActMessage(webrtcSession, MessageStatus.READED,"未接通");
sendActMessage(webrtcSession, MessageStatus.READED, "未接通");
}
@Override
public void handup(Long uid) {
UserSession session = SessionContext.getSession();
log.info("挂断通话,sid:{},uid:{}", session.getUserId(), uid);
// 查询webrtc会话
WebrtcPrivateSession webrtcSession = getWebrtcSession(session.getUserId(), uid);
// 删除会话信息
@ -223,7 +233,7 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
// 通知对方取消会话
imClient.sendPrivateMessage(sendMessage);
// 生成通话消息
sendActMessage(webrtcSession, MessageStatus.READED,"通话时长 " + chatTimeText(webrtcSession));
sendActMessage(webrtcSession, MessageStatus.READED, "通话时长 " + chatTimeText(webrtcSession));
}
@Override
@ -286,7 +296,7 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
return webrtcSession.getAcceptorTerminal();
}
private void sendActMessage(WebrtcPrivateSession rtcSession, MessageStatus status,String content) {
private void sendActMessage(WebrtcPrivateSession rtcSession, MessageStatus status, String content) {
// 保存消息
PrivateMessage msg = new PrivateMessage();
msg.setSendId(rtcSession.getCallerId());
@ -313,7 +323,7 @@ public class WebrtcPrivateServiceImpl implements WebrtcPrivateService {
}
private String chatTimeText(WebrtcPrivateSession rtcSession) {
long chatTime = (System.currentTimeMillis() - rtcSession.getChatTimeStamp())/1000;
long chatTime = (System.currentTimeMillis() - rtcSession.getChatTimeStamp()) / 1000;
int min = Math.abs((int)chatTime / 60);
int sec = Math.abs((int)chatTime % 60);
String strTime = min < 10 ? "0" : "";

2
im-platform/src/main/java/com/bx/implatform/vo/PrivateMessageVO.java

@ -23,7 +23,7 @@ public class PrivateMessageVO {
@Schema(description = " 发送内容")
private String content;
@Schema(description = "消息内容类型 IMCmdType")
@Schema(description = "消息内容类型 MessageType")
private Integer type;
@Schema(description = " 状态")

13
im-server/Dockerfile

@ -1,13 +0,0 @@
FROM openjdk:8-jdk-alpine
ENV APP_FILE im-server.jar
ENV APP_HOME /data/boxim
WORKDIR $APP_HOME
COPY ./dist/$APP_FILE $APP_HOME/
EXPOSE 8877
EXPOSE 8878
CMD java -jar $APP_HOME/$APP_FILE --spring.profiles.active=prod

2
im-server/src/main/java/com/bx/imserver/constant/ChannelAttrKey.java

@ -16,6 +16,6 @@ public final class ChannelAttrKey {
/**
* 心跳次数
*/
public static final String HEARTBEAT_TIMES = "HEARTBEAt_TIMES";
public static final String HEARTBEAT_TIMES = "HEARTBEAT_TIMES";
}

2
im-server/src/main/java/com/bx/imserver/netty/processor/LoginProcessor.java

@ -62,7 +62,7 @@ public class LoginProcessor extends AbstractMessageProcessor<IMLoginInfo> {
AttributeKey<Integer> terminalAttr = AttributeKey.valueOf(ChannelAttrKey.TERMINAL_TYPE);
ctx.channel().attr(terminalAttr).set(terminal);
// 初始化心跳次数
AttributeKey<Long> heartBeatAttr = AttributeKey.valueOf("HEARTBEAt_TIMES");
AttributeKey<Long> heartBeatAttr = AttributeKey.valueOf(ChannelAttrKey.HEARTBEAT_TIMES);
ctx.channel().attr(heartBeatAttr).set(0L);
// 在redis上记录每个user的channelId,15秒没有心跳,则自动过期
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());

4
im-uniapp/common/messageType.js

@ -21,12 +21,12 @@ let isAction = function(type){
// 单人通话信令
let isRtcPrivate = function(type){
return type>=100 && type < 300;
return type>=100 && type < 200;
}
// 多人通话信令
let isRtcGroup = function(type){
return type>=200 && type < 400;
return type>=200 && type < 300;
}

2
im-uniapp/store/chatStore.js

@ -335,6 +335,8 @@ export default defineStore('chatStore', {
chatKeys: chatKeys
}
uni.setStorageSync(key, chatsData)
// 清理已删除的会话
this.chats = this.chats.filter(chat => !chat.delete)
},
clear(state) {
cacheChats = [];

4
im-web/src/api/messageType.js

@ -21,12 +21,12 @@ let isAction = function(type){
// 单人通话信令
let isRtcPrivate = function(type){
return type>=100 && type < 300;
return type>=100 && type < 200;
}
// 多人通话信令
let isRtcGroup = function(type){
return type>=200 && type < 400;
return type>=200 && type < 300;
}

4
im-web/src/components/chat/ChatBox.vue

@ -156,9 +156,9 @@
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.content = JSON.stringify(data);
msgInfo.receipt = this.isReceipt;
this.sendMessageRequest(msgInfo).then((id) => {
this.sendMessageRequest(msgInfo).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
msgInfo.id = m.id;
this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo);
})

15
im-web/src/store/chatStore.js

@ -102,22 +102,22 @@ export default {
chats[idx].stored = false;
this.commit("saveToStorage");
},
removePrivateChat(state,friendId){
removePrivateChat(state, friendId) {
let chats = this.getters.findChats();
for (let idx in chats) {
if (chats[idx].type == 'PRIVATE' &&
chats[idx].targetId === friendId) {
this.commit("removeChat",idx)
this.commit("removeChat", idx)
break;
}
}
},
removeGroupChat(state,groupId){
removeGroupChat(state, groupId) {
let chats = this.getters.findChats();
for (let idx in chats) {
if (chats[idx].type == 'GROUP' &&
chats[idx].targetId === groupId) {
this.commit("removeChat",idx)
this.commit("removeChat", idx)
break;
}
}
@ -322,6 +322,8 @@ export default {
chatKeys: chatKeys
}
localForage.setItem(key, chatsData)
// 清理已删除的会话
state.chats = state.chats.filter(chat => !chat.delete)
},
clear(state) {
cacheChats = []
@ -337,12 +339,11 @@ export default {
localForage.getItem(key).then((chatsData) => {
if (!chatsData) {
resolve();
}
else if(chatsData.chats){
} else if (chatsData.chats) {
// 兼容旧版本
context.commit("initChats", chatsData);
resolve();
}else if (chatsData.chatKeys) {
} else if (chatsData.chatKeys) {
const promises = [];
chatsData.chatKeys.forEach(key => {
promises.push(localForage.getItem(key))

Loading…
Cancel
Save