106 self:event("ready"); |
106 self:event("ready"); |
107 end |
107 end |
108 self:hook("session-success", stream_ready, -1) |
108 self:hook("session-success", stream_ready, -1) |
109 self:hook("bind-success", stream_ready, -1); |
109 self:hook("bind-success", stream_ready, -1); |
110 |
110 |
|
111 local _base_close = self.close; |
|
112 function self:close(reason) |
|
113 if not self.notopen then |
|
114 self:send("</stream:stream>"); |
|
115 end |
|
116 return _base_close(self); |
|
117 end |
|
118 |
111 -- Initialise connection |
119 -- Initialise connection |
112 self:connect(self.connect_host or self.host, self.connect_port or 5222); |
120 self:connect(self.connect_host or self.host, self.connect_port or 5222); |
113 self:reopen(); |
121 self:reopen(); |
114 end |
122 end |
115 |
123 |
116 function stream:reopen() |
124 function stream:reopen() |
117 self:reset(); |
125 self:reset(); |
118 self:send(st.stanza("stream:stream", { to = self.host, ["xmlns:stream"]='http://etherx.jabber.org/streams', |
126 self:send(st.stanza("stream:stream", { to = self.host, ["xmlns:stream"]='http://etherx.jabber.org/streams', |
119 xmlns = "jabber:client", version = "1.0" }):top_tag()); |
127 xmlns = "jabber:client", version = "1.0" }):top_tag()); |
120 end |
|
121 |
|
122 function stream:close(reason) |
|
123 if not self.notopen then |
|
124 self:send("</stream:stream>"); |
|
125 end |
|
126 local on_disconnect = self.conn.disconnect(); |
|
127 self.conn:close(); |
|
128 on_disconnect(conn, reason); |
|
129 end |
128 end |
130 |
129 |
131 function stream:send_iq(iq, callback) |
130 function stream:send_iq(iq, callback) |
132 local id = self:new_id(); |
131 local id = self:new_id(); |
133 self.tracked_iqs[id] = callback; |
132 self.tracked_iqs[id] = callback; |