2013-01-23 42 views
3

我是新來這個的Openfire和asmack,我希望用戶擁有多用戶聊天,所以我四處搜尋,我發現MUC我已經實現了這個創建房間,併發送邀請給其他用戶的功​​能這些作品中,其他用戶收到邀請,但其他用戶無法加入房間。MultipleChatUser XMPP asmack加入

我在其他用戶邀請接收

這裏連接這樣做,這是該用戶的連接和房間的是,我們在得到邀請的會議室名稱。

MultiUserChat MUC3 =新MultiUserChat(連接,室);

muc3.join( 「testbot3」);

testbot3只是一些隨機的名字。

但是這會拋出404錯誤。

我是否需要在發送邀請之前加入用戶,即如果用戶在邀請發送之前向B發送邀請A需要將這些用戶默認加入房間,然後依靠B拒絕或僅保留相當。

我在做什麼是B從B的InvitationListList中收到來自A的邀請我試圖加入上面的代碼。

我一直在試圖爲長現在我不知道是怎麼回事錯的,有些人能給出如何做到這一點,將是對我很大的幫助示例代碼。

感謝

這裏是我的問題

,因爲我去和檢查Openfire的,我可以看到由用戶創建的房間,他已經加入了自己作爲一個老闆,所以我不認爲這樣的詳細信息這將是一個房間創建的問題。

可能是這個問題,房間被鎖定,因爲我已經通過房間看完房間沒有完全創建時被鎖定,我想這是一個問題,當我們創建房間時,我沒有填寫表格中的密碼,這可能是一個問題嗎?

請參見下面的代碼下面的處理程序中我打電話的方法「checkInvitation」這確實與上面相同的代碼貼我仍然得到404能否請你告訴我,我錯在我的代碼。

請在需要添加暱稱可以是任何東西,或者需要一些用戶特定的?

公共無效createChatroom(){

MultiUserChat muc = null; 

    try { 
     muc = new MultiUserChat(connection, "[email protected]"); 
     muc.create("testbot"); 

     // Get the the room's configuration form 
     Form form = muc.getConfigurationForm(); 
     // Create a new form to submit based on the original form 
     Form submitForm = form.createAnswerForm(); 
     // Add default answers to the form to submit 
     for (Iterator fields = form.getFields(); fields.hasNext();) { 
      FormField field = (FormField) fields.next(); 
      if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) { 
       // Sets the default value as the answer 
       submitForm.setDefaultAnswer(field.getVariable()); 
      } 
     } 
     // Sets the new owner of the room 
     List owners = new ArrayList(); 
     owners.add("[email protected]"); 
     submitForm.setAnswer("muc#roomconfig_roomowners", owners); 
     // Send the completed form (with default values) to the server to configure the room 
     muc.sendConfigurationForm(submitForm); 
     muc.join("d"); 

     muc.invite("[email protected]", "Meet me in this excellent room"); 

     muc.addInvitationRejectionListener(new InvitationRejectionListener() { 
      public void invitationDeclined(String invitee, String reason) { 
       // Do whatever you need here... 
       System.out.println("Initee "+invitee+" reason"+reason); 
      } 
     }); 

    } catch (XMPPException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

    public void setConnection(XMPPConnection connection) { 
    this.connection = connection; 
    if (connection != null) { 
     // Add a packet listener to get messages sent to us 
     PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 
     connection.addPacketListener(new PacketListener() { 
      public void processPacket(Packet packet) { 
       Message message = (Message) packet; 
       if (message.getBody() != null) { 
        String fromName = StringUtils.parseBareAddress(message 
          .getFrom()); 
        Log.i("XMPPClient", "Got text [" + message.getBody() 
          + "] from [" + fromName + "]"); 
        messages.add(fromName + ":"); 
        messages.add(message.getBody()); 
        // Add the incoming message to the list view 
        mHandler.post(new Runnable() { 
         public void run() { 
          setListAdapter(); 
          checkInvitation(); 
         } 
        }); 
       } 
      } 
     }, filter); 


     mHandler.post(new Runnable() { 
      public void run() { 
       checkInvitation(); 
      } 
     }); 
    } 
} 
+0

嗨@Doniv我能夠將消息發送到在一個房間裏和processPacket方法的用戶稱爲每次當我發送郵件,但我沒有recieving在processPacket方法的任何消息沒有任何問題,或者我們需要設置任何其他聽衆? –

回答

9

404錯誤表明:

404 error can occur if the room does not exist or is locked 

所以,確保你的房間沒有被鎖定或存在!下面的代碼是我如何加入聊天室時,有一個在-邀請正在添加:

private void setChatRoomInvitationListener() { 
    MultiUserChat.addInvitationListener(mXmppConnection, 
      new InvitationListener() { 

       @Override 
       public void invitationReceived(Connection connection, 
         String room, String inviter, String reason, 
         String unKnown, Message message) { 

        //MultiUserChat.decline(mXmppConnection, room, inviter, 
         // "Don't bother me right now"); 
        // MultiUserChat.decline(mXmppConnection, room, inviter, 
        // "Don't bother me right now"); 
        try { 
         muc.join("test-nick-name"); 
         Log.e("abc","join room successfully"); 
         muc.sendMessage("I joined this room!! Bravo!!"); 
        } catch (XMPPException e) { 
         e.printStackTrace(); 
         Log.e("abc","join room failed!"); 
        } 
       } 
      }); 
} 

希望這有助於你的錯誤!

編輯:我這是怎麼配置的房間:

/* 
     * Create room 
     */ 
     muc.create(roomName); 

     // muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT)); 
     Form form = muc.getConfigurationForm(); 
     Form submitForm = form.createAnswerForm(); 

     for (Iterator fields = form.getFields(); fields.hasNext();) { 
      FormField field = (FormField) fields.next(); 
      if (!FormField.TYPE_HIDDEN.equals(field.getType()) 
        && field.getVariable() != null) { 
       show("field: " + field.getVariable()); 
       // Sets the default value as the answer 
       submitForm.setDefaultAnswer(field.getVariable()); 
      } 
     } 

     List<String> owners = new ArrayList<String>(); 
     owners.add(DataConfig.USERNAME + "@" + DataConfig.SERVICE); 
     submitForm.setAnswer("muc#roomconfig_roomowners", owners); 
     submitForm.setAnswer("muc#roomconfig_roomname", roomName); 
     submitForm.setAnswer("muc#roomconfig_persistentroom", true); 

     muc.sendConfigurationForm(submitForm); 
     // submitForm. 
     show("created room!"); 
     muc.addMessageListener(new PacketListener() { 
      @Override 
      public void processPacket(Packet packet) { 
       show(packet.toXML()); 
       Message mess = (Message) packet; 
       showMessageToUI(mess.getFrom() + ": " + mess.getBody()); 
      } 
     }); 

有了這個cofiguration,我可以很容易地加入一個房間,沒有密碼。

+0

當我去檢查Openfire時,我可以看到用戶創建的房間,並且他已經將自己添加爲所有者,所以我不這麼認爲,這將是創建問題。 – Doniv

+0

你有沒有嘗試加入不是房間所有者的用戶帳戶的房間? –

+0

嗨@Kingfisher我能夠將消息發送到在一個房間裏和processPacket方法的用戶稱爲每次當我發送郵件,但我沒有recieving在processPacket方法的任何消息沒有任何問題,或者我們需要設置任何其他監聽器??? –

相關問題