|
1 local st = require "util.stanza"; |
|
2 local xmlns_session = "urn:ietf:params:xml:ns:xmpp-session"; |
|
3 |
|
4 function verse.plugins.session(stream) |
|
5 local function handle_binding(jid) |
|
6 stream:debug("Establishing Session..."); |
|
7 stream:send_iq(st.iq({ type = "set" }):tag("session", {xmlns=xmlns_session}), |
|
8 function (reply) |
|
9 if reply.attr.type == "result" then |
|
10 stream:event("session-success"); |
|
11 elseif reply.attr.type == "error" then |
|
12 local err = reply:child_with_name("error"); |
|
13 local type, condition, text = reply:get_error(); |
|
14 stream:event("session-failure", { error = condition, text = text, type = type }); |
|
15 end |
|
16 end); |
|
17 end |
|
18 stream:hook("binding-success", handle_binding); |
|
19 return true; |
|
20 end |