Skip to content

Commit

Permalink
修复将二进制消息作为文本消息发送的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
[moon] committed Jul 23, 2022
1 parent 3d160c5 commit 2feebeb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>plus.jdk</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```
## 配置
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>plus.jdk</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>plus.jdk</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>

<name>spring-boot-starter-websocket</name>
<description>A simple websocket component base on netty </description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected void sendBroadcast(Object userId, String path, byte[] data, Monitor[]
builder.setData(ByteString.copyFrom(data));
builder.setUid(userId == null ? "" : userId.toString());
builder.setPath(path);
builder.setType(messageType);
WsMessage wsMessage = builder.build();
udpMessageBroadcaster.publish(new BroadcastMessage(wsMessage.toByteArray(), Arrays.asList(monitors)));
}
Expand All @@ -77,6 +78,9 @@ public void run(ApplicationArguments args) throws Exception {
WsMessage wsMessage = WsMessage.parseFrom(msg.getContent());
SessionGroupManager sessionGroupManager = beanFactory.getBean(SessionGroupManager.class);
ConcurrentLinkedDeque<IWsSession<?>> sessions = sessionGroupManager.getSession(wsMessage.getUid(), wsMessage.getPath());
if(properties.getPrintBroadcastMessage()) {
log.info("receive broadcast message: {}", wsMessage);
}
for (IWsSession<?> session : sessions) {
if(MessageType.MESSAGE_TYPE_TEXT.equals(wsMessage.getType())) {
session.sendText(new String(wsMessage.getData().toByteArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public class WebsocketProperties {
*/
private Integer broadcastMonitorPort = 10300;

/**
* 是否将接收到的udp广播内容打印到日志中
*/
private Boolean printBroadcastMessage = true;

/**
* 认证器
Expand Down

0 comments on commit 2feebeb

Please sign in to comment.