Search in sources :

Example 1 with OutgoingRinger

use of org.thoughtcrime.securesms.webrtc.audio.OutgoingRinger in project Signal-Android by WhisperSystems.

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 2 with OutgoingRinger

use of org.thoughtcrime.securesms.webrtc.audio.OutgoingRinger 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)

Aggregations

NonNull (androidx.annotation.NonNull)2 WebRtcViewModel (org.thoughtcrime.securesms.events.WebRtcViewModel)2 RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)2 OutgoingRinger (org.thoughtcrime.securesms.webrtc.audio.OutgoingRinger)2