Example #1
0
  /**
   * Utility method for extracting info about channels allocated from JVB response. FIXME: this
   * might not work as expected when channels for multiple peers with single query were allocated.
   *
   * @param conferenceResponse JVB response to allocate channels request.
   * @param peerContents list of peer media contents that has to be matched with allocated channels.
   * @return the Colibri IQ that describes allocated channels.
   */
  public static ColibriConferenceIQ getResponseContents(
      ColibriConferenceIQ conferenceResponse, List<ContentPacketExtension> peerContents) {
    ColibriConferenceIQ conferenceResult = new ColibriConferenceIQ();

    conferenceResult.setFrom(conferenceResponse.getFrom());
    conferenceResult.setID(conferenceResponse.getID());

    // FIXME: we support single bundle for all channels
    String bundleId = null;
    for (ContentPacketExtension content : peerContents) {
      MediaType mediaType = JingleUtils.getMediaType(content);

      ColibriConferenceIQ.Content contentResponse =
          conferenceResponse.getContent(mediaType.toString());

      if (contentResponse != null) {
        String contentName = contentResponse.getName();
        ColibriConferenceIQ.Content contentResult = new ColibriConferenceIQ.Content(contentName);

        conferenceResult.addContent(contentResult);

        for (ColibriConferenceIQ.Channel channelResponse : contentResponse.getChannels()) {
          contentResult.addChannel(channelResponse);

          bundleId = readChannelBundle(channelResponse, bundleId);
        }

        for (ColibriConferenceIQ.SctpConnection sctpConnResponse :
            contentResponse.getSctpConnections()) {
          contentResult.addSctpConnection(sctpConnResponse);

          bundleId = readChannelBundle(sctpConnResponse, bundleId);
        }
      }
    }

    // Copy only peer's bundle(JVB returns all bundles)
    if (bundleId != null) {
      for (ColibriConferenceIQ.ChannelBundle bundle : conferenceResponse.getChannelBundles()) {
        if (bundleId.equals(bundle.getId())) {
          conferenceResult.addChannelBundle(bundle);
          break;
        }
      }
    }

    return conferenceResult;
  }