Skip to content

Commit 76c2905

Browse files
committed
chore: update resty.websocket annotations
1 parent c43a933 commit 76c2905

File tree

4 files changed

+128
-130
lines changed

4 files changed

+128
-130
lines changed

meta/3rd/OpenResty/library/resty.websocket.client.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@meta
22

33
---@class resty.websocket.client : resty.websocket
4-
resty_websocket_client = {
4+
local client = {
55
_VERSION = "0.09"
66
}
77

@@ -14,7 +14,7 @@ resty_websocket_client = {
1414
---@param opts? resty.websocket.new.opts
1515
---@return resty.websocket.client? client
1616
---@return string? error
17-
function resty_websocket_client:new(opts) end
17+
function client:new(opts) end
1818

1919
---Connects to the remote WebSocket service port and performs the websocket
2020
---handshake process on the client side.
@@ -27,7 +27,7 @@ function resty_websocket_client:new(opts) end
2727
---@param opts? resty.websocket.client.connect.opts
2828
---@return boolean ok
2929
---@return string? error
30-
function resty_websocket_client:connect(uri, opts) end
30+
function client:connect(uri, opts) end
3131

3232
--- Puts the current WebSocket connection immediately into the ngx_lua cosocket connection pool.
3333
---
@@ -41,15 +41,15 @@ function resty_websocket_client:connect(uri, opts) end
4141
---@param pool_size integer
4242
---@return boolean ok
4343
---@return string? error
44-
function resty_websocket_client:set_keepalive(max_idle_timeout, pool_size) end
44+
function client:set_keepalive(max_idle_timeout, pool_size) end
4545

4646
---Closes the current WebSocket connection.
4747
---
4848
---If no close frame is sent yet, then the close frame will be automatically sent.
4949
---
5050
---@return boolean ok
5151
---@return string? error
52-
function resty_websocket_client:close() end
52+
function client:close() end
5353

5454
---@class resty.websocket.client.connect.opts : table
5555
---
@@ -60,4 +60,4 @@ function resty_websocket_client:close() end
6060
---@field headers string[] custom headers to be sent in the handshake request. The table is expected to contain strings in the format {"a-header: a header value", "another-header: another header value"}.
6161

6262

63-
return resty_websocket_client
63+
return client

meta/3rd/OpenResty/library/resty.websocket.lua

Lines changed: 0 additions & 116 deletions
This file was deleted.

meta/3rd/OpenResty/library/resty.websocket.protocol.lua

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,124 @@
11
---@meta
22

33
---@class resty.websocket.protocol
4-
resty_websocket_protocol = {
4+
local protocol = {
55
_VERSION = "0.09",
66
}
77

8+
--- websocket object
9+
--- https://github.com/openresty/lua-resty-websocket
10+
---
11+
---@class resty.websocket : table
12+
---@field sock tcpsock
13+
---@field fatal boolean
14+
---@field max_payload_len number
15+
---@field send_masked boolean
16+
local websocket = {}
17+
18+
---@param ms integer sets the timeout delay (in milliseconds) for the network-related operations
19+
function websocket:set_timeout(ms) end
20+
21+
---Sends the text argument out as an unfragmented data frame of the text type.
22+
---
23+
---Returns the number of bytes that have actually been sent on the TCP level.
24+
---
25+
---In case of errors, returns nil and a string describing the error.
26+
---
27+
---@param text string
28+
---@return integer? bytes
29+
---@return string? error
30+
function websocket:send_text(text) end
31+
32+
---Sends the data argument out as an unfragmented data frame of the binary type.
33+
---
34+
---Returns the number of bytes that have actually been sent on the TCP level.
35+
---
36+
---In case of errors, returns nil and a string describing the error.
37+
---
38+
---@param data string
39+
---@return integer? bytes
40+
---@return string? error
41+
function websocket:send_binary(data) end
42+
43+
---Sends out a ping frame with an optional message specified by the msg argument.
44+
---Returns the number of bytes that have actually been sent on the TCP level.
45+
---
46+
---In case of errors, returns nil and a string describing the error.
47+
---
48+
---Note that this method does not wait for a pong frame from the remote end.
49+
---
50+
---@param msg? string
51+
---@return integer? bytes
52+
---@return string? error
53+
function websocket:send_ping(msg) end
54+
55+
---Sends out a pong frame with an optional message specified by the msg argument.
56+
---Returns the number of bytes that have actually been sent on the TCP level.
57+
---
58+
---In case of errors, returns nil and a string describing the error.
59+
---@param msg? string
60+
---@return integer? bytes
61+
---@return string? error
62+
function websocket:send_pong(msg) end
63+
64+
---Sends out a close frame with an optional status code and a message.
65+
---
66+
---In case of errors, returns nil and a string describing the error.
67+
---
68+
---For a list of valid status code, see the following document:
69+
---
70+
---http://tools.ietf.org/html/rfc6455#section-7.4.1
71+
---
72+
---Note that this method does not wait for a close frame from the remote end.
73+
---@param code? integer
74+
---@param msg? string
75+
---@return integer? bytes
76+
---@return string? error
77+
function websocket:send_close(code, msg) end
78+
79+
---Sends out a raw websocket frame by specifying the fin field (boolean value), the opcode, and the payload.
80+
---
81+
---For a list of valid opcode, see
82+
---
83+
---http://tools.ietf.org/html/rfc6455#section-5.2
84+
---
85+
---In case of errors, returns nil and a string describing the error.
86+
---
87+
---To control the maximal payload length allowed, you can pass the max_payload_len option to the new constructor.
88+
---
89+
---To control whether to send masked frames, you can pass true to the send_masked option in the new constructor method. By default, unmasked frames are sent.
90+
---@param fin boolean
91+
---@param opcode resty.websocket.protocol.opcode
92+
---@param payload string
93+
---@return integer? bytes
94+
---@return string? error
95+
function websocket:send_frame(fin, opcode, payload) end
96+
97+
---Receives a WebSocket frame from the wire.
98+
---
99+
---In case of an error, returns two nil values and a string describing the error.
100+
---
101+
---The second return value is always the frame type, which could be one of continuation, text, binary, close, ping, pong, or nil (for unknown types).
102+
---
103+
---For close frames, returns 3 values: the extra status message (which could be an empty string), the string "close", and a Lua number for the status code (if any). For possible closing status codes, see
104+
---
105+
---http://tools.ietf.org/html/rfc6455#section-7.4.1
106+
---
107+
---For other types of frames, just returns the payload and the type.
108+
---
109+
---For fragmented frames, the err return value is the Lua string "again".
110+
---
111+
---@return string? data
112+
---@return resty.websocket.protocol.type? typ
113+
---@return string|integer? error_or_status_code
114+
function websocket:recv_frame() end
115+
116+
---@class resty.websocket.new.opts : table
117+
---@field max_payload_len integer maximal length of payload allowed when sending and receiving WebSocket frames
118+
---@field send_masked boolean whether to send out masked WebSocket frames
119+
---@field timeout integer network timeout threshold in milliseconds
120+
121+
8122
--- Websocket op code
9123
---
10124
--- Defines the interpretation of the payload data.
@@ -34,7 +148,7 @@ resty_websocket_protocol = {
34148
---@param payload string
35149
---@param masking boolean
36150
---@return string
37-
function resty_websocket_protocol.build_frame(fin, opcode, payload_len, payload, masking) end
151+
function protocol.build_frame(fin, opcode, payload_len, payload, masking) end
38152

39153
--- Sends a raw WebSocket frame.
40154
---@param sock tcpsock
@@ -45,7 +159,7 @@ function resty_websocket_protocol.build_frame(fin, opcode, payload_len, payload,
45159
---@param masking boolean
46160
---@return bytes? number
47161
---@return string? error
48-
function resty_websocket_protocol.send_frame(sock, fin, opcode, payload, max_payload_len, masking) end
162+
function protocol.send_frame(sock, fin, opcode, payload, max_payload_len, masking) end
49163

50164
--- Receives a WebSocket frame from the wire.
51165
---@param sock tcpsock
@@ -54,6 +168,6 @@ function resty_websocket_protocol.send_frame(sock, fin, opcode, payload, max_pay
54168
---@return string? data
55169
---@return resty.websocket.protocol.type? typ
56170
---@return string? error
57-
function resty_websocket_protocol.recv_frame(sock, max_payload_len, force_masking) end
171+
function protocol.recv_frame(sock, max_payload_len, force_masking) end
58172

59-
return resty_websocket_protocol
173+
return protocol
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---@meta
22

33
---@class resty.websocket.server : resty.websocket
4-
resty_websocket_server = {
4+
local server = {
55
_VERSION = "0.09"
66
}
77

@@ -11,6 +11,6 @@ resty_websocket_server = {
1111
---@param opts? resty.websocket.new.opts
1212
---@return resty.websocket.server? server
1313
---@return string? error
14-
function resty_websocket_server:new(opts) end
14+
function server:new(opts) end
1515

16-
return resty_websocket_server
16+
return server

0 commit comments

Comments
 (0)