@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); break; case "show_faces": setVisualization(session, jsonMessage); break; case "scale_factor": setScaleFactor(session, jsonMessage); break; case "process_num_frames": setProcessNumberFrames(session, jsonMessage); break; case "width_to_process": setWidthToProcess(session, jsonMessage); break; case "get_stats": getStats(session); break; case "euclidean_dis": setEuclideanDistance(session, jsonMessage); break; case "area_threshold": setAreaThreshold(session, jsonMessage); break; case "track_treshold": setTrackThreshold(session, jsonMessage); break; case "stop": { UserSession user = users.remove(session.getId()); if (user != null) { user.release(); } break; } case "onIceCandidate": { JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject(); UserSession user = users.get(session.getId()); if (user != null) { user.addCandidate(candidate); } break; } default: error(session, "Invalid message with id " + jsonMessage.get("id").getAsString()); break; } }
@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); break; case "show_mouths": setVisualization(session, jsonMessage); break; case "scale_factor": log.debug("Case scale factor"); setScaleFactor(session, jsonMessage); break; case "process_num_frames": log.debug("Case process num frames"); setProcessNumberFrames(session, jsonMessage); break; case "width_to_process": log.debug("Case width to process"); setWidthToProcess(session, jsonMessage); break; case "stop": { UserSession user = users.remove(session.getId()); if (user != null) { user.release(); } break; } case "onIceCandidate": { JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject(); UserSession user = users.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; } default: sendError(session, "Invalid message with id " + jsonMessage.get("id").getAsString()); break; } }
private void release(WebSocketSession session) { UserSession user = users.remove(session.getId()); if (user != null) { user.release(); } }