Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.Presence


        }

        try{
            connection.login(user, password);
            System.out.println("Logged in as " + connection.getUser());
            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);

        } catch (XMPPException ex){
            Logger.getLogger(JabberWorkItemHandler.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Failed to log in as " + connection.getUser());
View Full Code Here


    /**
     * Processes incoming presence packets (from group chats)
     */
    public void processPacket(Packet packet) {
        final Presence presence = (Presence) packet;
        final String from = packet.getFrom();

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                boolean redraw = false;
                //right now we find out if we have already received a packet
                // from them,
                //and if not, we set up an information "account" in the system
                MUCBuddyStatus buddy = window.getBuddyStatus(from);

                window.removeBuddy(buddy.getUser());

                // get the role and affiliation information
                MUCUser user = (MUCUser) presence.getExtension("x",
                        "http://jabber.org/protocol/muc#user");
                if (user != null) {
                    buddy.setMUCUser(user);
                    MUCUser.Item item = user.getItem();
                    if (item != null) {
                        if (item.getAffiliation() != null)
                            buddy.setAffiliation(item.getAffiliation());
                        if (item.getRole() != null)
                            buddy.setRole(item.getRole());

                        if(item.getAffiliation()!=null && item.getRole()!=null)
                        {
                            if(item.getAffiliation().equals("none") && item.getRole().equals("none"))
                            {
                                presence.setType(Presence.Type.UNAVAILABLE);
                            }
                        }
                    }
                }

                // update the relavent presence information
                if (presence.getType() == Presence.Type.UNAVAILABLE ) {
                    ConversationPanel conv = buddy.getConversation();
                    if ((conv != null) && (conv instanceof ChatPanel))
                        ((ChatPanel) conv).signedOff();

                } else {
                    buddy.addResource("_no resource_", 5, presence.getMode(),
                            presence.getStatus());
                }

                //if we need to, reload the nicklist.
                if (presence.getType() == Presence.Type.AVAILABLE) {
                    window.addBuddy(buddy.getUser());
                    String name = buddy.getName();
                    if (name == null)
                        return;
                    if (nickChange == null && !buddy.getIsInRoom()) {

                        String message = buddy.getName();
                        if( buddy.getJid() != null )
                        {
                            message += " (" + buddy.getJid() + ") ";
                        }

                        message += " has entered the room";

                        window.serverNoticeMessage(message);
                        PluginChain.fireEvent(new MUCEvent(buddy.getUser(),
                                MUCEvent.EVENT_PARTICIPANT_JOINED, "",
                                new Date()));
                    } else if (nickChange != null) {
                        nickChange.setIsInRoom(false);
                        window.serverNoticeMessage(nickChange.getName()
                                + " is now known as " + buddy.getName());
                        window.removeBuddy(nickChange.getUser());
                    }

                    buddy.setIsInRoom(true);

                    nickChange = null;
                } else if (presence.getType() == Presence.Type.UNAVAILABLE) {
                    buddy.setIsInRoom(false);
                    window.getBuddyStatuses().remove(buddy);
                    String leaveMessage = buddy.getName()
                            + " has left the room";
                    PluginChain.fireEvent(new MUCEvent(buddy.getUser(),
                            MUCEvent.EVENT_PARTICIPANT_PARTED, "", new Date()));

                    if (presence.getStatus() != null
                            && !presence.getStatus().equals("")) {
                        leaveMessage += ": " + presence.getStatus();
                    }

                    if (nickChange == null)
                        window.serverNoticeMessage(leaveMessage);
                    else
View Full Code Here

    }

    class TransportListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == signOnItem) {
                Presence p = new Presence(Presence.Type.AVAILABLE);
                p.setTo(buddy.getUser());
                BuddyList.getInstance().getConnection().sendPacket(p);
            } else if (e.getSource() == signOffItem) {
                Presence p = new Presence(Presence.Type.UNAVAILABLE);
                p.setTo(buddy.getUser());
                BuddyList.getInstance().getConnection().sendPacket(p);
            }
        }
View Full Code Here

                ChatRoomPanel window = (ChatRoomPanel) panel;
                MultiUserChat chat = window.getChat();
                if( chat == null || !chat.isJoined() ) continue;

                //set up a packet to be sent to my user in every groupchat
                Presence presence = new Presence(Presence.Type.AVAILABLE,
                        status, 0, mode);
                presence.setTo(window.getRoomName() + '/'
                        + window.getNickname());

                if (!BuddyList.getInstance().checkConnection()) {
                    BuddyList.getInstance().connectionError();
                    return;
View Full Code Here

          indicateNewMessage.setTooltip(getTranslator().translate("groupchat.new.msg"), true);
        }
          appendToMsgHistory(msg);
      }
    } else if (imEvent.getCommand().equals("participant")) {
      Presence presence = (Presence) imEvent.getPacket();
      if (isLogDebugEnabled()) logDebug("incoming presence change for groupchat: "+presence.getFrom() +" : "+ presence.getType(), null);
     
      if (presence.getFrom() != null) {
        if (presence.getFrom().startsWith("coursemodule-") && presence.getType() == Presence.Type.unavailable && !presence.getFrom().endsWith(NICKNAME_ANONYMOUS)) {
          //workaround for smack bug, that does not instantly update the occupants count when someone leaves the room
          if (occupantsCount != 1) occupantsCount--;
        } else {
        occupantsCount = Integer.valueOf(muc.getOccupantsCount());
          if (occupantsCount.equals(Integer.valueOf(0))) occupantsCount = Integer.valueOf(1);
View Full Code Here

   */
  void addParticipationsListener() {
    participationsListener = new PacketListener() {

      public void processPacket(Packet packet) {
        Presence presence = (Presence) packet;
        if (log.isDebug()) log.debug("processPacket Presence: to=" + presence.getTo() + " , " );
        if (presence.getFrom() != null) {
          listeningController.event(new InstantMessagingEvent(presence, "participant"));
        }
      }
    };
    muc.addParticipantListener(participationsListener);
View Full Code Here

   * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
   */
  public void event(Event event) {
    InstantMessagingEvent imEvent = (InstantMessagingEvent)event;
    if (imEvent.getCommand().equals("presence")) {
      Presence presence = (Presence) imEvent.getPacket();
      if (isLogDebugEnabled()) logDebug("incoming presence for user: "+presence.getFrom() +" type: "+presence, null);

      getWindowControl().getWindowBackOffice().invokeLater(new Runnable(){
        public void run() {
          //smack does not immediately update it's presence information, so when testing only with one person the OnlineOffline count value can be wrong
          //in a productive environment there are normally lot's of presence packages
View Full Code Here

    if (status != null) status = status.replaceAll("&", "&");
    if (connection == null || !connection.isConnected()) return;
    if (collaborationDisabled) return;

    setStatus(mode);
    Presence presence = new Presence(type);
    if (status == null) {
      if (mode == Presence.Mode.available) {
        status = InstantMessagingConstants.PRESENCE_MODE_AVAILABLE;
      } else if (mode == Presence.Mode.away) {
        status = InstantMessagingConstants.PRESENCE_MODE_AWAY;
      } else if (mode == Presence.Mode.chat) {
        status = InstantMessagingConstants.PRESENCE_MODE_CHAT;
      } else if (mode == Presence.Mode.dnd) {
        status = InstantMessagingConstants.PRESENCE_MODE_DND;
      } else if (mode == Presence.Mode.xa) {
        status = InstantMessagingConstants.PRESENCE_MODE_XAWAY;
      }
      presence.setStatus(status);
    } else {
      presence.setStatus(status);
    }
    setStatusMsg(presence.getStatus());
    //setting prio when type == unavailable causes error on IM server
    if (presence.getType() == Presence.Type.available) presence.setPriority(priority);
    if (mode != null) presence.setMode(mode);
    try {
      connection.sendPacket(presence);
    } catch (RuntimeException ex) {
      Tracing.logWarn("Error while trying to send Instant Messaging packet for user: " + username + " .Errormessage: ", ex,
          InstantMessagingClient.class);
View Full Code Here

  public void addSubscriptionListener() {
    PacketFilter filter = new PacketTypeFilter(Presence.class);
    connection.createPacketCollector(filter);
    PacketListener myListener = new PacketListener() {
      public void processPacket(Packet packet) {
        Presence presence = (Presence) packet;
        if (presence.getType() == Presence.Type.subscribe) {
          Presence response = new Presence(Presence.Type.subscribe);
          response.setTo(presence.getFrom());
          // System.out.println("subscribed to: "+presence.getFrom());
          connection.sendPacket(response);
          // ask also for subscription
          if (!subscribedUsers.contains(presence.getFrom())) {
            response = null;
            response = new Presence(Presence.Type.subscribe);
            response.setTo(presence.getFrom());
            connection.sendPacket(response);
            // update the roster with the new user
            RosterPacket rosterPacket = new RosterPacket();
            rosterPacket.setType(IQ.Type.SET);
            RosterPacket.Item item = new RosterPacket.Item(presence.getFrom(), parseName(presence.getFrom()));
View Full Code Here

   * Ask an other online user to subscribe to their roster
   *
   * @param uname
   */
  protected void subscribeToUser(String uname) {
    Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(uname + "@" + jabberServer);
    try {
      connection.sendPacket(presence);
    } catch (RuntimeException e) {
      Tracing.logWarn("Error while trying to send Instant Messaging packet.", e, InstantMessagingClient.class);
    }
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.