View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.websocket;
16  
17  import java.nio.ByteBuffer;
18  
19  /**
20   * Helper to have no direct dependency to the WebSockt client
21   * implementation used by HtmlUnit.
22   *
23   * @author Ronald Brill
24   */
25  public interface WebSocketListener {
26  
27      /**
28       * Callback to be called when connecting.
29       */
30      void onWebSocketConnecting();
31  
32      /**
33       * Callback to be called when opened.
34       */
35      void onWebSocketOpen();
36  
37      /**
38       * Callback to be called when closed.
39       *
40       * @param statusCode the status code
41       * @param reason the reason
42       */
43      void onWebSocketClose(int statusCode, String reason);
44  
45      /**
46       * Callback to be called when closed.
47       *
48       * @param message the message
49       */
50      void onWebSocketText(String message);
51  
52      /**
53       * Callback to be called when binary data retrieved.
54       *
55       * @param payload a {@link ByteBuffer}
56       */
57      void onWebSocketBinary(ByteBuffer payload);
58  
59      /**
60       * Callback to be called on connect error.
61       *
62       * @param cause the cause
63       */
64      void onWebSocketConnectError(Throwable cause);
65  
66      /**
67       * Callback to be called on error.
68       *
69       * @param cause the cause
70       */
71      void onWebSocketError(Throwable cause);
72  }