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
84190ade
Commit
84190ade
authored
Oct 12, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis管理rtc频道
parent
81e302e0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
236 additions
and
0 deletions
+236
-0
common/src/main/java/com/wecloud/im/ws/strategy/concrete/SingleRtcConcrete.java
+0
-0
common/src/main/java/com/wecloud/im/ws/utils/RedisUtils.java
+46
-0
common/src/main/java/com/wecloud/rtc/RtcRedisKey.java
+44
-0
common/src/main/java/com/wecloud/rtc/service/MangerRtcChannelService.java
+43
-0
common/src/main/java/com/wecloud/rtc/service/impl/MangerRtcChannelServiceImpl.java
+103
-0
No files found.
common/src/main/java/com/wecloud/im/ws/strategy/concrete/SingleRtcConcrete.java
View file @
84190ade
This diff is collapsed.
Click to expand it.
common/src/main/java/com/wecloud/im/ws/utils/RedisUtils.java
View file @
84190ade
...
@@ -22,6 +22,52 @@ public class RedisUtils {
...
@@ -22,6 +22,52 @@ public class RedisUtils {
@Autowired
@Autowired
private
StringRedisTemplate
redisTemplate
;
private
StringRedisTemplate
redisTemplate
;
public
StringRedisTemplate
redisTemplate
()
{
return
redisTemplate
;
}
/**
* 添加Key:value
*
* @param key
* @param value
*/
public
void
setKey
(
String
key
,
String
value
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
}
/**
* 删除Key
*
* @param key
*/
public
boolean
delKey
(
String
key
)
{
return
redisTemplate
.
delete
(
key
);
}
/**
* 获取Key
*
* @param key
*/
public
String
getKey
(
String
key
)
{
return
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 模糊查询
*
* @param key
* @return
*/
public
Set
<
String
>
keys
(
String
key
)
{
return
redisTemplate
.
keys
(
key
);
}
/**
/**
* 获取hash中field对应的值
* 获取hash中field对应的值
*
*
...
...
common/src/main/java/com/wecloud/rtc/RtcRedisKey.java
0 → 100644
View file @
84190ade
package
com
.
wecloud
.
rtc
;
import
java.io.Serializable
;
public
class
RtcRedisKey
implements
Serializable
{
/**
* 维护所有用户当前在线的频道ID
* new Map<String,Long> map
* map.put("clientA",10001)
* map.put("clientB",10001)
* map.put("clientC",10002)
* map.put("clientD",10003)
* <p>
* redis Key:
* user_join_channel = ujc
* rcu:clientA:10001
* rcu:clientB:10001
* rcu:clientC:10002
* rcu:clientD:10003
*/
public
static
final
String
USER_JOIN_CHANNEL
=
"ujc:%s:%s"
;
/**
* 维护频道中存在的用户
* Map<Long,List<String>> map
* <p>
* new List<String> list
* list.add("clientA")
* list.add("clientB")
* <p>
* map.put(10001,list)
* <p>
* redis Key:
* rtc_channel_users = rcu
* key = rcu:10001:clientA
* key = rcu:10001:clientB
* key = rcu:10002:clientC
* key = rcu:10003:clientD
*/
public
static
final
String
RTC_CHANNEL_USERS
=
"rcu:%s:%s"
;
}
common/src/main/java/com/wecloud/rtc/service/MangerRtcChannelService.java
0 → 100644
View file @
84190ade
package
com
.
wecloud
.
rtc
.
service
;
import
java.util.List
;
/**
* 管理rtc频道
*/
public
interface
MangerRtcChannelService
{
/**
* 创建一个频道
*/
Long
create
(
String
appKey
,
String
clientId
,
Long
rtcChannelId
);
/**
* 加入频道
*/
void
join
(
String
appKey
,
String
clientId
,
Long
rtcChannelId
);
/**
* 退出频道
*/
void
remove
(
String
appKey
,
String
clientId
,
Long
rtcChannelId
);
/**
* 根据频道ID获取频道内所有client
*/
List
<
String
>
getClientListByRtcChannelId
(
Long
rtcChannelId
);
/**
* 根据客户端ID获取该客户端加入的频道ID
*/
Long
getRtcChannelIdListByClientId
(
String
appKey
,
String
clientId
);
/**
* 获取客户端忙线/空闲状态
* @param appKey
* @param clientId
* @return true:忙线,false空闲
*/
boolean
getBusyStatus
(
String
appKey
,
String
clientId
);
}
common/src/main/java/com/wecloud/rtc/service/impl/MangerRtcChannelServiceImpl.java
0 → 100644
View file @
84190ade
package
com
.
wecloud
.
rtc
.
service
.
impl
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.rtc.RtcRedisKey
;
import
com.wecloud.rtc.service.MangerRtcChannelService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
@Service
public
class
MangerRtcChannelServiceImpl
implements
MangerRtcChannelService
{
@Autowired
private
RedisUtils
redisUtils
;
@Override
public
Long
create
(
String
appKey
,
String
clientId
,
Long
rtcChannelId
)
{
//用户当前在线的频道ID
String
userJoinChannelKey
=
String
.
format
(
RtcRedisKey
.
USER_JOIN_CHANNEL
,
appKey
+
clientId
,
rtcChannelId
);
//频道中存在的用户
String
rtcChannelUsersKey
=
String
.
format
(
RtcRedisKey
.
RTC_CHANNEL_USERS
,
rtcChannelId
,
appKey
+
clientId
);
redisUtils
.
setKey
(
userJoinChannelKey
,
""
);
redisUtils
.
setKey
(
rtcChannelUsersKey
,
""
);
return
null
;
}
@Override
public
void
join
(
String
appKey
,
String
clientId
,
Long
rtcChannelId
)
{
//用户当前在线的频道ID
String
userJoinChannelKey
=
String
.
format
(
RtcRedisKey
.
USER_JOIN_CHANNEL
,
appKey
+
clientId
,
rtcChannelId
);
//频道中存在的用户
String
rtcChannelUsersKey
=
String
.
format
(
RtcRedisKey
.
RTC_CHANNEL_USERS
,
rtcChannelId
,
appKey
+
clientId
);
redisUtils
.
setKey
(
userJoinChannelKey
,
""
);
redisUtils
.
setKey
(
rtcChannelUsersKey
,
""
);
}
@Override
public
void
remove
(
String
appKey
,
String
clientId
,
Long
rtcChannelId
)
{
//用户当前在线的频道ID
String
userJoinChannelKey
=
String
.
format
(
RtcRedisKey
.
USER_JOIN_CHANNEL
,
appKey
+
clientId
,
rtcChannelId
);
//频道中存在的用户
String
rtcChannelUsersKey
=
String
.
format
(
RtcRedisKey
.
RTC_CHANNEL_USERS
,
rtcChannelId
,
appKey
+
clientId
);
redisUtils
.
delKey
(
userJoinChannelKey
);
redisUtils
.
delKey
(
rtcChannelUsersKey
);
}
@Override
public
List
<
String
>
getClientListByRtcChannelId
(
Long
rtcChannelId
)
{
String
rtcChannelUsersKey
=
String
.
format
(
RtcRedisKey
.
RTC_CHANNEL_USERS
,
rtcChannelId
,
"*"
);
Set
<
String
>
keys
=
redisUtils
.
keys
(
rtcChannelUsersKey
);
List
<
String
>
clientList
=
new
ArrayList
<>();
for
(
String
next:
keys
){
String
s
=
next
.
split
(
":"
)[
2
];
clientList
.
add
(
s
);
}
return
clientList
;
}
@Override
public
Long
getRtcChannelIdListByClientId
(
String
appKey
,
String
clientId
)
{
String
userJoinChannelKey
=
String
.
format
(
RtcRedisKey
.
USER_JOIN_CHANNEL
,
appKey
+
clientId
,
"*"
);
Set
<
String
>
keys
=
redisUtils
.
keys
(
userJoinChannelKey
);
String
next
=
keys
.
iterator
().
next
();
return
Long
.
valueOf
(
next
.
split
(
":"
)[
2
]);
}
@Override
public
boolean
getBusyStatus
(
String
appKey
,
String
clientId
)
{
//用户当前在线的频道ID
String
userJoinChannelKey
=
String
.
format
(
RtcRedisKey
.
USER_JOIN_CHANNEL
,
appKey
+
clientId
,
"*"
);
Set
<
String
>
keys
=
redisUtils
.
keys
(
userJoinChannelKey
);
if
(
keys
==
null
||
keys
.
isEmpty
())
{
return
false
;
}
else
{
return
true
;
}
}
}
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