1 module hunt.http.codec.websocket.stream.WebSocketConnection;
2 
3 import hunt.http.codec.http.model.MetaData;
4 import hunt.http.codec.websocket.stream.IOState;
5 import hunt.http.codec.websocket.stream.WebSocketPolicy;
6 import hunt.http.codec.websocket.model.OutgoingFrames;
7 import hunt.net.Connection;
8 
9 
10 import hunt.container.ByteBuffer;
11 import hunt.lang.common;
12 import hunt.util.concurrent.CompletableFuture;
13 
14 interface WebSocketConnection : OutgoingFrames, Connection {
15 
16     /**
17      * Register the connection close callback.
18      *
19      * @param closedListener The connection close callback.
20      * @return The WebSocket connection.
21      */
22     WebSocketConnection onClose(Action1!(WebSocketConnection) closedListener);
23 
24     /**
25      * Register the exception callback.
26      *
27      * @param exceptionListener The exception callback.
28      * @return The WebSocket connection.
29      */
30     WebSocketConnection onException(Action2!(WebSocketConnection, Exception) exceptionListener);
31 
32     /**
33      * Get the read/write idle timeout.
34      *
35      * @return the idle timeout in milliseconds
36      */
37     // long getIdleTimeout();
38 
39     /**
40      * Get the IOState of the connection.
41      *
42      * @return the IOState of the connection.
43      */
44     IOState getIOState();
45 
46     /**
47      * The policy that the connection is running under.
48      *
49      * @return the policy for the connection
50      */
51     WebSocketPolicy getPolicy();
52 
53     /**
54      * Generate random 4bytes mask key
55      *
56      * @return the mask key
57      */
58     byte[] generateMask();
59 
60     /**
61      * Send text message.
62      *
63      * @param text The text message.
64      * @return The future result.
65      */
66     CompletableFuture!(bool) sendText(string text);
67 
68     /**
69      * Send binary message.
70      *
71      * @param data The binary message.
72      * @return The future result.
73      */
74     CompletableFuture!(bool) sendData(byte[] data);
75 
76     /**
77      * Send binary message.
78      *
79      * @param data The binary message.
80      * @return The future result.
81      */
82     CompletableFuture!(bool) sendData(ByteBuffer data);
83 
84     /**
85      * Get the websocket upgrade request.
86      *
87      * @return The upgrade request.
88      */
89     HttpRequest getUpgradeRequest();
90 
91     /**
92      * Get the websocket upgrade response.
93      *
94      * @return The upgrade response.
95      */
96     HttpResponse getUpgradeResponse();
97 
98 }