Beispiel #1
0
  /**
   * Jirecon packets processing logic.
   *
   * <p>{@inheritDoc}
   */
  @Override
  public void processPacket(Packet packet) {
    JireconIq recording = (JireconIq) packet;

    if (JireconIq.Action.INFO != recording.getAction() && IQ.Type.RESULT == recording.getType()
        || StringUtils.isNullOrEmpty(recording.getRid())) {
      logger.warn("Discarded: " + recording.toXML());
      return;
    }

    if (!recording.getRid().equals(recordingId)) {
      logger.warn("Received IQ for unknown session: " + recording.toXML());
      return;
    }

    if (status != recording.getStatus()) {
      status = recording.getStatus();

      logger.info("Recording " + recordingId + " status: " + status);

      if (status == JireconIq.Status.STOPPED) {
        logger.info("Recording STOPPED: " + recordingId);
        recordingId = null;
      }
    } else {
      logger.info("Ignored status change: " + recording.toXML());
    }
  }
  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);
  }
  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);
  }
Beispiel #4
0
  /** {@inheritDoc} */
  @Override
  public boolean setRecording(String from, String token, State doRecord, String path) {
    if (!StringUtils.isNullOrEmpty(this.token) && !this.token.equals(token)) {
      return false;
    }

    if (!isRecording() && doRecord.equals(State.ON)) {
      // Send start recording IQ
      JireconIq recording = new JireconIq();

      recording.setTo(recorderComponentJid);
      recording.setType(IQ.Type.SET);
      recording.setFrom(from);

      recording.setMucJid(mucRoomJid);
      recording.setAction(JireconIq.Action.START);
      recording.setOutput(path);

      Packet reply = xmpp.getXmppConnection().sendPacketAndGetReply(recording);
      if (reply instanceof JireconIq) {
        JireconIq recResponse = (JireconIq) reply;
        if (JireconIq.Status.INITIATING.equals(recResponse.getStatus())) {
          recordingId = recResponse.getRid();
          logger.info("Received recording ID: " + recordingId);
          status = JireconIq.Status.INITIATING;
        } else {
          logger.error("Unexpected status received: " + recResponse.toXML());
        }
      } else {
        logger.error("Unexpected response: " + IQUtils.responseToXML(reply));
      }
    } else if (isRecording() && doRecord.equals(State.OFF)) {
      // Send stop recording IQ
      JireconIq recording = new JireconIq();

      recording.setTo(recorderComponentJid);
      recording.setType(IQ.Type.SET);
      recording.setFrom(from);

      recording.setRid(recordingId);
      recording.setMucJid(mucRoomJid);
      recording.setAction(JireconIq.Action.STOP);

      xmpp.getXmppConnection().sendPacket(recording);

      status = JireconIq.Status.STOPPING;
    }

    return true;
  }
  /**
   * 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));
        }
      }
    }
  }