コード例 #1
0
 private void updateStatus() {
   final CustomPresence newPresence = new CustomPresence(type, status.toString(), 1, mode);
   newPresence.setInvisible(invisible);
   try {
     connection.sendPacket(newPresence);
   } catch (final NotConnectedException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
 /** Disconnects from chatserver and releases all resources. */
 public void disconnect() {
   connection.getRoster().removeRosterListener(leagueRosterListener);
   try {
     connection.disconnect();
   } catch (final NotConnectedException e) {
     e.printStackTrace();
   }
   stop = true;
 }
コード例 #3
0
ファイル: XMPPUtil.java プロジェクト: ChenQingZhen/XMPPChat
  /**
   * ע��
   *
   * @param account ע���ʺ�
   * @param password ע������
   * @return 1��ע��ɹ� 0��������û�з��ؽ��2������˺��Ѿ�����3��ע��ʧ��
   */
  public String regist(String account, String password) {
    if (getConnection() == null) return "0";
    AccountManager am = AccountManager.getInstance(getConnection());
    am.sensitiveOperationOverInsecureConnection(true);
    try {
      am.createAccount(account, password);
      return "1";
    } catch (NoResponseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (XMPPErrorException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NotConnectedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return "3";

    //        Registration reg = new Registration();
    //        reg.setType(IQ.Type.set);
    //        reg.setTo(getConnection().getServiceName());
    //        // ע������createAccountע��ʱ��������UserName������jid����"@"ǰ��IJ��֡�
    //        reg.setUsername(account);
    //        reg.setPassword(password);
    //        // ���addAttribute����Ϊ�գ�������?����������־��android�ֻ��İɣ���������
    //        reg.addAttribute("android", "geolo_createUser_android");
    //        PacketFilter filter = new AndFilter(new PacketIDFilter(
    //                reg.getPacketID()), new PacketTypeFilter(IQ.class));
    //        PacketCollector collector = getConnection().createPacketCollector(
    //                filter);
    //        getConnection().sendPacket(reg);
    //        IQ result = (IQ) collector.nextResult(SmackConfiguration
    //                .getDefaultPacketReplyTimeout());
    //        // Stop queuing resultsֹͣ����results���Ƿ�ɹ��Ľ��
    //        collector.cancel();
    //        if (result == null) {
    //            Log.e("regist", "No response from server.");
    //            return "0";
    //        } else if (result.getType() == IQ.Type.RESULT) {
    //            Log.v("regist", "regist success.");
    //            return "1";
    //        } else { // if (result.getType() == IQ.Type.ERROR)
    //            if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
    //                Log.e("regist", "IQ.Type.ERROR: "
    //                        + result.getError().toString());
    //                return "2";
    //            } else {
    //                Log.e("regist", "IQ.Type.ERROR: "
    //                        + result.getError().toString());
    //                return "3";
    //            }
    //        }
  }
コード例 #4
0
 /**
  * 邀请人员
  *
  * @param object
  * @return
  */
 public String invite(JSONObject object, String sessionID) {
   // 被邀请人的名称
   String invitedName = object.get("invitedName") + DOMAIN_NAME;
   // 邀请原因
   String reason = (String) object.get("reason");
   // 房间名称
   String mucname = (String) object.get("mucname");
   AbstractXMPPConnection connection = conn_map.get(sessionID);
   MultiUserChat muc2 = MultiUserChatManager.getInstanceFor(connection).getMultiUserChat(mucname);
   try {
     // 邀请 invitedName
     muc2.invite(invitedName, object.toString());
   } catch (NotConnectedException e) {
     e.printStackTrace();
   }
   return "";
 }
コード例 #5
0
  // 消息发送
  public String msg(JSONObject object, String sessionID) {
    String jid = (String) object.get("mucname");
    String msg = (String) object.get("msg");
    MultiUserChatManager mgr = MultiUserChatManager.getInstanceFor(conn_map.get(sessionID));
    try {
      MultiUserChat muc = mgr.getMultiUserChat(jid);
      //			List<Occupant> ls = muc.getParticipants();
      //			Iterator<Occupant> iterator = ls.iterator();
      //			while(iterator.hasNext()){
      //				System.out.println( iterator.next().getJid() +"--------Occupant");
      //			}
      muc.sendMessage(msg);
    } catch (NotConnectedException e) {
      e.printStackTrace();
    }
    ;

    return null;
  }
コード例 #6
0
ファイル: DummyConnection.java プロジェクト: randhika/Smack
  /**
   * Processes a packet through the installed packet collectors and listeners and letting them
   * examine the packet to see if they are a match with the filter.
   *
   * @param packet the packet to process.
   */
  public void processPacket(Packet packet) {
    if (packet == null) {
      return;
    }

    // Loop through all collectors and notify the appropriate ones.
    for (PacketCollector collector : getPacketCollectors()) {
      collector.processPacket(packet);
    }

    if (DEBUG_ENABLED) {
      System.out.println("[RECV]: " + packet.toXML());
    }

    // Deliver the incoming packet to listeners.
    for (ListenerWrapper listenerWrapper : recvListeners.values()) {
      try {
        listenerWrapper.notifyListener(packet);
      } catch (NotConnectedException e) {
        e.printStackTrace();
      }
    }
  }