コード例 #1
0
    public void onEvent(PlayerEvent event) {

      Player player = event.getSource();
      MediaGroup mg = player.getContainer();
      if (!isBye) {
        if (event.isSuccessful() && (PlayerEvent.PLAY_COMPLETED == event.getEventType())) {

          MediaSession mediaSession = event.getSource().getMediaSession();

          SipSession sipSession = (SipSession) mediaSession.getAttribute("SIP_SESSION");

          sipSession.setAttribute("MEDIA_GROUP", mg);

          SipApplicationSession sipAppSession = sipSession.getApplicationSession();

          try {
            Recorder recoredr = mg.getRecorder();
            logger.info("recording the user at " + RECORDER);
            URI prompt = URI.create(RECORDER);

            recoredr.record(prompt, null, null);

            TimerService timer = (TimerService) getServletContext().getAttribute(TIMER_SERVICE);
            timer.createTimer(sipAppSession, RECORDING_DELAY, false, sipSession.getId());

          } catch (MsControlException e) {
            logger.error("An unexpected error happened ", e);
          }
        } else {
          logger.error("Player didn't complete successfully ");
        }
      }
    }
コード例 #2
0
  @Override
  protected void doAck(SipServletRequest req) throws ServletException, IOException {
    SipSession sipSession = req.getSession();

    MediaSession ms = (MediaSession) sipSession.getAttribute("MEDIA_SESSION");
    try {
      MediaGroup mg = ms.createMediaGroup(MediaGroup.PLAYER_RECORDER_SIGNALDETECTOR);
      mg.addListener(new MyJoinEventListener());

      NetworkConnection nc = (NetworkConnection) sipSession.getAttribute("NETWORK_CONNECTION");
      mg.joinInitiate(Direction.DUPLEX, nc, this);

    } catch (MsControlException e) {
      logger.error(e);
      // Clean up media session
      terminate(sipSession, ms);
    }
  }
  public void onEvent(PlayerEvent event) {
    try {
      logger.info("ENDING CALL ");
      Player player = event.getSource();
      MediaGroup mg = player.getContainer();
      if (event.isSuccessful() && (PlayerEvent.PLAY_COMPLETED == event.getEventType())) {
        MediaSession session = (MediaSession) sipSession.getAttribute("mediaSession");
        session.release();
        Thread.sleep(1500);

        SipServletRequest byeRequest = sipSession.createRequest("BYE");
        byeRequest.send();
      }

    } catch (Exception e) {
      logger.error("Error", e);
    }
  }