X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fmod_websocket.lua;h=a3f5318c9b54636f8caec1b747bf39fd56bd9033;hb=b6afa2fd923572e78b5e1c9711e324aa37b43226;hp=418cd84639f0aa07df2ec6d3d9c512103eeee6be;hpb=165acbdc755e95ab0250070016d334284e63b271;p=prosody.git diff --git a/plugins/mod_websocket.lua b/plugins/mod_websocket.lua index 418cd846..a3f5318c 100644 --- a/plugins/mod_websocket.lua +++ b/plugins/mod_websocket.lua @@ -226,8 +226,7 @@ function handle_request(event) frame.opcode = 0xA; conn:write(build_frame(frame)); return ""; - elseif opcode == 0xA then -- Pong frame - module:log("warn", "Received unexpected pong frame: " .. tostring(frame.data)); + elseif opcode == 0xA then -- Pong frame, MAY be sent unsolicited, eg as keepalive return ""; else log("warn", "Received frame with unsupported opcode %i", opcode); @@ -275,7 +274,7 @@ function handle_request(event) attr["xmlns:stream"] = attr["xmlns:stream"] or xmlns_streams; end return stanza; - end); + end, -1000); add_filter(session, "bytes/out", function(data) return build_frame({ FIN = true, opcode = 0x01, data = tostring(data)}); @@ -291,6 +290,15 @@ function handle_request(event) return ""; end +local function keepalive(event) + local session = event.session; + if session.open_stream == session_open_stream then + return session.conn:write(build_frame({ opcode = 0x9, })); + end +end + +module:hook("c2s-read-timeout", keepalive, -0.9); + function module.add_host(module) module:depends("http"); module:provides("http", { @@ -301,4 +309,5 @@ function module.add_host(module) ["GET /"] = handle_request; }; }); + module:hook("c2s-read-timeout", keepalive, -0.9); end