Example #1
0
 /**
  * Deletes the currently logged-in account from the server. This operation can only be performed
  * after a successful login operation has been completed. Not all servers support deleting
  * accounts; an XMPPException will be thrown when that is the case.
  *
  * @throws IllegalStateException if not currently logged-in to the server.
  * @throws XMPPException if an error occurs when deleting the account.
  */
 public void deleteAccount() throws XMPPException {
   if (!connection.isAuthenticated()) {
     throw new IllegalStateException("Must be logged in to delete a account.");
   }
   Registration reg = new Registration();
   reg.setType(IQ.Type.SET);
   reg.setTo(connection.getServiceName());
   Map<String, String> attributes = new HashMap<String, String>();
   // To delete an account, we add a single attribute, "remove", that is blank.
   attributes.put("remove", "");
   reg.setAttributes(attributes);
   PacketFilter filter =
       new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
   PacketCollector collector = connection.createPacketCollector(filter);
   connection.sendPacket(reg);
   IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
   // Stop queuing results
   collector.cancel();
   if (result == null) {
     throw new XMPPException("No response from server.");
   } else if (result.getType() == IQ.Type.ERROR) {
     throw new XMPPException(result.getError());
   }
 }
Example #2
0
 @Override
 public boolean IsConnect() {
   if (connection == null) return false;
   if (connection.isAuthenticated() == false) return false;
   return true; // connection.isConnected();
 }
Example #3
0
  /**
   * Creates a new workgroup instance using the specified workgroup JID (eg
   * [email protected]) and XMPP connection. The connection must have undergone a
   * successful login before being used to construct an instance of this class.
   *
   * @param workgroupJID the JID of the workgroup.
   * @param connection an XMPP connection which must have already undergone a successful login.
   */
  public Workgroup(String workgroupJID, Connection connection) {
    // Login must have been done before passing in connection.
    if (!connection.isAuthenticated()) {
      throw new IllegalStateException("Must login to server before creating workgroup.");
    }

    this.workgroupJID = workgroupJID;
    this.connection = connection;
    inQueue = false;
    invitationListeners = new ArrayList<WorkgroupInvitationListener>();
    queueListeners = new ArrayList<QueueListener>();

    // Register as a queue listener for internal usage by this instance.
    addQueueListener(
        new QueueListener() {
          public void joinedQueue() {
            inQueue = true;
          }

          public void departedQueue() {
            inQueue = false;
            queuePosition = -1;
            queueRemainingTime = -1;
          }

          public void queuePositionUpdated(int currentPosition) {
            queuePosition = currentPosition;
          }

          public void queueWaitTimeUpdated(int secondsRemaining) {
            queueRemainingTime = secondsRemaining;
          }
        });

    /**
     * Internal handling of an invitation.Recieving an invitation removes the user from the queue.
     */
    MultiUserChat.addInvitationListener(
        connection,
        new org.jivesoftware.smackx.muc.InvitationListener() {
          public void invitationReceived(
              Connection conn,
              String room,
              String inviter,
              String reason,
              String password,
              Message message) {
            inQueue = false;
            queuePosition = -1;
            queueRemainingTime = -1;
          }
        });

    // Register a packet listener for all the messages sent to this client.
    PacketFilter typeFilter = new PacketTypeFilter(Message.class);

    connection.addPacketListener(
        new PacketListener() {
          public void processPacket(Packet packet) {
            handlePacket(packet);
          }
        },
        typeFilter);
  }