@@ -182,6 +182,17 @@ public RCConnection(RCConnectionListener connectionListener)
182182 this .listener = connectionListener ;
183183 }
184184
185+ // could not use the previous constructor with connectionListener = null, hence created this:
186+ public RCConnection ()
187+ {
188+ this .listener = null ;
189+ }
190+
191+ public void updateListener (RCConnectionListener listener )
192+ {
193+ this .listener = listener ;
194+ }
195+
185196 // 'Copy' constructor
186197 public RCConnection (RCConnection connection )
187198 {
@@ -202,12 +213,32 @@ public void setupWebrtcAndCall(GLSurfaceView videoView, SharedPreferences prefs,
202213 iceServers .add (new PeerConnection .IceServer ("stun:stun.l.google.com:19302" , "" , "" ));
203214 this .signalingParameters = new SignalingParameters (iceServers , true , "" , sipUri , "" , null , null );
204215
205- startCall ();
216+ startCall (this .signalingParameters );
217+ }
218+
219+ public void setupWebrtcForIncomingCall (GLSurfaceView videoView , SharedPreferences prefs )
220+ {
221+ initializeWebrtc (videoView , prefs );
222+ }
223+
224+ // TODO: remove this when ready
225+ public void answerCall (String sipUri , String sdp )
226+ {
227+
228+ LinkedList <PeerConnection .IceServer > iceServers = new LinkedList <>();
229+ iceServers .add (new PeerConnection .IceServer ("stun:stun.l.google.com:19302" , "" , "" ));
230+ this .signalingParameters = new SignalingParameters (iceServers , false , "" , sipUri , "" , null , null );
231+ SignalingParameters params = SignalingParameters .extractCandidates (new SessionDescription (SessionDescription .Type .OFFER , sdp ));
232+ this .signalingParameters .offerSdp = params .offerSdp ;
233+ this .signalingParameters .iceCandidates = params .iceCandidates ;
234+
235+ startCall (this .signalingParameters );
206236 }
207237
208238 // initialize webrtc facilities for the call
209239 private void initializeWebrtc (GLSurfaceView videoView , SharedPreferences prefs )
210240 {
241+ Log .e (TAG , "@@@@@ initializeWebrtc " );
211242 Context context = RCClient .getInstance ().context ;
212243 keyprefVideoCallEnabled = context .getString (R .string .pref_videocall_key );
213244 keyprefResolution = context .getString (R .string .pref_resolution_key );
@@ -231,6 +262,7 @@ private void initializeWebrtc(GLSurfaceView videoView, SharedPreferences prefs)
231262
232263 public void setupWebrtc (GLSurfaceView videoView , SharedPreferences prefs )
233264 {
265+ Log .e (TAG , "@@@@@ setupWebrtc" );
234266 Context context = RCClient .getInstance ().context ;
235267 //Thread.setDefaultUncaughtExceptionHandler(
236268 // new UnhandledExceptionHandler(this));
@@ -393,8 +425,9 @@ public void run() {
393425 */
394426 }
395427
396- private void startCall ()
428+ private void startCall (SignalingParameters signalingParameters )
397429 {
430+ Log .e (TAG , "@@@@@ startCall" );
398431 callStartedTimeMs = System .currentTimeMillis ();
399432
400433 // Start room connection.
@@ -423,6 +456,7 @@ public void run() {
423456
424457 // Disconnect from remote resources, dispose of local resources, and exit.
425458 public void disconnectWebrtc () {
459+ Log .e (TAG , "@@@@@ disconnectWebrtc" );
426460 activityRunning = false ;
427461 /* Signaling is already disconnected
428462 if (appRtcClient != null) {
@@ -462,6 +496,7 @@ private void createPeerConnectionFactory() {
462496 Runnable myRunnable = new Runnable () {
463497 @ Override
464498 public void run () {
499+ Log .e (TAG , "@@@@@ createPeerConnectionFactory" );
465500 if (peerConnectionClient == null ) {
466501 final long delta = System .currentTimeMillis () - callStartedTimeMs ;
467502 Log .d (TAG , "Creating peer connection factory, delay=" + delta + "ms" );
@@ -502,6 +537,7 @@ public void onLocalDescription(final SessionDescription sdp) {
502537 Runnable myRunnable = new Runnable () {
503538 @ Override
504539 public void run () {
540+ Log .e (TAG , "@@@@@ onLocalDescription" );
505541 if (signalingParameters != null && !signalingParameters .sipUrl .isEmpty ()) {
506542 logAndToast ("Sending " + sdp .type + ", delay=" + delta + "ms" );
507543 if (signalingParameters .initiator ) {
@@ -510,6 +546,13 @@ public void run() {
510546 //appRtcClient.sendOfferSdp(sdp);
511547 } else {
512548 //appRtcClient.sendAnswerSdp(sdp);
549+ connection .signalingParameters .answerSdp = sdp ;
550+ // for an incoming call we have already stored the offer candidates there, now
551+ // we are done with those and need to come up with answer candidates
552+ // TODO: this might prove dangerous as the signalingParms struct used to be all const,
553+ // but I changed it since with JAIN sip signalling where various parts are picked up
554+ // at different points in time
555+ connection .signalingParameters .iceCandidates .clear ();
513556 }
514557 }
515558 }
@@ -524,7 +567,7 @@ public void onIceCandidate(final IceCandidate candidate) {
524567 Runnable myRunnable = new Runnable () {
525568 @ Override
526569 public void run () {
527- Log .e (TAG , "onIceCandidate:" );
570+ Log .e (TAG , "@@@@@ onIceCandidate:" );
528571 connection .signalingParameters .addIceCandidate (candidate );
529572 /*
530573 if (appRtcClient != null) {
@@ -544,9 +587,17 @@ public void onIceGatheringComplete()
544587 Runnable myRunnable = new Runnable () {
545588 @ Override
546589 public void run () {
547- Log .e (TAG , "onIceGatheringComplete" );
548- // we have gathered all candidates and SDP. Combine then in SIP SDP and send over to JAIN SIP
549- DeviceImpl .GetInstance ().CallWebrtc (signalingParameters .sipUrl , connection .signalingParameters .generateSipSdp ());
590+ Log .e (TAG , "@@@@@ onIceGatheringComplete" );
591+ if (signalingParameters .initiator ) {
592+ // we have gathered all candidates and SDP. Combine then in SIP SDP and send over to JAIN SIP
593+ DeviceImpl .GetInstance ().CallWebrtc (signalingParameters .sipUrl ,
594+ connection .signalingParameters .generateSipSdp (connection .signalingParameters .offerSdp ,
595+ connection .signalingParameters .iceCandidates ));
596+ }
597+ else {
598+ DeviceImpl .GetInstance ().AcceptWebrtc (connection .signalingParameters .generateSipSdp (connection .signalingParameters .answerSdp ,
599+ connection .signalingParameters .iceCandidates ));
600+ }
550601 }
551602 };
552603 mainHandler .post (myRunnable );
@@ -560,6 +611,7 @@ public void onIceConnected() {
560611 Runnable myRunnable = new Runnable () {
561612 @ Override
562613 public void run () {
614+ Log .e (TAG , "@@@@@ onIceConnected" );
563615 logAndToast ("ICE connected, delay=" + delta + "ms" );
564616 iceConnected = true ;
565617 //callConnected();
@@ -574,6 +626,7 @@ public void onIceDisconnected() {
574626 Runnable myRunnable = new Runnable () {
575627 @ Override
576628 public void run () {
629+ Log .e (TAG , "@@@@@ onIceDisconnected" );
577630 logAndToast ("ICE disconnected" );
578631 iceConnected = false ;
579632 disconnect ();
@@ -584,6 +637,7 @@ public void run() {
584637
585638 @ Override
586639 public void onPeerConnectionClosed () {
640+ Log .e (TAG , "@@@@@ onPeerConnectionClosed" );
587641 }
588642
589643 @ Override
@@ -624,6 +678,7 @@ public void run() {
624678 }
625679
626680 private void onConnectedToRoomInternal (final SignalingParameters params ) {
681+ Log .e (TAG , "@@@@@ onConnectedToRoomInternal" );
627682 final long delta = System .currentTimeMillis () - callStartedTimeMs ;
628683
629684 signalingParameters = params ;
@@ -668,6 +723,7 @@ public void onRemoteDescription(final SessionDescription sdp) {
668723 Runnable myRunnable = new Runnable () {
669724 @ Override
670725 public void run () {
726+ Log .e (TAG , "@@@@@ onRemoteDescription" );
671727 if (peerConnectionClient == null ) {
672728 Log .e (TAG , "Received remote SDP for non-initilized peer connection." );
673729 return ;
@@ -690,6 +746,7 @@ public void run() {
690746
691747 //@Override
692748 public void onRemoteIceCandidates (final List <IceCandidate > candidates ) {
749+ Log .e (TAG , "@@@@@ onRemoteIceCandidates" );
693750 // no need to run it in UI thread it is already there due to onRemoteDescription
694751 if (peerConnectionClient == null ) {
695752 Log .e (TAG ,
@@ -770,6 +827,14 @@ public void accept()
770827 }
771828 }
772829
830+ private void acceptWebrtc (final String sdp )
831+ {
832+ if (haveConnectivity ()) {
833+ DeviceImpl .GetInstance ().AcceptWebrtc (sdp );
834+ this .state = state .CONNECTED ;
835+ }
836+ }
837+
773838 /**
774839 * Ignore incoming connection
775840 */
@@ -873,9 +938,10 @@ public void onSipUAConnected(SipEvent event)
873938 this .state = ConnectionState .CONNECTED ;
874939 final RCConnection finalConnection = new RCConnection (this );
875940
876- // notify RCDevice (this is temporary)
877- //RCDevice device = RCClient.getInstance().listDevices().get(0);
878- onRemoteDescription (event .sdp );
941+ // we want to notify webrtc onRemoteDescription *only* on an outgoing call
942+ if (!this .isIncoming ()) {
943+ onRemoteDescription (event .sdp );
944+ }
879945
880946 // Important: need to fire the event in UI context cause currently we 're in JAIN SIP thread
881947 Handler mainHandler = new Handler (RCClient .getInstance ().context .getMainLooper ());
0 commit comments