Skip to content

Commit 1b2709e

Browse files
author
atsakiridis
committed
Did various fixes, but still having some timeouts when sending BYE to proxy
1 parent 310221f commit 1b2709e

File tree

1 file changed

+59
-14
lines changed
  • restcomm.android.client.sdk/src/main/java/org/mobicents/restcomm/android/sipua/impl

1 file changed

+59
-14
lines changed

restcomm.android.client.sdk/src/main/java/org/mobicents/restcomm/android/sipua/impl/SipManager.java

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ enum CallDirection {
114114

115115
// Constructors/Initializers
116116
public SipManager(SipProfile sipProfile, boolean connectivity) {
117+
RCLogger.v(TAG, "SipManager()");
118+
117119
this.sipProfile = sipProfile;
118120
initialize(connectivity);
119121
}
@@ -137,6 +139,11 @@ private boolean initialize(boolean connectivity)
137139
}
138140
*/
139141
properties.setProperty("android.javax.sip.STACK_NAME", "androidSip");
142+
// You need 16 for logging traces. 32 for debug + traces.
143+
// Your code will limp at 32 but it is best for debugging.
144+
properties.setProperty("android.gov.nist.javax.sip.TRACE_LEVEL", "32");
145+
properties.setProperty("android.gov.nist.javax.sip.DEBUG_LOG", "/storage/emulated/legacy/Download/debug.log");
146+
properties.setProperty("android.gov.nist.javax.sip.SERVER_LOG", "/storage/emulated/legacy/Download/server.log");
140147
//latestProxyIp = sipProfile.getRemoteIp();
141148

142149
try {
@@ -254,6 +261,8 @@ public void bind()
254261

255262
public void refreshNetworking(int expiry) throws ParseException, TransactionUnavailableException
256263
{
264+
RCLogger.v(TAG, "refreshNetworking()");
265+
257266
// keep the old contact around to use for unregistration
258267
Address oldAddress = createContactAddress();
259268

@@ -295,6 +304,8 @@ public void setCustomHeaders(HashMap<String, String> customHeaders) {
295304
// *** Client API (used by DeviceImpl) *** //
296305
// Accept incoming call
297306
public void AcceptCall(final int port) {
307+
RCLogger.v(TAG, "AcceptCall()");
308+
298309
if (currentServerTransaction == null)
299310
return;
300311
Thread thread = new Thread() {
@@ -350,6 +361,8 @@ public void run() {
350361
}
351362

352363
public void AcceptCallWebrtc(final String sdp) {
364+
RCLogger.v(TAG, "AcceptCallWebrtc()");
365+
353366
if (currentServerTransaction == null)
354367
return;
355368
Thread thread = new Thread() {
@@ -393,12 +406,15 @@ public void run() {
393406
}
394407

395408
public void RejectCall() {
409+
RCLogger.v(TAG, "RejectCall()");
410+
396411
sendDecline(currentServerTransaction.getRequest());
397412
sipManagerState = SipManagerState.IDLE;
398413
}
399414

400415
@Override
401416
public void Register(int expiry) throws ParseException, TransactionUnavailableException {
417+
RCLogger.v(TAG, "Register()");
402418
if (sipProvider == null) {
403419
return;
404420
}
@@ -448,6 +464,7 @@ public void run() {
448464
}
449465

450466
public void Unregister(Address contact) throws ParseException, TransactionUnavailableException {
467+
RCLogger.v(TAG, "Unregister()");
451468
if (sipProvider == null) {
452469
return;
453470
}
@@ -500,6 +517,7 @@ public void run() {
500517
@Override
501518
public void Call(String to, int localRtpPort, HashMap<String, String> sipHeaders)
502519
throws NotInitializedException, ParseException {
520+
RCLogger.v(TAG, "Call()");
503521
if (!initialized)
504522
throw new NotInitializedException("Sip Stack not initialized");
505523
this.sipManagerState = SipManagerState.CALLING;
@@ -513,6 +531,7 @@ public void run() {
513531
// note: we might need to make this 'syncrhonized' to avoid race at some point
514532
currentClientTransaction = transaction;
515533
transaction.sendRequest();
534+
dialog = transaction.getDialog();
516535
} catch (Exception e) {
517536
// DNS error (error resolving registrar URI)
518537
dispatchSipError(ISipEventListener.ErrorContext.ERROR_CONTEXT_CALL, RCClient.ErrorCodes.SIGNALLING_CALL_ERROR,
@@ -533,6 +552,7 @@ public void run() {
533552

534553
public void CallWebrtc(String to, String sdp, HashMap<String, String> sipHeaders)
535554
throws NotInitializedException, ParseException {
555+
RCLogger.v(TAG, "CallWebrtc()");
536556
if (!initialized)
537557
throw new NotInitializedException("Sip Stack not initialized");
538558
this.sipManagerState = SipManagerState.CALLING;
@@ -546,6 +566,7 @@ public void run() {
546566
// note: we might need to make this 'syncrhonized' to avoid race at some point
547567
currentClientTransaction = transaction;
548568
transaction.sendRequest();
569+
dialog = transaction.getDialog();
549570
} catch (Exception e) {
550571
// DNS error (error resolving registrar URI)
551572
dispatchSipError(ISipEventListener.ErrorContext.ERROR_CONTEXT_CALL, RCClient.ErrorCodes.SIGNALLING_CALL_ERROR,
@@ -567,6 +588,7 @@ public void run() {
567588
@Override
568589
public void SendMessage(String to, String message)
569590
throws NotInitializedException {
591+
RCLogger.v(TAG, "SendMessage()");
570592
if (!initialized)
571593
throw new NotInitializedException("Sip Stack not initialized");
572594
Message inviteRequest = new Message();
@@ -598,6 +620,7 @@ public void run() {
598620
@Override
599621
public void Hangup() throws NotInitializedException
600622
{
623+
RCLogger.v(TAG, "Hangup()");
601624
if (!initialized)
602625
throw new NotInitializedException("Sip Stack not initialized");
603626

@@ -615,6 +638,7 @@ else if (direction == CallDirection.INCOMING) {
615638

616639
public void Cancel() throws NotInitializedException
617640
{
641+
RCLogger.v(TAG, "Cancel");
618642
if (!initialized)
619643
throw new NotInitializedException("Sip Stack not initialized");
620644

@@ -628,6 +652,7 @@ public void Cancel() throws NotInitializedException
628652

629653
@Override
630654
public void SendDTMF(String digit) throws NotInitializedException {
655+
RCLogger.v(TAG, "SendDTMF()");
631656
if (!initialized)
632657
throw new NotInitializedException("Sip Stack not initialized");
633658

@@ -691,6 +716,7 @@ public void run() {
691716
// *** JAIN SIP: Incoming request *** //
692717
@Override
693718
public void processRequest(RequestEvent arg0) {
719+
RCLogger.v(TAG, "processRequest()");
694720
Request request = (Request) arg0.getRequest();
695721
ServerTransaction serverTransactionId = arg0.getServerTransaction();
696722
SIPMessage sp = (SIPMessage) request;
@@ -728,17 +754,16 @@ public void processRequest(RequestEvent arg0) {
728754
// *** JAIN SIP: Incoming response *** //
729755
@Override
730756
public void processResponse(ResponseEvent arg0) {
731-
732757
ResponseEventExt responseEvent = (ResponseEventExt)arg0;
733758
Response response = (Response) arg0.getResponse();
734-
RCLogger.i(TAG, "processResponse, status code: " + response.getStatusCode());
759+
RCLogger.i(TAG, "processResponse(), status code: " + response.getStatusCode());
735760

736-
Dialog responseDialog = null;
761+
//Dialog responseDialog = null;
737762
ClientTransaction tid = arg0.getClientTransaction();
738763
if (tid != null) {
739-
responseDialog = tid.getDialog();
764+
//responseDialog = tid.getDialog();
740765
} else {
741-
responseDialog = arg0.getDialog();
766+
//responseDialog = arg0.getDialog();
742767
}
743768
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
744769
if (response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED
@@ -765,6 +790,10 @@ public void processResponse(ResponseEvent arg0) {
765790
.handleChallenge(response, tid, sipProvider, 5, true);
766791
currentClientTransaction = inviteTid;
767792
inviteTid.sendRequest();
793+
if (cseq.getMethod().equals(Request.INVITE)) {
794+
// only update the dialog if we are responding to INVITE with new invite
795+
dialog = inviteTid.getDialog();
796+
}
768797
registerAuthenticationMap.put(callId.toString(), attempts + 1);
769798
}
770799
else {
@@ -787,10 +816,10 @@ public void processResponse(ResponseEvent arg0) {
787816
if (cseq.getMethod().equals(Request.INVITE)) {
788817
RCLogger.i(TAG, "Dialog after 200 OK " + dialog);
789818
try {
790-
Request ackRequest = responseDialog.createAck(cseq
791-
.getSeqNumber());
792819
RCLogger.i(TAG, "Sending ACK");
793-
responseDialog.sendAck(ackRequest);
820+
//Request ackRequest = dialog.createAck(cseq.getSeqNumber());
821+
Request ackRequest = dialog.createAck(((CSeqHeader)response.getHeader(CSeqHeader.NAME)).getSeqNumber());
822+
dialog.sendAck(ackRequest);
794823
byte[] rawContent = response.getRawContent();
795824
String sdpContent = new String(rawContent, "UTF-8");
796825
SDPAnnounceParser parser = new SDPAnnounceParser(sdpContent);
@@ -900,7 +929,7 @@ public void processTransactionTerminated(TransactionTerminatedEvent transactionT
900929
// *** JAIN SIP: Dialog terminated *** //
901930
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
902931
RCLogger.i(TAG, "SipManager.processDialogTerminated: " + dialogTerminatedEvent.toString() + "\n" +
903-
"\tdialog: " + dialogTerminatedEvent.getDialog());
932+
"\tdialog: " + dialogTerminatedEvent.getDialog().toString());
904933
}
905934

906935
// *** JAIN SIP: Time out *** //
@@ -930,7 +959,7 @@ public void processTimeout(TimeoutEvent timeoutEvent) {
930959
// Send event to the higher level listener (i.e. DeviceImpl)
931960
@SuppressWarnings("unchecked")
932961
private void dispatchSipEvent(SipEvent sipEvent) {
933-
RCLogger.i(TAG, "Dispatching event:" + sipEvent.type);
962+
RCLogger.i(TAG, "dispatchSipEvent():" + sipEvent.type);
934963
ArrayList<ISipEventListener> tmpSipListenerList;
935964

936965
synchronized (this) {
@@ -947,7 +976,7 @@ private void dispatchSipEvent(SipEvent sipEvent) {
947976

948977
// caller needs to run on main thread
949978
private void dispatchSipError(ISipEventListener.ErrorContext errorContext, RCClient.ErrorCodes errorCode, String errorText) {
950-
RCLogger.i(TAG, "Dispatching error:" + errorText);
979+
RCLogger.i(TAG, "dispatchSipError():" + errorText);
951980
ArrayList<ISipEventListener> tmpSipListenerList;
952981

953982
synchronized (this) {
@@ -964,8 +993,8 @@ private void dispatchSipError(ISipEventListener.ErrorContext errorContext, RCCli
964993

965994
private void incomingBye(Request request,
966995
ServerTransaction serverTransactionId) {
996+
RCLogger.i(TAG, "incomingBye()");
967997
try {
968-
RCLogger.i(TAG, "BYE received");
969998
if (serverTransactionId == null) {
970999
RCLogger.i(TAG, "shootist: null TID.");
9711000
return;
@@ -986,6 +1015,8 @@ private void incomingBye(Request request,
9861015

9871016
private void incomingInvite(RequestEvent requestEvent,
9881017
ServerTransaction serverTransaction) {
1018+
RCLogger.i(TAG, "incomingInvite()");
1019+
9891020
if (sipManagerState != SipManagerState.IDLE
9901021
&& sipManagerState != SipManagerState.READY
9911022
&& sipManagerState != SipManagerState.INCOMING
@@ -996,6 +1027,7 @@ private void incomingInvite(RequestEvent requestEvent,
9961027
sipManagerState = SipManagerState.INCOMING;
9971028
Request request = requestEvent.getRequest();
9981029
SIPMessage sm = (SIPMessage) request;
1030+
dialog = serverTransaction.getDialog();
9991031

10001032
try {
10011033
ServerTransaction st = requestEvent.getServerTransaction();
@@ -1033,6 +1065,8 @@ private void incomingInvite(RequestEvent requestEvent,
10331065

10341066
private void incomingCancel(Request request,
10351067
ServerTransaction serverTransactionId) {
1068+
RCLogger.i(TAG, "incomingCancel()");
1069+
10361070
try {
10371071
RCLogger.i(TAG, "CANCEL received");
10381072
if (serverTransactionId == null) {
@@ -1061,6 +1095,8 @@ private void incomingCancel(Request request,
10611095
}
10621096

10631097
private void sendDecline(Request request) {
1098+
RCLogger.i(TAG, "sendDecline()");
1099+
10641100
Thread thread = new Thread() {
10651101
public void run() {
10661102

@@ -1088,6 +1124,8 @@ public void run() {
10881124
}
10891125

10901126
private void sendOk(RequestEvent requestEvt) {
1127+
RCLogger.i(TAG, "sendOk()");
1128+
10911129
Response response;
10921130
try {
10931131
response = messageFactory.createResponse(200,
@@ -1115,8 +1153,8 @@ private void sendOk(RequestEvent requestEvt) {
11151153
// introduced separate sendByeClient method because the client initiated BYE
11161154
// is different -at some point we should merge those methods
11171155
private void sendByeClient(Transaction transaction) {
1118-
RCLogger.i(TAG, "Sending BYE request");
1119-
final Dialog dialog = transaction.getDialog();
1156+
RCLogger.i(TAG, "sendByeClient()");
1157+
//final Dialog dialog = transaction.getDialog();
11201158
if (dialog == null) {
11211159
RCLogger.i(TAG, "Hmm, weird: dialog is already terminated -avoiding BYE");
11221160
}
@@ -1155,6 +1193,7 @@ public void run() {
11551193
}
11561194

11571195
private void sendCancel(ClientTransaction transaction) {
1196+
RCLogger.i(TAG, "sendCancel()");
11581197
try {
11591198
final Request request = transaction.createCancel();
11601199

@@ -1180,6 +1219,7 @@ public void run() {
11801219

11811220
// *** Various Helpers *** //
11821221
public static String getIPAddress(boolean useIPv4) {
1222+
RCLogger.i(TAG, "getIPAddress()");
11831223
try {
11841224
List<NetworkInterface> interfaces = Collections
11851225
.list(NetworkInterface.getNetworkInterfaces());
@@ -1211,6 +1251,7 @@ public static String getIPAddress(boolean useIPv4) {
12111251
}
12121252

12131253
public ArrayList<ViaHeader> createViaHeader() {
1254+
RCLogger.i(TAG, "createViaHeader()");
12141255
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
12151256
ViaHeader myViaHeader;
12161257
try {
@@ -1228,6 +1269,7 @@ public ArrayList<ViaHeader> createViaHeader() {
12281269
}
12291270

12301271
public Address createContactAddress() {
1272+
RCLogger.i(TAG, "createContactAddress()");
12311273
try {
12321274
return this.addressFactory.createAddress("sip:"
12331275
+ getSipProfile().getSipUserName() + "@"
@@ -1239,19 +1281,22 @@ public Address createContactAddress() {
12391281
}
12401282

12411283
public synchronized void addSipListener(ISipEventListener listener) {
1284+
RCLogger.i(TAG, "addSipListener()");
12421285
if (!sipEventListenerList.contains(listener)) {
12431286
sipEventListenerList.add(listener);
12441287
}
12451288
}
12461289

12471290
public synchronized void removeSipListener(ISipEventListener listener) {
1291+
RCLogger.i(TAG, "createContactAddress()");
12481292
if (sipEventListenerList.contains(listener)) {
12491293
sipEventListenerList.remove(listener);
12501294
}
12511295
}
12521296

12531297
public UserAgentHeader generateUserAgentHeader()
12541298
{
1299+
RCLogger.i(TAG, "generateUserAgentHeader()");
12551300
List<String> userAgentTokens = new LinkedList<String>();
12561301
UserAgentHeader header = null;
12571302
userAgentTokens.add(USERAGENT_STRING);

0 commit comments

Comments
 (0)