private void sendRequest(final SipRequestVerb verb, final Request request) { Thread transactionHandler = new Thread() { public void run() { try { // Create the client transaction // TODO put this in Connection class sipConnection.setClientTransaction( sipConnection.getProvider().getNewClientTransaction(request)); final ClientTransaction clientTransaction = sipConnection.getClientTransaction(); // and send the request if (SipRequestVerb.REGISTER == verb || SipRequestVerb.INVITE == verb || SipRequestVerb.MESSAGE == verb || SipRequestVerb.CANCEL == verb) { clientTransaction.sendRequest(); } else if (SipRequestVerb.BYE == verb) { sipConnection.getCurrentDialog().sendRequest(clientTransaction); } else if (SipRequestVerb.ACK == verb) { sipConnection.getCurrentDialog().sendAck(request); } } catch (Exception e) { e.printStackTrace(); } } }; transactionHandler.start(); if (SipRequestVerb.INVITE == verb || SipRequestVerb.MESSAGE == verb) { sipConnection.setCurrentDialog(sipConnection.getClientTransaction().getDialog()); } }
private void add(SipConnection conn) { if (SC_DBG) log("add:"); SipCall call = conn.getCall(); if (call == this) return; if (call != null) call.mConnections.remove(conn); mConnections.add(conn); conn.changeOwner(this); }
void initIncomingCall(SipAudioCall sipAudioCall, boolean makeCallWait) { SipProfile callee = sipAudioCall.getPeerProfile(); SipConnection c = new SipConnection(this, callee); mConnections.add(c); Call.State newState = makeCallWait ? State.WAITING : State.INCOMING; c.initIncomingCall(sipAudioCall, newState); setState(newState); notifyNewRingingConnectionP(c); }
public void customizeRequest(SipRequest request, SipConnection connection) { SipConnector connector = _tx.getRequest().getConnection().getConnector(); if (getRecordRoute() && connection.getConnector() != connector) { SipURI rrUri = newProxyURI(connection.getConnector(), true); rrUri.setParameter(SipParams.DRR, "2"); _branchRRUri.setParameter(SipParams.DRR, ""); if (connector.getTransportOrdinal() == SipConnectors.TCP_ORDINAL) _branchRRUri.setTransportParam("tcp"); if (connection.getConnector().getTransportOrdinal() == SipConnectors.TCP_ORDINAL) rrUri.setTransportParam("tcp"); request.addRecordRoute(new NameAddr(rrUri)); } }
public boolean sendAck(final SipRequestState state) { // create new response for the request try { Request request = sipConnection.getCurrentDialog().createAck(sipConnection.incrementCallSequence()); if (null != stateMachine && stateMachine.canRequestBeSent(SipRequestVerb.ACK, request)) { sendRequest(SipRequestVerb.ACK, request); return true; } sendRequest(SipRequestVerb.ACK, request); } catch (Exception e) { e.printStackTrace(); } return false; }
void onConnectionStateChanged(SipConnection conn) { // this can be called back when a conf call is formed if (SC_DBG) log("onConnectionStateChanged: conn=" + conn); if (mState != State.ACTIVE) { setState(conn.getState()); } }
void merge(SipCall that) throws CallStateException { if (SC_DBG) log("merge:"); AudioGroup audioGroup = getAudioGroup(); // copy to an array to avoid concurrent modification as connections // in that.connections will be removed in add(SipConnection). Connection[] cc = that.mConnections.toArray(new Connection[that.mConnections.size()]); for (Connection c : cc) { SipConnection conn = (SipConnection) c; add(conn); if (conn.getState() == Call.State.HOLDING) { conn.unhold(audioGroup); } } that.setState(Call.State.IDLE); }
private void takeOver(SipCall that) { if (SC_DBG) log("takeOver"); mConnections = that.mConnections; mState = that.mState; for (Connection c : mConnections) { ((SipConnection) c).changeOwner(this); } }
void unhold() throws CallStateException { if (SC_DBG) log("unhold:"); setState(State.ACTIVE); AudioGroup audioGroup = new AudioGroup(); for (Connection c : mConnections) { ((SipConnection) c).unhold(audioGroup); } setAudioGroupMode(); }
Connection dial(String originalNumber) throws SipException { if (SC_DBG) log("dial: num=" + (SC_VDBG ? originalNumber : "xxx")); // TODO: Should this be synchronized? String calleeSipUri = originalNumber; if (!calleeSipUri.contains("@")) { String replaceStr = Pattern.quote(mProfile.getUserName() + "@"); calleeSipUri = mProfile.getUriString().replaceFirst(replaceStr, calleeSipUri + "@"); } try { SipProfile callee = new SipProfile.Builder(calleeSipUri).build(); SipConnection c = new SipConnection(this, callee, originalNumber); c.dial(); mConnections.add(c); setState(Call.State.DIALING); return c; } catch (ParseException e) { throw new SipException("dial", e); } }
public boolean sendInvite( final SipRequestState state, final SipProfile sipProfile, final SipContact sipContact) { SipRequest sipRequest = createSipRequest(SipRequestVerb.INVITE, state, sipProfile, sipContact); if (null != stateMachine && stateMachine.canRequestBeSent(SipRequestVerb.INVITE, sipRequest.getRequest())) { sipConnection.setCurrentCallId(sipRequest.getCallIdHeader()); sendRequest(SipRequestVerb.INVITE, sipRequest.getRequest()); return true; } return false; }
public boolean sendRegister(final SipRequestState state, final SipProfile sipProfile) { SipRequest sipRequest = createSipRequest(SipRequestVerb.REGISTER, state, sipProfile, null); if (null != stateMachine && stateMachine.canRequestBeSent(SipRequestVerb.REGISTER, sipRequest.getRequest())) { sipConnection.setCurrentCallId(sipRequest.getCallIdHeader()); sendRequest(SipRequestVerb.REGISTER, sipRequest.getRequest()); return true; } return false; }
public boolean sendBye(final SipRequestState state) { try { // create Request from dialog Request request = sipConnection.getCurrentDialog().createRequest(Request.BYE); if (null != stateMachine && stateMachine.canRequestBeSent(SipRequestVerb.BYE, request)) { sendRequest(SipRequestVerb.BYE, request); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
public boolean sendCancel(final SipRequestState state) { try { // create Request from dialog Request request = sipConnection.getClientTransaction().createCancel(); if (null != stateMachine && stateMachine.canRequestBeSent(SipRequestVerb.CANCEL, request)) { sendRequest(SipRequestVerb.CANCEL, request); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
private SipRequest createSipRequest( final SipRequestVerb sipRequestVerb, final SipRequestState state, final SipProfile sipProfile, final SipContact sipContact, final String textMessage) { // On REGISTER method, the sip contact must be the same as sip // profile sender. final SipContact newSipContact = (null == sipContact ? new SipContact(sipProfile) : sipContact); SipRequest sipRequest = null; try { sipRequest = new SipRequest( state, sipProfile, newSipContact, addressFactory, headerFactory, messageFactory, sipConnection.getProvider(), sipRequestVerbToRequestMethod(sipRequestVerb), sipConnection.getCallSequence(), 70, 300, textMessage); // update current CallId header of sipConnection sipConnection.setCurrentCallId(sipRequest.getCallIdHeader()); } catch (ParseException | InvalidArgumentException | SipException | SdpException e) { e.printStackTrace(); } return sipRequest; }
private void sendResponse( SipRequestVerb verb, final int sipResponseCode, final Request incomingRequest, final Response response, final ServerTransaction associatedTransactionWithIncomingRequest, final SipProfile sipProfile) { try { if (null == associatedTransactionWithIncomingRequest) { // Create the contact name address SipURI contactURI = addressFactory.createSipURI(sipProfile.getUsername(), sipProfile.getLocalIpAddress()); contactURI.setPort(sipProfile.getLocalSipPort()); Address contactAddress = addressFactory.createAddress(contactURI); contactAddress.setDisplayName(sipProfile.getDisplayName()); // Create a new Contact header ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress); contactHeader.setExpires(300); // 5 minutes response.addHeader(contactHeader); ContentTypeHeader contentTypeHeader = null; Object content = null; if (SipRequestVerb.INVITE == verb) { contentTypeHeader = headerFactory.createContentTypeHeader("application", "sdp"); SessionDescription sdp = SipRequestUtils.createSDP(incomingRequest, sipProfile); content = sdp.toString(); } else if (SipRequestVerb.MESSAGE == verb) { contentTypeHeader = headerFactory.createContentTypeHeader("text", "plain"); content = incomingRequest.getContent().toString(); } response.setContent(content, contentTypeHeader); // Send the created response if (sipConnection.getServerTransaction() == null) sipConnection.setServerTransaction( sipConnection.getProvider().getNewServerTransaction(incomingRequest)); Thread transactionHandler = new Thread() { public void run() { try { sipConnection.getServerTransaction().sendResponse(response); } catch (Exception e) { e.printStackTrace(); } } }; transactionHandler.start(); } else { Thread associatedTransactionHandler = new Thread() { public void run() { try { associatedTransactionWithIncomingRequest.sendResponse(response); } catch (Exception e) { e.printStackTrace(); } } }; associatedTransactionHandler.start(); } } catch (Exception e) { e.printStackTrace(); } }
void hold() throws CallStateException { if (SC_DBG) log("hold:"); setState(State.HOLDING); for (Connection c : mConnections) ((SipConnection) c).hold(); setAudioGroupMode(); }
void setMute(boolean muted) { if (SC_DBG) log("setMute: muted=" + muted); for (Connection c : mConnections) { ((SipConnection) c).setMute(muted); } }