Example usage for org.springframework.boot.devtools.livereload Frame Frame

List of usage examples for org.springframework.boot.devtools.livereload Frame Frame

Introduction

In this page you can find the example usage for org.springframework.boot.devtools.livereload Frame Frame.

Prototype

Frame(Type type) 

Source Link

Usage

From source file:org.springframework.boot.devtools.livereload.Connection.java

private void runWebSocket(String header) throws Exception {
    String accept = getWebsocketAcceptResponse();
    this.outputStream.writeHeaders("HTTP/1.1 101 Switching Protocols", "Upgrade: websocket",
            "Connection: Upgrade", "Sec-WebSocket-Accept: " + accept);
    new Frame("{\"command\":\"hello\",\"protocols\":" + "[\"http://livereload.com/protocols/official-7\"],"
            + "\"serverName\":\"spring-boot\"}").write(this.outputStream);
    Thread.sleep(100);/*from  ww  w  .  j  a v  a  2 s . co  m*/
    this.webSocket = true;
    while (this.running) {
        readWebSocketFrame();
    }
}

From source file:org.springframework.boot.devtools.livereload.Connection.java

private void readWebSocketFrame() throws IOException {
    try {/*  w ww . j  av  a 2 s . co m*/
        Frame frame = Frame.read(this.inputStream);
        if (frame.getType() == Frame.Type.PING) {
            writeWebSocketFrame(new Frame(Frame.Type.PONG));
        } else if (frame.getType() == Frame.Type.CLOSE) {
            throw new ConnectionClosedException();
        } else if (frame.getType() == Frame.Type.TEXT) {
            logger.debug("Recieved LiveReload text frame " + frame);
        } else {
            throw new IOException("Unexpected Frame Type " + frame.getType());
        }
    } catch (SocketTimeoutException ex) {
        writeWebSocketFrame(new Frame(Frame.Type.PING));
        Frame frame = Frame.read(this.inputStream);
        if (frame.getType() != Frame.Type.PONG) {
            throw new IllegalStateException("No Pong");
        }
    }
}

From source file:org.springframework.boot.devtools.livereload.Connection.java

/**
 * Trigger livereload for the client using this connection.
 * @throws IOException in case of I/O errors
 *///from w w  w  . j  av a2  s. c  o m
public void triggerReload() throws IOException {
    if (this.webSocket) {
        logger.debug("Triggering LiveReload");
        writeWebSocketFrame(new Frame("{\"command\":\"reload\",\"path\":\"/\"}"));
    }
}