private void removeParticipant(String name) { checkClosed(); participants.remove(name); log.debug("ROOM {}: notifying all users that {} is leaving the room", this.name, name); final JsonObject participantLeftJson = new JsonObject(); participantLeftJson.addProperty("id", "participantLeft"); participantLeftJson.addProperty("name", name); for (final RoomParticipant participant : participants.values()) { participant.cancelSendingVideoTo(name); participant.sendMessage(participantLeftJson); } }
public RoomParticipant join(String userName, WebSocketSession session) { checkClosed(); if (pipeline == null) { log.info("ROOM {}: Creating MediaPipeline", userName); pipeline = kurento.createMediaPipeline(); } log.info("ROOM {}: adding participant {}", userName, userName); final RoomParticipant participant = new RoomParticipant(userName, this, session, this.pipeline); sendParticipantNames(participant); final JsonObject newParticipantMsg = new JsonObject(); newParticipantMsg.addProperty("id", "newParticipantArrived"); newParticipantMsg.addProperty("name", participant.getName()); log.debug( "ROOM {}: notifying other participants {} of new participant {}", name, participants.values(), participant.getName()); for (final RoomParticipant participant1 : participants.values()) { participant1.sendMessage(newParticipantMsg); } participants.put(participant.getName(), participant); log.debug( "ROOM {}: Notified other participants {} of new participant {}", name, participants.values(), participant.getName()); return participant; }
public void sendParticipantNames(RoomParticipant user) { checkClosed(); log.debug("PARTICIPANT {}: sending a list of participants", user.getName()); final JsonArray participantsArray = new JsonArray(); for (final RoomParticipant participant : this.getParticipants()) { log.debug("PARTICIPANT {}: visiting participant", user.getName(), participant.getName()); if (!participant.equals(user)) { final JsonElement participantName = new JsonPrimitive(participant.getName()); participantsArray.add(participantName); } } final JsonObject existingParticipantsMsg = new JsonObject(); existingParticipantsMsg.addProperty("id", "existingParticipants"); existingParticipantsMsg.add("data", participantsArray); log.debug( "PARTICIPANT {}: sending a list of {} participants", user.getName(), participantsArray.size()); user.sendMessage(existingParticipantsMsg); }