package vs;

import java.io.IOException;

import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;

@ServerEndpoint("/service/{user}")
public class Service {

	@OnOpen
	public void init(Session s, @PathParam("user") String nickName) throws IOException {
		s.getUserProperties().put("nickName", nickName);
	}

	@OnMessage
	public void onMessage(String m, Session s) throws IOException {
		String nickName = (String) s.getUserProperties().get("nickName");
		s.getBasicRemote().sendText(nickName + ", empfangen: " + m);
	}

}
