Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.Presence


   * @see org.olat.instantMessaging.InstantMessagingClient#addSubscriptionListener()
   * @param uname
   * @param groupname
   */
  protected void subscribeToUser(String uname, String groupname) {
    Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(uname + "@" + jabberServer);
    try {
      connection.sendPacket(presence);

      RosterPacket rosterPacket = new RosterPacket();
      rosterPacket.setType(IQ.Type.SET);
View Full Code Here


  public String buddyCountOnline() {
      int onlineBuddyEntries = connection.getRoster().getEntryCount();
      int allBuddies = onlineBuddyEntries;
      for (Iterator l = connection.getRoster().getEntries().iterator(); l.hasNext();) {
        RosterEntry entry = (RosterEntry) l.next();
        Presence presence = connection.getRoster().getPresence(entry.getUser());
        if (presence.getType() == Presence.Type.unavailable) onlineBuddyEntries--;
      }
      // final string looks like e.g. "(3/5)"
      StringBuilder sb = new StringBuilder(10);
      sb.append("(");
      sb.append(onlineBuddyEntries);
View Full Code Here

      RosterGroup rosterGroup = connection.getRoster().getGroup(groupname);
      int buddyEntries = rosterGroup.getEntryCount();
      int allBuddies = buddyEntries;
      for (Iterator I = rosterGroup.getEntries().iterator(); I.hasNext();) {
        RosterEntry entry = (RosterEntry) I.next();
        Presence presence = connection.getRoster().getPresence(entry.getUser());
        if (presence.getType() == Presence.Type.unavailable) buddyEntries--;
      }
      // final string looks like e.g. "(3/5)"
      StringBuilder sb = new StringBuilder(10);
      sb.append("(");
      sb.append(buddyEntries);
View Full Code Here

   *
   * @param jid
   * @return get a presence for a specific user
   */
  protected String getUserPresence(String jid) {
    Presence presence = connection.getRoster().getPresence(jid);
    String imageName = "offline"; // default
    // mode == null is equals available!!
    if (presence.getMode() == null && presence.getType() == Presence.Type.available) imageName = Presence.Mode.available
        .toString();
    if (presence.getMode() != null) imageName = presence.getMode().toString();
    return imageName;
  }
View Full Code Here

          GenericEventListener listener = listeners.get(username);
          if (listener == null) {
            log.warn("could not route presence event as presence listener is null for user: "+username);
          } else {
            listener.event(new InstantMessagingEvent(packet, "presence"));
            Presence presence = (Presence) packet;
            if (log.isDebug()) log.debug("routing presence event to controller of: "+presence.getTo());
          }
        } catch(Throwable th){
          log.warn("Presence package", th);
        }
      }
View Full Code Here

   * helper method to trigger a presence update even if the server does not send
   * a presence packet itself (e.g. entering a test but no other buddies are online)
   * @param username
   */
  public void sendPresenceEvent(Presence.Type type, String username) {
    Presence presence = new Presence(type);
    presence.setTo(username);
    GenericEventListener listener = listeners.get(username);
    if (listener != null) {
      listener.event(new InstantMessagingEvent(presence, "presence"));
    }
  }
View Full Code Here

    protected XMPPConnection connect(String resource) throws XMPPException {
      XMPPConnection c = new XMPPConnection(connConfig);
     
        c.connect();
        c.login(username, passwd, resource);       
        Presence presence = new Presence(Presence.Type.available);
        c.sendPacket(presence);
       
        return c;
    }
View Full Code Here

                LOG.info("Logging in anonymously to XMPP on connection: " + connection);
                connection.loginAnonymously();
            }

            // now lets send a presence
            connection.sendPacket(new Presence(Presence.Type.AVAILABLE));
        }
        return connection;
    }
View Full Code Here

                connection.loginAnonymously();
            }

            // now lets send a presence

            connection.sendPacket(new Presence(Presence.Type.AVAILABLE));
        }
    }
View Full Code Here

                }
            });

            Chat chat = null;
            if (to != null) {
                Presence presence = new Presence(Presence.Type.subscribe);
                presence.setFrom(connection.getUser());
                String toEntity = to + "@vysper.org";
                presence.setTo(toEntity);
                connection.sendPacket(presence);

                chat = connection.getChatManager().createChat(toEntity, new MessageListener() {
                    public void processMessage(Chat inchat, Message message) {
                        System.out.println("log received message: " + message.getBody());
                    }
                });
            }

            connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));

            Thread.sleep(1000);

            // query server version
            sendIQGetWithTimestamp(connection, new Version());

            // query server time
            sendIQGetWithTimestamp(connection, new Time());

            /*            while (to != null) {
            //                chat.sendMessage("Hello " + to + " at " + new Date());
                            try { Thread.sleep((new Random().nextInt(15)+1)*1000 ); } catch (InterruptedException e) { ; }
                        }*/

            for (int i = 0; i < 10; i++) {
                connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));
                try {
                    Thread.sleep((new Random().nextInt(15) + 10) * 1000);
                } catch (InterruptedException e) {
                    ;
                }
                connection.sendPacket(new Presence(Presence.Type.available, "nickes", 1, Presence.Mode.away));
                try {
                    Thread.sleep((new Random().nextInt(15) + 10) * 1000);
                } catch (InterruptedException e) {
                    ;
                }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.packet.Presence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.