public void hangup ( boolean shouldSendHangupSignal ) { if ( ! isHangingUp ) { isHangingUp = true ; if ( shouldSendHangupSignal ) { try { JSONObject data = new JSONObject ( "{'signalType':'bye','version':'1.0'}" ) ; data . put ( "target" , directConnectionOnly ? "directConnection" : "call" ) ; data . put ( "sessionId" , sessionID ) ; data . put ( "signalId" , Respoke . makeGUID ( ) ) ; // Keep a second reference to the listener since the disconnect method will clear it before the success handler is fired final WeakReference < Listener > hangupListener = listenerReference ; if ( null != signalingChannel ) { signalingChannel . sendSignal ( data , toEndpointId , toConnection , toType , true , new Respoke . TaskCompletionListener ( ) { @ Override public void onSuccess ( ) { if ( null != hangupListener ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { Listener listener = hangupListener . get ( ) ; if ( null != listener ) { listener . onHangup ( RespokeCall . this ) ; } } } ) ; } } @ Override public void onError ( String errorMessage ) { postErrorToListener ( errorMessage ) ; } } ) ; } } catch ( JSONException e ) { postErrorToListener ( "Error encoding signal to json" ) ; } } disconnect ( ) ; } }
Tear down the call and release resources