CoordinatorSocketConnection

open class CoordinatorSocketConnection(apiKey: ApiKey, url: String, user: User, token: String, httpClient: OkHttpClient, networkStateProvider: NetworkStateProvider, scope: CoroutineScope = UserScope(ClientScope()), lifecycle: Lifecycle, tokenProvider: TokenProvider) : SocketListener<VideoEvent, ConnectedEvent> , SocketActions<VideoEvent, VideoEvent, StreamWebSocketEvent.Error, VideoSocketState, UserToken, User>

PersistentSocket architecture

  • Health monitor that sends a ping every 30 seconds

  • Automatically reconnects if it encounters a temp failure

  • Raises the error if there is a permanent failure

  • Flow to avoid concurrency related bugs

  • Ability to wait till the socket is connected (important to prevent race conditions)

Constructors

Link copied to clipboard
constructor(apiKey: ApiKey, url: String, user: User, token: String, httpClient: OkHttpClient, networkStateProvider: NetworkStateProvider, scope: CoroutineScope = UserScope(ClientScope()), lifecycle: Lifecycle, tokenProvider: TokenProvider)

Inherited properties

Link copied to clipboard

The callbacks are by default delivered on the main thread. Changing this property to false will deliver the callbacks on their originating threads.

Functions

Link copied to clipboard
open suspend override fun connect(connectData: User)

Connect the user.

Link copied to clipboard
open override fun connectionId(): StateFlow<String?>

Get the connection id.

Link copied to clipboard
open suspend override fun disconnect()

Disconnect the socket.

Link copied to clipboard
open override fun errors(): Flow<StreamWebSocketEvent.Error>

Socket errors as Flow

Link copied to clipboard
open override fun events(): Flow<VideoEvent>

Socket events as Flow

Link copied to clipboard
open override fun onConnected(event: ConnectedEvent)

Invoked when we receive the first ConnectedEventType in this connection.

Link copied to clipboard
open override fun onConnecting()

Invoked when the connection begins to establish and socket state changes to Connecting.

Link copied to clipboard
open override fun onCreated()

Called when the socket is created.

Link copied to clipboard
open override fun onDisconnected(cause: DisconnectCause)

Invoked when the web socket connection is disconnected.

Link copied to clipboard
open override fun onError(error: StreamWebSocketEvent.Error)

Invoked when there is any error in this web socket connection.

Link copied to clipboard
open override fun onEvent(event: VideoEvent)

Invoked when we receive any successful event.

Link copied to clipboard
open suspend override fun reconnect(data: User, force: Boolean)

Reconnect the user to the socket.

Link copied to clipboard
open override fun sendData(data: String)

Send raw data to the socket. If you already have a parsed event that can be sent.

Link copied to clipboard
open suspend override fun sendEvent(event: VideoEvent): Boolean

Send event to the socket.

Link copied to clipboard
open override fun state(): StateFlow<VideoSocketState>

State of the socket as StateFlow

Link copied to clipboard
open override fun updateToken(token: UserToken)

Update the token from the outside.

Link copied to clipboard
open override fun whenConnected(connectionTimeout: Long, connected: suspend (connectionId: String) -> Unit)

When connected to the socket.