1 /*
2 * Copyright (c) 2002-2025 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 /**
18 * Helper to have no direct dependency to the WebSockt client
19 * implementation used by HtmlUnit.
20 *
21 * @author Ronald Brill
22 */
23 public interface WebSocketListener {
24
25 /**
26 * Callback to be called when connecting.
27 */
28 void onWebSocketConnecting();
29
30 /**
31 * Callback to be called when connected.
32 */
33 void onWebSocketConnect();
34
35 /**
36 * Callback to be called when closed.
37 *
38 * @param statusCode the status code
39 * @param reason the reason
40 */
41 void onWebSocketClose(int statusCode, String reason);
42
43 /**
44 * Callback to be called when closed.
45 *
46 * @param message the message
47 */
48 void onWebSocketText(String message);
49
50 /**
51 * Callback to be called when binary data retrieved.
52 *
53 * @param data the bytes
54 * @param offset start offset
55 * @param length the length
56 */
57 void onWebSocketBinary(byte[] data, int offset, int length);
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 }