1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 22:12:05 +01:00

Added ability to sign off with a custom presence packet (SMACK-195).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7081 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2007-02-13 02:23:28 +00:00 committed by matt
parent 5f9456db0d
commit 322292cad9
2 changed files with 20 additions and 4 deletions

View file

@ -213,7 +213,7 @@ class PacketReader {
void notifyConnectionError(Exception e) { void notifyConnectionError(Exception e) {
done = true; done = true;
// Closes the connection temporary. A reconnection is possible // Closes the connection temporary. A reconnection is possible
connection.shutdown(); connection.shutdown(new Presence(Presence.Type.unavailable));
// Print the stack trace to help catch the problem // Print the stack trace to help catch the problem
e.printStackTrace(); e.printStackTrace();
// Notify connection listeners of the error. // Notify connection listeners of the error.

View file

@ -556,10 +556,12 @@ public class XMPPConnection {
* dealing with an unexpected disconnection. Unlike {@link #disconnect()} the connection's * dealing with an unexpected disconnection. Unlike {@link #disconnect()} the connection's
* packet reader, packet writer, and {@link Roster} will not be removed; thus * packet reader, packet writer, and {@link Roster} will not be removed; thus
* connection's state is kept. * connection's state is kept.
*
* @param unavailablePresence the presence packet to send during shutdown.
*/ */
protected void shutdown() { protected void shutdown(Presence unavailablePresence) {
// Set presence to offline. // Set presence to offline.
packetWriter.sendPacket(new Presence(Presence.Type.unavailable)); packetWriter.sendPacket(unavailablePresence);
packetReader.shutdown(); packetReader.shutdown();
packetWriter.shutdown(); packetWriter.shutdown();
// Wait 150 ms for processes to clean-up, then shutdown. // Wait 150 ms for processes to clean-up, then shutdown.
@ -602,7 +604,21 @@ public class XMPPConnection {
* again. * again.
*/ */
public void disconnect() { public void disconnect() {
this.shutdown(); disconnect(new Presence(Presence.Type.unavailable));
}
/**
* Closes the connection. A custom unavailable presence is sent to the server, followed
* by closing the stream. The XMPPConnection can still be used for connecting to the server
* again. A custom unavilable presence is useful for communicating offline presence
* information such as "On vacation". Typically, just the status text of the presence
* packet is set with online information, but most XMPP servers will deliver the full
* presence packet with whatever data is set.
*
* @param unavailablePresence the presence packet to send during shutdown.
*/
public void disconnect(Presence unavailablePresence) {
this.shutdown(unavailablePresence);
this.roster = null; this.roster = null;