CommunicationsServer

Server for remote communications services.

Communications services are services than run on one or more remote devices. These can be made available by creating a CommunicationsServer object and telling it what service it provides by providing it with a CommunicationsServerFactory inside the specified serverContext.

All remote services are defined using a Protobuf file. Kotlin code will be automatically generated from this file. The generated code for a service contains a server stub interface, that should be implemented and provided by the CommunicationsServerFactory to make the service available.

Servers can have zero or one clients connected to it at the same time. When a new client is connected a new server stub will be automatically created by calling CommunicationsServerFactory.create. Once this has happened this server stub is immediately active.

Example

val mutableConversations = MutableLiveData<Map<ConversationId, Conversation?>>()
val mutableMessages = MutableLiveData<Map<MessageId, Message?>>()

inner class CommunicationsMessagingServiceFactory : CommunicationsServerFactory {
inner class CommunicationMessageService : MessagingService.Stub() {
override val conversations = mutableConversations
override val messages = mutableMessages
override suspend fun sendMessage(message: Message): SendMessageResult {
// Implement message sending.
}
}
override val serviceUuid = MessagingService.serviceUuid
override fun create(): CommunicationsServiceBase {
return CommunicationMessageService()
}
}

val messagingCommunicationServer = CommunicationsServer(
CommunicationsServerContext(applicationContext, this, CommunicationsMessagingServiceFactory())
)

Constructors

Link copied to clipboard

Functions

Link copied to clipboard
open override fun onCreate(owner: LifecycleOwner)
Link copied to clipboard
open override fun onDestroy(owner: LifecycleOwner)

Inherited functions

Link copied to clipboard
open override fun onPause(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun onResume(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun onStart(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun onStop(@NonNull p0: LifecycleOwner)