Search in sources :

Example 16 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project mollyim-android by mollyim.

the class OutgoingCallActionProcessor method handleStartOutgoingCall.

@Override
@NonNull
protected WebRtcServiceState handleStartOutgoingCall(@NonNull WebRtcServiceState currentState, @NonNull RemotePeer remotePeer, @NonNull OfferMessage.Type offerType) {
    Log.i(TAG, "handleStartOutgoingCall():");
    WebRtcServiceStateBuilder builder = currentState.builder();
    remotePeer.dialing();
    Log.i(TAG, "assign activePeer callId: " + remotePeer.getCallId() + " key: " + remotePeer.hashCode() + " type: " + offerType);
    boolean isVideoCall = offerType == OfferMessage.Type.VIDEO_CALL;
    webRtcInteractor.setCallInProgressNotification(TYPE_OUTGOING_RINGING, remotePeer);
    webRtcInteractor.setDefaultAudioDevice(isVideoCall ? SignalAudioManager.AudioDevice.SPEAKER_PHONE : SignalAudioManager.AudioDevice.EARPIECE, false);
    webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context));
    webRtcInteractor.initializeAudioForCall();
    webRtcInteractor.startOutgoingRinger();
    RecipientUtil.setAndSendUniversalExpireTimerIfNecessary(context, Recipient.resolved(remotePeer.getId()), SignalDatabase.threads().getThreadIdIfExistsFor(remotePeer.getId()));
    webRtcInteractor.insertOutgoingCall(remotePeer, isVideoCall);
    EglBaseWrapper.replaceHolder(EglBaseWrapper.OUTGOING_PLACEHOLDER, remotePeer.getCallId().longValue());
    webRtcInteractor.retrieveTurnServers(remotePeer);
    return builder.changeCallSetupState(remotePeer.getCallId()).enableVideoOnCreate(isVideoCall).commit().changeCallInfoState().activePeer(remotePeer).callState(WebRtcViewModel.State.CALL_OUTGOING).commit().changeLocalDeviceState().build();
}
Also used : WebRtcServiceStateBuilder(org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder) NonNull(androidx.annotation.NonNull)

Example 17 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project mollyim-android by mollyim.

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 18 with WebRtcServiceStateBuilder

use of org.thoughtcrime.securesms.service.webrtc.state.WebRtcServiceStateBuilder in project mollyim-android by mollyim.

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