mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Возможность отправлять сообщения всем клиентам
This commit is contained in:
parent
47e33b0588
commit
b807dd871a
2 changed files with 21 additions and 0 deletions
|
@ -1,8 +1,11 @@
|
|||
package ru.gravit.launchserver.command.basic;
|
||||
|
||||
import ru.gravit.launcher.events.PingEvent;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.command.Command;
|
||||
import ru.gravit.launchserver.websocket.NettyServerSocketHandler;
|
||||
import ru.gravit.launchserver.websocket.WebSocketFrameHandler;
|
||||
import ru.gravit.launchserver.websocket.WebSocketService;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
|
@ -33,5 +36,9 @@ public void invoke(String... args) throws Exception {
|
|||
if (args[0].equals("stop")) {
|
||||
handler.close();
|
||||
}
|
||||
if (args[0].equals("eventAll"))
|
||||
{
|
||||
WebSocketFrameHandler.service.sendObjectAll(new PingEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,20 @@ public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) {
|
|||
ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type)));
|
||||
}
|
||||
|
||||
public void sendObjectAll(Object obj) {
|
||||
for(Channel ch : channels)
|
||||
{
|
||||
ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class)));
|
||||
}
|
||||
}
|
||||
|
||||
public void sendObjectAll(Object obj, Type type) {
|
||||
for(Channel ch : channels)
|
||||
{
|
||||
ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type)));
|
||||
}
|
||||
}
|
||||
|
||||
public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj) {
|
||||
ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue