Search in sources :

Example 1 with Message

use of com.baeldung.model.Message in project tutorials by eugenp.

the class ChatEndpoint method onClose.

@OnClose
public void onClose(Session session) throws IOException, EncodeException {
    chatEndpoints.remove(this);
    Message message = new Message();
    message.setFrom(users.get(session.getId()));
    message.setContent("Disconnected!");
    broadcast(message);
}
Also used : Message(com.baeldung.model.Message) OnMessage(javax.websocket.OnMessage) OnClose(javax.websocket.OnClose)

Example 2 with Message

use of com.baeldung.model.Message in project tutorials by eugenp.

the class ChatEndpoint method onOpen.

@OnOpen
public void onOpen(Session session, @PathParam("username") String username) throws IOException, EncodeException {
    this.session = session;
    chatEndpoints.add(this);
    users.put(session.getId(), username);
    Message message = new Message();
    message.setFrom(username);
    message.setContent("Connected!");
    broadcast(message);
}
Also used : Message(com.baeldung.model.Message) OnMessage(javax.websocket.OnMessage) OnOpen(javax.websocket.OnOpen)

Aggregations

Message (com.baeldung.model.Message)2 OnMessage (javax.websocket.OnMessage)2 OnClose (javax.websocket.OnClose)1 OnOpen (javax.websocket.OnOpen)1