Package org.apache.vysper.xmpp.modules.extension.xep0045_muc.model

Examples of org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Room


       
        assertNotNull(error);
    }

    public void testEnterNonExistingRoom() throws Exception {
        Room room = conference.findRoom(ROOM2_JID);
        assertNull(room);

        enterRoom(OCCUPANT1_JID, ROOM2_JID_WITH_NICK);

        room = conference.findRoom(ROOM2_JID);
        assertNotNull(room);
        assertEquals(1, room.getOccupants().size());
        Occupant occupant = room.getOccupants().iterator().next();
       
        assertEquals(OCCUPANT1_JID, occupant.getJid());
        assertEquals("nick", occupant.getName());
    }
View Full Code Here


        assertPresenceErrorStanza(response, ROOM1_JID, OCCUPANT1_JID, "modify", "jid-malformed");
    }
   
    public void testEnterWithPassword() throws Exception {
        Room room = conference.createRoom(ROOM2_JID, "Room 1", RoomType.PasswordProtected);
        room.setPassword("secret");

        // no error should be returned
        assertNull(enterRoom(OCCUPANT1_JID, ROOM2_JID_WITH_NICK, "secret", null, false));
        assertEquals(1, room.getOccupants().size());
    }
View Full Code Here

        assertNull(enterRoom(OCCUPANT1_JID, ROOM2_JID_WITH_NICK, "secret", null, false));
        assertEquals(1, room.getOccupants().size());
    }
   
    public void testEnterWithoutPassword() throws Exception {
        Room room = conference.createRoom(ROOM2_JID, "Room 1", RoomType.PasswordProtected);
        room.setPassword("secret");

        // try entering without a password
        Stanza response = enterRoom(OCCUPANT1_JID, ROOM2_JID_WITH_NICK);
       
        assertPresenceErrorStanza(response, ROOM2_JID, OCCUPANT1_JID, "auth", "not-authorized");
View Full Code Here

   
    public void testEnterRoomWithRelays() throws Exception {


        // add one occupant to the room
        Room room = conference.findOrCreateRoom(ROOM1_JID, "Room 1");
        room.addOccupant(OCCUPANT2_JID, "Some nick");
       
        // now, let user 1 enter room
        enterRoom(OCCUPANT1_JID, ROOM1_JID_WITH_NICK);

        // verify stanzas to existing occupants on the new user
View Full Code Here

       
    }

    public void testDiscussionHistory() throws Exception {
        // add some messages
        Room room = conference.findOrCreateRoom(ROOM1_JID, "Room 1");
        room.getHistory().append(StanzaBuilder.createMessageStanza(OCCUPANT2_JID, ROOM1_JID, MessageStanzaType.GROUPCHAT, null, "Body").build(),
                new Occupant(OCCUPANT2_JID, "nick2", Affiliation.None, Role.Participant));
        room.getHistory().append(StanzaBuilder.createMessageStanza(OCCUPANT2_JID, ROOM1_JID, MessageStanzaType.GROUPCHAT, null, "Body2").build(),
                new Occupant(OCCUPANT2_JID, "nick2", Affiliation.None, Role.Participant));
        room.getHistory().append(StanzaBuilder.createMessageStanza(OCCUPANT2_JID, ROOM1_JID, MessageStanzaType.GROUPCHAT, null, "Body3").build(),
                new Occupant(OCCUPANT2_JID, "nick2", Affiliation.None, Role.Participant));
       
        // now, let user 1 enter room
        enterRoom(OCCUPANT1_JID, ROOM1_JID_WITH_NICK, null, new History(2, null, null, null), false);
View Full Code Here

    protected abstract String getNamespace();
   
    public void testDisco() throws Exception {
        // add occupants to the room
        Room room = conference.findOrCreateRoom(ROOM1_JID, "Room 1");
        room.addOccupant(OCCUPANT1_JID, "nick");
        room.addOccupant(OCCUPANT2_JID, "Nick 2");

        StanzaBuilder request = StanzaBuilder.createIQStanza(OCCUPANT1_JID, new EntityImpl(ROOM1_JID, "Nick 2"), IQStanzaType.GET, "123");
        request.startInnerElement("query", getNamespace()).endInnerElement();

        // send message to room
View Full Code Here

   
    private Stanza available(PresenceStanza stanza, Entity roomJid,
            Entity newOccupantJid, String nick, ServerRuntimeContext serverRuntimeContext) {
       
        // TODO what to use for the room name?
        Room room = conference.findOrCreateRoom(roomJid, roomJid.getNode());
       
       
        if(room.isInRoom(newOccupantJid)) {
            // user is already in room, change nick
            logger.debug("{} has requested to change nick in room {}", newOccupantJid, roomJid);

            // occupant is already in room
            Occupant occupant = room.findOccupantByJID(newOccupantJid);
            if(nick.equals(occupant.getName())) {
                // nick unchanged, change show and status
                for(Occupant receiver : room.getOccupants()) {
                    sendChangeShowStatus(occupant, receiver, room, getInnerElementText(stanza, "show"),
                            getInnerElementText(stanza, "status"), serverRuntimeContext);
                }
            } else {
                if(room.isInRoom(nick)) {
                    // user with this nick is already in room
                    return createPresenceErrorStanza(roomJid, newOccupantJid, stanza.getID(), "cancel", "conflict");
                }
               
                String oldNick = occupant.getName();
                // update the nick
                occupant.setName(nick);
               
                // send out unavailable presences to all existing occupants
                for(Occupant receiver : room.getOccupants()) {
                    sendChangeNickUnavailable(occupant, oldNick, receiver, room, serverRuntimeContext);
                }
               
                // send out available presences to all existing occupants
                for(Occupant receiver : room.getOccupants()) {
                    sendChangeNickAvailable(occupant, receiver, room, serverRuntimeContext);
                }

            }
        } else {
            logger.debug("{} has requested to enter room {}", newOccupantJid, roomJid);
           
            if(room.isInRoom(nick)) {
                // user with this nick is already in room
                return createPresenceErrorStanza(roomJid, newOccupantJid, stanza.getID(), "cancel", "conflict");
            }
           
            // check password if password protected
            if(room.isRoomType(RoomType.PasswordProtected)) {
                X x = X.fromStanza(stanza);
                String password = null;
                if(x != null) {
                    password = x.getPasswordValue();
                }
               
                if(password == null || !password.equals(room.getPassword())) {
                    // password missing or not matching
                    return createPresenceErrorStanza(roomJid, newOccupantJid, stanza.getID(), "auth", "not-authorized");
                }
            }
           
            Occupant newOccupant = room.addOccupant(newOccupantJid, nick);
            if(newOccupant == null) {
                // outcast
                return createPresenceErrorStanza(roomJid, newOccupantJid, stanza.getID(), "auth", "forbidden");
            }
            if(room.isRoomType(RoomType.MembersOnly) && newOccupant.getAffiliation() == Affiliation.None) {
                // non-member can not enter members only room
                return createPresenceErrorStanza(roomJid, newOccupantJid, stanza.getID(), "auth", "registration-required");
            }
           
            // relay presence of all existing room occupants to the now joined occupant
            for(Occupant occupant : room.getOccupants()) {
                sendExistingOccupantToNewOccupant(newOccupant, occupant, room, serverRuntimeContext);
            }
           
            // relay presence of the newly added occupant to all existing occupants
            for(Occupant occupant : room.getOccupants()) {
                sendNewOccupantPresenceToExisting(newOccupant, occupant, room, serverRuntimeContext);
            }
           
            // send discussion history to user
            boolean includeJid = room.isRoomType(RoomType.NonAnonymous);
            List<Stanza> history = room.getHistory().createStanzas(newOccupant, includeJid, History.fromStanza(stanza));
            relayStanzas(newOccupantJid, history, serverRuntimeContext);
           
            logger.debug("{} successfully entered room {}", newOccupantJid, roomJid);
        }
        return null;
View Full Code Here

        return null;
    }  
   
    private Stanza unavailable(PresenceStanza stanza, Entity roomJid,
            Entity occupantJid, String nick, ServerRuntimeContext serverRuntimeContext) {
        Room room = conference.findRoom(roomJid);
       
        // room must exist, or we do nothing
        if(room != null) {
            Occupant exitingOccupant = room.findOccupantByJID(occupantJid);
           
            // user must by in room, or we do nothing
            if(exitingOccupant != null) {
                Set<Occupant> allOccupants = room.getOccupants();
               
                room.removeOccupant(occupantJid);

                // TODO replace with use of X
                String statusMessage = null;
                try {
                    XMLElement statusElement = stanza.getSingleInnerElementsNamed("status");
                    if(statusElement != null && statusElement.getInnerText() != null) {
                        statusMessage = statusElement.getInnerText().getText();
                    }
                } catch (XMLSemanticError e) {
                    // ignore, status element did not exist
                }
               
                // relay presence of the newly added occupant to all existing occupants
                for(Occupant occupant : allOccupants) {
                    sendExitRoomPresenceToExisting(exitingOccupant, occupant, room, statusMessage, serverRuntimeContext);
                }
               
                if(room.isRoomType(RoomType.Temporary) && room.isEmpty()) {
                    conference.deleteRoom(roomJid);                   
                }
            }
        }
       
View Full Code Here

            if (request.getTo().getNode() == null) {
                List<InfoElement> serverInfos = conference.getServerInfosFor(request);
                return serverInfos;
            } else {
                // might be an items request on a room
                Room room = conference.findRoom(request.getTo().getBareJID());
                if (room != null) {
                    if (request.getTo().getResource() != null) {
                        // request for an occupant
                        Occupant occupant = room.findOccupantByNick(request.getTo().getResource());
                        // request for occupant, relay
                        if (occupant != null) {
                            relayDiscoStanza(occupant.getJid(), request, NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO);
                        }
                    } else {
                        return room.getInfosFor(request);
                    }
                }

            }
        }
View Full Code Here

                return componentItem;
            }
            return null;
        } else if (fullDomain.getDomain().equals(to.getDomain())) {
            // might be an items request on a room
            Room room = conference.findRoom(to.getBareJID());
            if (room != null) {
                if (to.getResource() != null) {
                    // request for an occupant
                    Occupant occupant = room.findOccupantByNick(to.getResource());
                    // request for occupant, relay
                    if (occupant != null) {
                        relayDiscoStanza(occupant.getJid(), request, NamespaceURIs.XEP0030_SERVICE_DISCOVERY_ITEMS);
                    }
                } else {
                    return room.getItemsFor(request);
                }
            }
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Room

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.