Interface WebSocket

All Known Implementing Classes:
WebSocketImpl

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

    • onClose

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

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

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

      void offFrameReceived(Consumer<WebSocketFrame> handler)
      Removes handler that was previously added with onFrameReceived(handler).
    • onFrameSent

      void onFrameSent(Consumer<WebSocketFrame> handler)
      Fired when the websocket sends a frame.
    • offFrameSent

      void offFrameSent(Consumer<WebSocketFrame> handler)
      Removes handler that was previously added with onFrameSent(handler).
    • onSocketError

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

      void offSocketError(Consumer<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

      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