Search in sources :

Example 61 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class ActiveCallActionProcessorDelegate method handleLocalHangup.

@Override
@NonNull
protected WebRtcServiceState handleLocalHangup(@NonNull WebRtcServiceState currentState) {
    RemotePeer remotePeer = currentState.getCallInfoState().getActivePeer();
    if (remotePeer == null) {
        Log.i(tag, "handleLocalHangup(): no active peer");
    } else {
        Log.i(tag, "handleLocalHangup(): call_id: " + remotePeer.getCallId());
    }
    ApplicationDependencies.getSignalServiceAccountManager().cancelInFlightRequests();
    ApplicationDependencies.getSignalServiceMessageSender().cancelInFlightRequests();
    try {
        webRtcInteractor.getCallManager().hangup();
        currentState = currentState.builder().changeCallInfoState().callState(WebRtcViewModel.State.CALL_DISCONNECTED).build();
        webRtcInteractor.postStateUpdate(currentState);
        return terminate(currentState, remotePeer);
    } catch (CallException e) {
        return callFailure(currentState, "hangup() failed: ", e);
    }
}
Also used : CallException(org.signal.ringrtc.CallException) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 62 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class ActiveCallActionProcessorDelegate method handleSetupFailure.

@Override
@NonNull
protected WebRtcServiceState handleSetupFailure(@NonNull WebRtcServiceState currentState, @NonNull CallId callId) {
    Log.i(tag, "handleSetupFailure(): call_id: " + callId);
    RemotePeer activePeer = currentState.getCallInfoState().getActivePeer();
    if (activePeer != null && activePeer.getCallId().equals(callId)) {
        try {
            if (activePeer.getState() == CallState.DIALING || activePeer.getState() == CallState.REMOTE_RINGING) {
                webRtcInteractor.getCallManager().hangup();
            } else {
                webRtcInteractor.getCallManager().drop(callId);
            }
        } catch (CallException e) {
            return callFailure(currentState, "Unable to drop call due to setup failure", e);
        }
        currentState = currentState.builder().changeCallInfoState().callState(WebRtcViewModel.State.NETWORK_FAILURE).build();
        webRtcInteractor.postStateUpdate(currentState);
        if (activePeer.getState() == CallState.ANSWERING || activePeer.getState() == CallState.LOCAL_RINGING) {
            webRtcInteractor.insertMissedCall(activePeer, activePeer.getCallStartTimestamp(), currentState.getCallSetupState(activePeer).isRemoteVideoOffer());
        }
        return terminate(currentState, activePeer);
    }
    return currentState;
}
Also used : CallException(org.signal.ringrtc.CallException) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 63 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class ActiveCallActionProcessorDelegate method handleScreenSharingEnable.

@Override
@NonNull
protected WebRtcServiceState handleScreenSharingEnable(@NonNull WebRtcServiceState currentState, boolean enable) {
    RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();
    Log.i(tag, "handleScreenSharingEnable(): call_id: " + activePeer.getCallId() + " enable: " + enable);
    CallParticipant oldParticipant = Objects.requireNonNull(currentState.getCallInfoState().getRemoteCallParticipant(activePeer.getRecipient()));
    CallParticipant newParticipant = oldParticipant.withScreenSharingEnabled(enable);
    return currentState.builder().changeCallInfoState().putParticipant(activePeer.getRecipient(), newParticipant).build();
}
Also used : CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 64 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class ActiveCallActionProcessorDelegate method handleEndedRemote.

@Override
@NonNull
protected WebRtcServiceState handleEndedRemote(@NonNull WebRtcServiceState currentState, @NonNull CallEvent endedRemoteEvent, @NonNull RemotePeer remotePeer) {
    Log.i(tag, "handleEndedRemote(): call_id: " + remotePeer.getCallId() + " action: " + endedRemoteEvent);
    WebRtcViewModel.State state = currentState.getCallInfoState().getCallState();
    RemotePeer activePeer = currentState.getCallInfoState().getActivePeer();
    boolean remotePeerIsActive = remotePeer.callIdEquals(activePeer);
    boolean outgoingBeforeAccept = remotePeer.getState() == CallState.DIALING || remotePeer.getState() == CallState.REMOTE_RINGING;
    boolean incomingBeforeAccept = remotePeer.getState() == CallState.ANSWERING || remotePeer.getState() == CallState.LOCAL_RINGING;
    if (remotePeerIsActive && ENDED_REMOTE_EVENT_TO_STATE.containsKey(endedRemoteEvent)) {
        state = Objects.requireNonNull(ENDED_REMOTE_EVENT_TO_STATE.get(endedRemoteEvent));
    }
    if (endedRemoteEvent == CallEvent.ENDED_REMOTE_HANGUP) {
        if (remotePeerIsActive) {
            state = outgoingBeforeAccept ? WebRtcViewModel.State.RECIPIENT_UNAVAILABLE : WebRtcViewModel.State.CALL_DISCONNECTED;
        }
        if (incomingBeforeAccept) {
            webRtcInteractor.insertMissedCall(remotePeer, remotePeer.getCallStartTimestamp(), currentState.getCallSetupState(remotePeer).isRemoteVideoOffer());
        }
    } else if (endedRemoteEvent == CallEvent.ENDED_REMOTE_BUSY && remotePeerIsActive) {
        activePeer.receivedBusy();
        OutgoingRinger ringer = new OutgoingRinger(context);
        ringer.start(OutgoingRinger.Type.BUSY);
        ThreadUtil.runOnMainDelayed(ringer::stop, SignalCallManager.BUSY_TONE_LENGTH);
    } else if (endedRemoteEvent == CallEvent.ENDED_REMOTE_GLARE && incomingBeforeAccept) {
        webRtcInteractor.insertMissedCall(remotePeer, remotePeer.getCallStartTimestamp(), currentState.getCallSetupState(remotePeer).isRemoteVideoOffer());
    }
    if (state == WebRtcViewModel.State.CALL_ACCEPTED_ELSEWHERE) {
        webRtcInteractor.insertReceivedCall(remotePeer, currentState.getCallSetupState(remotePeer).isRemoteVideoOffer());
    }
    currentState = currentState.builder().changeCallInfoState().callState(state).build();
    webRtcInteractor.postStateUpdate(currentState);
    return terminate(currentState, remotePeer);
}
Also used : OutgoingRinger(org.thoughtcrime.securesms.webrtc.audio.OutgoingRinger) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) WebRtcViewModel(org.thoughtcrime.securesms.events.WebRtcViewModel) NonNull(androidx.annotation.NonNull)

Example 65 with RemotePeer

use of org.thoughtcrime.securesms.ringrtc.RemotePeer in project Signal-Android by signalapp.

the class CallSetupActionProcessorDelegate method handleCallConnected.

@Override
@NonNull
public WebRtcServiceState handleCallConnected(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer) {
    if (!remotePeer.callIdEquals(currentState.getCallInfoState().getActivePeer())) {
        Log.w(tag, "handleCallConnected(): Ignoring for inactive call.");
        return currentState;
    }
    Log.i(tag, "handleCallConnected(): call_id: " + remotePeer.getCallId());
    RemotePeer activePeer = currentState.getCallInfoState().requireActivePeer();
    ApplicationDependencies.getAppForegroundObserver().removeListener(webRtcInteractor.getForegroundListener());
    webRtcInteractor.startAudioCommunication();
    activePeer.connected();
    if (currentState.getLocalDeviceState().getCameraState().isEnabled()) {
        webRtcInteractor.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
    } else {
        webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
    }
    currentState = currentState.builder().actionProcessor(new ConnectedCallActionProcessor(webRtcInteractor)).changeCallInfoState().callState(WebRtcViewModel.State.CALL_CONNECTED).callConnectedTime(System.currentTimeMillis()).commit().changeLocalDeviceState().build();
    webRtcInteractor.setCallInProgressNotification(TYPE_ESTABLISHED, activePeer);
    webRtcInteractor.unregisterPowerButtonReceiver();
    try {
        CallManager callManager = webRtcInteractor.getCallManager();
        callManager.setCommunicationMode();
        callManager.setAudioEnable(currentState.getLocalDeviceState().isMicrophoneEnabled());
        callManager.setVideoEnable(currentState.getLocalDeviceState().getCameraState().isEnabled());
    } catch (CallException e) {
        return callFailure(currentState, "Enabling audio/video failed: ", e);
    }
    if (currentState.getCallSetupState(activePeer).isAcceptWithVideo()) {
        currentState = currentState.getActionProcessor().handleSetEnableVideo(currentState, true);
    }
    if (currentState.getCallSetupState(activePeer).isAcceptWithVideo() || currentState.getLocalDeviceState().getCameraState().isEnabled()) {
        webRtcInteractor.setDefaultAudioDevice(SignalAudioManager.AudioDevice.SPEAKER_PHONE, false);
    } else {
        webRtcInteractor.setDefaultAudioDevice(SignalAudioManager.AudioDevice.EARPIECE, false);
    }
    return currentState;
}
Also used : CallManager(org.signal.ringrtc.CallManager) CallException(org.signal.ringrtc.CallException) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Aggregations

RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)70 NonNull (androidx.annotation.NonNull)44 CallException (org.signal.ringrtc.CallException)32 CallId (org.signal.ringrtc.CallId)14 Recipient (org.thoughtcrime.securesms.recipients.Recipient)14 CallParticipant (org.thoughtcrime.securesms.events.CallParticipant)10 GroupId (org.thoughtcrime.securesms.groups.GroupId)10 WebRtcData (org.thoughtcrime.securesms.service.webrtc.WebRtcData)10 OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)10 Context (android.content.Context)8 Build (android.os.Build)8 Nullable (androidx.annotation.Nullable)8 Stream (com.annimon.stream.Stream)8 IOException (java.io.IOException)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 LinkedList (java.util.LinkedList)8 List (java.util.List)8 UUID (java.util.UUID)8 Log (org.signal.core.util.logging.Log)8