use of io.micronaut.websocket.annotation.OnMessage in project micronaut-core by micronaut-projects.
the class BinaryChatServerWebSocket method onMessage.
@OnMessage
public void onMessage(String topic, String username, byte[] message, WebSocketSession session) {
assert ServerRequestContext.currentRequest().isPresent();
Set<? extends WebSocketSession> openSessions = session.getOpenSessions();
System.out.println("Server received message = " + new String(message));
System.out.println("Server openSessions = " + openSessions);
for (WebSocketSession openSession : openSessions) {
if (isValid(topic, session, openSession)) {
String msg = "[" + username + "] " + new String(message);
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
}
}
}
use of io.micronaut.websocket.annotation.OnMessage in project micronaut-core by micronaut-projects.
the class ReactivePojoChatServerWebSocket method onClose.
// end::onmessage[]
@OnClose
public Publisher<Message> onClose(String topic, String username, WebSocketSession session) {
String text = "[" + username + "] Disconnected!";
Message message = new Message(text);
assert ServerRequestContext.currentRequest().isPresent();
return broadcaster.broadcast(message, isValid(topic, session));
}
use of io.micronaut.websocket.annotation.OnMessage in project micronaut-core by micronaut-projects.
the class ReactivePojoChatServerWebSocket method onMessage.
// tag::onmessage[]
@OnMessage
public Publisher<Message> onMessage(String topic, String username, Message message, WebSocketSession session) {
String text = "[" + username + "] " + message.getText();
Message newMessage = new Message(text);
assert ServerRequestContext.currentRequest().isPresent();
return broadcaster.broadcast(newMessage, isValid(topic, session));
}
use of io.micronaut.websocket.annotation.OnMessage in project micronaut-core by micronaut-projects.
the class ReactivePojoChatServerWebSocket method onClose.
// end::onmessage[]
@OnClose
public Publisher<Message> onClose(String topic, String username, WebSocketSession session) {
String text = "[" + username + "] Disconnected!";
Message message = new Message(text);
return broadcaster.broadcast(message, isValid(topic, session));
}
use of io.micronaut.websocket.annotation.OnMessage in project micronaut-core by micronaut-projects.
the class ReactivePojoChatServerWebSocket method onMessage.
// tag::onmessage[]
@OnMessage
public Publisher<Message> onMessage(String topic, String username, Message message, WebSocketSession session) {
String text = "[" + username + "] " + message.getText();
Message newMessage = new Message(text);
return broadcaster.broadcast(newMessage, isValid(topic, session));
}
Aggregations