Search in sources :

Example 1 with OfferMessage

use of org.whispersystems.signalservice.api.messages.calls.OfferMessage in project libsignal-service-java by signalapp.

the class SignalServiceMessageSender method createCallContent.

private byte[] createCallContent(SignalServiceCallMessage callMessage) {
    Content.Builder container = Content.newBuilder();
    CallMessage.Builder builder = CallMessage.newBuilder();
    if (callMessage.getOfferMessage().isPresent()) {
        OfferMessage offer = callMessage.getOfferMessage().get();
        builder.setOffer(CallMessage.Offer.newBuilder().setId(offer.getId()).setDescription(offer.getDescription()));
    } else if (callMessage.getAnswerMessage().isPresent()) {
        AnswerMessage answer = callMessage.getAnswerMessage().get();
        builder.setAnswer(CallMessage.Answer.newBuilder().setId(answer.getId()).setDescription(answer.getDescription()));
    } else if (callMessage.getIceUpdateMessages().isPresent()) {
        List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();
        for (IceUpdateMessage update : updates) {
            builder.addIceUpdate(CallMessage.IceUpdate.newBuilder().setId(update.getId()).setSdp(update.getSdp()).setSdpMid(update.getSdpMid()).setSdpMLineIndex(update.getSdpMLineIndex()));
        }
    } else if (callMessage.getHangupMessage().isPresent()) {
        builder.setHangup(CallMessage.Hangup.newBuilder().setId(callMessage.getHangupMessage().get().getId()));
    } else if (callMessage.getBusyMessage().isPresent()) {
        builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
    }
    container.setCallMessage(builder);
    return container.build().toByteArray();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) CallMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.CallMessage) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage)

Example 2 with OfferMessage

use of org.whispersystems.signalservice.api.messages.calls.OfferMessage in project Signal-Android by WhisperSystems.

the class SignalServiceContent method createCallMessage.

private static SignalServiceCallMessage createCallMessage(SignalServiceProtos.CallMessage content) {
    boolean isMultiRing = content.getMultiRing();
    Integer destinationDeviceId = content.hasDestinationDeviceId() ? content.getDestinationDeviceId() : null;
    if (content.hasOffer()) {
        SignalServiceProtos.CallMessage.Offer offerContent = content.getOffer();
        return SignalServiceCallMessage.forOffer(new OfferMessage(offerContent.getId(), offerContent.hasSdp() ? offerContent.getSdp() : null, OfferMessage.Type.fromProto(offerContent.getType()), offerContent.hasOpaque() ? offerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.hasAnswer()) {
        SignalServiceProtos.CallMessage.Answer answerContent = content.getAnswer();
        return SignalServiceCallMessage.forAnswer(new AnswerMessage(answerContent.getId(), answerContent.hasSdp() ? answerContent.getSdp() : null, answerContent.hasOpaque() ? answerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.getIceUpdateCount() > 0) {
        List<IceUpdateMessage> iceUpdates = new LinkedList<>();
        for (SignalServiceProtos.CallMessage.IceUpdate iceUpdate : content.getIceUpdateList()) {
            iceUpdates.add(new IceUpdateMessage(iceUpdate.getId(), iceUpdate.hasOpaque() ? iceUpdate.getOpaque().toByteArray() : null, iceUpdate.hasSdp() ? iceUpdate.getSdp() : null));
        }
        return SignalServiceCallMessage.forIceUpdates(iceUpdates, isMultiRing, destinationDeviceId);
    } else if (content.hasLegacyHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getLegacyHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasBusy()) {
        SignalServiceProtos.CallMessage.Busy busy = content.getBusy();
        return SignalServiceCallMessage.forBusy(new BusyMessage(busy.getId()), isMultiRing, destinationDeviceId);
    } else if (content.hasOpaque()) {
        SignalServiceProtos.CallMessage.Opaque opaque = content.getOpaque();
        return SignalServiceCallMessage.forOpaque(new OpaqueMessage(opaque.getData().toByteArray(), null), isMultiRing, destinationDeviceId);
    }
    return SignalServiceCallMessage.empty();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) LinkedList(java.util.LinkedList) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) HangupMessage(org.whispersystems.signalservice.api.messages.calls.HangupMessage) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) BusyMessage(org.whispersystems.signalservice.api.messages.calls.BusyMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 3 with OfferMessage

use of org.whispersystems.signalservice.api.messages.calls.OfferMessage in project Signal-Android by WhisperSystems.

the class WebRtcCallService method handleOutgoingCall.

private void handleOutgoingCall(Intent intent) {
    Log.w(TAG, "handleOutgoingCall...");
    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.pendingIceUpdates = new LinkedList<>();
        initializeVideo();
        sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
        lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
        audioManager.initializeAudioForCall();
        audioManager.startOutgoingRinger(OutgoingRinger.Type.SONAR);
        bluetoothStateManager.setWantsConnection(true);
        setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
        DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getNumber());
        timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
        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);
                    WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, isAlwaysTurn);
                    WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
                    WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
                    SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
                    WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
                    Log.w(TAG, "Sending offer: " + sdp.description);
                    ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
                    listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {

                        @Override
                        public void onFailureContinue(Throwable error) {
                            Log.w(TAG, error);
                            if (error instanceof UntrustedIdentityException) {
                                sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException) error).getIdentityKey(), localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof UnregisteredUserException) {
                                sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof IOException) {
                                sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            }
                            terminate();
                        }
                    });
                } catch (PeerConnectionException e) {
                    Log.w(TAG, e);
                    terminate();
                }
            }
        });
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PeerConnection(org.webrtc.PeerConnection) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PeerConnectionWrapper(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper) MediaConstraints(org.webrtc.MediaConstraints) ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with OfferMessage

use of org.whispersystems.signalservice.api.messages.calls.OfferMessage in project Signal-Android by signalapp.

the class WebRtcCallService method handleOutgoingCall.

private void handleOutgoingCall(Intent intent) {
    Log.w(TAG, "handleOutgoingCall...");
    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();
        sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
        lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
        audioManager.initializeAudioForCall();
        audioManager.startOutgoingRinger(OutgoingRinger.Type.SONAR);
        bluetoothStateManager.setWantsConnection(true);
        setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
        DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getAddress());
        timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
        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);
                    WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, isAlwaysTurn);
                    WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
                    WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
                    SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
                    WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
                    Log.w(TAG, "Sending offer: " + sdp.description);
                    ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
                    listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {

                        @Override
                        public void onFailureContinue(Throwable error) {
                            Log.w(TAG, error);
                            if (error instanceof UntrustedIdentityException) {
                                sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException) error).getIdentityKey(), localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof UnregisteredUserException) {
                                sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof IOException) {
                                sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            }
                            terminate();
                        }
                    });
                } catch (PeerConnectionException e) {
                    Log.w(TAG, e);
                    terminate();
                }
            }
        });
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PeerConnection(org.webrtc.PeerConnection) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PeerConnectionWrapper(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper) MediaConstraints(org.webrtc.MediaConstraints) ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) List(java.util.List) LinkedList(java.util.LinkedList)

Example 5 with OfferMessage

use of org.whispersystems.signalservice.api.messages.calls.OfferMessage in project Signal-Android by WhisperSystems.

the class WebRtcActionProcessor method handleSendOffer.

@NonNull
protected final WebRtcServiceState handleSendOffer(@NonNull WebRtcServiceState currentState, @NonNull CallMetadata callMetadata, @NonNull OfferMetadata offerMetadata, boolean broadcast) {
    Log.i(tag, "handleSendOffer(): id: " + callMetadata.getCallId().format(callMetadata.getRemoteDevice()));
    OfferMessage offerMessage = new OfferMessage(callMetadata.getCallId().longValue(), offerMetadata.getSdp(), offerMetadata.getOfferType(), offerMetadata.getOpaque());
    Integer destinationDeviceId = broadcast ? null : callMetadata.getRemoteDevice();
    SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOffer(offerMessage, true, destinationDeviceId);
    Recipient callRecipient = currentState.getCallInfoState().getCallRecipient();
    RecipientUtil.shareProfileIfFirstSecureMessage(context, callRecipient);
    webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
    return currentState;
}
Also used : OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NonNull(androidx.annotation.NonNull)

Aggregations

OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)7 SignalServiceCallMessage (org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage)5 LinkedList (java.util.LinkedList)4 AnswerMessage (org.whispersystems.signalservice.api.messages.calls.AnswerMessage)4 IceUpdateMessage (org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage)4 IOException (java.io.IOException)3 List (java.util.List)3 OpaqueMessage (org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)3 NonNull (androidx.annotation.NonNull)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 ListenableFutureTask (org.thoughtcrime.securesms.util.ListenableFutureTask)2 PeerConnectionWrapper (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper)2 PeerConnectionException (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)2 MediaConstraints (org.webrtc.MediaConstraints)2 PeerConnection (org.webrtc.PeerConnection)2 SessionDescription (org.webrtc.SessionDescription)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)2 SuppressLint (android.annotation.SuppressLint)1