示例#1
0
  public void leave(RoomParticipant user) {

    checkClosed();

    log.debug("PARTICIPANT {}: Leaving room {}", user.getName(), this.name);
    this.removeParticipant(user.getName());
    user.close();
  }
示例#2
0
  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);
    }
  }
示例#3
0
  @Override
  public void close() {

    if (!closed) {

      executor.shutdown();

      for (final RoomParticipant user : participants.values()) {
        user.close();
      }

      participants.clear();

      if (pipeline != null) {
        pipeline.release(
            new Continuation<Void>() {

              @Override
              public void onSuccess(Void result) throws Exception {
                log.trace("ROOM {}: Released Pipeline", Room.this.name);
              }

              @Override
              public void onError(Throwable cause) throws Exception {
                log.warn("PARTICIPANT " + Room.this.name + ": Could not release Pipeline", cause);
              }
            });
      }

      log.debug("Room {} closed", this.name);

      this.closed = true;
    } else {
      log.warn("Closing a yet closed room {}", this.name);
    }
  }
示例#4
0
  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);
  }
示例#5
0
  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;
  }