Interface WebSocket


  • public interface WebSocket
    The WebSocket class represents websocket connections in the page.
    • Method Detail

      • onClose

        void onClose​(Consumer<WebSocket> handler)
        Fired when the websocket closes.
      • onFrameReceived

        void onFrameReceived​(Consumer<WebSocketFrame> handler)
        Fired when the websocket receives a frame.
      • onSocketError

        void onSocketError​(Consumer<String> handler)
        Fired when the websocket has an error.
      • isClosed

        boolean isClosed()
        Indicates that the web socket has been closed.
        Since:
        v1.8
      • url

        String url()
        Contains the URL of the WebSocket.
        Since:
        v1.8
      • waitForFrameReceived

        default WebSocketFrame waitForFrameReceived​(Runnable callback)
        Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate function and waits for predicate(webSocketFrame) to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is received.
        Parameters:
        callback - Callback that performs the action triggering the event.
        Since:
        v1.10
      • waitForFrameReceived

        WebSocketFrame waitForFrameReceived​(WebSocket.WaitForFrameReceivedOptions options,
                                            Runnable callback)
        Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate function and waits for predicate(webSocketFrame) to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is received.
        Parameters:
        callback - Callback that performs the action triggering the event.
        Since:
        v1.10
      • waitForFrameSent

        default WebSocketFrame waitForFrameSent​(Runnable callback)
        Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate function and waits for predicate(webSocketFrame) to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is sent.
        Parameters:
        callback - Callback that performs the action triggering the event.
        Since:
        v1.10
      • waitForFrameSent

        WebSocketFrame waitForFrameSent​(WebSocket.WaitForFrameSentOptions options,
                                        Runnable callback)
        Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate function and waits for predicate(webSocketFrame) to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is sent.
        Parameters:
        callback - Callback that performs the action triggering the event.
        Since:
        v1.10