diff --git a/lua/firenvim-websocket.lua b/lua/firenvim-websocket.lua index 33a7f74a..4c14d146 100644 --- a/lua/firenvim-websocket.lua +++ b/lua/firenvim-websocket.lua @@ -137,6 +137,14 @@ local function encode_frame(data) return header .. len .. data end +local function pong_frame(decoded_frame) + -- 137: 10001010 + -- Fin: 1 + -- RSV{1,2,3}: 0 + -- Opcode: 0xA (pong) + return string.char(138) .. decoded_frame.payload_length .. decoded_frame.payload_data +end + local function close_frame() local frame = encode_frame("") return string.char(136) .. string.sub(frame, 2) @@ -149,4 +157,5 @@ return { encode_frame = encode_frame, opcodes = opcodes, parse_headers = parse_headers, + pong_frame = pong_frame, } diff --git a/lua/firenvim.lua b/lua/firenvim.lua index 720ab36d..300105ac 100644 --- a/lua/firenvim.lua +++ b/lua/firenvim.lua @@ -68,8 +68,7 @@ local function connection_handler(server, sock, token) current_payload = "" end elseif decoded_frame.opcode == websocket.opcodes.ping then - -- TODO: implement websocket.pong_frame - -- sock:write(websocket.pong_frame(decoded_frame)) + sock:write(websocket.pong_frame(decoded_frame)) return elseif decoded_frame.opcode == websocket.opcodes.close then sock:write(websocket.close_frame(decoded_frame))