/**
   * Initiate an image sharing session
   *
   * @param contact Contact
   * @param file Image file
   * @param thumbnail Thumbnail option
   * @throws ServerApiException
   */
  public IImageSharingSession initiateImageSharing(String contact, String file, boolean thumbnail)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate an image sharing session with " + contact);
    }

    // Check permission
    ServerApiUtils.testPermission();

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Create an image content
      FileDescription desc = FileFactory.getFactory().getFileDescription(file);
      MmContent content = ContentManager.createMmContentFromUrl(file, desc.getSize());

      // Initiate a sharing session
      ImageTransferSession session =
          Core.getInstance()
              .getRichcallService()
              .initiateImageSharingSession(contact, content, thumbnail);

      // Update rich call history
      RichCall.getInstance()
          .addCall(
              contact,
              session.getSessionID(),
              RichCallData.EVENT_OUTGOING,
              session.getContent(),
              RichCallData.STATUS_STARTED);

      // Add session in the list
      ImageSharingSession sessionApi = new ImageSharingSession(session);
      addImageSharingSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
Example #2
0
  /**
   * Initiate a live video sharing session
   *
   * @param contact Remote contact
   * @param content Video content to share
   * @param player Media player
   * @return CSh session
   * @throws CoreException
   * @throws RemoteException
   */
  public VideoStreamingSession initiateLiveVideoSharingSession(String contact, IMediaPlayer player)
      throws CoreException, RemoteException {
    if (logger.isActivated()) {
      logger.info("Initiate a live video sharing session");
    }

    // Test if call is established
    if (!getImsModule().getCallManager().isCallConnected()) {
      if (logger.isActivated()) {
        logger.debug("Rich call not established: cancel the initiation");
      }
      throw new CoreException("Call not established");
    }

    // Reject if there are already 2 bidirectional sessions with a given contact
    boolean rejectInvitation = false;
    Vector<ContentSharingSession> currentSessions = getCShSessions();
    if (currentSessions.size() >= 2) {
      // Already a bidirectional session
      if (logger.isActivated()) {
        logger.debug("Max sessions reached");
      }
      rejectInvitation = true;
    } else if (currentSessions.size() == 1) {
      ContentSharingSession currentSession = currentSessions.elementAt(0);
      if (!(currentSession instanceof TerminatingVideoStreamingSession)) {
        // Originating session already used
        if (logger.isActivated()) {
          logger.debug("Max originating sessions reached");
        }
        rejectInvitation = true;
      } else if (!PhoneUtils.compareNumbers(contact, currentSession.getRemoteContact())) {
        // Not the same contact
        if (logger.isActivated()) {
          logger.debug(
              "contact = "
                  + contact
                  + ", currentSession.getRemoteContact() = "
                  + currentSession.getRemoteContact());
          logger.debug("Only bidirectional session with same contact authorized");
        }
        rejectInvitation = true;
      }
    }
    if (rejectInvitation) {
      if (logger.isActivated()) {
        logger.debug("The max number of sharing sessions is achieved: cancel the initiation");
      }
      throw new CoreException("Max content sharing sessions achieved");
    }

    // Create a new session
    OriginatingLiveVideoStreamingSession session =
        new OriginatingLiveVideoStreamingSession(
            this,
            player,
            ContentManager.createGenericLiveVideoContent(),
            PhoneUtils.formatNumberToSipUri(contact));

    // Start the session
    session.startSession();
    return session;
  }