Comparison

plugins/mod_s2s_bidi.lua @ 10250:1006739de449

mod_s2s_bidi: Enables bi-directional streams via XEP-0288
author Kim Alvefur <zash@zash.se>
date Sun, 08 Sep 2019 19:45:39 +0200
child 10458:602dd1e2f399
comparison
equal deleted inserted replaced
10249:790c6ae54dd6 10250:1006739de449
1 -- Prosody IM
2 -- Copyright (C) 2019 Kim Alvefur
3 --
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
6 --
7
8 local st = require "util.stanza";
9
10 local xmlns_bidi_feature = "urn:xmpp:features:bidi"
11 local xmlns_bidi = "urn:xmpp:bidi";
12
13 module:hook("s2s-stream-features", function(event)
14 local origin, features = event.origin, event.features;
15 if origin.type == "s2sin_unauthed" then
16 features:tag("bidi", { xmlns = xmlns_bidi_feature }):up();
17 end
18 end);
19
20 module:hook_tag("http://etherx.jabber.org/streams", "features", function (session, stanza)
21 if session.type == "s2sout_unauthed" then
22 local bidi = stanza:get_child("bidi", xmlns_bidi_feature);
23 if bidi then
24 session.incoming = true;
25 session.log("debug", "Requesting bidirectional stream");
26 session.sends2s(st.stanza("bidi", { xmlns = xmlns_bidi }));
27 end
28 end
29 end, 200);
30
31 module:hook_tag("urn:xmpp:bidi", "bidi", function(session)
32 if session.type == "s2sin_unauthed" then
33 session.log("debug", "Requested bidirectional stream");
34 session.outgoing = true;
35 return true;
36 end
37 end);
38