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