Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
347ad0b6
Commit
347ad0b6
authored
Oct 20, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化webrtc缓存 : 删除ChannelInfo; 获取RtcChannelInfo
parent
104ec405
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
94 additions
and
24 deletions
+94
-24
common/src/main/java/com/wecloud/im/netty/core/NettyChannelInitializer.java
+1
-1
common/src/main/java/com/wecloud/im/ws/service/impl/MangerChannelServiceImpl.java
+6
-6
common/src/main/java/com/wecloud/im/ws/strategy/concrete/SingleRtcConcrete.java
+1
-1
common/src/main/java/com/wecloud/rtc/entity/RtcSubCmd.java
+1
-1
common/src/main/java/com/wecloud/rtc/entity/redis/RtcChannelInfo.java
+3
-0
common/src/main/java/com/wecloud/rtc/service/MangerRtcCacheService.java
+27
-1
common/src/main/java/com/wecloud/rtc/service/impl/MangerRtcCacheServiceImpl.java
+29
-4
common/src/main/java/com/wecloud/rtc/service/impl/RtcServiceImpl.java
+9
-7
开发记录.md
+17
-3
No files found.
common/src/main/java/com/wecloud/im/netty/core/NettyChannelInitializer.java
View file @
347ad0b6
...
...
@@ -44,7 +44,7 @@ public class NettyChannelInitializer extends ChannelInitializer<SocketChannel> {
* allIdleTime—状态为IdleState的IdleStateEvent。在一定时间内不读不写会触发ALL_IDLE。指定0禁用。
* unit—readerIdleTime、writeIdleTime和allIdleTime的时间单位
*/
pipeline
.
addLast
(
new
IdleStateHandler
(
1
5
,
0
,
0
,
TimeUnit
.
SECONDS
));
pipeline
.
addLast
(
new
IdleStateHandler
(
5
,
0
,
0
,
TimeUnit
.
SECONDS
));
}
}
common/src/main/java/com/wecloud/im/ws/service/impl/MangerChannelServiceImpl.java
View file @
347ad0b6
...
...
@@ -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
(
...
...
common/src/main/java/com/wecloud/im/ws/strategy/concrete/SingleRtcConcrete.java
View file @
347ad0b6
...
...
@@ -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
;
...
...
common/src/main/java/com/wecloud/rtc/RtcSubCmd.java
→
common/src/main/java/com/wecloud/rtc/
entity/
RtcSubCmd.java
View file @
347ad0b6
package
com
.
wecloud
.
rtc
;
package
com
.
wecloud
.
rtc
.
entity
;
import
java.io.Serializable
;
...
...
common/src/main/java/com/wecloud/rtc/entity/redis/RtcChannelInfo.java
View file @
347ad0b6
...
...
@@ -14,6 +14,9 @@ public class RtcChannelInfo implements Serializable {
@ApiModelProperty
(
"当前房主"
)
private
String
owner
;
private
String
appKey
;
// private String appId;
@ApiModelProperty
(
"创建时间"
)
private
Long
createTimestamp
;
}
common/src/main/java/com/wecloud/rtc/service/MangerRtcCacheService.java
View file @
347ad0b6
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
;
/**
* 创建一个频道
...
...
common/src/main/java/com/wecloud/rtc/service/impl/MangerRtcCacheServiceImpl.java
View file @
347ad0b6
...
...
@@ -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
());
...
...
common/src/main/java/com/wecloud/rtc/service/impl/RtcServiceImpl.java
View file @
347ad0b6
...
...
@@ -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
)
{
...
...
开发记录.md
View file @
347ad0b6
...
...
@@ -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提供一个本地路径即可。
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment