X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_websocket.lua;h=086eab62603bde1de809829bdbc0bf493559d340;hb=bc7858df342295ecba0b5d9ec2b6ea98a9c589f3;hp=418cd84639f0aa07df2ec6d3d9c512103eeee6be;hpb=b6d336cbfe79bf837dbf89f80d4852aa58a110c4;p=prosody.git diff --git a/plugins/mod_websocket.lua b/plugins/mod_websocket.lua index 418cd846..086eab62 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,12 @@ function handle_request(event) return ""; end +local function keepalive(event) + return conn:write(build_frame({ opcode = 0x9, })); +end + +module:hook("c2s-read-timeout", keepalive, -0.9); + function module.add_host(module) module:depends("http"); module:provides("http", { @@ -301,4 +306,5 @@ function module.add_host(module) ["GET /"] = handle_request; }; }); + module:hook("c2s-read-timeout", keepalive, -0.9); end