Search in sources :

Example 1 with OnClose

use of io.micronaut.websocket.annotation.OnClose 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));
}
Also used : OnMessage(io.micronaut.websocket.annotation.OnMessage) OnClose(io.micronaut.websocket.annotation.OnClose)

Example 2 with OnClose

use of io.micronaut.websocket.annotation.OnClose 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));
}
Also used : OnMessage(io.micronaut.websocket.annotation.OnMessage) OnClose(io.micronaut.websocket.annotation.OnClose)

Example 3 with OnClose

use of io.micronaut.websocket.annotation.OnClose in project micronaut-core by micronaut-projects.

the class BinaryChatServerWebSocket method onClose.

@OnClose
public void onClose(String topic, String username, WebSocketSession session) {
    assert ServerRequestContext.currentRequest().isPresent();
    Set<? extends WebSocketSession> openSessions = session.getOpenSessions();
    System.out.println("Server session closing for username = " + username);
    for (WebSocketSession openSession : openSessions) {
        if (isValid(topic, session, openSession)) {
            String msg = "[" + username + "] Disconnected!";
            System.out.println("Server sending msg = " + msg);
            openSession.sendSync(msg.getBytes());
        }
    }
}
Also used : WebSocketSession(io.micronaut.websocket.WebSocketSession) OnClose(io.micronaut.websocket.annotation.OnClose)

Aggregations

OnClose (io.micronaut.websocket.annotation.OnClose)3 OnMessage (io.micronaut.websocket.annotation.OnMessage)2 WebSocketSession (io.micronaut.websocket.WebSocketSession)1