Example usage for io.vertx.core.http WebSocketFrame isBinary

List of usage examples for io.vertx.core.http WebSocketFrame isBinary

Introduction

In this page you can find the example usage for io.vertx.core.http WebSocketFrame isBinary.

Prototype

boolean isBinary();

Source Link

Usage

From source file:io.sqp.proxy.testhelpers.WebSocketFrameMatcher.java

License:Open Source License

@Override
public boolean matches(Object argument) {
    if (!(argument instanceof WebSocketFrame)) {
        return false;
    }//  w w w. j  a va 2  s  . c  om
    WebSocketFrame frame = (WebSocketFrame) argument;
    if (_isFinal != frame.isFinal()) {
        return false;
    }

    if (_frameType.equals(FrameType.Binary) && !frame.isBinary()) {
        return false;
    } else if (_frameType.equals(FrameType.Text) && !frame.isText()) {
        return false;
    } else if (_frameType.equals(FrameType.Continuation) && !frame.isContinuation()) {
        return false;
    }

    byte[] frameContent = frame.binaryData().getBytes();
    return Arrays.equals(_expectedContent, frameContent);
}

From source file:io.sqp.proxy.vertx.VertxClientConnection.java

License:Open Source License

public void handleFrame(WebSocketFrame frame) {
    ByteBuffer buf = new VertxByteBuffer(frame.binaryData());
    boolean isFinal = frame.isFinal();
    boolean isText = frame.isText();

    try {/*from   w  w w  .  j  a  v  a  2  s .co m*/
        if (isText || frame.isBinary()) {
            DataFormat format = isText ? DataFormat.Text : DataFormat.Binary;
            _msgReceiver.newMessage(format, buf, isFinal);
        } else if (frame.isContinuation()) {
            _msgReceiver.continueMessage(buf, isFinal);
        } else {
            throw new InvalidFrameException("Invalid frame type");
        }
    } catch (SqpException e) {
        _session.handleError(e);
    }
}

From source file:org.entcore.workspace.controllers.AudioRecorderHandler.java

License:Open Source License

@Override
public void handle(final ServerWebSocket ws) {
    ws.pause();// www .j  a  v  a2 s . c om
    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"));
                            }
                        }
                    }));
        }
    });
}