public void onEvent(javax.media.mscontrol.join.JoinEvent event) {

      MediaGroup mg = (MediaGroup) event.getThisJoinable();
      if (event.isSuccessful()) {

        if (JoinEvent.JOINED == event.getEventType()) {
          // NC Joined to MG

          try {
            Player player = mg.getPlayer();
            player.addListener(new PlayerListener());

            URI prompt = URI.create(WELCOME_MSG);

            player.play(prompt, null, null);

          } catch (MsControlException e) {
            logger.error(e);
          }
        } else if (JoinEvent.UNJOINED == event.getEventType()) {
          if (logger.isDebugEnabled()) {
            logger.debug("Un-Joined MG and NC");
          }
        }

      } else {
        logger.error("Joining of MG and NC failed");
      }
    }
    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 ");
        }
      }
    }
 @Override
 protected void doBye(SipServletRequest request) throws ServletException, IOException {
   MediaGroup mediaGroup = (MediaGroup) request.getSession().getAttribute("MEDIA_GROUP");
   if (mediaGroup != null) {
     logger.info("Bye received, stopping the recording");
     try {
       mediaGroup.getRecorder().stop();
     } catch (MsControlException e) {
       logger.info("recording couldn't be stopped", e);
     }
   }
   super.doBye(request);
 }
 /* (non-Javadoc)
  * @see org.mobicents.servlet.sip.conference.ConferenceLeg#leave(org.mobicents.servlet.sip.conference.Conference)
  */
 public void leave(Conference conference) {
   try {
     mg.release();
   } catch (Exception e) {
     logger.error("Error", e);
   }
 }
 private void join(final Conference conference, Direction direction) {
   // provider.addNotificationListener(this);
   try {
     mg.joinInitiate(direction, conference.getMixer(), null);
   } catch (MsControlException e) {
     logger.error("Error", e);
   }
 }
  @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);
    }
  }
 @Override
 public void unmute(Conference conference) {
   try {
     mg.joinInitiate(Direction.DUPLEX, conference.getMixer(), null);
   } catch (MsControlException e) {
     logger.error("Error", e);
   }
   muted = false;
 }
 /* (non-Javadoc)
  * @see org.mobicents.servlet.sip.conference.ConferenceLeg#join(org.mobicents.servlet.sip.conference.Conference)
  */
 @SuppressWarnings("serial")
 public void join(final Conference conference) {
   join(conference, Direction.DUPLEX);
   try {
     Thread.sleep(800);
     mg.getPlayer().play(URI.create(url), null, null);
   } catch (Exception e) {
     logger.error("Error", e);
   }
 }
Exemple #9
0
 @Override
 public synchronized void move(final boolean direction, final long time) {
   if (!_future.isDone()) {
     final Parameters params = _group.getParameters(null);
     final int oldValue = (Integer) params.get(Player.JUMP_TIME);
     params.put(Player.JUMP_TIME, time);
     _group.setParameters(params);
     try {
       if (direction) {
         _group.triggerAction(Player.JUMP_FORWARD);
       } else {
         _group.triggerAction(Player.JUMP_BACKWARD);
       }
     } finally {
       params.put(Player.JUMP_TIME, oldValue);
       _group.setParameters(params);
     }
   }
 }
  public void timeout(ServletTimer servletTimer) {

    String sessionId = (String) servletTimer.getInfo();
    logger.info("Timer fired on sip session " + sessionId);
    SipSession sipSession = servletTimer.getApplicationSession().getSipSession(sessionId);

    if (sipSession != null) {
      MediaGroup mediaGroup = (MediaGroup) sipSession.getAttribute("MEDIA_GROUP");
      if (mediaGroup != null) {
        logger.info("Timer fired, stopping the recording");
        try {
          mediaGroup.getRecorder().stop();
        } catch (MsControlException e) {
          logger.info("recording couldn't be stopped", e);
        }
      }
    } else {
      logger.info("the session has not been found, it may have been already invalidated");
    }
  }
Exemple #11
0
 @Override
 public void stop() {
   if (!_future.isDone()) {
     _group.triggerAction(Player.STOP);
     try {
       _future.get();
     } catch (InterruptedException e) {
       // ignore
     } catch (ExecutionException e) {
       // ignore
     }
   }
 }
Exemple #12
0
  @Override
  public void speed(final boolean upOrDown) {
    lock.lock();
    try {
      if (!_future.isDone()) {
        if (upOrDown) {
          _group.triggerAction(Player.SPEED_UP);
        } else {
          _group.triggerAction(Player.SPEED_DOWN);
        }

        while (!speedResult && !_future.isDone()) {
          try {
            speedActionResult.await(5, TimeUnit.SECONDS);
          } catch (InterruptedException e) {
            // ignore
          }
        }
        speedResult = false;
      }
    } finally {
      lock.unlock();
    }
  }
Exemple #13
0
  @Override
  public void resume() {
    lock.lock();
    try {
      if (!_future.isDone() && paused) {
        _group.triggerAction(Recorder.RESUME);

        while (!resumeResult && !_future.isDone()) {
          try {
            resumeActionResult.await(5, TimeUnit.SECONDS);
          } catch (InterruptedException e) {
            // ignore
          }
        }

        resumeResult = false;
      }
    } finally {
      lock.unlock();
    }
  }
Exemple #14
0
  @Override
  public void pause() {
    lock.lock();
    try {
      if (!_future.isDone() && !paused) {
        _group.triggerAction(Player.PAUSE);

        while (!pauseResult && !_future.isDone()) {
          try {
            pauseActionResult.await(5, TimeUnit.SECONDS);
          } catch (InterruptedException e) {
            // ignore
          }
        }

        pauseResult = false;
      }
    } finally {
      lock.unlock();
    }
  }
Exemple #15
0
 @Override
 public synchronized void jump(final int index) {
   if (!_future.isDone()) {
     final Parameters params = _group.getParameters(null);
     final int oldValue = (Integer) params.get(Player.JUMP_PLAYLIST_INCREMENT);
     try {
       if (index > 0) {
         params.put(Player.JUMP_PLAYLIST_INCREMENT, index);
         _group.setParameters(params);
         _group.triggerAction(Player.JUMP_FORWARD_IN_PLAYLIST);
       } else if (index < 0) {
         params.put(Player.JUMP_PLAYLIST_INCREMENT, -index);
         _group.setParameters(params);
         _group.triggerAction(Player.JUMP_BACKWARD_IN_PLAYLIST);
       }
     } finally {
       params.put(Player.JUMP_PLAYLIST_INCREMENT, oldValue);
       _group.setParameters(params);
     }
   }
 }