|
|
|
@ -415,72 +415,68 @@ public class WebRtcCallService extends Service implements InjectableType,
|
|
|
|
|
|
|
|
|
|
if (callState != CallState.STATE_IDLE) throw new IllegalStateException("Dialing from non-idle?");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.callState = CallState.STATE_DIALING;
|
|
|
|
|
this.recipient = getRemoteRecipient(intent);
|
|
|
|
|
this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
|
|
|
|
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
initializeVideo();
|
|
|
|
|
this.callState = CallState.STATE_DIALING;
|
|
|
|
|
this.recipient = getRemoteRecipient(intent);
|
|
|
|
|
this.callId = new SecureRandom().nextLong();
|
|
|
|
|
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
|
|
|
|
|
audioManager.initializeAudioForCall();
|
|
|
|
|
audioManager.startOutgoingRinger(OutgoingRinger.Type.RINGING);
|
|
|
|
|
bluetoothStateManager.setWantsConnection(true);
|
|
|
|
|
initializeVideo();
|
|
|
|
|
|
|
|
|
|
setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
|
|
|
|
|
DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getAddress());
|
|
|
|
|
sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
|
|
|
|
|
audioManager.initializeAudioForCall();
|
|
|
|
|
audioManager.startOutgoingRinger(OutgoingRinger.Type.RINGING);
|
|
|
|
|
bluetoothStateManager.setWantsConnection(true);
|
|
|
|
|
|
|
|
|
|
timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
|
|
|
|
|
setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
|
|
|
|
|
DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getAddress());
|
|
|
|
|
|
|
|
|
|
retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccessContinue(List<PeerConnection.IceServer> result) {
|
|
|
|
|
try {
|
|
|
|
|
boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
|
|
|
|
|
timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, WebRtcCallService.this, eglBase, isAlwaysTurn);
|
|
|
|
|
WebRtcCallService.this.localCameraState = WebRtcCallService.this.peerConnection.getCameraState();
|
|
|
|
|
WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
|
|
|
|
|
WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
|
|
|
|
|
retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccessContinue(List<PeerConnection.IceServer> result) {
|
|
|
|
|
try {
|
|
|
|
|
boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
|
|
|
|
|
|
|
|
|
|
SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
|
|
|
|
|
WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
|
|
|
|
|
WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, WebRtcCallService.this, eglBase, isAlwaysTurn);
|
|
|
|
|
WebRtcCallService.this.localCameraState = WebRtcCallService.this.peerConnection.getCameraState();
|
|
|
|
|
WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
|
|
|
|
|
WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Sending offer: " + sdp.description);
|
|
|
|
|
SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
|
|
|
|
|
WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
|
|
|
|
|
|
|
|
|
|
ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
|
|
|
|
|
Log.i(TAG, "Sending offer: " + sdp.description);
|
|
|
|
|
|
|
|
|
|
listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailureContinue(Throwable error) {
|
|
|
|
|
Log.w(TAG, error);
|
|
|
|
|
ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
|
|
|
|
|
|
|
|
|
|
if (error instanceof UntrustedIdentityException) {
|
|
|
|
|
sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException)error).getIdentityKey(), localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
} else if (error instanceof UnregisteredUserException) {
|
|
|
|
|
sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
} else if (error instanceof IOException) {
|
|
|
|
|
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
}
|
|
|
|
|
listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailureContinue(Throwable error) {
|
|
|
|
|
Log.w(TAG, error);
|
|
|
|
|
|
|
|
|
|
terminate();
|
|
|
|
|
if (error instanceof UntrustedIdentityException) {
|
|
|
|
|
sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException)error).getIdentityKey(), localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
} else if (error instanceof UnregisteredUserException) {
|
|
|
|
|
sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
} else if (error instanceof IOException) {
|
|
|
|
|
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (recipient != null) {
|
|
|
|
|
sendMessage(viewModelStateFor(callState), recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
terminate();
|
|
|
|
|
}
|
|
|
|
|
} catch (PeerConnectionException e) {
|
|
|
|
|
Log.w(TAG, e);
|
|
|
|
|
terminate();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (recipient != null) {
|
|
|
|
|
sendMessage(viewModelStateFor(callState), recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
|
|
|
}
|
|
|
|
|
} catch (PeerConnectionException e) {
|
|
|
|
|
Log.w(TAG, e);
|
|
|
|
|
terminate();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
throw new AssertionError(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleResponseMessage(Intent intent) {
|
|
|
|
|