Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optional calling [WPB-9999] #3043

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ interface Calling : Library {
)

companion object {
val INSTANCE by lazy { Native.load("avs", Calling::class.java)!! }
val INSTANCE: Calling? by lazy {
try {
Native.load("avs", Calling::class.java)
} catch (e: UnsatisfiedLinkError) {
println("Failed to load calling library: ${e.message}")
null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import java.util.Collections

@Suppress("LongParameterList", "TooManyFunctions")
class CallManagerImpl internal constructor(
private val calling: Calling,
private val calling: Calling?,
Garzas marked this conversation as resolved.
Show resolved Hide resolved
private val callRepository: CallRepository,
private val userRepository: UserRepository,
private val currentClientIdProvider: CurrentClientIdProvider,
Expand Down Expand Up @@ -186,7 +186,7 @@ class CallManagerImpl internal constructor(

val waitInitializationJob = Job()

val handle = calling.wcall_create(
val handle = calling?.wcall_create(
userId = selfUserId,
clientId = selfClientId,
readyHandler = ReadyHandler { version: Int, arg: Pointer? ->
Expand Down Expand Up @@ -228,13 +228,13 @@ class CallManagerImpl internal constructor(
callingLogger.d("$TAG - wcall_create() called")
// TODO(edge-case): Add a timeout. Perhaps make some functions (like onCallingMessageReceived) return Eithers.
waitInitializationJob.join()
handle
handle ?: Uint32_t(0)
Garzas marked this conversation as resolved.
Show resolved Hide resolved
}
}

private suspend fun <T> withCalling(action: suspend Calling.(handle: Handle) -> T): T {
val handle = deferredHandle.await()
return calling.action(handle)
return calling?.action(handle) ?: error("Calling is not initialized")
}

override suspend fun onCallingMessageReceived(
Expand Down Expand Up @@ -471,7 +471,7 @@ class CallManagerImpl internal constructor(
}
val clientsJson = CallClientList(clients).toJsonString()
val conversationIdString = federatedIdMapper.parseToFederatedId(conversationId)
calling.wcall_request_video_streams(
calling?.wcall_request_video_streams(
inst = it,
conversationId = conversationIdString,
mode = DEFAULT_REQUEST_VIDEO_STREAMS_MODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ actual class GlobalCallManager(
}

private val calling by lazy {
Calling.INSTANCE.apply {
Calling.INSTANCE?.apply {
if (CurrentPlatform().type == PlatformType.ANDROID)
wcall_init(env = ENVIRONMENT_DEFAULT)
else {
Expand All @@ -70,6 +70,10 @@ actual class GlobalCallManager(
arg = null
)
callingLogger.i("GlobalCallManager -> wcall_init")
}.also {
if (it == null) {
callingLogger.e("GlobalCallManager -> failed to load calling library")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ internal interface CallingMessageSender {

@Suppress("FunctionNaming")
internal fun CallingMessageSender(
handle: Deferred<Handle>,
calling: Calling,
handle: Deferred<Handle?>,
calling: Calling?,
messageSender: MessageSender,
callingScope: CoroutineScope,
selfConversationIdProvider: SelfConversationIdProvider
Expand Down Expand Up @@ -143,12 +143,14 @@ internal fun CallingMessageSender(
HttpStatusCode.BadRequest.value to "Couldn't send Calling Message"
}
}
calling.wcall_resp(
inst = handle.await(),
status = code,
reason = message,
arg = messageInstructions.context
)
handle.await()?.let { handle ->
calling?.wcall_resp(
inst = handle,
status = code,
reason = message,
arg = messageInstructions.context
)
}
}

@Suppress("LongParameterList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class PocIntegrationTest {
}
}

@Ignore("needs to be checked and fix")
@Test
fun givenEmailAndPasswordWhenLoggingInThenRegisterClientAndLogout() = runTest {
val mockedRequests = mutableListOf<TestRequestHandler>().apply {
Expand Down
Loading