Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.Chat


                    + XmppEndpoint.getConnectionMessage(connection), exchange, e);
        }

        ChatManager chatManager = connection.getChatManager();
        LOG.debug("Looking for existing chat instance with thread ID " + endpoint.getChatId());
        Chat chat = chatManager.getThreadChat(endpoint.getChatId());
        if (chat == null) {
            LOG.debug("Creating new chat instance with thread ID " + endpoint.getChatId());
            chat = chatManager.createChat(getParticipant(), endpoint.getChatId(), new MessageListener() {
                public void processMessage(Chat chat, Message message) {
                    // not here to do conversation
                    LOG.debug("Received and discarding message from " + getParticipant() + " : " + message.getBody());
                }
            });
        }

        Message message = null;
        try {
            message = new Message();
            message.setTo(getParticipant());
            message.setThread(endpoint.getChatId());
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message.getBody());
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Cannot send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
        } catch (Exception e) {
            throw new RuntimeExchangeException("Cannot send XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
View Full Code Here


        if (endpoint.getRoom() == null) {

            // if an existing chat session has been opened (for example by a producer) let's
            // just add a listener to that chat
            Chat privateChat = connection.getChatManager().getThreadChat(endpoint.getParticipant());

            if (privateChat != null) {
                LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
                privateChat.addMessageListener(this);
            } else {               
                privateChat = connection.getChatManager().createChat(endpoint.getParticipant(), endpoint.getParticipant(), this);
                LOG.debug("Opening private chat to " + privateChat.getParticipant());
            }

        } else {
            // add the presence packet listener to the connection so we only get packets that concers us
            // we must add the listener before creating the muc
View Full Code Here

            throw new RuntimeExchangeException("Cannot connect to: "
                    + XmppEndpoint.getConnectionMessage(connection), exchange, e);
        }

        ChatManager chatManager = connection.getChatManager();
        Chat chat = chatManager.getThreadChat(getParticipant());
        if (chat == null) {
            chat = chatManager.createChat(getParticipant(), getParticipant(), new MessageListener() {
                public void processMessage(Chat chat, Message message) {
                    // not here to do conversation
                }
            });
        }

        Message message = null;
        try {
            message = new Message();
            message.setTo(getParticipant());
            message.setThread(getParticipant());
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message: " + message.getBody());
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Cannot send XMPP message: " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
        } catch (Exception e) {
            throw new RuntimeExchangeException("Cannot send XMPP message: " + message
View Full Code Here

            throw new RuntimeExchangeException("Cannot connect to: "
                    + XmppEndpoint.getConnectionMessage(connection), exchange, e);
        }

        ChatManager chatManager = connection.getChatManager();
        Chat chat = getOrCreateChat(chatManager);
        Message message = null;
        try {
            message = new Message();
            message.setTo(getParticipant());
            message.setThread(endpoint.getChatId());
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message to {} from {} : {}", new Object[]{endpoint.getParticipant(), endpoint.getUser(), message.getBody()});
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Cannot send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
        } catch (Exception e) {
            throw new RuntimeExchangeException("Cannot send XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
View Full Code Here

    private synchronized Chat getOrCreateChat(ChatManager chatManager) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Looking for existing chat instance with thread ID {}", endpoint.getChatId());
        }
        Chat chat = chatManager.getThreadChat(endpoint.getChatId());
        if (chat == null) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Creating new chat instance with thread ID {}", endpoint.getChatId());
            }
            chat = chatManager.createChat(getParticipant(), endpoint.getChatId(), new MessageListener() {
View Full Code Here

        }

        ChatManager chatManager = connection.getChatManager();

        LOG.trace("Looking for existing chat instance with thread ID {}", endpoint.getChatId());
        Chat chat = chatManager.getThreadChat(endpoint.getChatId());
        if (chat == null) {
            LOG.trace("Creating new chat instance with thread ID {}", endpoint.getChatId());
            chat = chatManager.createChat(getParticipant(), endpoint.getChatId(), new MessageListener() {
                public void processMessage(Chat chat, Message message) {
                    // not here to do conversation
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Received and discarding message from {} : {}", getParticipant(), message.getBody());
                    }
                }
            });
        }

        Message message = null;
        try {
            message = new Message();
            message.setTo(getParticipant());
            message.setThread(endpoint.getChatId());
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message to {} from {} : {}", new Object[]{endpoint.getParticipant(), endpoint.getUser(), message.getBody()});
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Cannot send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
        } catch (Exception e) {
            throw new RuntimeExchangeException("Cannot send XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
View Full Code Here

        } else {
            thread = "Chat:" + participant + ":" + endpoint.getUser();
        }

        ChatManager chatManager = connection.getChatManager();
        Chat chat = getOrCreateChat(chatManager, participant, thread);
        Message message = null;
        try {
            message = new Message();

            message.setTo(participant);
            message.setThread(thread);
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Sending XMPP message to {} from {} : {}", new Object[]{participant, endpoint.getUser(), message.getBody()});
            }
            chat.sendMessage(message);
        } catch (XMPPException xmppe) {
            throw new RuntimeExchangeException("Could not send XMPP message: to " + participant + " from " + endpoint.getUser() + " : " + message
                    + " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
        } catch (Exception e) {
            throw new RuntimeExchangeException("Could not send XMPP message to " + participant + " from " + endpoint.getUser() + " : " + message
View Full Code Here

    private synchronized Chat getOrCreateChat(ChatManager chatManager, final String participant, String thread) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Looking for existing chat instance with thread ID {}", endpoint.getChatId());
        }
        Chat chat = chatManager.getThreadChat(thread);
        if (chat == null) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Creating new chat instance with thread ID {}", thread);
            }
            chat = chatManager.createChat(participant, thread, new MessageListener() {
View Full Code Here

    }

  public Sequence eval( Sequence[] args, Sequence contextSequence ) throws XPathException
  {
    long chatHandle = ((IntegerValue) args[0].itemAt(0)).getLong();
    Chat chat = XMPPModule.retrieveChat(chatHandle);

    String message = args[1].itemAt(0).getStringValue();
   
    try {
      chat.sendMessage(message);
      return BooleanValue.TRUE;
    } catch (XMPPException e) {
      return BooleanValue.FALSE;
    }
   
View Full Code Here

       
        long chatHandle = XMPPModule.getHandle();
   
        Listener listener = new Listener(chatHandle, contextSequence, chatListenerFunctionRef, listenerParam);
       
    Chat chat = connection.getChatManager().createChat(jid, listener);
   
    // store the chat and return the handle of the chat
     
    IntegerValue integerValue = new IntegerValue( XMPPModule.storeChat( chat, chatHandle ) );
    return integerValue;
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.Chat

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.