Search in sources :

Example 6 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project Signal-Android by signalapp.

the class GroupJoiningActionProcessor method handleGroupLocalDeviceStateChanged.

@Override
@NonNull
protected WebRtcServiceState handleGroupLocalDeviceStateChanged(@NonNull WebRtcServiceState currentState) {
    Log.i(tag, "handleGroupLocalDeviceStateChanged():");
    GroupCall groupCall = currentState.getCallInfoState().requireGroupCall();
    GroupCall.LocalDeviceState device = groupCall.getLocalDeviceState();
    Log.i(tag, "local device changed: " + device.getConnectionState() + " " + device.getJoinState());
    WebRtcServiceStateBuilder builder = currentState.builder();
    switch(device.getConnectionState()) {
        case NOT_CONNECTED:
        case RECONNECTING:
            builder.changeCallInfoState().groupCallState(WebRtcUtil.groupCallStateForConnection(device.getConnectionState())).commit();
            break;
        case CONNECTING:
        case CONNECTED:
            if (device.getJoinState() == GroupCall.JoinState.JOINED) {
                webRtcInteractor.setCallInProgressNotification(TYPE_ESTABLISHED, currentState.getCallInfoState().getCallRecipient());
                webRtcInteractor.startAudioCommunication();
                if (currentState.getLocalDeviceState().getCameraState().isEnabled()) {
                    webRtcInteractor.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
                } else {
                    webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
                }
                try {
                    groupCall.setOutgoingVideoMuted(!currentState.getLocalDeviceState().getCameraState().isEnabled());
                    groupCall.setOutgoingAudioMuted(!currentState.getLocalDeviceState().isMicrophoneEnabled());
                    groupCall.setBandwidthMode(NetworkUtil.getCallingBandwidthMode(context, device.getNetworkRoute().getLocalAdapterType()));
                } catch (CallException e) {
                    Log.e(tag, e);
                    throw new RuntimeException(e);
                }
                if (FeatureFlags.groupCallRinging() && currentState.getCallSetupState(RemotePeer.GROUP_CALL_ID).shouldRingGroup()) {
                    try {
                        groupCall.ringAll();
                    } catch (CallException e) {
                        return groupCallFailure(currentState, "Unable to ring group", e);
                    }
                }
                builder.changeCallInfoState().callState(WebRtcViewModel.State.CALL_CONNECTED).groupCallState(WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED).callConnectedTime(System.currentTimeMillis()).commit().changeLocalDeviceState().commit().actionProcessor(new GroupConnectedActionProcessor(webRtcInteractor));
            } else if (device.getJoinState() == GroupCall.JoinState.JOINING) {
                builder.changeCallInfoState().groupCallState(WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINING).commit();
            } else {
                builder.changeCallInfoState().groupCallState(WebRtcUtil.groupCallStateForConnection(device.getConnectionState())).commit();
            }
            break;
    }
    return builder.build();
}
Also used : CallException(org.signal.ringrtc.CallException) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) GroupCall(org.signal.ringrtc.GroupCall) NonNull(androidx.annotation.NonNull)

Example 7 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project Signal-Android by signalapp.

the class WebRtcVideoUtil method initializeVideo.

@NonNull
public static WebRtcServiceState initializeVideo(@NonNull Context context, @NonNull CameraEventListener cameraEventListener, @NonNull WebRtcServiceState currentState, @NonNull Object eglBaseHolder) {
    final WebRtcServiceStateBuilder builder = currentState.builder();
    ThreadUtil.runOnMainSync(() -> {
        EglBaseWrapper eglBase = EglBaseWrapper.acquireEglBase(eglBaseHolder);
        BroadcastVideoSink localSink = new BroadcastVideoSink(eglBase, true, false, currentState.getLocalDeviceState().getOrientation().getDegrees());
        Camera camera = new Camera(context, cameraEventListener, eglBase, CameraState.Direction.FRONT);
        camera.setOrientation(currentState.getLocalDeviceState().getOrientation().getDegrees());
        builder.changeVideoState().eglBase(eglBase).localSink(localSink).camera(camera).commit().changeLocalDeviceState().cameraState(camera.getCameraState()).commit();
    });
    return builder.build();
}
Also used : BroadcastVideoSink(org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) EglBaseWrapper(org.thoughtcrime.securesms.components.webrtc.EglBaseWrapper) Camera(org.thoughtcrime.securesms.ringrtc.Camera) NonNull(androidx.annotation.NonNull)

Example 8 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project Signal-Android by WhisperSystems.

the class WebRtcActionProcessor method handleMessageSentError.

@NonNull
protected WebRtcServiceState handleMessageSentError(@NonNull WebRtcServiceState currentState, @NonNull CallId callId, @NonNull WebRtcViewModel.State errorCallState, @NonNull Optional<IdentityKey> identityKey) {
    Log.w(tag, "handleMessageSentError():");
    try {
        webRtcInteractor.getCallManager().messageSendFailure(callId);
    } catch (CallException e) {
        currentState = callFailure(currentState, "callManager.messageSendFailure() failed: ", e);
    }
    RemotePeer activePeer = currentState.getCallInfoState().getActivePeer();
    if (activePeer == null) {
        return currentState;
    }
    WebRtcServiceStateBuilder builder = currentState.builder();
    if (errorCallState == WebRtcViewModel.State.UNTRUSTED_IDENTITY) {
        CallParticipant participant = Objects.requireNonNull(currentState.getCallInfoState().getRemoteCallParticipant(activePeer.getRecipient()));
        CallParticipant untrusted = participant.withIdentityKey(identityKey.orElse(null));
        builder.changeCallInfoState().callState(WebRtcViewModel.State.UNTRUSTED_IDENTITY).putParticipant(activePeer.getRecipient(), untrusted).commit();
    }
    return builder.build();
}
Also used : CallException(org.signal.ringrtc.CallException) CallParticipant(org.thoughtcrime.securesms.events.CallParticipant) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) RemotePeer(org.thoughtcrime.securesms.ringrtc.RemotePeer) NonNull(androidx.annotation.NonNull)

Example 9 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project Signal-Android by WhisperSystems.

the class WebRtcActionProcessor method callFailure.

// endregion
// region Global call operations
@NonNull
public WebRtcServiceState callFailure(@NonNull WebRtcServiceState currentState, @Nullable String message, @Nullable Throwable error) {
    Log.w(tag, "callFailure(): " + message, error);
    WebRtcServiceStateBuilder builder = currentState.builder();
    if (currentState.getCallInfoState().getActivePeer() != null) {
        builder.changeCallInfoState().callState(WebRtcViewModel.State.CALL_DISCONNECTED);
    }
    try {
        webRtcInteractor.getCallManager().reset();
    } catch (CallException e) {
        Log.w(tag, "Unable to reset call manager: ", e);
    }
    EglBaseWrapper.forceRelease();
    currentState = builder.changeCallInfoState().clearPeerMap().build();
    return terminate(currentState, currentState.getCallInfoState().getActivePeer());
}
Also used : CallException(org.signal.ringrtc.CallException) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) NonNull(androidx.annotation.NonNull)

Example 10 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project Signal-Android by WhisperSystems.

the class GroupJoiningActionProcessor method handleGroupLocalDeviceStateChanged.

@Override
@NonNull
protected WebRtcServiceState handleGroupLocalDeviceStateChanged(@NonNull WebRtcServiceState currentState) {
    Log.i(tag, "handleGroupLocalDeviceStateChanged():");
    GroupCall groupCall = currentState.getCallInfoState().requireGroupCall();
    GroupCall.LocalDeviceState device = groupCall.getLocalDeviceState();
    Log.i(tag, "local device changed: " + device.getConnectionState() + " " + device.getJoinState());
    WebRtcServiceStateBuilder builder = currentState.builder();
    switch(device.getConnectionState()) {
        case NOT_CONNECTED:
        case RECONNECTING:
            builder.changeCallInfoState().groupCallState(WebRtcUtil.groupCallStateForConnection(device.getConnectionState())).commit();
            break;
        case CONNECTING:
        case CONNECTED:
            if (device.getJoinState() == GroupCall.JoinState.JOINED) {
                webRtcInteractor.setCallInProgressNotification(TYPE_ESTABLISHED, currentState.getCallInfoState().getCallRecipient());
                webRtcInteractor.startAudioCommunication();
                if (currentState.getLocalDeviceState().getCameraState().isEnabled()) {
                    webRtcInteractor.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
                } else {
                    webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
                }
                try {
                    groupCall.setOutgoingVideoMuted(!currentState.getLocalDeviceState().getCameraState().isEnabled());
                    groupCall.setOutgoingAudioMuted(!currentState.getLocalDeviceState().isMicrophoneEnabled());
                    groupCall.setBandwidthMode(NetworkUtil.getCallingBandwidthMode(context, device.getNetworkRoute().getLocalAdapterType()));
                } catch (CallException e) {
                    Log.e(tag, e);
                    throw new RuntimeException(e);
                }
                if (FeatureFlags.groupCallRinging() && currentState.getCallSetupState(RemotePeer.GROUP_CALL_ID).shouldRingGroup()) {
                    try {
                        groupCall.ringAll();
                    } catch (CallException e) {
                        return groupCallFailure(currentState, "Unable to ring group", e);
                    }
                }
                builder.changeCallInfoState().callState(WebRtcViewModel.State.CALL_CONNECTED).groupCallState(WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINED).callConnectedTime(System.currentTimeMillis()).commit().changeLocalDeviceState().commit().actionProcessor(new GroupConnectedActionProcessor(webRtcInteractor));
            } else if (device.getJoinState() == GroupCall.JoinState.JOINING) {
                builder.changeCallInfoState().groupCallState(WebRtcViewModel.GroupCallState.CONNECTED_AND_JOINING).commit();
            } else {
                builder.changeCallInfoState().groupCallState(WebRtcUtil.groupCallStateForConnection(device.getConnectionState())).commit();
            }
            break;
    }
    return builder.build();
}
Also used : CallException(org.signal.ringrtc.CallException) WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) GroupCall(org.signal.ringrtc.GroupCall) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)18 WebRtcServiceStateBuilder (org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder)18 CallException (org.signal.ringrtc.CallException)9 Camera (org.thoughtcrime.securesms.ringrtc.Camera)6 GroupCall (org.signal.ringrtc.GroupCall)3 BroadcastVideoSink (org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink)3 EglBaseWrapper (org.thoughtcrime.securesms.components.webrtc.EglBaseWrapper)3 CallParticipant (org.thoughtcrime.securesms.events.CallParticipant)3 RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)3