public void timeout(ServletTimer timer, SipSession sipSession) { serverEntryLog(); String reasonPhrase; if (sipSession.getAttribute("cancelled") != null) { reasonPhrase = "got cancelled"; } else { logger.error("***ERROR: didn't receive notification of CANCEL***"); reasonPhrase = "didn't get cancelled"; } try { SipServletRequest invite = (SipServletRequest) sipSession.getAttribute("invite"); SipServletResponse resp = invite.createResponse(500, reasonPhrase); try { resp.send(); } catch (IOException ex) { logger.error("***failed to send subsequent request***", ex); } logger.error( "***ERROR: sending final response after CANCEL didn't " + "cause IllegalStateException***"); } catch (IllegalStateException ex) { logger.info( "===SUCCESS: sending final response after CANCEL " + "cause IllegalStateException==="); } }
@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(); }
@Override protected void doBye(SipServletRequest req) { SipSession session = req.getSession(false); SipSession linkedSession = (SipSession) session.getAttribute(Constant.LINKED_SESSION); logger.info("SIP BYE From : " + req.getFrom().toString()); // caller session if (null != session.getAttribute(Constant.INVITE_USER_REQUEST)) { doBye(session, req); } // callee session else { logger.info("callee do bye!"); doBye(linkedSession, req); } }
public static SipServletRequest getLinkedRequest(SipServletMessage message) { SipSession linkedB2BUASession = getLinkedSession(message); if (linkedB2BUASession != null) { SipServletRequest linkedRequest = (SipServletRequest) linkedB2BUASession.getAttribute(B2BUA_LAST_REQUEST); return linkedRequest; } return null; }
@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 static SipServletResponse getLinkedResponse(SipServletMessage message) { SipSession linkedB2BUASession = getLinkedSession(message); // if this is an ACK that belongs to a B2BUA session, then we proxy it to the other client if (linkedB2BUASession != null) { SipServletResponse response = (SipServletResponse) linkedB2BUASession.getAttribute(B2BUA_LAST_RESPONSE); return response; } return null; }
@Override protected void preprocessState(SipSession session, State state) { BigInteger version = (BigInteger) session.getAttribute(Constants.VERSION_ATTRIBUTE); if (version == null) version = BigInteger.ZERO; else version = version.add(BigInteger.ONE); Watcherinfo watcherinfo = ((WatcherinfoDocument) state.getContent()).getWatcherinfo(); watcherinfo.setVersion(version); session.setAttribute(Constants.VERSION_ATTRIBUTE, version); }
@Override protected void doBye(SipServletRequest request) throws ServletException, IOException { logger.info("Got bye"); SipSession session = request.getSession(); SipSession linkedSession = (SipSession) session.getAttribute("LinkedSession"); if (linkedSession != null) { SipServletRequest bye = linkedSession.createRequest("BYE"); logger.info("Sending bye to " + linkedSession.getRemoteParty()); bye.send(); } CallStatusContainer calls = (CallStatusContainer) getServletContext().getAttribute("activeCalls"); calls.removeCall(request.getFrom().getURI().toString(), request.getTo().getURI().toString()); calls.removeCall(request.getTo().getURI().toString(), request.getFrom().getURI().toString()); SipServletResponse ok = request.createResponse(SipServletResponse.SC_OK); ok.send(); }
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); } }
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"); } }
private void doBye(SipSession session, SipServletRequest request) { // send bye to its linked user session and notify SipSession reqSession = request.getSession(false); if (null == reqSession.getAttribute(Constant.INVITE_USER_REQUEST)) { logger.info("callee ok"); SipServletRequest bye = session.createRequest(Constant.BYE); try { bye.send(); } catch (IOException e) { e.printStackTrace(); } } // send 200 OK to the session SipServletResponse resp = request.createResponse(SipServletResponse.SC_OK); try { resp.send(); } catch (IOException e) { e.printStackTrace(); } }
@Override protected void doSuccessResponse(SipServletResponse resp) throws ServletException, IOException { logger.info("Got OK"); SipSession session = resp.getSession(); if (resp.getStatus() == SipServletResponse.SC_OK) { Boolean inviteSent = (Boolean) session.getAttribute("InviteSent"); if (inviteSent != null && inviteSent.booleanValue()) { return; } Address secondPartyAddress = (Address) resp.getSession().getAttribute("SecondPartyAddress"); if (secondPartyAddress != null) { SipServletRequest invite = sipFactory.createRequest( resp.getApplicationSession(), "INVITE", session.getRemoteParty(), secondPartyAddress); logger.info("Found second party -- sending INVITE to " + secondPartyAddress); String contentType = resp.getContentType(); if (contentType.trim().equals("application/sdp")) { invite.setContent(resp.getContent(), "application/sdp"); } session.setAttribute("LinkedSession", invite.getSession()); invite.getSession().setAttribute("LinkedSession", session); SipServletRequest ack = resp.createAck(); invite.getSession().setAttribute("FirstPartyAck", ack); invite.getSession().setAttribute("FirstPartyContent", resp.getContent()); Call call = (Call) session.getAttribute("call"); // The call links the two sessions, add the new session to the call call.addSession(invite.getSession()); invite.getSession().setAttribute("call", call); invite.send(); session.setAttribute("InviteSent", Boolean.TRUE); } else { String cSeqValue = resp.getHeader("CSeq"); if (cSeqValue.indexOf("INVITE") != -1) { logger.info("Got OK from second party -- sending ACK"); SipServletRequest secondPartyAck = resp.createAck(); SipServletRequest firstPartyAck = (SipServletRequest) resp.getSession().getAttribute("FirstPartyAck"); // if (resp.getContentType() != null && // resp.getContentType().equals("application/sdp")) { firstPartyAck.setContent(resp.getContent(), "application/sdp"); secondPartyAck.setContent( resp.getSession().getAttribute("FirstPartyContent"), "application/sdp"); // } firstPartyAck.send(); secondPartyAck.send(); } } } }