Commit 347ad0b6 by giaogiao

优化webrtc缓存 : 删除ChannelInfo; 获取RtcChannelInfo

parent 104ec405
......@@ -44,7 +44,7 @@ public class NettyChannelInitializer extends ChannelInitializer<SocketChannel> {
* allIdleTime—状态为IdleState的IdleStateEvent。在一定时间内不读不写会触发ALL_IDLE。指定0禁用。
* unit—readerIdleTime、writeIdleTime和allIdleTime的时间单位
*/
pipeline.addLast(new IdleStateHandler(15, 0, 0, TimeUnit.SECONDS));
pipeline.addLast(new IdleStateHandler(5, 0, 0, TimeUnit.SECONDS));
}
}
......@@ -310,22 +310,22 @@ public class MangerChannelServiceImpl implements MangerChannelService {
NioSocketChannel nioSocketChannel = get(toAppKey, toClientId);
if (null == nioSocketChannel) {
// userCache.offline(toAppKey + toClientId);
if (log.isDebugEnabled()) {
// if (log.isDebugEnabled()) {
log.info("writeData连接为空:" + toAppKey + toClientId + "," + msg);
}
// }
return false;
}
// 判断连接是否断开
if (nioSocketChannel.isShutdown()) {
if (log.isDebugEnabled()) {
// if (log.isDebugEnabled()) {
log.info("writeData连接断开:" + toAppKey + toClientId + "," + msg + ",\nchannelId:" + nioSocketChannel.id().asLongText());
}
// }
return false;
}
if (log.isDebugEnabled()) {
// if (log.isDebugEnabled()) {
log.info("writeData:" + toAppKey + "," + toClientId + "," + msg + ",\nchannelId:" + nioSocketChannel.id().asLongText());
}
// }
ChannelFuture channelFuture = nioSocketChannel.writeAndFlush(new TextWebSocketFrame(msg));
channelFuture.addListener(
......
......@@ -14,7 +14,7 @@ import com.wecloud.im.ws.model.request.ReceiveModel;
import com.wecloud.im.ws.sender.SystemPush;
import com.wecloud.im.ws.service.WriteDataService;
import com.wecloud.im.ws.strategy.ImCmdAbstract;
import com.wecloud.rtc.RtcSubCmd;
import com.wecloud.rtc.entity.RtcSubCmd;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......
package com.wecloud.rtc;
package com.wecloud.rtc.entity;
import java.io.Serializable;
......
......@@ -14,6 +14,9 @@ public class RtcChannelInfo implements Serializable {
@ApiModelProperty("当前房主")
private String owner;
private String appKey;
// private String appId;
@ApiModelProperty("创建时间")
private Long createTimestamp;
}
package com.wecloud.rtc.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wecloud.rtc.entity.redis.RtcChannelInfo;
import java.util.List;
......@@ -9,7 +10,32 @@ import java.util.List;
*/
public interface MangerRtcCacheService {
boolean isEmpty(String appKey, String clientId, Long rtcChannelId);
/**
* 移除频道信息
*
* @param rtcChannelId
* @return
*/
boolean delChannelInfo(Long rtcChannelId);
/**
* 频道中客户端是否为空
*
* @param rtcChannelId
* @return
*/
boolean channelIsEmpty(Long rtcChannelId);
/**
* 获取频道信息
*
* @param rtcChannelId
* @return
* @throws JsonProcessingException
*/
RtcChannelInfo getRtcChannelInfo(Long rtcChannelId) throws JsonProcessingException;
/**
* 创建一个频道
......
......@@ -23,21 +23,46 @@ public class MangerRtcCacheServiceImpl implements MangerRtcCacheService {
@Override
public boolean isEmpty(String appKey, String clientId, Long rtcChannelId) {
public boolean delChannelInfo(Long rtcChannelId) {
String channelKey = String.format(RtcRedisKey.RTC_CHANNEL_INFO, rtcChannelId);
redisUtils.delKey(channelKey);
return true;
}
@Override
public boolean channelIsEmpty(Long rtcChannelId) {
List<String> clientListByRtcChannelId = getClientListByRtcChannelId(rtcChannelId);
// 移除自己
clientListByRtcChannelId.remove(appKey + clientId);
// // 移除自己
// clientListByRtcChannelId.remove(appKey + clientId);
return clientListByRtcChannelId.isEmpty();
}
@Override
public RtcChannelInfo getRtcChannelInfo(Long rtcChannelId) throws JsonProcessingException {
// 频道信息
String channelKey = String.format(RtcRedisKey.RTC_CHANNEL_INFO, rtcChannelId);
String value = redisUtils.getKey(channelKey);
if (StringUtils.isBlank(value)) {
return null;
}
JsonMapper jsonMapper = new JsonMapper();
return jsonMapper.readValue(value, RtcChannelInfo.class);
}
@Override
public void create(String appKey, String clientId, Long rtcChannelId) throws JsonProcessingException {
// --- 频道信息
RtcChannelInfo rtcChannelInfo = new RtcChannelInfo();
rtcChannelInfo.setAppKey(appKey);
// rtcChannelInfo.setAppId("");
//当前房主
rtcChannelInfo.setOwner(appKey + clientId);
rtcChannelInfo.setOwner(clientId);
//创建时间
rtcChannelInfo.setCreateTimestamp(new Date().getTime());
......
......@@ -124,7 +124,7 @@ public class RtcServiceImpl implements RtcService {
//获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(joinRtcChannelParam.getChannelId());
// 移除自己
clientListByRtcChannelId.remove(imApplication.getAppKey() + client.getClientId());
clientListByRtcChannelId.remove(client.getClientId());
for (String toClientId : clientListByRtcChannelId) {
......@@ -149,7 +149,7 @@ public class RtcServiceImpl implements RtcService {
//获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(rejectRtcChannelParam.getChannelId());
// 移除自己
clientListByRtcChannelId.remove(imApplication.getAppKey() + client.getClientId());
clientListByRtcChannelId.remove(client.getClientId());
for (String toClientId : clientListByRtcChannelId) {
......@@ -184,7 +184,7 @@ public class RtcServiceImpl implements RtcService {
//获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(leaveRtcChannelParam.getChannelId());
// 移除自己
clientListByRtcChannelId.remove(imApplication.getAppKey() + client.getClientId());
clientListByRtcChannelId.remove(client.getClientId());
for (String toClientId : clientListByRtcChannelId) {
......@@ -198,8 +198,10 @@ public class RtcServiceImpl implements RtcService {
}
// 判断频道内是否无其他人了
// if (clientListByRtcChannelId == null) {
// }
if (mangerRtcCacheService.channelIsEmpty(leaveRtcChannelParam.getChannelId())) {
// 移除频道信息
mangerRtcCacheService.delChannelInfo(leaveRtcChannelParam.getChannelId());
}
}
@Override
......@@ -224,7 +226,7 @@ public class RtcServiceImpl implements RtcService {
//获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(sdpForwardParam.getChannelId());
// 移除自己
clientListByRtcChannelId.remove(imApplication.getAppKey() + client.getClientId());
clientListByRtcChannelId.remove(client.getClientId());
for (String toClientId : clientListByRtcChannelId) {
......@@ -265,7 +267,7 @@ public class RtcServiceImpl implements RtcService {
//获取频道内所有client
List<String> clientListByRtcChannelId = mangerRtcCacheService.getClientListByRtcChannelId(candidateForwardParam.getChannelId());
// 移除自己
clientListByRtcChannelId.remove(imApplication.getAppKey() + client.getClientId());
clientListByRtcChannelId.remove(client.getClientId());
for (String toClientId : clientListByRtcChannelId) {
......
......@@ -6,11 +6,9 @@ String appSecret = "a5e619003868258e0f7c5b5821ea00fb6b2302faf2ab3737";
--
clientA1
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWIiLCJjbGllbnRJZCI6ImNsaWVudEExIiwiaXNzIjoid2VjbG91ZF9pbSIsImFwcEtleSI6IlFOdFAzRWp0THcyNmVrdDAiLCJleHAiOjE2ODQwMDA2NjIsImlhdCI6MTYzNDAyMTY1NCwianRpIjoiYzBiMDExOWNmYzE5NDk1YjgzYWU5YjQ3ZmFlZmM5ZTMifQ.2d_oQT-KwYmSOVZ7zXiuBTB8zRA4H8UgP2m_cMerGHE
--
aaaaa2
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ3ZWIiLCJjbGllbnRJZCI6ImFhYWFhMiIsImlzcyI6IndlY2xvdWRfaW0iLCJhcHBLZXkiOiJRTnRQM0VqdEx3MjZla3QwIiwiZXhwIjoxNjg0MDAwNzAwLCJpYXQiOjE2MzQwMjE2OTIsImp0aSI6IjFhY2RhNWEzNGI3NjQwZTA4MDBlMWNiMTRhNTBmMWI5In0.m18ZspfoKDx_RjrBJ07o5CP1nSaLAMEwKmSUvh94ilc
--
......@@ -257,3 +255,19 @@ ws
若房间内只剩一个人 ,下发只剩一个人的通知 并要求仅剩的客户端上传offer的SDP 与candidate, 使原发起方成为"房主"来等待接收方来应答"answer"
原发起方来重连时, 调用join接口,则返回另一端的offer的SDP,同时上传自己的answer SDP
##webrtc测试时https的问题
https://blog.csdn.net/sxc1989/article/details/81291320
在chorme中需要在https的情况下才能使用webrtc,在没有正式证书情况下, 可采用以下几种方式。
mac
用命令行启动chrome
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --unsafely-treat-insecure-origin-as-secure="http://192.168.1.250:5500" --user-data-dir=/Users/giaogiao/Downloads
win
右击chrome游览器图标,选择“属性”,在目标后面加入如下内容:
--unsafely-treat-insecure-origin-as-secure="http://ip:port" --user-data-dir="C:/temp"
1
其中ip、port为服务端地址,–user-data-dir提供一个本地路径即可。
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment