/**
   * send an xmpp message to a specified Chat Room.
   *
   * @param xmppChatRoom room to send message to.
   * @param xmppMessage text to be sent in the body of the message
   * @return true if message is sent, false otherwise
   */
  public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) {

    MultiUserChat groupChat;

    if (rooms.containsKey(xmppChatRoom)) {
      groupChat = rooms.get(xmppChatRoom);
    } else {
      LOG.debug("Adding room: {}", xmppChatRoom);
      groupChat = new MultiUserChat(xmpp, xmppChatRoom);
      rooms.put(xmppChatRoom, groupChat);
    }

    if (!groupChat.isJoined()) {
      LOG.debug("Joining room: {}", xmppChatRoom);
      try {
        groupChat.join(xmppUser);
      } catch (XMPPException e) {
        LOG.error("XMPP Exception joining chat room ", e);
        return false;
      }
    }

    try {
      groupChat.sendMessage(xmppMessage);
      LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom);
    } catch (XMPPException e) {
      LOG.error("XMPP Exception sending message to Chat room", e);
      return false;
    }

    return true;
  }
示例#2
0
 /**
  * Writes a formatted message to a room and creates the room if necessary, followed by an invite
  * to the default notification address to join the room
  *
  * @param number
  * @param contact
  * @param message
  * @throws XMPPException
  */
 public void writeRoom(String number, String contact, XmppMsg message, int mode) throws Exception {
   MultiUserChat muc;
   muc = inviteRoom(number, contact, mode);
   if (muc != null) {
     try {
       Message msg = new Message(muc.getRoom());
       msg.setBody(message.generateFmtTxt());
       if (mode == MODE_SHELL) {
         XHTMLManager.addBody(msg, message.generateXHTMLText().toString());
       }
       msg.setType(Message.Type.groupchat);
       muc.sendMessage(msg);
     } catch (Exception e) {
       muc.sendMessage(message.generateTxt());
     }
   }
 }
示例#3
0
 public static void sendMucMessage(String message, int chanid) {
   try {
     if (Application.mucchannels.containsKey(chanid)) {
       MultiUserChat muc = Application.mucchannels.get(chanid);
       muc.sendMessage(message);
     }
   } catch (XMPPException exp) {
     exp.printStackTrace();
   }
 }
 @Override
 public void processPacket(Packet packet) {
   Message message = (Message) packet;
   try {
     muc2.sendMessage(message);
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   // System.out.println("got message " + message.toXML());
 }
示例#5
0
 @Override
 public void sendMucMessage(String message) throws RemoteException {
   if (isConnected() && muc != null) {
     try {
       muc.sendMessage(message);
     } catch (XMPPException e) {
       Log.e("social-lable", "failed to send muc message", e);
       throw new RemoteException(e.getMessage());
     }
   }
 }
 public void sendMessage(String message) {
   try {
     if (chat != null) {
       chat.sendMessage(message);
     }
     if (muc2 != null) {
       muc2.sendMessage(message);
     }
   } catch (XMPPException e) {
     e.printStackTrace();
   }
 }
 @Override
 public void interceptPacket(Packet packet) {
   System.out.println("Sending message: " + packet.toString());
   Message message = muc2.createMessage();
   message.setBody("Hello from producer, message " + " ");
   try {
     muc2.sendMessage(message);
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#8
0
 /** {@inheritDoc} */
 @Override
 public void sendMessage(com.rei.lolchat.service.Message message) throws RemoteException {
   org.jivesoftware.smack.packet.Message send = new org.jivesoftware.smack.packet.Message();
   send.setTo(message.getTo());
   Log.w(TAG, "message to " + message.getTo());
   send.setBody(message.getBody());
   send.setType(org.jivesoftware.smack.packet.Message.Type.groupchat);
   // TODO gerer les messages contenant des XMPPError
   // send.set
   try {
     mAdaptee.sendMessage(send);
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  // 消息发送
  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;
  }
示例#10
0
  public static void createMucChannel(
      String channelname, String channeltopic, int userid, int channelid) {
    try {
      if (!Application.mucchannels.containsKey(channelid)) {
        // create MUC
        MultiUserChat muc =
            new MultiUserChat(Application.conn, channelname + "@conference.webchat");
        System.out.println("Channelname: " + channelname);
        muc.create(channelname);

        Application.mucchannels.put(channelid, muc);

        Form form = muc.getConfigurationForm();
        Form submitForm = form.createAnswerForm();

        for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) {
          FormField field = (FormField) fields.next();
          if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
            submitForm.setDefaultAnswer(field.getVariable());
          }
        }

        List<String> owners = new ArrayList<String>();
        owners.add("webchat@webchat");
        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        muc.sendConfigurationForm(submitForm);
        muc.invite(
            models.User.find.byId(userid).username + "@webchat/Smack",
            "Einladung in Channel " + channelname);
        final int chanid = channelid;
        muc.sendMessage("Willkommen: Topic lautet " + channeltopic + "!");
        muc.addMessageListener(
            new PacketListener() {
              @Override
              public void processPacket(Packet packet) {
                if (packet instanceof Message) {
                  String[] temp;
                  temp = ((Message) packet).getFrom().split("/");
                  if (!temp[1].equals(models.Channel.find.byId(chanid).name)) {
                    System.out.println("Received user: "******"@webchat/Smack",
            "Einladung in Channel " + channelname);
        muc.sendMessage("Willkommen: Topic lautet" + channeltopic + "!");
      }
    } catch (XMPPException exp) {
      exp.printStackTrace();
    }
  }