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;
}
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();
}
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);
}
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;
}
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;
}
}
}
});
}
Aggregations