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
61a0ab9d
Commit
61a0ab9d
authored
Sep 29, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化Response指令为枚举类;
添加指令:单人WebRTC音视频通话; 优化Cmd策略模式抽象类和实现类名
parent
b6b1e169
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
63 additions
and
58 deletions
+63
-58
common/src/main/java/com/wecloud/im/service/impl/ImInboxServiceImpl.java
+3
-1
common/src/main/java/com/wecloud/im/ws/annotation/CmdTypeAnnotation.java
+1
-1
common/src/main/java/com/wecloud/im/ws/enums/WsRequestCmdEnum.java
+6
-1
common/src/main/java/com/wecloud/im/ws/enums/WsResponseCmdEnum.java
+15
-4
common/src/main/java/com/wecloud/im/ws/model/ResponseModel.java
+2
-17
common/src/main/java/com/wecloud/im/ws/receive/ReadWsData.java
+4
-4
common/src/main/java/com/wecloud/im/ws/sender/SystemPush.java
+7
-7
common/src/main/java/com/wecloud/im/ws/strategy/ImCmdAbstract.java
+2
-2
common/src/main/java/com/wecloud/im/ws/strategy/ImCmdContext.java
+4
-4
common/src/main/java/com/wecloud/im/ws/strategy/ImCmdStrategyProcessor.java
+6
-6
common/src/main/java/com/wecloud/im/ws/strategy/concrete/ImChatConcrete.java
+13
-11
common/src/main/java/com/wecloud/im/ws/strategy/concrete/SingleRtcConcrete.java
+0
-0
No files found.
common/src/main/java/com/wecloud/im/service/impl/ImInboxServiceImpl.java
View file @
61a0ab9d
package
com
.
wecloud
.
im
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
...
...
@@ -14,6 +15,7 @@ import com.wecloud.im.service.ImClientService;
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.service.WriteDataService
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
...
...
@@ -191,7 +193,7 @@ public class ImInboxServiceImpl extends BaseServiceImpl<ImInboxMapper, ImInbox>
}
// 向接收方推送
ResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
ResponseModel
<>();
responseModel
.
setCmd
(
ResponseModel
.
ONLINE_EVENT_MSG
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_EVENT_MSG
.
getCmdCode
()
);
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
...
...
common/src/main/java/com/wecloud/im/ws/annotation/
Receive
TypeAnnotation.java
→
common/src/main/java/com/wecloud/im/ws/annotation/
Cmd
TypeAnnotation.java
View file @
61a0ab9d
...
...
@@ -17,7 +17,7 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
//RUNTIME运行时保留
@Target
(
ElementType
.
TYPE
)
//type描述类、接口
@Documented
public
@interface
Receive
TypeAnnotation
{
public
@interface
Cmd
TypeAnnotation
{
WsRequestCmdEnum
type
();
}
common/src/main/java/com/wecloud/im/ws/enums/WsRequestCmdEnum.java
View file @
61a0ab9d
...
...
@@ -15,7 +15,12 @@ public enum WsRequestCmdEnum {
/**
* ping
*/
PING
(
2
);
PING
(
2
),
/**
* 单人WebRTC音视频通话
*/
SINGLE_RTC
(
3
);
private
final
int
cmdCode
;
...
...
common/src/main/java/com/wecloud/im/ws/enums/WsResponseCmdEnum.java
View file @
61a0ab9d
...
...
@@ -8,14 +8,25 @@ package com.wecloud.im.ws.enums;
public
enum
WsResponseCmdEnum
{
/**
*
离线消息下发完成指令
*
下发单人在线RTC事件
*/
OFFLINE_MSG_SUC
(
100
),
SINGLE_RTC_MSG
(
4
),
/**
*
主动下发消息指令
*
下发在线事件消息
*/
WRITE_MSG
(
101
);
ONLINE_EVENT_MSG
(
3
),
/**
* 下发在线基本类型消息
*/
ONLINE_MSG
(
2
),
/**
* 响应数据类型
*/
RES
(
1
);
private
final
int
cmdCode
;
...
...
common/src/main/java/com/wecloud/im/ws/model/ResponseModel.java
View file @
61a0ab9d
...
...
@@ -15,23 +15,8 @@ import java.io.Serializable;
public
class
ResponseModel
<
T
>
implements
Serializable
{
/**
* 下发在线事件消息
*/
public
static
final
Integer
ONLINE_EVENT_MSG
=
3
;
/**
* 下发在线基本类型消息
*/
public
static
final
Integer
ONLINE_MSG
=
2
;
/**
* 响应数据类型
*/
public
static
final
Integer
RES
=
1
;
/**
* 枚举类UriPathEnum 请求uri的编码
* 由于websocket使用同一个通道发送数据,需要区分不同类型请求
* 枚举类WsResponseCmdEnum 请求uri的编码
* 由于webSocket使用同一个通道发送数据,需要区分不同类型请求
*/
private
Integer
cmd
;
...
...
common/src/main/java/com/wecloud/im/ws/receive/ReadWsData.java
View file @
61a0ab9d
...
...
@@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.json.JsonMapper;
import
com.wecloud.im.ws.enums.WsRequestCmdEnum
;
import
com.wecloud.im.ws.model.request.ReceiveModel
;
import
com.wecloud.im.ws.service.WriteDataService
;
import
com.wecloud.im.ws.strategy.
AbstractReceiveStrategy
;
import
com.wecloud.im.ws.strategy.
ReceiveStrategy
Context
;
import
com.wecloud.im.ws.strategy.
ImCmdAbstract
;
import
com.wecloud.im.ws.strategy.
ImCmd
Context
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.netty.channel.ChannelHandlerContext
;
import
org.slf4j.Logger
;
...
...
@@ -26,7 +26,7 @@ public class ReadWsData {
// idea此处报红 属于正常
// @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Resource
private
ReceiveStrategy
Context
receiveStrategyContext
;
private
ImCmd
Context
receiveStrategyContext
;
@Resource
private
WriteDataService
writeDataService
;
...
...
@@ -57,7 +57,7 @@ public class ReadWsData {
WsRequestCmdEnum
wsRequestUriPathEnum
=
WsRequestCmdEnum
.
getByCode
(
receiveModel
.
getCmd
());
// 使用策略模式, 根据不同类型请求调用不同实现类
AbstractReceiveStrategy
receiveStrategy
=
receiveStrategyContext
.
getStrategy
(
wsRequestUriPathEnum
);
ImCmdAbstract
receiveStrategy
=
receiveStrategyContext
.
getStrategy
(
wsRequestUriPathEnum
);
receiveStrategy
.
process
(
receiveModel
,
ctx
,
data
,
appKey
,
clientId
);
}
...
...
common/src/main/java/com/wecloud/im/ws/sender/
PushTask
.java
→
common/src/main/java/com/wecloud/im/ws/sender/
SystemPush
.java
View file @
61a0ab9d
...
...
@@ -30,7 +30,7 @@ import java.util.Map;
*/
@Component
@Slf4j
public
class
PushTask
{
public
class
SystemPush
{
@Autowired
private
ImIosApnsService
imIosApnsService
;
...
...
@@ -56,7 +56,7 @@ public class PushTask {
* @param imClientReceiver
*/
@Async
public
void
push
(
HashMap
<
String
,
String
>
pushMap
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
public
void
push
(
HashMap
<
String
,
String
>
pushMap
,
ImClient
imClientReceiver
,
ImApplication
imApplication
,
PushType
pushType
)
{
log
.
info
(
"push:"
+
imClientReceiver
.
getClientId
());
PushModel
pushModel
=
new
PushModel
();
...
...
@@ -82,7 +82,7 @@ public class PushTask {
// 设备类型1:ios; 2:android
if
(
imClientReceiver
.
getDeviceType
()
==
1
)
{
ios
(
pushModel
,
imClientReceiver
,
imApplication
);
ios
(
pushModel
,
imClientReceiver
,
imApplication
,
pushType
);
}
else
{
android
(
pushModel
,
imClientReceiver
,
imApplication
);
...
...
@@ -122,7 +122,7 @@ public class PushTask {
}
}
private
void
ios
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
private
void
ios
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
,
PushType
pushType
)
{
// ios推送通道,友盟:1;firebase:2; apns原生:3
if
(
imApplication
.
getIosPushChannel
()
==
1
)
{
log
.
info
(
"友盟"
);
...
...
@@ -153,7 +153,7 @@ public class PushTask {
// apns原生:3
log
.
info
(
"apns原生"
);
apnsPush
(
pushModel
,
imClientReceiver
,
imApplication
);
apnsPush
(
pushModel
,
imClientReceiver
,
imApplication
,
pushType
);
}
else
{
log
.
info
(
"没有找到推送类型"
);
}
...
...
@@ -200,7 +200,7 @@ public class PushTask {
}
}
private
void
apnsPush
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
)
{
private
void
apnsPush
(
PushModel
pushModel
,
ImClient
imClientReceiver
,
ImApplication
imApplication
,
PushType
pushType
)
{
// 查询apns证书
ImIosApns
apns
=
imIosApnsService
.
getImIosApnsByAppId
(
imApplication
.
getId
());
Map
<
String
,
Object
>
customProperty
=
new
HashMap
<
String
,
Object
>(
1
);
...
...
@@ -227,7 +227,7 @@ public class PushTask {
IosPush
.
push
(
certificatePassword
,
inputStream2
,
productFlag
,
deviceToken
,
alertTitle
,
alertBody
,
contentAvailable
,
customProperty
,
badge
,
DeliveryPriority
.
IMMEDIATE
,
PushType
.
ALERT
,
topicBundleId
,
,
DeliveryPriority
.
IMMEDIATE
,
pushType
,
topicBundleId
,
sound
);
}
...
...
common/src/main/java/com/wecloud/im/ws/strategy/
AbstractReceiveStrategy
.java
→
common/src/main/java/com/wecloud/im/ws/strategy/
ImCmdAbstract
.java
View file @
61a0ab9d
...
...
@@ -6,12 +6,12 @@ import com.wecloud.im.ws.model.request.ReceiveModel;
import
io.netty.channel.ChannelHandlerContext
;
/**
* @Description
接收netty不同类型
请求
* @Description
处理Cmd
请求
* 抽象类 策略设计模式
* @Author hewei hwei1233@163.com
* @Date 2020-01-02
*/
public
abstract
class
AbstractReceiveStrategy
{
public
abstract
class
ImCmdAbstract
{
/**
* 处理业务流程
...
...
common/src/main/java/com/wecloud/im/ws/strategy/
ReceiveStrategy
Context.java
→
common/src/main/java/com/wecloud/im/ws/strategy/
ImCmd
Context.java
View file @
61a0ab9d
...
...
@@ -11,15 +11,15 @@ import java.util.Map;
* 维护指令码与策略实现的对应
* @Author hewei hwei1233@163.com
*/
public
class
ReceiveStrategy
Context
{
public
class
ImCmd
Context
{
private
final
Map
<
WsRequestCmdEnum
,
Class
>
strategyMap
;
public
ReceiveStrategy
Context
(
Map
<
WsRequestCmdEnum
,
Class
>
strategyMap
)
{
public
ImCmd
Context
(
Map
<
WsRequestCmdEnum
,
Class
>
strategyMap
)
{
this
.
strategyMap
=
strategyMap
;
}
public
AbstractReceiveStrategy
getStrategy
(
WsRequestCmdEnum
wsRequestPathEnum
)
{
public
ImCmdAbstract
getStrategy
(
WsRequestCmdEnum
wsRequestPathEnum
)
{
if
(
wsRequestPathEnum
==
null
)
{
throw
new
IllegalArgumentException
(
"not fond enum"
);
...
...
@@ -35,6 +35,6 @@ public class ReceiveStrategyContext {
throw
new
IllegalArgumentException
(
"not fond strategy for type:"
+
wsRequestPathEnum
.
getCmdCode
());
}
return
(
AbstractReceiveStrategy
)
SpringBeanUtils
.
getBean
(
aClass
);
return
(
ImCmdAbstract
)
SpringBeanUtils
.
getBean
(
aClass
);
}
}
common/src/main/java/com/wecloud/im/ws/strategy/
Receive
StrategyProcessor.java
→
common/src/main/java/com/wecloud/im/ws/strategy/
ImCmd
StrategyProcessor.java
View file @
61a0ab9d
package
com
.
wecloud
.
im
.
ws
.
strategy
;
import
com.google.common.collect.Maps
;
import
com.wecloud.im.ws.annotation.
Receive
TypeAnnotation
;
import
com.wecloud.im.ws.annotation.
Cmd
TypeAnnotation
;
import
com.wecloud.im.ws.enums.WsRequestCmdEnum
;
import
com.wecloud.im.ws.utils.ClassScanner
;
import
org.springframework.beans.BeansException
;
...
...
@@ -22,7 +22,7 @@ import java.util.Set;
* @Date 2020-01-02
*/
@Component
public
class
Receive
StrategyProcessor
implements
BeanFactoryPostProcessor
{
public
class
ImCmd
StrategyProcessor
implements
BeanFactoryPostProcessor
{
// 扫码注解的包路径
private
static
final
String
STRATEGY_PACK
=
"com.wecloud.im.ws.strategy.concrete"
;
...
...
@@ -32,20 +32,20 @@ public class ReceiveStrategyProcessor implements BeanFactoryPostProcessor {
Map
<
WsRequestCmdEnum
,
Class
>
handlerMap
=
Maps
.
newHashMapWithExpectedSize
(
5
);
// 扫码ReceiveTypeAnnotation注解的类
Set
<
Class
<?>>
classSet
=
ClassScanner
.
scan
(
STRATEGY_PACK
,
Receive
TypeAnnotation
.
class
);
Set
<
Class
<?>>
classSet
=
ClassScanner
.
scan
(
STRATEGY_PACK
,
Cmd
TypeAnnotation
.
class
);
classSet
.
forEach
(
clazz
->
{
// 获取注解中的类型值,与枚举类一一对应
WsRequestCmdEnum
type
=
clazz
.
getAnnotation
(
Receive
TypeAnnotation
.
class
).
type
();
WsRequestCmdEnum
type
=
clazz
.
getAnnotation
(
Cmd
TypeAnnotation
.
class
).
type
();
handlerMap
.
put
(
type
,
clazz
);
});
// 初始化Contenxt, 将其注册到spring容器当中
ReceiveStrategyContext
context
=
new
ReceiveStrategy
Context
(
handlerMap
);
ImCmdContext
context
=
new
ImCmd
Context
(
handlerMap
);
try
{
configurableListableBeanFactory
.
registerResolvableDependency
(
Class
.
forName
(
ReceiveStrategy
Context
.
class
.
getName
()),
context
);
configurableListableBeanFactory
.
registerResolvableDependency
(
Class
.
forName
(
ImCmd
Context
.
class
.
getName
()),
context
);
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
...
...
common/src/main/java/com/wecloud/im/ws/strategy/concrete/ImC
oncreteReceiveStrategy
.java
→
common/src/main/java/com/wecloud/im/ws/strategy/concrete/ImC
hatConcrete
.java
View file @
61a0ab9d
...
...
@@ -3,6 +3,7 @@ package com.wecloud.im.ws.strategy.concrete;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.json.JsonMapper
;
import
com.turo.pushy.apns.PushType
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImConversationMembers
;
...
...
@@ -15,13 +16,14 @@ import com.wecloud.im.service.ImClientService;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImInboxService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.ws.annotation.
Receive
TypeAnnotation
;
import
com.wecloud.im.ws.annotation.
Cmd
TypeAnnotation
;
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.request.ReceiveModel
;
import
com.wecloud.im.ws.sender.
PushTask
;
import
com.wecloud.im.ws.sender.
SystemPush
;
import
com.wecloud.im.ws.service.WriteDataService
;
import
com.wecloud.im.ws.strategy.
AbstractReceiveStrategy
;
import
com.wecloud.im.ws.strategy.
ImCmdAbstract
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil
;
...
...
@@ -38,10 +40,10 @@ import java.util.List;
/**
* @Description 处理app数据消息
*/
@
Receive
TypeAnnotation
(
type
=
WsRequestCmdEnum
.
DATA
)
@
Cmd
TypeAnnotation
(
type
=
WsRequestCmdEnum
.
DATA
)
@Service
@Slf4j
public
class
ImC
oncreteReceiveStrategy
extends
AbstractReceiveStrategy
{
public
class
ImC
hatConcrete
extends
ImCmdAbstract
{
private
static
final
String
TO_CONVERSATION_KEY
=
"toConversation"
;
private
static
final
String
PUSH_KEY
=
"push"
;
...
...
@@ -71,7 +73,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
private
ImClientService
imClientService
;
@Autowired
private
PushTask
pushTask
;
private
SystemPush
pushTask
;
@Override
public
void
process
(
ReceiveModel
receiveModel
,
ChannelHandlerContext
ctx
,
String
data
,
String
appKey
,
String
clientId
)
throws
JsonProcessingException
{
...
...
@@ -172,7 +174,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
// 向接收方推送
ResponseModel
<
ImMessageOnlineSend
>
responseModel
=
new
ResponseModel
<>();
responseModel
.
setCmd
(
ResponseModel
.
ONLINE_MSG
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_MSG
.
getCmdCode
()
);
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
...
...
@@ -181,13 +183,13 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
writeDataService
.
write
(
responseModel
,
appKey
,
imClientReceiver
.
getClientId
());
// 异步推送系统通知消息
pushTask
.
push
(
pushMap
,
imClientReceiver
,
imApplication
);
pushTask
.
push
(
pushMap
,
imClientReceiver
,
imApplication
,
PushType
.
ALERT
);
}
// 响应发送方消息id等信息
ResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
ResponseModel
<>();
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCmd
(
ResponseModel
.
RES
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
()
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
HashMap
<
String
,
Long
>
stringHashMap
=
new
HashMap
<>(
3
);
...
...
@@ -234,7 +236,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
// 响应发送方
ResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
ResponseModel
<>();
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
IS_BE_BLACK
);
responseModel
.
setCmd
(
ResponseModel
.
RES
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
()
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setReqId
(
receiveModel
.
getReqId
());
...
...
@@ -249,7 +251,7 @@ public class ImConcreteReceiveStrategy extends AbstractReceiveStrategy {
// 响应发送方
ResponseModel
<
HashMap
<
String
,
Long
>>
responseModel
=
new
ResponseModel
<>();
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
IS_TO_BLACK
);
responseModel
.
setCmd
(
ResponseModel
.
RES
);
responseModel
.
setCmd
(
WsResponseCmdEnum
.
RES
.
getCmdCode
()
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setReqId
(
receiveModel
.
getReqId
());
...
...
common/src/main/java/com/wecloud/im/ws/strategy/concrete/SingleRtcConcrete.java
0 → 100644
View file @
61a0ab9d
This diff is collapsed.
Click to expand it.
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