List of usage examples for io.vertx.core.http WebSocketFrame textData
@CacheReturn String textData();
From source file:org.entcore.workspace.controllers.AudioRecorderHandler.java
License:Open Source License
@Override public void handle(final ServerWebSocket ws) { ws.pause();//from w ww . j a v a 2 s . c o m String sessionId = CookieHelper.getInstance().getSigned(SESSION_ID, ws); UserUtils.getSession(Server.getEventBus(vertx), sessionId, new Handler<JsonObject>() { public void handle(final JsonObject infos) { if (infos == null) { ws.reject(); return; } final String id = ws.path().replaceFirst("/audio/", ""); eb.send(AudioRecorderWorker.class.getSimpleName(), new JsonObject().put("action", "open").put("id", id), handlerToAsyncHandler(new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> m) { if ("ok".equals(m.body().getString("status"))) { ws.frameHandler(new Handler<WebSocketFrame>() { @Override public void handle(WebSocketFrame frame) { if (frame.isBinary()) { log.debug("frame handler"); eb.send(AudioRecorderWorker.class.getSimpleName() + id, frame.binaryData().getBytes(), new DeliveryOptions().setSendTimeout(TIMEOUT), new Handler<AsyncResult<Message<JsonObject>>>() { @Override public void handle( AsyncResult<Message<JsonObject>> ar) { if (ar.failed() || !"ok".equals( ar.result().body().getString("status"))) { ws.writeTextMessage("audio.chunk.error"); } } }); } else { final String command = frame.textData(); if (command != null && command.startsWith("save-")) { save(id, command.substring(5), infos, ws); } else if ("cancel".equals(command)) { cancel(id, ws); } else if ("rawdata".equals(command)) { disableCompression(id, ws); } } } }); ws.closeHandler(new Handler<Void>() { @Override public void handle(Void event) { cancel(id, null); } }); ws.resume(); } else { ws.writeTextMessage(m.body().getString("message")); } } })); } }); }