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
4f218eb9
Commit
4f218eb9
authored
Oct 19, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WebRtc webSocket下发指令数据
parent
aafeadd9
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
499 additions
and
79 deletions
+499
-79
common/src/main/java/com/wecloud/im/controller/ImRtcController.java
+17
-17
common/src/main/java/com/wecloud/im/param/rtc/CandidateForwardParam.java
+25
-0
common/src/main/java/com/wecloud/im/param/rtc/CreateRtcChannelParam.java
+3
-6
common/src/main/java/com/wecloud/im/param/rtc/CreateRtcChannelResult.java
+1
-1
common/src/main/java/com/wecloud/im/param/rtc/JoinRtcChannelParam.java
+3
-3
common/src/main/java/com/wecloud/im/param/rtc/LeaveRtcChannelParam.java
+22
-0
common/src/main/java/com/wecloud/im/param/rtc/RejectRtcChannelParam.java
+22
-0
common/src/main/java/com/wecloud/im/param/rtc/SdpForwardParam.java
+26
-0
common/src/main/java/com/wecloud/im/service/impl/ImInboxServiceImpl.java
+2
-2
common/src/main/java/com/wecloud/im/ws/enums/WsResponseCmdEnum.java
+1
-1
common/src/main/java/com/wecloud/im/ws/model/WsResponseModel.java
+1
-1
common/src/main/java/com/wecloud/im/ws/service/WriteDataService.java
+2
-2
common/src/main/java/com/wecloud/im/ws/service/impl/WriteDataServiceImpl.java
+3
-3
common/src/main/java/com/wecloud/im/ws/strategy/concrete/ImChatConcrete.java
+5
-5
common/src/main/java/com/wecloud/rtc/entity/redis/RtcChannelInfo.java
+1
-1
common/src/main/java/com/wecloud/rtc/entity/redis/RtcJoinUser.java
+4
-3
common/src/main/java/com/wecloud/rtc/entity/redis/RtcJoinUsers.java
+1
-1
common/src/main/java/com/wecloud/rtc/entity/redis/RtcRedisKey.java
+4
-9
common/src/main/java/com/wecloud/rtc/entity/response/RtcCallResponse.java
+1
-1
common/src/main/java/com/wecloud/rtc/service/RtcService.java
+26
-8
common/src/main/java/com/wecloud/rtc/service/WsRtcWrite.java
+45
-0
common/src/main/java/com/wecloud/rtc/service/impl/MangerRtcCacheServiceImpl.java
+2
-2
common/src/main/java/com/wecloud/rtc/service/impl/RtcServiceImpl.java
+135
-13
common/src/main/java/com/wecloud/rtc/service/impl/WsRtcWriteImpl.java
+147
-0
No files found.
common/src/main/java/com/wecloud/im/controller/ImRtcController.java
View file @
4f218eb9
package
com
.
wecloud
.
im
.
controller
;
import
com.wecloud.im.param.CreateRtcChannelResult
;
import
com.wecloud.im.param.add.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CandidateForwardParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelResult
;
import
com.wecloud.im.param.rtc.JoinRtcChannelParam
;
import
com.wecloud.im.param.rtc.LeaveRtcChannelParam
;
import
com.wecloud.im.param.rtc.RejectRtcChannelParam
;
import
com.wecloud.im.param.rtc.SdpForwardParam
;
import
com.wecloud.rtc.service.RtcService
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.controller.BaseController
;
...
...
@@ -35,47 +40,42 @@ public class ImRtcController extends BaseController {
@PostMapping
(
"/createAndCall"
)
@ApiOperation
(
value
=
"创建频道,并邀请客户端加入"
,
notes
=
"创建频道,并邀请客户端加入"
)
public
ApiResult
<
CreateRtcChannelResult
>
createAndCall
(
@RequestBody
CreateRtcChannelParam
createRtcChannelParam
)
throws
Exception
{
CreateRtcChannelResult
createRtcChannelResult
=
rtcService
.
createAndCall
(
createRtcChannelParam
);
return
ApiResult
.
ok
(
createRtcChannelResult
);
return
rtcService
.
createAndCall
(
createRtcChannelParam
);
}
@PostMapping
(
"/join"
)
@ApiOperation
(
value
=
"同意进入频道"
,
notes
=
""
)
public
ApiResult
<
Boolean
>
join
()
{
public
ApiResult
<
Boolean
>
join
(
@RequestBody
JoinRtcChannelParam
joinRtcChannelParam
)
{
return
ApiResult
.
result
(
true
);
}
@PostMapping
(
"/reject"
)
@ApiOperation
(
value
=
"拒接进入频道"
,
notes
=
""
)
public
ApiResult
<
Boolean
>
reject
()
{
return
ApiResult
.
result
(
true
);
public
ApiResult
<
Boolean
>
reject
(
@RequestBody
RejectRtcChannelParam
rejectRtcChannelParam
)
{
return
rtcService
.
reject
(
rejectRtcChannelParam
);
}
@PostMapping
(
"/leave"
)
@ApiOperation
(
value
=
"主动挂断(离开频道)"
,
notes
=
""
)
public
ApiResult
<
Boolean
>
leave
()
{
return
ApiResult
.
result
(
true
);
public
ApiResult
<
Boolean
>
leave
(
@RequestBody
LeaveRtcChannelParam
leaveRtcChannelParam
)
{
return
rtcService
.
leave
(
leaveRtcChannelParam
);
}
@PostMapping
(
"/sdpForward"
)
@ApiOperation
(
value
=
"SDP数据转发"
,
notes
=
""
)
public
ApiResult
<
Boolean
>
sdpForward
()
{
return
ApiResult
.
result
(
true
);
public
ApiResult
<
Boolean
>
sdpForward
(
@RequestBody
SdpForwardParam
sdpForwardParam
)
{
return
rtcService
.
sdpForward
(
sdpForwardParam
);
}
@PostMapping
(
"/candidateForward"
)
@ApiOperation
(
value
=
"candidate候选者数据转发"
,
notes
=
""
)
public
ApiResult
<
Boolean
>
candidateForward
()
{
return
ApiResult
.
result
(
true
);
public
ApiResult
<
Boolean
>
candidateForward
(
@RequestBody
CandidateForwardParam
candidateForwardParam
)
{
return
rtcService
.
candidateForward
(
candidateForwardParam
);
}
...
...
common/src/main/java/com/wecloud/im/param/rtc/CandidateForwardParam.java
0 → 100644
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel
(
value
=
"CandidateForwardParam"
)
public
class
CandidateForwardParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
"频道id"
)
private
Long
channelId
;
/**
* 转发的候选者数据
*/
private
String
candidateData
;
}
common/src/main/java/com/wecloud/im/param/
add
/CreateRtcChannelParam.java
→
common/src/main/java/com/wecloud/im/param/
rtc
/CreateRtcChannelParam.java
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
.
add
;
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -27,12 +27,9 @@ public class CreateRtcChannelParam implements Serializable {
private
String
type
;
@ApiModelProperty
(
value
=
"绑定的会话id,可选"
,
required
=
false
)
private
String
toConversation
;
private
Long
conversationId
;
@ApiModelProperty
(
value
=
"接收方展示的系统推送内容,可"
,
required
=
false
,
example
=
"{"
+
" \"title\":\"xxx正在邀请你视频通话\","
+
" \"subTitle\":\"点击接听\""
+
" }"
)
@ApiModelProperty
(
value
=
"接收方展示的系统推送内容,可"
,
required
=
false
)
private
String
push
;
@ApiModelProperty
(
value
=
"是否需要给对方发系统通知"
,
required
=
true
)
...
...
common/src/main/java/com/wecloud/im/param/CreateRtcChannelResult.java
→
common/src/main/java/com/wecloud/im/param/
rtc/
CreateRtcChannelResult.java
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
;
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
common/src/main/java/com/wecloud/im/param/
add
/JoinRtcChannelParam.java
→
common/src/main/java/com/wecloud/im/param/
rtc
/JoinRtcChannelParam.java
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
.
add
;
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -7,13 +7,13 @@ import lombok.Data;
import
java.io.Serializable
;
/**
*
创建
频道请求参数
*
加入
频道请求参数
*
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel
(
value
=
"
Create
RtcChannelParam"
)
@ApiModel
(
value
=
"
Join
RtcChannelParam"
)
public
class
JoinRtcChannelParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
common/src/main/java/com/wecloud/im/param/rtc/LeaveRtcChannelParam.java
0 → 100644
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* 退出频道 请求
*
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel
(
value
=
"LeaveRtcChannelParam"
)
public
class
LeaveRtcChannelParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
"频道id"
)
private
Long
channelId
;
}
common/src/main/java/com/wecloud/im/param/rtc/RejectRtcChannelParam.java
0 → 100644
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* 拒接加入频道 请求
*
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel
(
value
=
"RejectRtcChannelParam"
)
public
class
RejectRtcChannelParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
"频道id"
)
private
Long
channelId
;
}
common/src/main/java/com/wecloud/im/param/rtc/SdpForwardParam.java
0 → 100644
View file @
4f218eb9
package
com
.
wecloud
.
im
.
param
.
rtc
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author wei
* @since 2021-04-29
*/
@Data
@ApiModel
(
value
=
"SdpForwardParam"
)
public
class
SdpForwardParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
"频道id"
)
private
Long
channelId
;
@ApiModelProperty
(
"sdp转发的数据"
)
private
String
sdpData
;
@ApiModelProperty
(
"sdp类型: Offer或Answer"
)
private
String
sdpType
;
}
common/src/main/java/com/wecloud/im/service/impl/ImInboxServiceImpl.java
View file @
4f218eb9
...
...
@@ -16,7 +16,7 @@ import com.wecloud.im.service.ImConversationMembersService;
import
com.wecloud.im.service.ImInboxService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
import
com.wecloud.im.ws.model.ResponseModel
;
import
com.wecloud.im.ws.model.
Ws
ResponseModel
;
import
com.wecloud.im.ws.service.WriteDataService
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
...
...
@@ -205,7 +205,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
continue
;
}
// 向接收方推送
ResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
ResponseModel
<>();
WsResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
Ws
ResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_EVENT_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
...
...
common/src/main/java/com/wecloud/im/ws/enums/WsResponseCmdEnum.java
View file @
4f218eb9
...
...
@@ -8,7 +8,7 @@ package com.wecloud.im.ws.enums;
public
enum
WsResponseCmdEnum
{
/**
* 下发
单人
在线RTC事件
* 下发在线RTC事件
*/
SINGLE_RTC_MSG
(
4
),
...
...
common/src/main/java/com/wecloud/im/ws/model/ResponseModel.java
→
common/src/main/java/com/wecloud/im/ws/model/
Ws
ResponseModel.java
View file @
4f218eb9
...
...
@@ -12,7 +12,7 @@ import java.io.Serializable;
*/
@Data
@Accessors
(
chain
=
true
)
public
class
ResponseModel
<
T
>
implements
Serializable
{
public
class
Ws
ResponseModel
<
T
>
implements
Serializable
{
/**
* 枚举类WsResponseCmdEnum 请求uri的编码
...
...
common/src/main/java/com/wecloud/im/ws/service/WriteDataService.java
View file @
4f218eb9
package
com
.
wecloud
.
im
.
ws
.
service
;
import
com.wecloud.im.ws.model.ResponseModel
;
import
com.wecloud.im.ws.model.
Ws
ResponseModel
;
import
com.wecloud.im.ws.model.request.ReceiveModel
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
...
...
@@ -47,7 +47,7 @@ public interface WriteDataService {
*
* @param responseModel
*/
void
write
(
ResponseModel
responseModel
,
String
toAppKey
,
String
toClientId
);
void
write
(
Ws
ResponseModel
responseModel
,
String
toAppKey
,
String
toClientId
);
}
common/src/main/java/com/wecloud/im/ws/service/impl/WriteDataServiceImpl.java
View file @
4f218eb9
...
...
@@ -3,7 +3,7 @@ package com.wecloud.im.ws.service.impl;
import
cn.hutool.core.thread.ThreadFactoryBuilder
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.json.JsonMapper
;
import
com.wecloud.im.ws.model.ResponseModel
;
import
com.wecloud.im.ws.model.
Ws
ResponseModel
;
import
com.wecloud.im.ws.model.WsConstants
;
import
com.wecloud.im.ws.model.request.ReceiveModel
;
import
com.wecloud.im.ws.service.MangerChannelService
;
...
...
@@ -62,7 +62,7 @@ public class WriteDataServiceImpl implements WriteDataService {
@Override
public
void
dataAndStatus
(
ReceiveModel
receiveModel
,
ApiCode
apiCode
,
Object
data
,
String
toAppKey
,
String
toClientId
)
{
ApiResult
<
Boolean
>
apiResult
=
ApiResult
.
result
(
apiCode
);
ResponseModel
responseModel
=
new
ResponseModel
();
WsResponseModel
responseModel
=
new
Ws
ResponseModel
();
responseModel
.
setMsg
(
apiResult
.
getMessage
());
responseModel
.
setCmd
(
receiveModel
.
getCmd
());
responseModel
.
setReqId
(
receiveModel
.
getReqId
());
...
...
@@ -72,7 +72,7 @@ public class WriteDataServiceImpl implements WriteDataService {
}
@Override
public
void
write
(
ResponseModel
responseModel
,
String
toAppKey
,
String
toClientId
)
{
public
void
write
(
Ws
ResponseModel
responseModel
,
String
toAppKey
,
String
toClientId
)
{
WRITE_TASK_THREAD_POOL_EXECUTOR
.
execute
(
()
->
{
...
...
common/src/main/java/com/wecloud/im/ws/strategy/concrete/ImChatConcrete.java
View file @
4f218eb9
...
...
@@ -19,7 +19,7 @@ import com.wecloud.im.service.ImMessageService;
import
com.wecloud.im.ws.annotation.CmdTypeAnnotation
;
import
com.wecloud.im.ws.enums.WsRequestCmdEnum
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
import
com.wecloud.im.ws.model.ResponseModel
;
import
com.wecloud.im.ws.model.
Ws
ResponseModel
;
import
com.wecloud.im.ws.model.request.ReceiveModel
;
import
com.wecloud.im.ws.sender.SystemPush
;
import
com.wecloud.im.ws.service.WriteDataService
;
...
...
@@ -172,7 +172,7 @@ public class ImChatConcrete extends ImCmdAbstract {
}
// 向接收方推送
ResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
ResponseModel
<>();
WsResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
Ws
ResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
...
...
@@ -186,7 +186,7 @@ public class ImChatConcrete extends ImCmdAbstract {
}
// 响应发送方消息id等信息
ResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
ResponseModel
<>();
WsResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
Ws
ResponseModel
<>();
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
());
responseModel
.
setCode
(
result
.
getCode
());
...
...
@@ -233,7 +233,7 @@ public class ImChatConcrete extends ImCmdAbstract {
log
.
info
(
"被对方拉黑了"
);
// 响应发送方
ResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
ResponseModel
<>();
WsResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
Ws
ResponseModel
<>();
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
IS_BE_BLACK
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
());
responseModel
.
setCode
(
result
.
getCode
());
...
...
@@ -248,7 +248,7 @@ public class ImChatConcrete extends ImCmdAbstract {
if
(
black
)
{
log
.
info
(
"你把对方拉黑了"
);
// 响应发送方
ResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
ResponseModel
<>();
WsResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
Ws
ResponseModel
<>();
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
IS_TO_BLACK
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
());
responseModel
.
setCode
(
result
.
getCode
());
...
...
common/src/main/java/com/wecloud/rtc/entity/RtcChannelInfo.java
→
common/src/main/java/com/wecloud/rtc/entity/
redis/
RtcChannelInfo.java
View file @
4f218eb9
package
com
.
wecloud
.
rtc
.
entity
;
package
com
.
wecloud
.
rtc
.
entity
.
redis
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
...
...
common/src/main/java/com/wecloud/rtc/entity/RtcJoinUser.java
→
common/src/main/java/com/wecloud/rtc/entity/
redis/
RtcJoinUser.java
View file @
4f218eb9
package
com
.
wecloud
.
rtc
.
entity
;
package
com
.
wecloud
.
rtc
.
entity
.
redis
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
...
...
@@ -17,7 +17,8 @@ public class RtcJoinUser implements Serializable {
@ApiModelProperty
(
"加入时间"
)
private
Long
createTimestamp
;
@ApiModelProperty
(
"sdp"
)
private
String
sdp
;
private
String
sdpData
;
private
String
sdpType
;
}
common/src/main/java/com/wecloud/rtc/entity/RtcJoinUsers.java
→
common/src/main/java/com/wecloud/rtc/entity/
redis/
RtcJoinUsers.java
View file @
4f218eb9
package
com
.
wecloud
.
rtc
.
entity
;
package
com
.
wecloud
.
rtc
.
entity
.
redis
;
import
lombok.Data
;
...
...
common/src/main/java/com/wecloud/rtc/RtcRedisKey.java
→
common/src/main/java/com/wecloud/rtc/
entity/redis/
RtcRedisKey.java
View file @
4f218eb9
package
com
.
wecloud
.
rtc
;
package
com
.
wecloud
.
rtc
.
entity
.
redis
;
import
java.io.Serializable
;
public
class
RtcRedisKey
implements
Serializable
{
/**
* 维护频道信息
* 维护频道信息
(kv)
*/
public
static
final
String
RTC_CHANNEL_INFO
=
"rci:%s"
;
/**
* 维护所有用户当前在线的频道ID
* 维护所有用户当前在线的频道ID
( kv)
* user_join_channel = ujc
* rcu:clientA = 10001
* rcu:clientB = 10001
...
...
@@ -22,9 +20,7 @@ public class RtcRedisKey implements Serializable {
public
static
final
String
USER_JOIN_CHANNEL
=
"ujc:%s"
;
/**
* 维护频道中存在的用户
* <p>
* redis Key (set 集合):
* 维护频道中存在的用户 (set 集合):
* rtc_channel_users = rcu
* rcu:10001 = clientA , clientB
* rcu:10002 = clientC
...
...
@@ -32,5 +28,4 @@ public class RtcRedisKey implements Serializable {
*/
public
static
final
String
RTC_CHANNEL_USERS
=
"rcu:%s"
;
}
common/src/main/java/com/wecloud/rtc/entity/response/RtcCallResponse.java
View file @
4f218eb9
...
...
@@ -10,6 +10,6 @@ import java.io.Serializable;
public
class
RtcCallResponse
extends
RtcSubDataBase
implements
Serializable
{
private
String
type
;
private
Long
toConversation
;
private
Long
conversationId
;
}
common/src/main/java/com/wecloud/rtc/service/RtcService.java
View file @
4f218eb9
package
com
.
wecloud
.
rtc
.
service
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.wecloud.im.param.CreateRtcChannelResult
;
import
com.wecloud.im.param.add.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CandidateForwardParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelResult
;
import
com.wecloud.im.param.rtc.JoinRtcChannelParam
;
import
com.wecloud.im.param.rtc.LeaveRtcChannelParam
;
import
com.wecloud.im.param.rtc.RejectRtcChannelParam
;
import
com.wecloud.im.param.rtc.SdpForwardParam
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
/**
* 管理rtc频道
...
...
@@ -13,25 +19,37 @@ public interface RtcService {
/**
* 创建一个频道,并向接收方发送系统推送
*/
CreateRtcChannelResult
createAndCall
(
CreateRtcChannelParam
createRtcChannelParam
)
throws
JsonProcessingException
;
ApiResult
<
CreateRtcChannelResult
>
createAndCall
(
CreateRtcChannelParam
createRtcChannelParam
)
throws
JsonProcessingException
;
/**
* 加入频道
*/
void
join
(
);
ApiResult
<
Boolean
>
join
(
JoinRtcChannelParam
joinRtcChannelParam
);
/**
* 拒接加入频道
*/
void
reject
(
);
ApiResult
<
Boolean
>
reject
(
RejectRtcChannelParam
rejectRtcChannelParam
);
/**
* 退出频道
*/
void
leave
(
);
ApiResult
<
Boolean
>
leave
(
LeaveRtcChannelParam
leaveRtcChannelParam
);
void
sdpForward
();
/**
* SDP数据转发
*
* @param sdpForwardParam
* @return
*/
ApiResult
<
Boolean
>
sdpForward
(
SdpForwardParam
sdpForwardParam
);
void
candidateForward
();
/**
* candidate候选者数据转发
*
* @param candidateForwardParam
* @return
*/
ApiResult
<
Boolean
>
candidateForward
(
CandidateForwardParam
candidateForwardParam
);
}
common/src/main/java/com/wecloud/rtc/service/WsRtcWrite.java
0 → 100644
View file @
4f218eb9
package
com
.
wecloud
.
rtc
.
service
;
import
com.wecloud.rtc.entity.response.RtcCallResponse
;
import
com.wecloud.rtc.entity.response.RtcCandidateForwardResponse
;
import
com.wecloud.rtc.entity.response.RtcClientJoinResponse
;
import
com.wecloud.rtc.entity.response.RtcClientLeaveResponse
;
import
com.wecloud.rtc.entity.response.RtcClientRejectResponse
;
import
com.wecloud.rtc.entity.response.RtcSdpForwardResponse
;
/**
* WebRtc webSocket下发指令数据
*/
public
interface
WsRtcWrite
{
/**
* 接收到RTC邀请
*/
void
rtcCall
(
RtcCallResponse
rtcCallResponse
,
String
toAppKey
,
String
toClientId
);
/**
* 用户状态更新事件(用户加入频道)
*/
void
clientJoin
(
RtcClientJoinResponse
rtcClientJoinResponse
,
String
toAppKey
,
String
toClientId
);
/**
* 用户状态更新事件(用户退出频道)
*/
void
clientLeave
(
RtcClientLeaveResponse
rtcClientLeaveResponse
,
String
toAppKey
,
String
toClientId
);
/**
* 用户状态更新事件(用户拒接邀请;不同意进入频道)
*/
void
clientReject
(
RtcClientRejectResponse
rtcClientRejectResponse
,
String
toAppKey
,
String
toClientId
);
/**
* SDP数据转发
*/
void
sdpForward
(
RtcSdpForwardResponse
rtcSdpForwardResponse
,
String
toAppKey
,
String
toClientId
);
/**
* candidate候选者数据转发
*/
void
candidateForward
(
RtcCandidateForwardResponse
rtcCandidateForwardResponse
,
String
toAppKey
,
String
toClientId
);
}
common/src/main/java/com/wecloud/rtc/service/impl/MangerRtcCacheServiceImpl.java
View file @
4f218eb9
...
...
@@ -3,8 +3,8 @@ package com.wecloud.rtc.service.impl;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.json.JsonMapper
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.rtc.entity.RtcChannelInfo
;
import
com.wecloud.rtc.RtcRedisKey
;
import
com.wecloud.rtc.entity.
redis.
RtcChannelInfo
;
import
com.wecloud.rtc.
entity.redis.
RtcRedisKey
;
import
com.wecloud.rtc.service.MangerRtcCacheService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
common/src/main/java/com/wecloud/rtc/service/impl/RtcServiceImpl.java
View file @
4f218eb9
...
...
@@ -3,22 +3,41 @@ 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.param.CreateRtcChannelResult
;
import
com.wecloud.im.param.add.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CandidateForwardParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelParam
;
import
com.wecloud.im.param.rtc.CreateRtcChannelResult
;
import
com.wecloud.im.param.rtc.JoinRtcChannelParam
;
import
com.wecloud.im.param.rtc.LeaveRtcChannelParam
;
import
com.wecloud.im.param.rtc.RejectRtcChannelParam
;
import
com.wecloud.im.param.rtc.SdpForwardParam
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.ws.service.MangerChannelService
;
import
com.wecloud.rtc.entity.response.RtcCallResponse
;
import
com.wecloud.rtc.entity.response.RtcCandidateForwardResponse
;
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.ApiResult
;
import
io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
@Slf4j
@Service
public
class
RtcServiceImpl
implements
RtcService
{
@Autowired
private
ImApplicationService
imApplicationService
;
@Autowired
private
WsRtcWrite
wsRtcWrite
;
/**
* redis缓存
*/
...
...
@@ -28,50 +47,153 @@ public class RtcServiceImpl implements RtcService {
@Autowired
private
ImClientService
imClientService
;
@Autowired
private
MangerChannelService
mangerChannelService
;
@Override
public
CreateRtcChannelResult
createAndCall
(
CreateRtcChannelParam
createRtcChannelParam
)
throws
JsonProcessingException
{
public
ApiResult
<
CreateRtcChannelResult
>
createAndCall
(
CreateRtcChannelParam
createRtcChannelParam
)
throws
JsonProcessingException
{
ImClient
client
=
imClientService
.
getCurentClient
();
Long
rtcChannelId
=
SnowflakeUtil
.
getId
();
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getById
(
client
.
getFkAppid
());
// 判断发起方必须在线
boolean
onlineStatus
=
mangerChannelService
.
getOnlineStatus
(
imApplication
.
getAppKey
(),
client
.
getClientId
());
if
(!
onlineStatus
)
{
log
.
info
(
"发起方必须在线"
+
imApplication
.
getAppKey
()
+
client
.
getClientId
());
ApiResult
.
fail
();
}
// 添加缓存
mangerRtcCacheService
.
create
(
imApplication
.
getAppKey
(),
client
.
getClientId
(),
rtcChannelId
);
CreateRtcChannelResult
createRtcChannelResult
=
new
CreateRtcChannelResult
();
createRtcChannelResult
.
setChannelId
(
rtcChannelId
);
// ws向接收方发送通知
RtcCallResponse
rtcCallResponse
=
new
RtcCallResponse
();
rtcCallResponse
.
setType
(
createRtcChannelParam
.
getType
());
// rtcCallResponse.setConversationId(createRtcChannelParam.getConversationId());
rtcCallResponse
.
setChannelId
(
rtcChannelId
);
rtcCallResponse
.
setClientId
(
client
.
getClientId
());
rtcCallResponse
.
setTimestamp
(
new
Date
().
getTime
());
wsRtcWrite
.
rtcCall
(
rtcCallResponse
,
imApplication
.
getAppKey
(),
createRtcChannelParam
.
getToClient
());
//
向对方发送邀请
//
TODO 待开发 下发安卓和ios系统推送
return
createRtcChannelResult
;
return
ApiResult
.
ok
(
createRtcChannelResult
);
}
@Override
public
void
join
(
)
{
public
ApiResult
<
Boolean
>
join
(
JoinRtcChannelParam
joinRtcChannelParam
)
{
}
ImClient
client
=
imClientService
.
getCurentClient
();
@Override
public
void
reject
()
{
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getById
(
client
.
getFkAppid
());
// 修改缓存
mangerRtcCacheService
.
join
(
imApplication
.
getAppKey
(),
client
.
getClientId
(),
joinRtcChannelParam
.
getChannelId
());
return
null
;
}
@Override
public
void
leave
()
{
public
ApiResult
<
Boolean
>
reject
(
RejectRtcChannelParam
rejectRtcChannelParam
)
{
return
null
;
}
@Override
public
ApiResult
<
Boolean
>
leave
(
LeaveRtcChannelParam
leaveRtcChannelParam
)
{
return
null
;
}
@Override
public
void
sdpForward
()
{
public
ApiResult
<
Boolean
>
sdpForward
(
SdpForwardParam
sdpForwardParam
)
{
ImClient
client
=
imClientService
.
getCurentClient
();
Long
rtcChannelId
=
SnowflakeUtil
.
getId
();
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getById
(
client
.
getFkAppid
());
// 判断发起方必须在线
boolean
onlineStatus
=
mangerChannelService
.
getOnlineStatus
(
imApplication
.
getAppKey
(),
client
.
getClientId
());
if
(!
onlineStatus
)
{
log
.
info
(
"发起方必须在线"
+
imApplication
.
getAppKey
()
+
client
.
getClientId
());
ApiResult
.
fail
();
}
CreateRtcChannelResult
createRtcChannelResult
=
new
CreateRtcChannelResult
();
createRtcChannelResult
.
setChannelId
(
rtcChannelId
);
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
sdpForwardParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
imApplication
.
getAppKey
()
+
client
.
getClientId
());
for
(
String
id
:
clientListByRtcChannelId
)
{
// ws向接收方发送通知
RtcSdpForwardResponse
rtcSdpForwardResponse
=
new
RtcSdpForwardResponse
();
rtcSdpForwardResponse
.
setSdpData
(
sdpForwardParam
.
getSdpData
());
rtcSdpForwardResponse
.
setSdpType
(
sdpForwardParam
.
getSdpType
());
// rtcSdpForwardResponse.setConversationId(createRtcChannelParam.getConversationId());
rtcSdpForwardResponse
.
setChannelId
(
rtcChannelId
);
rtcSdpForwardResponse
.
setClientId
(
client
.
getClientId
());
rtcSdpForwardResponse
.
setTimestamp
(
new
Date
().
getTime
());
wsRtcWrite
.
sdpForward
(
rtcSdpForwardResponse
,
imApplication
.
getAppKey
(),
id
);
}
return
null
;
}
@Override
public
void
candidateForward
()
{
public
ApiResult
<
Boolean
>
candidateForward
(
CandidateForwardParam
candidateForwardParam
)
{
ImClient
client
=
imClientService
.
getCurentClient
();
Long
rtcChannelId
=
SnowflakeUtil
.
getId
();
// 根据appKey查询appid
ImApplication
imApplication
=
imApplicationService
.
getById
(
client
.
getFkAppid
());
// 判断发起方必须在线
boolean
onlineStatus
=
mangerChannelService
.
getOnlineStatus
(
imApplication
.
getAppKey
(),
client
.
getClientId
());
if
(!
onlineStatus
)
{
log
.
info
(
"发起方必须在线"
+
imApplication
.
getAppKey
()
+
client
.
getClientId
());
ApiResult
.
fail
();
}
CreateRtcChannelResult
createRtcChannelResult
=
new
CreateRtcChannelResult
();
createRtcChannelResult
.
setChannelId
(
rtcChannelId
);
//获取频道内所有client
List
<
String
>
clientListByRtcChannelId
=
mangerRtcCacheService
.
getClientListByRtcChannelId
(
candidateForwardParam
.
getChannelId
());
// 移除自己
clientListByRtcChannelId
.
remove
(
imApplication
.
getAppKey
()
+
client
.
getClientId
());
for
(
String
id
:
clientListByRtcChannelId
)
{
// ws向接收方发送通知
RtcCandidateForwardResponse
rtcCandidateForwardResponse
=
new
RtcCandidateForwardResponse
();
rtcCandidateForwardResponse
.
setCandidateData
(
candidateForwardParam
.
getCandidateData
());
// rtcCandidateForwardResponse.setConversationId(createRtcChannelParam.getConversationId());
rtcCandidateForwardResponse
.
setChannelId
(
rtcChannelId
);
rtcCandidateForwardResponse
.
setClientId
(
client
.
getClientId
());
rtcCandidateForwardResponse
.
setTimestamp
(
new
Date
().
getTime
());
wsRtcWrite
.
candidateForward
(
rtcCandidateForwardResponse
,
imApplication
.
getAppKey
(),
id
);
}
return
null
;
}
}
common/src/main/java/com/wecloud/rtc/service/impl/WsRtcWriteImpl.java
0 → 100644
View file @
4f218eb9
package
com
.
wecloud
.
rtc
.
service
.
impl
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
import
com.wecloud.im.ws.enums.WsRtcResponseSubCmdEnum
;
import
com.wecloud.im.ws.model.WsResponseModel
;
import
com.wecloud.im.ws.service.WriteDataService
;
import
com.wecloud.rtc.entity.response.RtcCallResponse
;
import
com.wecloud.rtc.entity.response.RtcCandidateForwardResponse
;
import
com.wecloud.rtc.entity.response.RtcClientJoinResponse
;
import
com.wecloud.rtc.entity.response.RtcClientLeaveResponse
;
import
com.wecloud.rtc.entity.response.RtcClientRejectResponse
;
import
com.wecloud.rtc.entity.response.RtcResponseBase
;
import
com.wecloud.rtc.entity.response.RtcSdpForwardResponse
;
import
com.wecloud.rtc.service.WsRtcWrite
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
WsRtcWriteImpl
implements
WsRtcWrite
{
// private static final JsonMapper JSON_MAPPER = new JsonMapper();
@Autowired
private
WriteDataService
writeDataService
;
@Override
public
void
rtcCall
(
RtcCallResponse
rtcCallResponse
,
String
toAppKey
,
String
toClientId
)
{
RtcResponseBase
<
RtcCallResponse
>
rtcResponseBase
=
new
RtcResponseBase
<>();
rtcResponseBase
.
setSubCmd
(
WsRtcResponseSubCmdEnum
.
RTC_CALL
.
getCmdCode
());
rtcResponseBase
.
setSubData
(
rtcCallResponse
);
// rtcResponseBase.setAttrs(rtcCallResponse.get);
// 向接收方推送
WsResponseModel
<
RtcResponseBase
<
RtcCallResponse
>>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
SINGLE_RTC_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
rtcResponseBase
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
toAppKey
,
toClientId
);
}
@Override
public
void
clientJoin
(
RtcClientJoinResponse
rtcClientJoinResponse
,
String
toAppKey
,
String
toClientId
)
{
RtcResponseBase
<
RtcClientJoinResponse
>
rtcResponseBase
=
new
RtcResponseBase
<>();
rtcResponseBase
.
setSubCmd
(
WsRtcResponseSubCmdEnum
.
CLIENT_JOIN
.
getCmdCode
());
rtcResponseBase
.
setSubData
(
rtcClientJoinResponse
);
// rtcResponseBase.setAttrs(rtcCallResponse.get);
// 向接收方推送
WsResponseModel
<
RtcResponseBase
<
RtcClientJoinResponse
>>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
SINGLE_RTC_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
rtcResponseBase
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
toAppKey
,
toClientId
);
}
@Override
public
void
clientLeave
(
RtcClientLeaveResponse
rtcClientLeaveResponse
,
String
toAppKey
,
String
toClientId
)
{
RtcResponseBase
<
RtcClientLeaveResponse
>
rtcResponseBase
=
new
RtcResponseBase
<>();
rtcResponseBase
.
setSubCmd
(
WsRtcResponseSubCmdEnum
.
CLIENT_LEAVE
.
getCmdCode
());
rtcResponseBase
.
setSubData
(
rtcClientLeaveResponse
);
// rtcResponseBase.setAttrs(rtcCallResponse.get);
// 向接收方推送
WsResponseModel
<
RtcResponseBase
<
RtcClientLeaveResponse
>>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
SINGLE_RTC_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
rtcResponseBase
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
toAppKey
,
toClientId
);
}
@Override
public
void
clientReject
(
RtcClientRejectResponse
rtcClientRejectResponse
,
String
toAppKey
,
String
toClientId
)
{
RtcResponseBase
<
RtcClientRejectResponse
>
rtcResponseBase
=
new
RtcResponseBase
<>();
rtcResponseBase
.
setSubCmd
(
WsRtcResponseSubCmdEnum
.
CLIENT_REJECT
.
getCmdCode
());
rtcResponseBase
.
setSubData
(
rtcClientRejectResponse
);
// rtcResponseBase.setAttrs(rtcCallResponse.get);
// 向接收方推送
WsResponseModel
<
RtcResponseBase
<
RtcClientRejectResponse
>>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
SINGLE_RTC_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
rtcResponseBase
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
toAppKey
,
toClientId
);
}
@Override
public
void
sdpForward
(
RtcSdpForwardResponse
rtcSdpForwardResponse
,
String
toAppKey
,
String
toClientId
)
{
RtcResponseBase
<
RtcSdpForwardResponse
>
rtcResponseBase
=
new
RtcResponseBase
<>();
rtcResponseBase
.
setSubCmd
(
WsRtcResponseSubCmdEnum
.
SDP_FORWARD
.
getCmdCode
());
rtcResponseBase
.
setSubData
(
rtcSdpForwardResponse
);
// rtcResponseBase.setAttrs(rtcCallResponse.get);
// 向接收方推送
WsResponseModel
<
RtcResponseBase
<
RtcSdpForwardResponse
>>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
SINGLE_RTC_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
rtcResponseBase
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
toAppKey
,
toClientId
);
}
@Override
public
void
candidateForward
(
RtcCandidateForwardResponse
rtcCandidateForwardResponse
,
String
toAppKey
,
String
toClientId
)
{
RtcResponseBase
<
RtcCandidateForwardResponse
>
rtcResponseBase
=
new
RtcResponseBase
<>();
rtcResponseBase
.
setSubCmd
(
WsRtcResponseSubCmdEnum
.
CANDIDATE_FORWARD
.
getCmdCode
());
rtcResponseBase
.
setSubData
(
rtcCandidateForwardResponse
);
// rtcResponseBase.setAttrs(rtcCallResponse.get);
// 向接收方推送
WsResponseModel
<
RtcResponseBase
<
RtcCandidateForwardResponse
>>
responseModel
=
new
WsResponseModel
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
SINGLE_RTC_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
rtcResponseBase
);
responseModel
.
setReqId
(
null
);
writeDataService
.
write
(
responseModel
,
toAppKey
,
toClientId
);
}
}
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