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
c722cbb3
Commit
c722cbb3
authored
Feb 10, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
频道问题处理
parent
bad888c7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
34 deletions
+25
-34
core/src/main/java/com/wecloud/rtc/service/impl/RtcServiceImpl.java
+25
-34
No files found.
core/src/main/java/com/wecloud/rtc/service/impl/RtcServiceImpl.java
View file @
c722cbb3
...
...
@@ -3,8 +3,6 @@ package com.wecloud.rtc.service.impl;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.enums.CallTypeEnum
;
import
com.wecloud.im.enums.FriendStateEnum
;
import
com.wecloud.im.param.rtc.CandidateForwardParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelResult
;
...
...
@@ -25,11 +23,10 @@ import com.wecloud.rtc.entity.response.RtcSdpForwardResponse;
import
com.wecloud.rtc.service.MangerRtcCacheService
;
import
com.wecloud.rtc.service.RtcService
;
import
com.wecloud.rtc.service.WsRtcWrite
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
com.wecloud.utils.SnowflakeUtil
;
import
io.geekidea.springbootplus.framework.common.
enums.BaseEnum
;
import
io.geekidea.springbootplus.framework.common.
api.ApiResult
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -81,20 +78,20 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
@Override
public
ApiResult
<
CreateRtcChannelResult
>
createAndCall
(
CreateRtcChannelParam
createRtcChannelParam
)
throws
JsonProcessingException
{
ImClient
client
=
imClientService
.
getCurentClient
();
ImClient
c
urrentC
lient
=
imClientService
.
getCurentClient
();
Long
rtcChannelId
=
SnowflakeUtil
.
getId
();
if
(
BaseEnum
.
valueOf
(
CallTypeEnum
.
class
,
createRtcChannelParam
.
getCallType
())
==
null
)
{
return
ApiResult
.
fail
(
ApiCode
.
PARAMETER_EXCEPTION
,
null
);
}
// 判断发起方必须在线
boolean
onlineStatus
=
userStateCacheManager
.
isOnline
(
client
.
getId
());
boolean
onlineStatus
=
userStateCacheManager
.
isOnline
(
c
urrentC
lient
.
getId
());
if
(!
onlineStatus
)
{
log
.
info
(
"发起方必须在线"
+
client
.
getFkAppid
()
+
client
.
getClientId
());
log
.
info
(
"发起方必须在线"
+
currentClient
.
getFkAppid
()
+
currentClient
.
getClientId
());
ApiResult
.
fail
();
}
ImClient
toClient
=
imClientService
.
getCacheImClient
(
currentClient
.
getFkAppid
(),
createRtcChannelParam
.
getToClient
());
if
(
toClient
==
null
)
{
ApiResult
.
fail
();
}
// 添加缓存
mangerRtcCacheService
.
create
(
client
.
getId
(),
rtcChannelId
);
mangerRtcCacheService
.
create
(
c
urrentClient
.
getId
(),
toC
lient
.
getId
(),
rtcChannelId
);
CreateRtcChannelResult
createRtcChannelResult
=
new
CreateRtcChannelResult
();
createRtcChannelResult
.
setChannelId
(
rtcChannelId
);
...
...
@@ -104,10 +101,9 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
rtcCallResponse
.
setCallType
(
createRtcChannelParam
.
getCallType
());
// rtcCallResponse.setConversationId(createRtcChannelParam.getConversationId());
rtcCallResponse
.
setChannelId
(
rtcChannelId
);
rtcCallResponse
.
setClientId
(
client
.
getClientId
());
rtcCallResponse
.
setClientId
(
c
urrentC
lient
.
getClientId
());
rtcCallResponse
.
setTimestamp
(
System
.
currentTimeMillis
());
ImClient
toClient
=
imClientService
.
getCacheImClient
(
client
.
getFkAppid
(),
createRtcChannelParam
.
getToClient
());
wsRtcWrite
.
rtcCall
(
rtcCallResponse
,
toClient
.
getId
());
// TODO 待开发 下发安卓和ios系统推送
...
...
@@ -128,7 +124,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
joinRtcChannelParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
client
.
get
ClientId
());
clientListByRtcChannelId
.
remove
(
client
.
get
Id
().
toString
());
for
(
String
toClientId
:
clientListByRtcChannelId
)
{
...
...
@@ -148,12 +144,10 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
public
ApiResult
<
Boolean
>
reject
(
RejectRtcChannelParam
rejectRtcChannelParam
)
{
ImClient
client
=
imClientService
.
getCurentClient
();
ImApplication
imApplication
=
imApplicationService
.
getCacheById
(
client
.
getFkAppid
());
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
rejectRtcChannelParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
client
.
get
ClientId
());
clientListByRtcChannelId
.
remove
(
client
.
get
Id
().
toString
());
for
(
String
toClientId
:
clientListByRtcChannelId
)
{
...
...
@@ -171,40 +165,37 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
@Override
public
ApiResult
<
Boolean
>
leave
(
LeaveRtcChannelParam
leaveRtcChannelParam
)
{
ImClient
client
=
imClientService
.
getCurentClient
();
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getCacheById
(
client
.
getFkAppid
());
this
.
leave
(
leaveRtcChannelParam
,
client
);
ImClient
currentClient
=
imClientService
.
getCurentClient
();
this
.
leave
(
leaveRtcChannelParam
,
currentClient
);
return
ApiResult
.
ok
(
true
);
}
private
void
leave
(
LeaveRtcChannelParam
leaveRtcChannelParam
,
ImClient
client
)
{
private
void
leave
(
LeaveRtcChannelParam
leaveRtcChannelParam
,
ImClient
c
urrentC
lient
)
{
// 修改缓存
mangerRtcCacheService
.
leave
(
client
.
getId
(),
leaveRtcChannelParam
.
getChannelId
());
mangerRtcCacheService
.
leave
(
c
urrentC
lient
.
getId
(),
leaveRtcChannelParam
.
getChannelId
());
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
leaveRtcChannelParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
client
.
getClientId
());
for
(
String
toClientId
:
clientListByRtcChannelId
)
{
// ws向接收方发送通知
RtcClientLeaveResponse
rtcClientLeaveResponse
=
new
RtcClientLeaveResponse
();
rtcClientLeaveResponse
.
setChannelId
(
leaveRtcChannelParam
.
getChannelId
());
rtcClientLeaveResponse
.
setClientId
(
client
.
getClientId
());
rtcClientLeaveResponse
.
setClientId
(
c
urrentC
lient
.
getClientId
());
rtcClientLeaveResponse
.
setTimestamp
(
System
.
currentTimeMillis
());
wsRtcWrite
.
clientLeave
(
rtcClientLeaveResponse
,
Long
.
valueOf
(
toClientId
));
}
// 判断频道内是否无其他人了
if
(
mangerRtcCacheService
.
channelIsEmpty
(
leaveRtcChannelParam
.
getChannelId
()
))
{
if
(
CollectionUtils
.
isEmpty
(
clientListByRtcChannelId
))
{
// 移除频道信息
mangerRtcCacheService
.
delChannelInfo
(
leaveRtcChannelParam
.
getChannelId
());
}
else
if
(
clientListByRtcChannelId
.
size
()
==
1
){
// 频道内只有一个人了 -- 删除频道 并将这个人设为离开
mangerRtcCacheService
.
leave
(
Long
.
valueOf
(
clientListByRtcChannelId
.
get
(
0
)),
leaveRtcChannelParam
.
getChannelId
());
mangerRtcCacheService
.
delChannelInfo
(
leaveRtcChannelParam
.
getChannelId
());
}
}
...
...
@@ -230,7 +221,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
sdpForwardParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
client
.
get
ClientId
());
clientListByRtcChannelId
.
remove
(
client
.
get
Id
().
toString
());
for
(
String
toClientId
:
clientListByRtcChannelId
)
{
...
...
@@ -271,7 +262,7 @@ public class RtcServiceImpl extends UserStateListener implements RtcService {
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
candidateForwardParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
client
.
get
ClientId
());
clientListByRtcChannelId
.
remove
(
client
.
get
Id
().
toString
());
for
(
String
toClientId
:
clientListByRtcChannelId
)
{
...
...
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