@SecuredAction public WebSocket<String> getSocket() { // User player = (User) ctx().args.get(SecureSocial.USER_KEY); User player = (User) SecureSocial.currentUser(env).get(100); logger.debug("[LobbyController:getSocket] getSocket called from User: "******"[LobbyController:getSocket] ...player found! Returning WebSocket for this player"); return lobbys.get(lobbyName).getSocketForPlayer(player); } } } logger.debug( "[LobbyController:getSocket] ...player not found. Player didn't joined a lobby. Rejecting WebSocket."); return WebSocket.reject(Results.badRequest("Player didn't joined a game.")); }
/** * Receives messages from clients and broadcasts them to all its connections. * * <p>This web socket is implemented on callbacks. * * <ul> * <li>onCreate - connection WebSocket sends responses count back to the client * <li>onMessage - broadcasts the message to all connected clients * <li>onClose - removes current connection from connections set * </ul> * * @return WebSocket object */ public WebSocket<String> responseDataSocket() { return WebSocket.whenReady( (in, out) -> { SOCKETS.add(out); Logger.info("Socket connection added."); out.write("{\"responsesCount\":" + responseService.getResponsesCount() + "}"); in.onMessage( (String message) -> { SOCKETS.forEach(s -> s.write(message)); Logger.info("Socket message received : {}.", message); }); in.onClose( () -> { SOCKETS.remove(out); Logger.debug("Socket connection closed."); }); }); }