Skip to content

Commit

Permalink
Send hangup message when terminating on call errors.
Browse files Browse the repository at this point in the history
When errors occur during a call, attempt to send the remote peer a
hangup message before terminating the call.  This allows the remote
peer to shutdown their side of the call in a timely manner.
  • Loading branch information
cbrune-signal authored and alan-signal committed Nov 9, 2019
1 parent 7348237 commit 17a1fe9
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/org/thoughtcrime/securesms/service/WebRtcCallService.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private void handleResponseMessage(Intent intent) {
} catch (CallException e) {
Log.w(TAG, e);
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
terminate();
hangupAndTerminate();
}
}

Expand Down Expand Up @@ -549,7 +549,7 @@ private void activateCallMedia() {
} catch (CallException e) {
Log.w(TAG, e);
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
terminate();
hangupAndTerminate();
}

}
Expand Down Expand Up @@ -672,13 +672,13 @@ private void handleAnswerCall(Intent intent) {
intent.putExtra(EXTRA_CALL_ID, callId);
intent.putExtra(EXTRA_REMOTE_RECIPIENT, recipient.getId());
handleCallConnected(intent);
activateCallMedia();
} catch (CallException e) {
Log.w(TAG, e);
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
terminate();
hangupAndTerminate();
}

activateCallMedia();
}

private void handleDenyCall(Intent intent) {
Expand Down Expand Up @@ -770,7 +770,8 @@ private void handleSetMuteVideo(Intent intent) {
} catch (CallException e) {
Log.w(TAG, e);
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
terminate();
hangupAndTerminate();
return;
}
}

Expand Down Expand Up @@ -890,7 +891,7 @@ private void handleCallError(Intent intent) {
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
break;
}
terminate();
hangupAndTerminate();

}

Expand Down Expand Up @@ -934,6 +935,22 @@ private void setCallInProgressNotification(int type, Recipient recipient) {
CallNotificationBuilder.getCallInProgressNotification(this, type, recipient));
}

private void hangupAndTerminate() {
if (callConnection != null && callId != null) {
accountManager.cancelInFlightRequests();
messageSender.cancelInFlightRequests();

try {
callConnection.hangUp();
} catch (CallException e) {
Log.w(TAG, e);
}

}

terminate();
}

private synchronized void terminate() {
Log.i(TAG, "terminate()");

Expand Down

0 comments on commit 17a1fe9

Please sign in to comment.