Skip to content

Commit

Permalink
Merge branch 'develop' into pinning_implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandar-apostolov authored Nov 16, 2023
2 parents 9a8081e + 1cba0fa commit cbff6ce
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class DirectCallActivity : ComponentActivity() {
}
is CancelCall -> {
lifecycleScope.launch {
val test = call.reject()
call.leave()
finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.util.Log
import com.google.android.gms.auth.GoogleAuthUtil
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter
Expand All @@ -29,7 +30,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import io.getstream.video.android.data.dto.GetGoogleAccountsResponseDto
import io.getstream.video.android.data.dto.asDomainModel
import io.getstream.video.android.models.GoogleAccount
import io.getstream.video.android.util.GoogleSignInHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
Expand All @@ -40,6 +40,7 @@ import javax.inject.Inject

class GoogleAccountRepository @Inject constructor(
@ApplicationContext private val context: Context,
private val googleSignInClient: GoogleSignInClient,
) {
private val baseUrl = "https://people.googleapis.com/v1/people:listDirectoryPeople"

Expand Down Expand Up @@ -76,8 +77,7 @@ class GoogleAccountRepository @Inject constructor(
}

private suspend fun signInSilently(): Boolean {
val gsc = GoogleSignInHelper.getGoogleSignInClient(context)
val task = gsc.silentSignIn()
val task = googleSignInClient.silentSignIn()

return if (task.isSuccessful) {
Log.d("Google Silent Sign In", "Successful")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
package io.getstream.video.android.di

import android.content.Context
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.Scope
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import io.getstream.video.android.R
import io.getstream.video.android.data.repositories.GoogleAccountRepository
import io.getstream.video.android.datastore.delegate.StreamUserDataStore
import javax.inject.Singleton
Expand All @@ -35,8 +40,20 @@ object AppModule {
return StreamUserDataStore.instance()
}

@Provides
@Singleton
fun provideGoogleSignInClient(
@ApplicationContext context: Context,
): GoogleSignInClient = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(context.getString(R.string.default_web_client_id))
.requestScopes(Scope("https://www.googleapis.com/auth/directory.readonly"))
.build()
.let { gso -> GoogleSignIn.getClient(context, gso) }

@Provides
fun provideGoogleAccountRepository(
@ApplicationContext context: Context,
) = GoogleAccountRepository(context)
googleSignInClient: GoogleSignInClient,
) = GoogleAccountRepository(context, googleSignInClient)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import io.getstream.video.android.core.RealtimeConnection
import io.getstream.video.android.core.call.state.ChooseLayout
import io.getstream.video.android.mock.StreamPreviewDataUtils
import io.getstream.video.android.mock.previewCall
import io.getstream.video.android.tooling.util.StreamFlavors
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -120,7 +121,8 @@ fun CallScreen(
call = call,
layout = layout,
enableInPictureInPicture = true,
enableDiagnostics = BuildConfig.DEBUG,
enableDiagnostics = BuildConfig.DEBUG ||
BuildConfig.FLAVOR == StreamFlavors.development,
onCallAction = {
when (it) {
ChooseLayout -> isShowingLayoutChooseMenu = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import io.getstream.video.android.BuildConfig
import io.getstream.video.android.R
import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.compose.ui.components.avatar.UserAvatar
import io.getstream.video.android.datastore.delegate.StreamUserDataStore
import io.getstream.video.android.mock.StreamPreviewDataUtils
import io.getstream.video.android.mock.previewUsers
import io.getstream.video.android.model.User
import io.getstream.video.android.tooling.util.StreamFlavors
import io.getstream.video.android.ui.theme.Colors
import io.getstream.video.android.ui.theme.StreamButton
Expand All @@ -95,6 +98,8 @@ fun CallJoinScreen(
navigateToBarcodeScanner: () -> Unit = {},
) {
val uiState by callJoinViewModel.uiState.collectAsState(CallJoinUiState.Nothing)
val user by callJoinViewModel.user.collectAsState(initial = null)

var isSignOutDialogVisible by remember { mutableStateOf(false) }
val isLoggedOut by callJoinViewModel.isLoggedOut.collectAsState(initial = false)

Expand All @@ -111,8 +116,8 @@ fun CallJoinScreen(
horizontalAlignment = Alignment.CenterHorizontally,
) {
CallJoinHeader(
user = user,
onAvatarLongClick = { isSignOutDialogVisible = true },
callJoinViewModel = callJoinViewModel,
onDirectCallClick = navigateToDirectCallJoin,
onSignOutClick = {
callJoinViewModel.autoLogInAfterLogOut = false
Expand Down Expand Up @@ -173,13 +178,11 @@ private fun HandleCallJoinUiState(
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun CallJoinHeader(
callJoinViewModel: CallJoinViewModel = hiltViewModel(),
user: User?,
onAvatarLongClick: () -> Unit,
onDirectCallClick: () -> Unit,
onSignOutClick: () -> Unit,
) {
val user by callJoinViewModel.user.collectAsState(initial = null)

Row(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -442,7 +445,13 @@ private fun CallJoinScreenPreview() {
VideoTheme {
StreamUserDataStore.install(LocalContext.current)
CallJoinScreen(
callJoinViewModel = CallJoinViewModel(StreamUserDataStore.instance()),
callJoinViewModel = CallJoinViewModel(
dataStore = StreamUserDataStore.instance(),
googleSignInClient = GoogleSignIn.getClient(
LocalContext.current,
GoogleSignInOptions.Builder().build(),
),
),
navigateToCallLobby = {},
navigateUpToLogin = {},
navigateToDirectCallJoin = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.getstream.video.android.ui.join

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.firebase.auth.FirebaseAuth
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import dagger.hilt.android.lifecycle.HiltViewModel
import io.getstream.chat.android.client.ChatClient
import io.getstream.video.android.core.Call
Expand All @@ -43,6 +43,7 @@ import javax.inject.Inject
@HiltViewModel
class CallJoinViewModel @Inject constructor(
private val dataStore: StreamUserDataStore,
private val googleSignInClient: GoogleSignInClient,
) : ViewModel() {
val user: Flow<User?> = dataStore.user
val isLoggedOut = dataStore.user.map { it == null }
Expand Down Expand Up @@ -97,7 +98,7 @@ class CallJoinViewModel @Inject constructor(

fun logOut() {
viewModelScope.launch {
FirebaseAuth.getInstance().signOut()
googleSignInClient.signOut()
dataStore.clear()
StreamVideo.instance().logOut()
ChatClient.instance().disconnect(true).enqueue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.SavedStateHandle
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import io.getstream.video.android.BuildConfig
import io.getstream.video.android.R
import io.getstream.video.android.compose.theme.VideoTheme
Expand Down Expand Up @@ -322,6 +324,10 @@ private fun CallLobbyScreenPreview() {
mapOf("cid" to "default:123"),
),
dataStore = StreamUserDataStore.instance(),
googleSignInClient = GoogleSignIn.getClient(
LocalContext.current,
GoogleSignInOptions.Builder().build(),
),
),
) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.util.Log
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.firebase.auth.FirebaseAuth
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import dagger.hilt.android.lifecycle.HiltViewModel
import io.getstream.chat.android.client.ChatClient
import io.getstream.video.android.core.Call
Expand Down Expand Up @@ -49,6 +49,7 @@ import javax.inject.Inject
class CallLobbyViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val dataStore: StreamUserDataStore,
private val googleSignInClient: GoogleSignInClient,
) : ViewModel() {

private val cid: String = checkNotNull(savedStateHandle["cid"])
Expand Down Expand Up @@ -167,7 +168,7 @@ class CallLobbyViewModel @Inject constructor(

fun signOut() {
viewModelScope.launch {
FirebaseAuth.getInstance().signOut()
googleSignInClient.signOut()
dataStore.clear()
StreamVideo.instance().logOut()
ChatClient.instance().disconnect(true).enqueue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import io.getstream.video.android.ui.theme.Colors
import io.getstream.video.android.ui.theme.LinkText
import io.getstream.video.android.ui.theme.LinkTextData
import io.getstream.video.android.ui.theme.StreamButton
import io.getstream.video.android.util.GoogleSignInHelper
import io.getstream.video.android.util.UserHelper

/**
Expand Down Expand Up @@ -344,9 +343,7 @@ private fun HandleLoginUiStates(
LaunchedEffect(key1 = loginUiState) {
when (loginUiState) {
is LoginUiState.GoogleSignIn -> {
signInLauncher.launch(
GoogleSignInHelper.getGoogleSignInClient(context).signInIntent,
)
signInLauncher.launch(loginUiState.signInIntent)
}

is LoginUiState.SignInComplete -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package io.getstream.video.android.ui.login

import android.content.Intent
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import dagger.hilt.android.lifecycle.HiltViewModel
import io.getstream.log.streamLog
import io.getstream.video.android.API_KEY
Expand Down Expand Up @@ -48,6 +50,7 @@ import javax.inject.Inject
@HiltViewModel
class LoginViewModel @Inject constructor(
private val dataStore: StreamUserDataStore,
private val googleSignInClient: GoogleSignInClient,
private val googleAccountRepository: GoogleAccountRepository,
) : ViewModel() {
var autoLogIn: Boolean = true
Expand All @@ -57,7 +60,11 @@ class LoginViewModel @Inject constructor(
.flatMapLatest { event ->
when (event) {
is LoginEvent.Loading -> flowOf(LoginUiState.Loading)
is LoginEvent.GoogleSignIn -> flowOf(LoginUiState.GoogleSignIn)
is LoginEvent.GoogleSignIn -> flowOf(
LoginUiState.GoogleSignIn(
signInIntent = googleSignInClient.signInIntent,
),
)
is LoginEvent.SignInSuccess -> signInSuccess(event.userId)
is LoginEvent.SignInFailure -> flowOf(
LoginUiState.SignInFailure(event.errorMessage),
Expand Down Expand Up @@ -138,10 +145,10 @@ sealed interface LoginUiState {

object Loading : LoginUiState

object GoogleSignIn : LoginUiState

object AlreadyLoggedIn : LoginUiState

data class GoogleSignIn(val signInIntent: Intent) : LoginUiState

data class SignInComplete(val tokenResponse: TokenResponse) : LoginUiState

data class SignInFailure(val errorMessage: String) : LoginUiState
Expand Down

This file was deleted.

9 changes: 5 additions & 4 deletions stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public final class io/getstream/video/android/core/CallHealthMonitor {
public final fun reconnect (ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun start ()V
public final fun stop ()V
public final fun stopTimer ()V
}

public final class io/getstream/video/android/core/CallKt {
Expand Down Expand Up @@ -4175,8 +4176,8 @@ public final class io/getstream/video/android/core/socket/ErrorResponse$Companio

public class io/getstream/video/android/core/socket/PersistentSocket : okhttp3/WebSocketListener {
public field connected Lkotlinx/coroutines/CancellableContinuation;
public fun <init> (Ljava/lang/String;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Ljava/lang/String;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Ljava/lang/String;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
protected final fun ackHealthMonitor ()V
public fun authenticate ()V
public final fun cleanup ()V
Expand Down Expand Up @@ -4226,8 +4227,8 @@ public final class io/getstream/video/android/core/socket/PersistentSocket$Disco
}

public final class io/getstream/video/android/core/socket/SfuSocket : io/getstream/video/android/core/socket/PersistentSocket {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlinx/coroutines/CoroutineScope;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlinx/coroutines/CoroutineScope;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlinx/coroutines/CoroutineScope;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlinx/coroutines/CoroutineScope;Lokhttp3/OkHttpClient;Lio/getstream/video/android/core/internal/network/NetworkStateProvider;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun authenticate ()V
public fun connect (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun connectMigrating (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
Loading

0 comments on commit cbff6ce

Please sign in to comment.