/**
   * Sends a message in pager mode to a contact and for a given service. The message may be any type
   * of content. 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 serviceId Service ID
   * @param contact Contact
   * @param content Message content
   * @return Returns true if sent successfully else returns false
   * @throws ServerApiException
   */
  public boolean sendMessage(String serviceId, String contact, byte[] content)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Send instant message to " + contact);
    }

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Send instant message
      String featureTag =
          FeatureTags.FEATURE_RCSE
              + "=\""
              + FeatureTags.FEATURE_RCSE_EXTENSION
              + "."
              + serviceId
              + "\"";
      return Core.getInstance().getSipService().sendInstantMessage(contact, featureTag, content);
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
Esempio n. 2
0
  /**
   * Shares a geolocation with a contact. 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 geoloc Geolocation info
   * @param listener Geoloc sharing event listener
   * @return Geoloc sharing
   * @throws ServerApiException
   */
  public IGeolocSharing shareGeoloc(String contact, Geoloc geoloc, IGeolocSharingListener listener)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate a geoloc sharing session with " + contact);
    }

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Create a geoloc content
      String msgId = ChatUtils.generateMessageId();
      GeolocPush geolocPush =
          new GeolocPush(
              geoloc.getLabel(),
              geoloc.getLatitude(),
              geoloc.getLongitude(),
              geoloc.getExpiration(),
              geoloc.getAccuracy());
      String geolocDoc =
          ChatUtils.buildGeolocDocument(
              geolocPush, ImsModule.IMS_USER_PROFILE.getPublicUri(), msgId);
      MmContent content =
          new GeolocContent("geoloc.xml", geolocDoc.getBytes().length, geolocDoc.getBytes());

      // Initiate a sharing session
      final GeolocTransferSession session =
          Core.getInstance()
              .getRichcallService()
              .initiateGeolocSharingSession(contact, content, geolocPush);

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

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

      // Add session in the list
      addGeolocSharingSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }
  /**
   * 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());
    }
  }
  /**
   * Initiates a new multimedia session for real time messaging with a remote contact and for a
   * given service. The messages exchanged in real time during the session may be from any type. 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 serviceId Service ID
   * @param contact Contact
   * @param listener Multimedia session event listener
   * @return Multimedia session
   * @throws ServerApiException
   */
  public IMultimediaSession initiateSession(
      String serviceId, String contact, IMultimediaSessionListener listener)
      throws ServerApiException {
    if (logger.isActivated()) {
      logger.info("Initiate a multimedia session with " + contact);
    }

    // Test IMS connection
    ServerApiUtils.testIms();

    try {
      // Initiate a new session
      String featureTag =
          FeatureTags.FEATURE_RCSE
              + "=\""
              + FeatureTags.FEATURE_RCSE_EXTENSION
              + "."
              + serviceId
              + "\"";
      final GenericSipSession session =
          Core.getInstance().getSipService().initiateSession(contact, featureTag);

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

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

      // Add session in the list
      MultimediaSessionServiceImpl.addSipSession(sessionApi);
      return sessionApi;
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Unexpected error", e);
      }
      throw new ServerApiException(e.getMessage());
    }
  }