Ejemplo n.º 1
0
  /**
   * Initiate a pre-recorded video sharing session
   *
   * @param contact Remote contact
   * @param content Video content to share
   * @param player Media player
   * @return CSh session
   * @throws CoreException
   */
  public VideoStreamingSession initiatePreRecordedVideoSharingSession(
      String contact, VideoContent content, IMediaPlayer player) throws CoreException {
    if (logger.isActivated()) {
      logger.info(
          "Initiate a pre-recorded video sharing session with contact "
              + contact
              + ", file "
              + content.toString());
    }

    // 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("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
    OriginatingPreRecordedVideoStreamingSession session =
        new OriginatingPreRecordedVideoStreamingSession(
            this, player, content, PhoneUtils.formatNumberToSipUri(contact));

    // Start the session
    session.startSession();
    return session;
  }
Ejemplo n.º 2
0
  /**
   * Receive an image sharing invitation
   *
   * @param invite Initial invite
   */
  public void receiveImageSharingInvitation(SipRequest invite) {
    if (logger.isActivated()) {
      logger.info("Receive an image sharing session invitation");
    }

    // Test if call is established
    if (!getImsModule().getCallManager().isCallConnected()) {
      if (logger.isActivated()) {
        logger.debug("Rich call not established: reject the invitation");
      }
      sendErrorResponse(invite, 606);
      return;
    }

    // Reject if there are already 2 bidirectional sessions with a given contact
    boolean rejectInvitation = false;
    String contact = SipUtils.getAssertedIdentity(invite);
    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 TerminatingImageTransferSession) {
        // Terminating session already used
        if (logger.isActivated()) {
          logger.debug("Max terminating sessions reached");
        }
        rejectInvitation = true;
      } else if (!PhoneUtils.compareNumbers(contact, currentSession.getRemoteContact())) {
        // Not the same contact
        if (logger.isActivated()) {
          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: reject the invitation");
      }
      sendErrorResponse(invite, 486);
      return;
    }

    // Create a new session
    ImageTransferSession session = new TerminatingImageTransferSession(this, invite);

    // Start the session
    session.startSession();

    // Notify listener
    getImsModule().getCore().getListener().handleContentSharingTransferInvitation(session);
  }
Ejemplo n.º 3
0
  /**
   * A new presence info notification has been received
   *
   * @param contact Contact
   * @param presense Presence info document
   */
  public void handlePresenceInfoNotification(String contact, PidfDocument presence) {
    if (logger.isActivated()) {
      logger.debug("Handle event presence info notification for " + contact);
    }

    try {
      // Test if person item is not null
      Person person = presence.getPerson();
      if (person == null) {
        if (logger.isActivated()) {
          logger.debug("Presence info is empty (i.e. no item person found) for contact " + contact);
        }
        return;
      }

      // Check if its a notification for a contact or for me
      String me = ImsModule.IMS_USER_PROFILE.getPublicUri();
      if (PhoneUtils.compareNumbers(me, contact)) {
        // Notification for me
        presenceInfoNotificationForMe(presence);
      } else {
        // Check that the contact exist in database
        int rcsStatus = ContactsManager.getInstance().getContactSharingStatus(contact);
        if (rcsStatus == -1) {
          if (logger.isActivated()) {
            logger.debug("Contact " + contact + " is not a RCS contact, by-pass the notification");
          }
          return;
        }

        // Notification for a contact
        presenceInfoNotificationForContact(contact, presence);
      }
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Internal exception", e);
      }
    }
  }
Ejemplo n.º 4
0
  /**
   * A new presence sharing notification has been received
   *
   * @param contact Contact
   * @param status Status
   * @param reason Reason
   */
  public void handlePresenceSharingNotification(String contact, String status, String reason) {
    if (logger.isActivated()) {
      logger.debug(
          "Handle event presence sharing notification for "
              + contact
              + " ("
              + status
              + ":"
              + reason
              + ")");
    }

    try {
      // Check if its a notification for a contact or for the end user
      String me = ImsModule.IMS_USER_PROFILE.getPublicUri();
      if (PhoneUtils.compareNumbers(me, contact)) {
        // End user notification
        if (logger.isActivated()) {
          logger.debug("Presence sharing notification for me: by-pass it");
        }
      } else {
        // Update contacts database
        ContactsManager.getInstance().setContactSharingStatus(contact, status, reason);

        // Broadcast intent
        Intent intent = new Intent(PresenceApiIntents.PRESENCE_SHARING_CHANGED);
        intent.putExtra("contact", contact);
        intent.putExtra("status", status);
        intent.putExtra("reason", reason);
        AndroidFactory.getApplicationContext().sendBroadcast(intent);
      }
    } catch (Exception e) {
      if (logger.isActivated()) {
        logger.error("Internal exception", e);
      }
    }
  }