Interface WebSocket

  • All Known Implementing Classes:
    WebSocketImpl

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

      • onClose

        void onClose​(java.util.function.Consumer<WebSocket> handler)
        Fired when the websocket closes.
      • offClose

        void offClose​(java.util.function.Consumer<WebSocket> handler)
        Removes handler that was previously added with onClose(handler).
      • onFrameReceived

        void onFrameReceived​(java.util.function.Consumer<WebSocketFrame> handler)
        Fired when the websocket receives a frame.
      • onFrameSent

        void onFrameSent​(java.util.function.Consumer<WebSocketFrame> handler)
        Fired when the websocket sends a frame.
      • onSocketError

        void onSocketError​(java.util.function.Consumer<java.lang.String> handler)
        Fired when the websocket has an error.
      • offSocketError

        void offSocketError​(java.util.function.Consumer<java.lang.String> handler)
        Removes handler that was previously added with onSocketError(handler).
      • isClosed

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

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

        default WebSocketFrame waitForFrameReceived​(java.lang.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,
                                            java.lang.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​(java.lang.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,
                                        java.lang.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