Пример #1
0
  private void handleMuteIq(MuteIq muteIq) {
    Boolean doMute = muteIq.getMute();
    String jid = muteIq.getJid();

    if (doMute == null || StringUtils.isNullOrEmpty(jid)) return;

    String from = muteIq.getFrom();
    JitsiMeetConference conference = getConferenceForMucJid(from);
    if (conference == null) {
      logger.debug("Mute error: room not found for JID: " + from);
      return;
    }

    IQ result;

    if (conference.handleMuteRequest(muteIq.getFrom(), jid, doMute)) {
      result = IQ.createResultIQ(muteIq);

      if (!muteIq.getFrom().equals(jid)) {
        MuteIq muteStatusUpdate = new MuteIq();
        muteStatusUpdate.setType(IQ.Type.SET);
        muteStatusUpdate.setTo(jid);

        muteStatusUpdate.setMute(doMute);

        smackXmpp.getXmppConnection().sendPacket(muteStatusUpdate);
      }
    } else {
      result =
          IQ.createErrorResponse(muteIq, new XMPPError(XMPPError.Condition.interna_server_error));
    }

    smackXmpp.getXmppConnection().sendPacket(result);
  }
Пример #2
0
    private void expireLoop() {
      while (enabled) {
        // Sleep
        try {
          synchronized (sleepLock) {
            sleepLock.wait(POLL_INTERVAL);
          }
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        }

        if (!enabled) break;

        // Loop over conferences
        for (JitsiMeetConference conference :
            new ArrayList<JitsiMeetConference>(conferences.values())) {
          long idleStamp = conference.getIdleTimestamp();
          // Is active ?
          if (idleStamp == -1) {
            continue;
          }
          if (System.currentTimeMillis() - idleStamp > timeout) {
            logger.info("Focus idle timeout for " + conference.getRoomName());

            conference.stop();
          }
        }
      }
    }
Пример #3
0
  private void handleRayoIQ(RayoIqProvider.DialIq dialIq) {
    String from = dialIq.getFrom();

    JitsiMeetConference conference = getConferenceForMucJid(from);

    if (conference == null) {
      logger.debug("Mute error: room not found for JID: " + from);
      return;
    }

    ChatRoomMemberRole role = conference.getRoleForMucJid(from);

    if (role == null) {
      // Only room members are allowed to send requests
      IQ error = createErrorResponse(dialIq, new XMPPError(XMPPError.Condition.forbidden));

      smackXmpp.getXmppConnection().sendPacket(error);

      return;
    }

    if (ChatRoomMemberRole.MODERATOR.compareTo(role) < 0) {
      // Moderator permission is required
      IQ error = createErrorResponse(dialIq, new XMPPError(XMPPError.Condition.not_allowed));

      smackXmpp.getXmppConnection().sendPacket(error);

      return;
    }

    // Check if Jigasi is available
    String jigasiJid = conference.getServices().getSipGateway();

    if (StringUtils.isNullOrEmpty(jigasiJid)) {
      // Not available
      IQ error =
          createErrorResponse(dialIq, new XMPPError(XMPPError.Condition.service_unavailable));

      smackXmpp.getXmppConnection().sendPacket(error);

      return;
    }

    // Redirect original request to Jigasi component
    String originalPacketId = dialIq.getPacketID();

    dialIq.setFrom(null);
    dialIq.setTo(jigasiJid);
    dialIq.setPacketID(IQ.nextID());

    IQ reply = (IQ) smackXmpp.getXmppConnection().sendPacketAndGetReply(dialIq);

    // Send Jigasi response back to the client
    reply.setFrom(null);
    reply.setTo(from);
    reply.setPacketID(originalPacketId);

    smackXmpp.getXmppConnection().sendPacket(reply);
  }
Пример #4
0
  /**
   * Destroys the conference for given room name.
   *
   * @param roomName full MUC room name to destroy.
   * @param reason optional reason string that will be advertised to the users upon exit.
   */
  public synchronized void destroyConference(String roomName, String reason) {
    JitsiMeetConference conference = getConference(roomName);
    if (conference == null) {
      logger.error("Unable to destroy the conference - not found: " + roomName);
      return;
    }

    conference.destroy(reason);
  }
Пример #5
0
  /**
   * Allocates new focus for given MUC room.
   *
   * @param room the name of MUC room for which new conference has to be allocated.
   * @param properties configuration properties map included in the request.
   * @return <tt>true</tt> if conference focus is in the room and ready to handle session
   *     participants.
   * @throws Exception if for any reason we have failed to create the conference
   */
  public synchronized boolean conferenceRequest(String room, Map<String, String> properties)
      throws Exception {
    if (StringUtils.isNullOrEmpty(room)) return false;

    if (shutdownInProgress && !conferences.containsKey(room)) return false;

    if (!conferences.containsKey(room)) {
      createConference(room, properties);
    }

    JitsiMeetConference conference = conferences.get(room);

    return conference.isInTheRoom();
  }
Пример #6
0
  /**
   * Makes sure that conference is allocated for given <tt>room</tt>.
   *
   * @param room name of the MUC room of Jitsi Meet conference.
   * @param properties configuration properties, see {@link JitsiMeetConfig} for the list of valid
   *     properties.
   * @throws Exception if any error occurs.
   */
  private void createConference(String room, Map<String, String> properties) throws Exception {
    JitsiMeetConfig config = new JitsiMeetConfig(properties);

    JitsiMeetConference conference =
        new JitsiMeetConference(room, focusUserName, protocolProviderHandler, this, config);

    conferences.put(room, conference);

    StringBuilder options = new StringBuilder();
    for (Map.Entry<String, String> option : properties.entrySet()) {
      options.append("\n    ").append(option.getKey()).append(": ").append(option.getValue());
    }

    logger.info(
        "Created new focus for "
            + room
            + "@"
            + focusUserDomain
            + " conferences count: "
            + conferences.size()
            + " options:"
            + options.toString());

    // Send focus created event
    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
    if (eventAdmin != null) {
      eventAdmin.sendEvent(EventFactory.focusCreated(conference.getId(), conference.getRoomName()));
    }

    try {
      conference.start();
    } catch (Exception e) {
      logger.info("Exception while trying to start the conference", e);

      // stop() method is called by the conference automatically in order
      // to not release the lock on JitsiMeetConference instance and avoid
      // a deadlock. It may happen when this thread is about to call
      // conference.stop() and another thread has entered the method
      // before us. That other thread will try to call
      // FocusManager.conferenceEnded, but we're still holding the lock
      // on FocusManager instance.

      // conference.stop();

      throw e;
    }
  }
Пример #7
0
  /** {@inheritDoc} */
  @Override
  public synchronized void conferenceEnded(JitsiMeetConference conference) {
    String roomName = conference.getRoomName();

    conferences.remove(roomName);

    logger.info(
        "Disposed conference for room: " + roomName + " conference count: " + conferences.size());

    if (focusAllocListener != null) {
      focusAllocListener.onFocusDestroyed(roomName);
    }

    // Send focus destroyed event
    FocusBundleActivator.getEventAdmin()
        .sendEvent(EventFactory.focusDestroyed(conference.getId(), conference.getRoomName()));

    maybeDoShutdown();
  }
Пример #8
0
  private void handleColibriIq(ColibriConferenceIQ colibriIQ) {
    ColibriConferenceIQ.Recording recording = colibriIQ.getRecording();
    String from = colibriIQ.getFrom();
    JitsiMeetConference conference = getConferenceForMucJid(colibriIQ.getFrom());
    if (conference == null) {
      logger.debug("Room not found for JID: " + from);
      return;
    }

    JitsiMeetRecording recordingHandler = conference.getRecording();
    if (recordingHandler == null) {
      logger.error("JitsiMeetRecording is null for iq: " + colibriIQ.toXML());

      // Internal server error
      smackXmpp
          .getXmppConnection()
          .sendPacket(
              IQ.createErrorResponse(
                  colibriIQ, new XMPPError(XMPPError.Condition.interna_server_error)));
      return;
    }

    State recordingState =
        recordingHandler.modifyRecordingState(
            colibriIQ.getFrom(),
            recording.getToken(),
            recording.getState(),
            recording.getDirectory(),
            colibriIQ.getTo());

    ColibriConferenceIQ response = new ColibriConferenceIQ();

    response.setType(IQ.Type.RESULT);
    response.setPacketID(colibriIQ.getPacketID());
    response.setTo(colibriIQ.getFrom());
    response.setFrom(colibriIQ.getTo());
    response.setName(colibriIQ.getName());

    response.setRecording(new ColibriConferenceIQ.Recording(recordingState));

    smackXmpp.getXmppConnection().sendPacket(response);
  }
Пример #9
0
  /**
   * Makes sure that conference is allocated for given <tt>room</tt>.
   *
   * @param room name of the MUC room of Jitsi Meet conference.
   * @param properties configuration properties, see {@link JitsiMeetConfig} for the list of valid
   *     properties.
   * @throws Exception if any error occurs.
   */
  private void createConference(String room, Map<String, String> properties) throws Exception {
    JitsiMeetConfig config = new JitsiMeetConfig(properties);

    JitsiMeetConference conference =
        new JitsiMeetConference(room, focusUserName, protocolProviderHandler, this, config);

    conferences.put(room, conference);

    StringBuilder options = new StringBuilder();
    for (Map.Entry<String, String> option : properties.entrySet()) {
      options.append("\n    ").append(option.getKey()).append(": ").append(option.getValue());
    }

    logger.info(
        "Created new focus for "
            + room
            + "@"
            + focusUserDomain
            + " conferences count: "
            + conferences.size()
            + " options:"
            + options.toString());

    // Send focus created event
    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
    if (eventAdmin != null) {
      eventAdmin.sendEvent(EventFactory.focusCreated(conference.getId(), conference.getRoomName()));
    }

    try {
      conference.start();
    } catch (Exception e) {
      logger.info("Exception while trying to start the conference", e);

      conference.stop();

      throw e;
    }
  }
Пример #10
0
  /** Handles XEP-0337 "log" extensions. */
  private void handleLogRequest(LogPacketExtension log, String jid) {
    JitsiMeetConference conference = getConferenceForMucJid(jid);

    if (conference == null) {
      logger.debug("Room not found for JID: " + jid);
      return;
    }

    Participant participant = conference.findParticipantForRoomJid(jid);

    if (participant == null) {
      logger.info("Ignoring log request from an unknown JID: " + jid);
      return;
    }

    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();

    if (eventAdmin == null) return;

    if (LogUtil.LOG_ID_PC_STATS.equals(log.getID())) {
      String content = LogUtil.getContent(log);

      if (content != null) {
        ColibriConference colibriConference = conference.getColibriConference();

        if (colibriConference != null) {
          Event event =
              EventFactory.peerConnectionStats(
                  colibriConference.getConferenceId(), participant.getEndpointId(), content);

          if (event != null) eventAdmin.sendEvent(event);
        } else {
          logger.warn("Unhandled log request" + " - no valid Colibri conference");
        }
      }
    } else if (logger.isInfoEnabled()) {
      logger.info("Ignoring log request with an unknown ID:" + log.getID());
    }
  }
Пример #11
0
  /**
   * Handles presence stanzas
   *
   * @param presence
   */
  private void handlePresence(Presence presence) {
    // unavailable is sent when user leaves the room
    if (!presence.isAvailable()) {
      return;
    }

    String from = presence.getFrom();
    JitsiMeetConference conference = getConferenceForMucJid(from);

    if (conference == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Room not found for JID: " + from);
      }
      return;
    }

    ChatRoomMemberRole role = conference.getRoleForMucJid(from);

    if (role != null && role.compareTo(ChatRoomMemberRole.MODERATOR) < 0) {
      StartMutedPacketExtension ext =
          (StartMutedPacketExtension)
              presence.getExtension(
                  StartMutedPacketExtension.ELEMENT_NAME, StartMutedPacketExtension.NAMESPACE);

      if (ext != null) {
        boolean[] startMuted = {ext.getAudioMuted(), ext.getVideoMuted()};

        conference.setStartMuted(startMuted);
      }
    }

    Participant participant = conference.findParticipantForRoomJid(from);
    ColibriConference colibriConference = conference.getColibriConference();

    if (participant != null && colibriConference != null) {
      // Check if this conference is valid
      String conferenceId = colibriConference.getConferenceId();
      if (StringUtils.isNullOrEmpty(conferenceId)) {
        logger.error("Unable to send DisplayNameChanged event" + " - no conference id");
        return;
      }

      // Check for changes to the display name
      String oldDisplayName = participant.getDisplayName();
      String newDisplayName = null;
      for (PacketExtension pe : presence.getExtensions()) {
        if (pe instanceof Nick) {
          newDisplayName = ((Nick) pe).getName();
          break;
        }
      }

      if (!Objects.equals(oldDisplayName, newDisplayName)) {
        participant.setDisplayName(newDisplayName);

        EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
        if (eventAdmin != null) {
          // Prevent NPE when adding to event hashtable
          if (newDisplayName == null) {
            newDisplayName = "";
          }
          eventAdmin.sendEvent(
              EventFactory.endpointDisplayNameChanged(
                  conferenceId, participant.getEndpointId(), newDisplayName));
        }
      }
    }
  }