List of usage examples for org.springframework.web.socket WebSocketSession getId
String getId();
From source file:com.github.mrstampy.gameboot.websocket.AbstractWebSocketProcessor.java
@Override public SystemIdKey getSystemId(WebSocketSession session) { return systemIds.get(session.getId()); }
From source file:com.github.sshw.websocket.SSHWebSocketHandler.java
@Override public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception { if (!(message instanceof TextMessage)) { throw new IllegalStateException("Unexpected WebSocket message type: " + message); }/* www .jav a 2 s . c o m*/ String messageText = ((TextMessage) message).getPayload(); SSHSession sshSession = sshSessionManager.sessionsByWebsocketID.get(session.getId()); if (sshSession == null) { log.info("linking {}:{}", session.getId(), messageText); // TODO is there a better way to do this? // Can the client send the websocket session id and username in a REST call to link them up? sshSession = sshSessionManager.sessionsByUsername.get(messageText); sshSession.setWebSocketSession(session); sshSessionManager.sessionsByWebsocketID.put(session.getId(), sshSession); } else { log.debug("message in {}:{}", session.getId(), messageText); sshSession.getSSHOutput().write((messageText + '\n').getBytes()); sshSession.getSSHOutput().flush(); } // if we receive a valid logout command, then close the websocket session. // the system will logout and tidy itself up... if (logoutCommands.contains(messageText.trim().toLowerCase())) { log.info("valid logout command received: {}", messageText); session.close(); } }
From source file:com.github.mrstampy.gameboot.websocket.AbstractWebSocketProcessor.java
@Override public void onDisconnection(WebSocketSession session) throws Exception { String id = session.getId(); SystemIdKey systemId = systemIds.remove(id); cleaner.cleanup(systemId);//from ww w . j a v a 2 s .c o m Set<Entry<AbstractRegistryKey<?>, WebSocketSession>> set = registry.getKeysForValue(session); set.forEach(e -> registry.remove(e.getKey())); }
From source file:com.github.mrstampy.gameboot.websocket.AbstractWebSocketProcessor.java
/** * Sets the system id./*from w w w . ja va2s . c o m*/ * * @param session * the session * @param systemId * the new system id */ public void setSystemId(WebSocketSession session, SystemIdKey systemId) { systemIds.put(session.getId(), systemId); }
From source file:org.kurento.tutorial.player.PlayerHandler.java
@Override public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class); String sessionId = session.getId(); log.debug("Incoming message {} from sessionId", jsonMessage, sessionId); try {/*from w w w .j a v a 2 s . co m*/ switch (jsonMessage.get("id").getAsString()) { case "start": start(session, jsonMessage); break; case "stop": stop(sessionId); break; case "pause": pause(sessionId); break; case "resume": resume(session); break; case "doSeek": doSeek(session, jsonMessage); break; case "getPosition": getPosition(session); break; case "onIceCandidate": onIceCandidate(sessionId, jsonMessage); break; default: sendError(session, "Invalid message with id " + jsonMessage.get("id").getAsString()); break; } } catch (Throwable t) { log.error("Exception handling message {} in sessionId {}", jsonMessage, sessionId, t); sendError(session, t.getMessage()); } }
From source file:org.kurento.tutorial.one2manycall.CallHandler.java
@Override public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class); log.debug("Incoming message from session '{}': {}", session.getId(), jsonMessage); switch (jsonMessage.get("id").getAsString()) { case "presenter": try {/*from www .ja v a2 s.c o m*/ presenter(session, jsonMessage); } catch (Throwable t) { handleErrorResponse(t, session, "presenterResponse"); } break; case "viewer": try { viewer(session, jsonMessage); } catch (Throwable t) { handleErrorResponse(t, session, "viewerResponse"); } break; case "onIceCandidate": { JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject(); UserSession user = null; if (presenterUserSession != null) { if (presenterUserSession.getSession() == session) { user = presenterUserSession; } else { user = viewers.get(session.getId()); } } if (user != null) { IceCandidate cand = new IceCandidate(candidate.get("candidate").getAsString(), candidate.get("sdpMid").getAsString(), candidate.get("sdpMLineIndex").getAsInt()); user.addCandidate(cand); } break; } case "stop": stop(session); break; default: break; } }
From source file:ch.rasc.wampspring.session.WebSocketRegistryListener.java
private void afterWsConnectionClosed(WebSocketSession wsSession) { String httpSessionId = (String) wsSession.getAttributes().get(SessionSupport.SPRING_SESSION_ID_ATTR_NAME); if (httpSessionId == null) { return;//from w w w . jav a 2s . co m } Map<String, WebSocketSession> sessions = this.httpSessionIdToWsSessions.get(httpSessionId); if (sessions != null) { String wsSessionId = wsSession.getId(); boolean result = sessions.remove(wsSessionId) != null; if (logger.isDebugEnabled()) { logger.debug("Removal of " + wsSessionId + " was " + result); } if (sessions.isEmpty()) { this.httpSessionIdToWsSessions.remove(httpSessionId); if (logger.isDebugEnabled()) { logger.debug("Removed the corresponding HTTP Session for " + wsSessionId + " since it contained no WebSocket mappings"); } } } }
From source file:org.kurento.tutorial.player.PlayerFrameSaverHandler.java
@Override public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class); String sessionId = session.getId(); log.debug("Incoming Message {} --- From Session-ID {}", jsonMessage, sessionId); try {/*from w w w. j a v a2 s. c om*/ switch (jsonMessage.get("id").getAsString()) { case "start": start(session, jsonMessage); break; case "stop": stop(sessionId); break; case "pause": pause(sessionId); break; case "resume": resume(session); break; case "doSeek": doSeek(session, jsonMessage); break; case "getPosition": getPosition(session); break; case "onIceCandidate": onIceCandidate(sessionId, jsonMessage); break; default: sendError(session, "Invalid message with id " + jsonMessage.get("id").getAsString()); break; } } catch (Throwable t) { log.error("Exception handling message {} in sessionId {}", jsonMessage, sessionId, t); sendError(session, t.getMessage()); } }
From source file:dk.apaq.orderly.CallHandler.java
@Override public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { BroadcastMessage bmsg = resolveMessage(message); //JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class); log.debug("Incoming message from session '{}': {}", session.getId(), bmsg); switch (bmsg.getId()) { case Presenter: try {/*from w w w. j a v a2 s .c o m*/ presenter(session, bmsg); } catch (Throwable t) { handleErrorResponse(t, session, BroadcastMessageType.PresenterResponse); } break; case Viewer: try { viewer(session, bmsg); } catch (Throwable t) { handleErrorResponse(t, session, BroadcastMessageType.ViewerResponse); } break; case OnIceCandidate: { IceCandidate candidate = bmsg.getCandidate(); UserSession user = null; if (presenterUserSession != null) { if (presenterUserSession.getSession() == session) { user = presenterUserSession; } else { user = viewers.get(session.getId()); } } if (user != null) { user.addCandidate(candidate.toOrg()); } break; } case Stop: stop(session); break; default: break; } }
From source file:org.kurento.tutorial.helloworld.HelloWorldHandler.java
@Override public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class); log.debug("Incoming message: {}", jsonMessage); switch (jsonMessage.get("id").getAsString()) { case "start": start(session, jsonMessage);// w w w. j av a 2s . c o m break; case "stop": { UserSession user = users.remove(session.getId()); if (user != null) { user.release(); } break; } case "onIceCandidate": { JsonObject jsonCandidate = jsonMessage.get("candidate").getAsJsonObject(); UserSession user = users.get(session.getId()); if (user != null) { IceCandidate candidate = new IceCandidate(jsonCandidate.get("candidate").getAsString(), jsonCandidate.get("sdpMid").getAsString(), jsonCandidate.get("sdpMLineIndex").getAsInt()); user.addCandidate(candidate); } break; } default: sendError(session, "Invalid message with id " + jsonMessage.get("id").getAsString()); break; } }