内网开发
This commit is contained in:
@@ -24,17 +24,18 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/v1/user/login")
|
||||
.excludePathPatterns("/v1/file/**")
|
||||
.excludePathPatterns("/v1/room/**")
|
||||
.excludePathPatterns("/v1/message/checkSend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600)
|
||||
.allowedHeaders("*");
|
||||
// registry.addMapping("/**")
|
||||
// .allowedOrigins("*")
|
||||
// .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
// .allowCredentials(true)
|
||||
// .maxAge(3600)
|
||||
// .allowedHeaders("*");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.lld.im.service.room.controller;
|
||||
|
||||
|
||||
import com.lld.im.common.ResponseVO;
|
||||
import com.lld.im.service.message.model.req.SendMessageReq;
|
||||
import com.lld.im.service.message.service.P2PMessageService;
|
||||
import com.lld.im.service.room.dao.ImRoomEntity;
|
||||
import com.lld.im.service.room.model.req.SRSCallBackReq;
|
||||
import com.lld.im.service.room.service.ImRoomService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("v1/room")
|
||||
public class RoomController {
|
||||
@Value("${custom.host}")
|
||||
private String host;
|
||||
|
||||
@Autowired
|
||||
ImRoomService roomService;
|
||||
|
||||
@PostMapping("/createRoom")
|
||||
public ResponseVO createRoom(@RequestBody ImRoomEntity roomEntity, Integer appId) {
|
||||
return ResponseVO.successResponse(roomService.createRoom(roomEntity));
|
||||
}
|
||||
|
||||
@PostMapping("/joinRoom")
|
||||
public ResponseVO joinRoom(@RequestBody ImRoomEntity roomEntity, Integer appId) {
|
||||
return ResponseVO.successResponse(roomService.joinRoom(roomEntity));
|
||||
}
|
||||
|
||||
@PostMapping("/getRoomInfo")
|
||||
public ResponseVO getRoomInfo(@RequestBody ImRoomEntity roomEntity) {
|
||||
return ResponseVO.successResponse(roomService.getRoomInfo(roomEntity));
|
||||
}
|
||||
|
||||
@PostMapping("/leaveRoom")
|
||||
public ResponseVO leaveRoom(@RequestBody ImRoomEntity roomEntity, Integer appId) {
|
||||
roomService.leaveRoom(roomEntity);
|
||||
return ResponseVO.successResponse(roomEntity.getPublishName()+"离开视频房间");
|
||||
}
|
||||
|
||||
@PostMapping("/unpublish")
|
||||
public ResponseVO unpublish(@RequestBody SRSCallBackReq callBackReq) {
|
||||
log.info(callBackReq.toString());
|
||||
/*
|
||||
POST /api/v1/streams HTTP/1.1
|
||||
Content-Type: application-json
|
||||
Body:
|
||||
{
|
||||
"server_id": "vid-0xk989d",
|
||||
"action": "on_publish",
|
||||
"client_id": "341w361a",
|
||||
"ip": "127.0.0.1",
|
||||
"vhost": "__defaultVhost__",
|
||||
"app": "live",
|
||||
"tcUrl": "rtmp://127.0.0.1:1935/live?vhost=__defaultVhost__",
|
||||
"stream": "livestream",
|
||||
"param": "",
|
||||
"stream_url": "video.test.com/live/livestream",
|
||||
"stream_id": "vid-124q9y3"
|
||||
}
|
||||
*/
|
||||
try {
|
||||
ImRoomEntity roomEntity = new ImRoomEntity();
|
||||
roomEntity.setRoomId(callBackReq.getApp());
|
||||
roomEntity.setPublishId(callBackReq.getStream());
|
||||
if(StringUtils.equals(callBackReq.getAction() ,"on_unpublish")){
|
||||
roomService.deleteUserFromRoom(roomEntity);
|
||||
}else if(StringUtils.equals(callBackReq.getAction() ,"on_publish")){
|
||||
roomEntity.setOffline(0);
|
||||
roomEntity.setIsOver(0);
|
||||
roomEntity.setWebrtcUrl("webrtc://"+this.host+"/"+callBackReq.getApp()+"/"+callBackReq.getStream());
|
||||
roomService.joinRoom(roomEntity);
|
||||
}
|
||||
return ResponseVO.srsOkResponse();
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(), e);
|
||||
return ResponseVO.srsOkResponse();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.lld.im.service.room.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("im_room")
|
||||
public class ImRoomEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
private String roomId;
|
||||
private String roomName;
|
||||
private String creatorId;
|
||||
private String creatorName;
|
||||
private String publishId;
|
||||
private String publishName;
|
||||
private Integer isOver;
|
||||
private String webrtcUrl;
|
||||
private String rtmpUrl;
|
||||
private String type;
|
||||
private Integer offline;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.lld.im.service.room.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lld.im.service.room.dao.ImRoomEntity;
|
||||
|
||||
public interface ImRoomMapper extends BaseMapper<ImRoomEntity> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.lld.im.service.room.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SRSCallBackReq {
|
||||
private String serverId;
|
||||
private String action;
|
||||
private String app;
|
||||
private String stream;
|
||||
private String streamUrl;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.lld.im.service.room.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.lld.im.common.enums.DelFlagEnum;
|
||||
import com.lld.im.service.message.dao.mapper.ImMessageBodyMapper;
|
||||
import com.lld.im.service.room.dao.ImRoomEntity;
|
||||
import com.lld.im.service.room.dao.mapper.ImRoomMapper;
|
||||
import com.lld.im.service.user.dao.ImUserDataEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ImRoomService {
|
||||
@Autowired
|
||||
ImRoomMapper imRoomMapper;
|
||||
|
||||
@Transactional
|
||||
public ImRoomEntity createRoom(ImRoomEntity entity) {
|
||||
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("room_id",entity.getRoomId());
|
||||
queryWrapper.eq("publish_id",entity.getPublishId());
|
||||
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
|
||||
if(roomEntityList.size()>0){
|
||||
imRoomMapper.delete(queryWrapper);
|
||||
}
|
||||
imRoomMapper.insert(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ImRoomEntity joinRoom(ImRoomEntity entity) {
|
||||
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("room_id",entity.getRoomId());
|
||||
queryWrapper.eq("publish_id",entity.getPublishId());
|
||||
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
|
||||
if(roomEntityList.size()>0){
|
||||
roomEntityList.get(0).setIsOver(0);
|
||||
roomEntityList.get(0).setOffline(0);
|
||||
roomEntityList.get(0).setWebrtcUrl(entity.getWebrtcUrl());
|
||||
imRoomMapper.updateById(roomEntityList.get(0));
|
||||
}else {
|
||||
entity.setOffline(0);
|
||||
entity.setIsOver(0);
|
||||
imRoomMapper.insert(entity);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
public void deleteUserFromRoom(ImRoomEntity entity){
|
||||
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("room_id",entity.getRoomId());
|
||||
queryWrapper.eq("publish_id",entity.getPublishId());
|
||||
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
|
||||
|
||||
imRoomMapper.delete(queryWrapper);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void updateRoomInfo(ImRoomEntity entity) {
|
||||
|
||||
}
|
||||
public List<ImRoomEntity> getRoomInfo(ImRoomEntity entity){
|
||||
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("room_id",entity.getRoomId());
|
||||
|
||||
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
|
||||
|
||||
return roomEntityList;
|
||||
}
|
||||
public void leaveRoom (ImRoomEntity entity){
|
||||
QueryWrapper<ImRoomEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("room_id",entity.getRoomId());
|
||||
queryWrapper.eq("publish_id",entity.getPublishId());
|
||||
List<ImRoomEntity> roomEntityList = imRoomMapper.selectList(queryWrapper);
|
||||
|
||||
if (roomEntityList.size()>0){
|
||||
imRoomMapper.delete(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: -1
|
||||
max-request-size: -1
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: beAs0LHX2GyTxMw4
|
||||
@@ -97,7 +101,8 @@ mqQueueName: 123
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 会正常输出日志
|
||||
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl # nologging.NoLoggingImpl
|
||||
mapper-locations: classpath*:mapper/*.xml
|
||||
global-config:
|
||||
db-config:
|
||||
@@ -124,3 +129,7 @@ minio:
|
||||
minio_name: admin
|
||||
minio_pass: 12345678
|
||||
bucketName: hd-im
|
||||
|
||||
|
||||
custom:
|
||||
host: 119.45.242.222
|
||||
|
||||
133
hs-im-server/im-service/src/main/resources/application-local.yml
Normal file
133
hs-im-server/im-service/src/main/resources/application-local.yml
Normal file
@@ -0,0 +1,133 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: local
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: -1
|
||||
max-request-size: -1
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: beAs0LHX2GyTxMw4
|
||||
url: jdbc:mysql://43.139.191.204:3306/im-core?serverTimezone=UTC&useSSL=false&characterEncoding=UTF8
|
||||
username: root
|
||||
|
||||
redis:
|
||||
host: 43.139.191.204
|
||||
port: 6379
|
||||
database: 8
|
||||
jedis:
|
||||
pool:
|
||||
max-active: 100
|
||||
max-idle: 100
|
||||
max-wait: 1000
|
||||
min-idle: 10
|
||||
password: dSMIXBQrCBXiHHjk123
|
||||
rabbitmq:
|
||||
host: 119.45.242.222
|
||||
port: 5672
|
||||
addresses: 119.45.242.222
|
||||
username: guest
|
||||
password: guest
|
||||
# virtual-host:
|
||||
listener:
|
||||
simple:
|
||||
concurrency: 5
|
||||
max-concurrency: 10
|
||||
acknowledge-mode: MANUAL
|
||||
prefetch: 1
|
||||
publisher-confirms: true
|
||||
publisher-returns: true
|
||||
template:
|
||||
mandatory: true
|
||||
cache:
|
||||
connection:
|
||||
mode: channel
|
||||
channel:
|
||||
size: 36
|
||||
checkout-timeout: 0
|
||||
application:
|
||||
name: im-core
|
||||
|
||||
|
||||
# logger 配置
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
|
||||
server:
|
||||
port: 28000
|
||||
|
||||
appConfig:
|
||||
appId: 10000
|
||||
privateKey: 123456
|
||||
zkAddr: 119.45.242.222:2181 # zk连接地址
|
||||
zkConnectTimeOut: 50000 #zk超时时间
|
||||
imRouteWay: 3 # 路由策略1轮训 2随机 3hash
|
||||
consistentHashWay: 1 # 如果选用一致性hash的话具体hash算法 1 TreeMap 2 自定义Map
|
||||
tcpPort: 19000 # tcp端口
|
||||
webSocketPort: 29000 # webSocket端口
|
||||
needWebSocket: true #是否需要开启webSocket
|
||||
loginModel: 1
|
||||
messageRecallTimeOut : 1200000000 #消息可撤回时间,单位毫秒
|
||||
# * 多端同步模式:1 只允许一端在线,手机/电脑/web 踢掉除了本client+imel的设备
|
||||
# * 2 允许手机/电脑的一台设备 + web在线 踢掉除了本client+imel的非web端设备
|
||||
# * 3 允许手机和电脑单设备 + web 同时在线 踢掉非本client+imel的同端设备
|
||||
# * 4 允许所有端多设备登录 不踢任何设备
|
||||
groupMaxMemberCount: 500
|
||||
sendMessageCheckFriend: false # 发送消息是否校验关系链
|
||||
sendMessageCheckBlack: false # 发送消息是否校验黑名单
|
||||
callbackUrl: http://127.0.0.1:8000/callback
|
||||
modifyUserAfterCallback: false # 用户资料变更之后回调开关
|
||||
addFriendAfterCallback: false # 添加好友之后回调开关
|
||||
addFriendBeforeCallback: false # 添加好友之前回调开关
|
||||
modifyFriendAfterCallback: false # 修改好友之后回调开关
|
||||
deleteFriendAfterCallback: false # 删除好友之后回调开关
|
||||
addFriendShipBlackAfterCallback: false #添加黑名单之后回调开关
|
||||
deleteFriendShipBlackAfterCallback: false #删除黑名单之后回调开关
|
||||
createGroupAfterCallback: false # 创建群聊之后回调开关
|
||||
modifyGroupAfterCallback: false # 修改群聊之后回调开关
|
||||
destroyGroupAfterCallback: false # 解散群聊之后回调开关
|
||||
deleteGroupMemberAfterCallback: false # 删除群成员之后回调
|
||||
addGroupMemberAfterCallback: false # 拉人入群之后回调
|
||||
addGroupMemberBeforeCallback: false # 拉人入群之前回调
|
||||
sendMessageAfterCallback: false # 发送单聊消息之后
|
||||
sendMessageBeforeCallback: false # 发送单聊消息之前
|
||||
sendGroupMessageAfterCallback: false # 发送群聊消息之后
|
||||
sendGroupMessageBeforeCallback: false # 发送群聊消息之前
|
||||
offlineMessageCount: 1000 #离线消息存储条数
|
||||
deleteConversationSyncMode: 1 #1多段同步
|
||||
|
||||
|
||||
mqQueueName: 123
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mapper-locations: classpath*:mapper/*.xml
|
||||
global-config:
|
||||
db-config:
|
||||
update-strategy: NOT_EMPTY
|
||||
|
||||
#mybatis:
|
||||
# configuration:
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
httpclient:
|
||||
maxTotal: 100
|
||||
defaultMaxPerRoute: 50
|
||||
connectTimeout: 2000
|
||||
connectionRequestTimeout: 2000
|
||||
socketTimeout: 5000
|
||||
staleConnectionCheckEnabled: true
|
||||
|
||||
mpp:
|
||||
entityBasePath: com.lld.im.service.friendship.dao
|
||||
|
||||
# minio文件上传
|
||||
minio:
|
||||
minio_url: http://43.139.240.200:9000
|
||||
minio_name: admin
|
||||
minio_pass: 12345678
|
||||
bucketName: hd-im
|
||||
|
||||
custom:
|
||||
host: 119.45.242.222
|
||||
@@ -1,6 +1,10 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
active: prod
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: -1
|
||||
max-request-size: -1
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
password: Mars@23600800
|
||||
@@ -117,3 +121,15 @@ httpclient:
|
||||
|
||||
mpp:
|
||||
entityBasePath: com.lld.im.service.friendship.dao
|
||||
|
||||
|
||||
# minio文件上传
|
||||
minio:
|
||||
minio_url: http://172.16.2.1:9000
|
||||
minio_name: admin
|
||||
minio_pass: WEf8TSZoYkOpejINGXfA5mDov5I8hAcy
|
||||
bucketName: hd-im
|
||||
|
||||
|
||||
custom:
|
||||
host: 172.16.3.19
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<!--控制台 Appender-->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>DEBUG</level>
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
@@ -85,4 +85,4 @@
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user