display.printHeader("Ping to: " + otherUri, Style.info);
new ChatManagerEventsSupervisor(roomManager, display);
new RoomManagerEventsSupervisor(roomManager, display);
final Room room = (Room) roomManager.open(roomUri);
// When the room is ready, we invite other
room.addChatStateChangedHandler(true, new StateChangedHandler() {
@Override
public void onStateChanged(final StateChangedEvent event) {
if (event.is(ChatStates.ready)) {
display.print("Room ready. Sending invitation to " + otherUri, Style.important);
pings++;
room.sendInvitationTo(otherUri, "ping invite " + pings);
}
}
});
room.addOccupantChangedHandler(new OccupantChangedHandler() {
@Override
public void onOccupantChanged(final OccupantChangedEvent event) {
final boolean isOtherOccupant = event.getOccupant().getUserUri().equalsNoResource(otherUri);
if (isOtherOccupant) {
if (event.isRemoved()) {
display.print("Invited removed... waiting to send invitation", Style.important);
new Timer() {
@Override
public void run() {
display.print("Sending invitation", Style.important);
pings++;
time += 1000;
room.sendInvitationTo(otherUri, "ping invite " + pings);
}
}.schedule(time);
} else if (event.isAdded()) {
display.print("Change subject", Style.important);
RoomSubject.requestSubjectChange(room, "Subject ping" + pings);