public void connectionOpenRequest(MsConnectionEvent event, SipServletRequest inviteRequest) {
    logger.info("connection opened " + event);

    String sdp = event.getConnection().getLocalDescriptor();
    SipServletResponse sipServletResponse = inviteRequest.createResponse(SipServletResponse.SC_OK);

    try {
      sipServletResponse.setContent(sdp, "application/sdp");
      sipServletResponse.send();
    } catch (Exception e) {
      logger.error(e);
    }
    provider = ConferenceCenter.getInstance().getProvider();
    MsConnection connection = event.getConnection();
    MsEndpoint endpoint = connection.getEndpoint();
    MsSession session = connection.getSession();
    String callerName = inviteRequest.getFrom().getURI().toString();

    ConferenceParticipant participant =
        new EndpointConferenceParticipant(callerName, endpoint, session, inviteRequest, connection);

    String key = ((SipURI) inviteRequest.getTo().getURI()).getUser();

    ConferenceCenter.getInstance().getConference(key).joinParticipant(participant);
  }
 @Observer("connectionOpen")
 public void doConnectionOpen(MsConnectionEvent event) throws IOException {
   conferenceEndpointName = event.getConnection().getEndpoint().getLocalName();
   SipServletRequest request = (SipServletRequest) sipSession.getAttribute("inviteRequest");
   SipServletResponse response = request.createResponse(200);
   response.setContent(event.getConnection().getLocalDescriptor(), "application/sdp");
   response.send();
 }
예제 #3
0
 protected synchronized void doPrack(final SipServletRequest req) throws IOException {
   if (_cstate == SIPCall.State.PROGRESSED) {
     final SipServletResponse res = req.createResponse(SipServletResponse.SC_OK);
     if (getLocalSDP() != null) {
       res.setContent(getLocalSDP(), "application/sdp");
     }
     res.send();
   }
 }
예제 #4
0
 @Override
 public synchronized void onEvent(final SdpPortManagerEvent event) {
   if (getSIPCallState() == SIPCall.State.PROGRESSING) {
     try {
       final byte[] sdp = event.getMediaServerSdp();
       this.setLocalSDP(sdp);
       final SipServletResponse res =
           getSipInitnalRequest().createResponse(SipServletResponse.SC_SESSION_PROGRESS);
       res.setContent(sdp, "application/sdp");
       try {
         res.sendReliably();
       } catch (final Rel100Exception e) {
         LOG.warn("", e);
         res.send();
       }
       setSIPCallState(SIPCall.State.PROGRESSED);
       this.notifyAll();
     } catch (final IOException e) {
       LOG.warn("", e);
     }
   }
   super.onEvent(event);
 }
예제 #5
0
  /**
   * @param response
   * @throws IOException
   */
  public static void forwardResponse(final SipServletResponse response) throws IOException {
    if (logger.isInfoEnabled()) {
      logger.info(String.format("B2BUA: Got response: \n %s", response));
    }
    CallDetailRecordsDao records = daoManager.getCallDetailRecordsDao();

    // container handles CANCEL related responses no need to forward them
    if (response.getStatus() == 487
        || (response.getStatus() == 200 && response.getMethod().equalsIgnoreCase("CANCEL"))) {
      if (logger.isDebugEnabled()) {
        logger.debug("response to CANCEL not forwarding");
      }
      // Update CallDetailRecord
      SipServletRequest request =
          (SipServletRequest) getLinkedSession(response).getAttribute(B2BUA_LAST_REQUEST);
      CallDetailRecord callRecord =
          records.getCallDetailRecord((Sid) request.getSession().getAttribute(CDR_SID));

      if (callRecord != null) {
        logger.info("CDR found! Updating");
        callRecord = callRecord.setStatus(CallStateChanged.State.CANCELED.name());
        final DateTime now = DateTime.now();
        callRecord = callRecord.setEndTime(now);
        final int seconds =
            (int) (DateTime.now().getMillis() - callRecord.getStartTime().getMillis()) / 1000;
        callRecord = callRecord.setDuration(seconds);
        records.updateCallDetailRecord(callRecord);
      }
      return;
    }
    // forward the response
    response.getSession().setAttribute(B2BUA_LAST_RESPONSE, response);
    SipServletRequest request =
        (SipServletRequest) getLinkedSession(response).getAttribute(B2BUA_LAST_REQUEST);
    SipServletResponse resp = request.createResponse(response.getStatus());
    CallDetailRecord callRecord =
        records.getCallDetailRecord((Sid) request.getSession().getAttribute(CDR_SID));

    if (response.getContent() != null) {
      final byte[] sdp = response.getRawContent();
      String offer = null;
      if (response.getContentType().equalsIgnoreCase("application/sdp")) {
        // Issue 306: https://telestax.atlassian.net/browse/RESTCOMM-306
        Registration registration =
            daoManager.getRegistrationsDao().getRegistration(callRecord.getTo());
        final String externalIp = registration.getLocation().split(":")[1].split("@")[1];
        try {
          logger.debug("Got original address from Registration :" + externalIp);
          offer = patch(sdp, externalIp);
        } catch (SdpException e) {
          logger.error("Unexpected exception while patching sdp ", e);
        }
        if (offer != null) {
          resp.setContent(offer, response.getContentType());
        } else {
          resp.setContent(sdp, response.getContentType());
        }
      }
    }
    resp.send();

    //        CallDetailRecord callRecord = records.getCallDetailRecord((Sid)
    // request.getSession().getAttribute(CDR_SID));
    if (callRecord != null) {
      logger.info("CDR found! Updating");
      if (!request.getMethod().equalsIgnoreCase("BYE")) {
        if (response.getStatus() == 100 || response.getStatus() == 180) {
          callRecord = callRecord.setStatus(CallStateChanged.State.RINGING.name());
        } else if (response.getStatus() == 200 || response.getStatus() == 202) {
          callRecord = callRecord.setStatus(CallStateChanged.State.IN_PROGRESS.name());
          callRecord = callRecord.setAnsweredBy(((SipURI) response.getTo().getURI()).getUser());
          final DateTime now = DateTime.now();
          callRecord = callRecord.setStartTime(now);

        } else if (response.getStatus() == 486 || response.getStatus() == 600) {
          callRecord = callRecord.setStatus(CallStateChanged.State.BUSY.name());
        } else if (response.getStatus() > 400) {
          callRecord = callRecord.setStatus(CallStateChanged.State.FAILED.name());
        }
      } else {
        callRecord = callRecord.setStatus(CallStateChanged.State.COMPLETED.name());
        final DateTime now = DateTime.now();
        callRecord = callRecord.setEndTime(now);
        final int seconds =
            (int) ((DateTime.now().getMillis() - callRecord.getStartTime().getMillis()) / 1000);
        callRecord = callRecord.setDuration(seconds);
      }

      records.updateCallDetailRecord(callRecord);
    }
  }