Search in sources :

Example 1 with IChatRoomContainer

use of org.eclipse.ecf.presence.chatroom.IChatRoomContainer in project ecf by eclipse.

the class ChatRoomRobotApplication method start.

public Object start(IApplicationContext context) throws Exception {
    // process program arguments
    String[] originalArgs = (String[]) context.getArguments().get("application.args");
    if (originalArgs.length < 4) {
        System.out.println("Parameters:  <senderAccount> <senderPassword> <chatroomname>.  e.g. sender@gmail.com senderpassword mychatroom");
        return new Integer(-1);
    }
    senderAccount = originalArgs[0];
    // Create client
    final XMPPChatRoomClient client = new XMPPChatRoomClient(this);
    // connect to senderAccount using senderPassword
    client.connect(senderAccount, originalArgs[1]);
    // get chat room
    final IChatRoomContainer chatRoomContainer = client.createChatRoom(originalArgs[2]);
    // join/connect to chat room
    chatRoomContainer.connect(client.getChatRoomInfo().getRoomID(), null);
    System.out.println("ECF chat room robot sender=" + senderAccount + "  Connected to room: " + client.getChatRoomInfo().getRoomID().getName());
    // Add message listener to chat room
    chatRoomContainer.addMessageListener(this);
    // Get chat room message sender
    sender = chatRoomContainer.getChatRoomMessageSender();
    sender.sendMessage("Hi, I'm a robot. To get rid of me, send me a direct message.");
    synchronized (lock) {
        while (!done) {
            lock.wait();
        }
    }
    return IApplication.EXIT_OK;
}
Also used : IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) XMPPChatRoomClient(org.eclipse.ecf.example.clients.XMPPChatRoomClient)

Example 2 with IChatRoomContainer

use of org.eclipse.ecf.presence.chatroom.IChatRoomContainer in project ecf by eclipse.

the class Bot method setup.

protected void setup() throws ECFException {
    if (container == null) {
        container = ContainerFactory.getDefault().createContainer(CONTAINER_TYPE);
        namespace = container.getConnectNamespace();
    }
    manager = (IChatRoomManager) container.getAdapter(IChatRoomManager.class);
    ID targetID = IDFactory.getDefault().createID(namespace, "irc://" + bot.getName() + "@" + bot.getServer());
    container.connect(targetID, null);
    IChatRoomInfo room = manager.getChatRoomInfo(bot.getChannel());
    IChatRoomContainer roomContainer = room.createChatRoomContainer();
    roomContainer.connect(room.getRoomID(), null);
    roomContainer.addMessageListener(this);
    sender = roomContainer.getChatRoomMessageSender();
}
Also used : IChatRoomInfo(org.eclipse.ecf.presence.chatroom.IChatRoomInfo) IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) ID(org.eclipse.ecf.core.identity.ID)

Example 3 with IChatRoomContainer

use of org.eclipse.ecf.presence.chatroom.IChatRoomContainer in project ecf by eclipse.

the class AbstractChatRoomInvitationTest method testSendInvitation.

public void testSendInvitation() throws Exception {
    final IChatRoomInvitationSender invitationSender = chat0.getInvitationSender();
    assertNotNull(invitationSender);
    final IChatRoomInfo roomInfo = chat0.getChatRoomInfo(CHAT_ROOM_NAME);
    if (roomInfo == null)
        return;
    final IChatRoomContainer chatRoomContainer = roomInfo.createChatRoomContainer();
    chatRoomContainer.connect(roomInfo.getRoomID(), null);
    invitationSender.sendInvitation(roomInfo.getRoomID(), getClient(1).getConnectedID(), null, "this is an invitation");
    try {
        synchronized (synchObject) {
            synchObject.wait(WAITTIME);
        }
    } catch (final Exception e) {
        throw e;
    }
    assertHasEvent(invitationsReceived, ID.class);
}
Also used : IChatRoomInfo(org.eclipse.ecf.presence.chatroom.IChatRoomInfo) IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) IChatRoomInvitationSender(org.eclipse.ecf.presence.chatroom.IChatRoomInvitationSender)

Example 4 with IChatRoomContainer

use of org.eclipse.ecf.presence.chatroom.IChatRoomContainer in project ecf by eclipse.

the class XMPPChatRoomManager method findReceiverChatRoom.

public IChatRoomContainer findReceiverChatRoom(ID toID) {
    if (toID == null)
        return null;
    XMPPRoomID roomID = null;
    if (toID instanceof XMPPRoomID) {
        roomID = (XMPPRoomID) toID;
        final String mucname = roomID.getMucString();
        List toNotify = null;
        synchronized (chatrooms) {
            toNotify = new ArrayList(chatrooms);
        }
        for (final Iterator i = toNotify.iterator(); i.hasNext(); ) {
            final IChatRoomContainer cont = (IChatRoomContainer) i.next();
            if (cont == null)
                continue;
            final ID tid = cont.getConnectedID();
            if (tid != null && tid instanceof XMPPRoomID) {
                final XMPPRoomID targetID = (XMPPRoomID) tid;
                final String tmuc = targetID.getMucString();
                if (tmuc.equals(mucname)) {
                    return cont;
                }
            }
        }
    }
    return null;
}
Also used : IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ArrayList(java.util.ArrayList) List(java.util.List) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ID(org.eclipse.ecf.core.identity.ID)

Example 5 with IChatRoomContainer

use of org.eclipse.ecf.presence.chatroom.IChatRoomContainer in project ecf by eclipse.

the class ChatRoomMessageHandler method preContainerConnect.

public void preContainerConnect(IContainer container, ID targetID) {
    File file = new File(Platform.getInstanceLocation().getURL().getPath(), "password.properties");
    if (file.exists()) {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(file));
            password = properties.getProperty("password");
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
    }
    this.container = container;
    IChatRoomContainer chatRoomContainer = (IChatRoomContainer) container.getAdapter(IChatRoomContainer.class);
    chatMessageSender = chatRoomContainer.getPrivateMessageSender();
    chatRoomContainer.addMessageListener(new IIMMessageListener() {

        public void handleMessageEvent(IIMMessageEvent e) {
            if (e instanceof IChatMessageEvent) {
                IChatMessageEvent event = (IChatMessageEvent) e;
                String msg = event.getChatMessage().getBody();
                switch(msg.charAt(0)) {
                    case '~':
                    case '!':
                        handleMessage(event.getFromID(), event.getFromID(), msg.substring(1).trim());
                        break;
                    default:
                        handleMessage(event.getFromID(), event.getFromID(), msg.trim());
                        break;
                }
            }
        }
    });
}
Also used : IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) FileNotFoundException(java.io.FileNotFoundException) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent)

Aggregations

IChatRoomContainer (org.eclipse.ecf.presence.chatroom.IChatRoomContainer)7 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ID (org.eclipse.ecf.core.identity.ID)2 IChatRoomInfo (org.eclipse.ecf.presence.chatroom.IChatRoomInfo)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 XMPPChatRoomClient (org.eclipse.ecf.example.clients.XMPPChatRoomClient)1 IIMMessageEvent (org.eclipse.ecf.presence.IIMMessageEvent)1 IIMMessageListener (org.eclipse.ecf.presence.IIMMessageListener)1 IChatRoomInvitationSender (org.eclipse.ecf.presence.chatroom.IChatRoomInvitationSender)1 IChatRoomManager (org.eclipse.ecf.presence.chatroom.IChatRoomManager)1 IChatMessageEvent (org.eclipse.ecf.presence.im.IChatMessageEvent)1 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)1 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)1