mirror of
https://github.com/element-hq/element-android
synced 2024-10-25 20:28:53 +03:00
Implementation of turn server api.
This commit is contained in:
parent
8f5918de4d
commit
4b85e39e3e
6 changed files with 109 additions and 7 deletions
|
@ -17,10 +17,11 @@
|
||||||
package im.vector.matrix.android.api.session.call
|
package im.vector.matrix.android.api.session.call
|
||||||
|
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
|
import im.vector.matrix.android.api.util.Cancelable
|
||||||
|
|
||||||
interface CallService {
|
interface CallService {
|
||||||
|
|
||||||
fun getTurnServer(callback: MatrixCallback<TurnServer?>)
|
fun getTurnServer(callback: MatrixCallback<TurnServer>): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an outgoing call
|
* Create an outgoing call
|
||||||
|
|
|
@ -30,6 +30,7 @@ import im.vector.matrix.android.internal.di.SessionAssistedInjectModule
|
||||||
import im.vector.matrix.android.internal.network.NetworkConnectivityChecker
|
import im.vector.matrix.android.internal.network.NetworkConnectivityChecker
|
||||||
import im.vector.matrix.android.internal.session.account.AccountModule
|
import im.vector.matrix.android.internal.session.account.AccountModule
|
||||||
import im.vector.matrix.android.internal.session.cache.CacheModule
|
import im.vector.matrix.android.internal.session.cache.CacheModule
|
||||||
|
import im.vector.matrix.android.internal.session.call.CallModule
|
||||||
import im.vector.matrix.android.internal.session.content.ContentModule
|
import im.vector.matrix.android.internal.session.content.ContentModule
|
||||||
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
||||||
import im.vector.matrix.android.internal.session.filter.FilterModule
|
import im.vector.matrix.android.internal.session.filter.FilterModule
|
||||||
|
@ -83,7 +84,8 @@ import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
|
||||||
AccountDataModule::class,
|
AccountDataModule::class,
|
||||||
ProfileModule::class,
|
ProfileModule::class,
|
||||||
SessionAssistedInjectModule::class,
|
SessionAssistedInjectModule::class,
|
||||||
AccountModule::class
|
AccountModule::class,
|
||||||
|
CallModule::class
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@SessionScope
|
@SessionScope
|
||||||
|
|
|
@ -275,6 +275,4 @@ internal abstract class SessionModule {
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindSharedSecretStorageService(service: DefaultSharedSecretStorageService): SharedSecretStorageService
|
abstract fun bindSharedSecretStorageService(service: DefaultSharedSecretStorageService): SharedSecretStorageService
|
||||||
|
|
||||||
@Binds
|
|
||||||
abstract fun bindCallService(service:DefaultCallService): CallService
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.internal.session.call
|
||||||
|
|
||||||
|
import dagger.Binds
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import im.vector.matrix.android.api.session.call.CallService
|
||||||
|
import im.vector.matrix.android.api.session.call.VoipApi
|
||||||
|
import im.vector.matrix.android.internal.session.SessionScope
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
|
||||||
|
@Module
|
||||||
|
internal abstract class CallModule {
|
||||||
|
|
||||||
|
@Module
|
||||||
|
companion object {
|
||||||
|
@Provides
|
||||||
|
@JvmStatic
|
||||||
|
@SessionScope
|
||||||
|
fun providesVoipApi(retrofit: Retrofit): VoipApi {
|
||||||
|
return retrofit.create(VoipApi::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindCallService(service:DefaultCallService): CallService
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindTurnServerTask(task: DefaultGetTurnServerTask): GetTurnServerTask
|
||||||
|
}
|
|
@ -28,11 +28,14 @@ import im.vector.matrix.android.api.session.events.model.toModel
|
||||||
import im.vector.matrix.android.api.session.room.model.call.CallAnswerContent
|
import im.vector.matrix.android.api.session.room.model.call.CallAnswerContent
|
||||||
import im.vector.matrix.android.api.session.room.model.call.CallHangupContent
|
import im.vector.matrix.android.api.session.room.model.call.CallHangupContent
|
||||||
import im.vector.matrix.android.api.session.room.model.call.CallInviteContent
|
import im.vector.matrix.android.api.session.room.model.call.CallInviteContent
|
||||||
|
import im.vector.matrix.android.api.util.Cancelable
|
||||||
import im.vector.matrix.android.internal.di.UserId
|
import im.vector.matrix.android.internal.di.UserId
|
||||||
import im.vector.matrix.android.internal.session.SessionScope
|
import im.vector.matrix.android.internal.session.SessionScope
|
||||||
import im.vector.matrix.android.internal.session.call.model.MxCallImpl
|
import im.vector.matrix.android.internal.session.call.model.MxCallImpl
|
||||||
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
||||||
import im.vector.matrix.android.internal.session.room.send.RoomEventSender
|
import im.vector.matrix.android.internal.session.room.send.RoomEventSender
|
||||||
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -41,13 +44,27 @@ internal class DefaultCallService @Inject constructor(
|
||||||
@UserId
|
@UserId
|
||||||
private val userId: String,
|
private val userId: String,
|
||||||
private val localEchoEventFactory: LocalEchoEventFactory,
|
private val localEchoEventFactory: LocalEchoEventFactory,
|
||||||
private val roomEventSender: RoomEventSender
|
private val roomEventSender: RoomEventSender,
|
||||||
|
private val taskExecutor: TaskExecutor,
|
||||||
|
private val turnServerTask: GetTurnServerTask
|
||||||
) : CallService {
|
) : CallService {
|
||||||
|
|
||||||
private val callListeners = mutableSetOf<CallsListener>()
|
private val callListeners = mutableSetOf<CallsListener>()
|
||||||
|
|
||||||
override fun getTurnServer(callback: MatrixCallback<TurnServer?>) {
|
override fun getTurnServer(callback: MatrixCallback<TurnServer>): Cancelable {
|
||||||
TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
|
return turnServerTask
|
||||||
|
.configureWith(GetTurnServerTask.Params) {
|
||||||
|
this.callback = object : MatrixCallback<TurnServer> {
|
||||||
|
override fun onSuccess(data: TurnServer) {
|
||||||
|
callback.onSuccess(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(failure: Throwable) {
|
||||||
|
callback.onFailure(failure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.executeBy(taskExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createOutgoingCall(roomId: String, otherUserId: String, isVideoCall: Boolean): MxCall {
|
override fun createOutgoingCall(roomId: String, otherUserId: String, isVideoCall: Boolean): MxCall {
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.internal.session.call
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.call.TurnServer
|
||||||
|
import im.vector.matrix.android.api.session.call.VoipApi
|
||||||
|
import im.vector.matrix.android.internal.network.executeRequest
|
||||||
|
import im.vector.matrix.android.internal.task.Task
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
internal abstract class GetTurnServerTask : Task<GetTurnServerTask.Params, TurnServer> {
|
||||||
|
object Params
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class DefaultGetTurnServerTask @Inject constructor(private val voipAPI: VoipApi,
|
||||||
|
private val eventBus: EventBus) : GetTurnServerTask() {
|
||||||
|
|
||||||
|
override suspend fun execute(params: Params): TurnServer {
|
||||||
|
return executeRequest(eventBus) {
|
||||||
|
apiCall = voipAPI.getTurnServer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue