/**
   * Shares a live video with a contact. The parameter renderer contains the video player provided
   * by the application. An exception if thrown if there is no ongoing CS call. The parameter
   * contact supports the following formats: MSISDN in national or international format, SIP
   * address, SIP-URI or Tel-URI. If the format of the contact is not supported an exception is
   * thrown.
   *
   * @param contact Contact
   * @param player Video player
   * @param listener Video sharing event listener
   * @return Video sharing
   * @throws ServerApiException
   */
  public IVideoSharing shareVideo(
      String contact, IVideoPlayer player, IVideoSharingListener listener)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate a live video session with " + contact);
    }

    // Test IMS connection
    ServerApiUtils.testIms();

    // Test if at least the audio media is configured
    if (player == null) {
      throw new ServerApiException("Missing video player");
    }

    try {
      // Initiate a new session
      final VideoStreamingSession session =
          Core.getInstance().getRichcallService().initiateLiveVideoSharingSession(contact, player);

      // Update rich call history
      RichCallHistory.getInstance()
          .addVideoSharing(
              contact,
              session.getSessionID(),
              VideoSharing.Direction.OUTGOING,
              session.getContent(),
              VideoSharing.State.INITIATED);

      // Add session listener
      VideoSharingImpl sessionApi = new VideoSharingImpl(session);
      sessionApi.addEventListener(listener);

      // Start the session
      Thread t =
          new Thread() {
            public void run() {
              session.startSession();
            }
          };
      t.start();

      // Add session in the list
      addVideoSharingSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
  /**
   * Add a video sharing session in the list
   *
   * @param session Video sharing session
   */
  protected static void addVideoSharingSession(VideoSharingImpl session) {
    if (logger.isActivated()) {
      logger.debug(
          "Add a video sharing session in the list (size=" + videoSharingSessions.size() + ")");
    }

    videoSharingSessions.put(session.getSharingId(), session);
  }