-
- All Implemented Interfaces:
-
io.getstream.video.android.core.socket.common.SocketActions
public class CoordinatorSocketConnection extends SocketListener<VideoEvent, ConnectedEvent> implements SocketActions<VideoEvent, VideoEvent, StreamWebSocketEvent.Error, VideoSocketState, String, 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)
This should be internal
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleandeliverOnMainThread
-
Constructor Summary
Constructors Constructor Description CoordinatorSocketConnection(String apiKey, String url, User user, String token, OkHttpClient httpClient, NetworkStateProvider networkStateProvider, CoroutineScope scope, Lifecycle lifecycle, TokenProvider tokenProvider, TokenRepository tokenRepository)Backwards-compatible constructor for callers that still pass a fixed User.
-
Method Summary
Modifier and Type Method Description BooleangetDeliverOnMainThread()The callbacks are by default delivered on the main thread. UnitonCreated()Called when the socket is created. UnitonConnecting()Invoked when the connection begins to establish and socket state changes to Connecting. UnitonConnected(ConnectedEvent event)Invoked when we receive the first ConnectedEventType in this connection. UnitonEvent(VideoEvent event)Invoked when we receive any successful event. UnitonError(StreamWebSocketEvent.Error error)Invoked when there is any error in this web socket connection. UnitonDisconnected(DisconnectCause cause)Invoked when the web socket connection is disconnected. StateFlow<String>connectionId()Get the connection id. UnitwhenConnected(Long connectionTimeout, SuspendFunction1<Throwable, Unit> connectionFailed, SuspendFunction1<String, Unit> connected)When connected to the socket. StateFlow<VideoSocketState>state()State of the socket as StateFlow Flow<VideoEvent>events()Socket events as Flow Flow<StreamWebSocketEvent.Error>errors()Socket errors as Flow <ERROR CLASS>sendData(String data)Send raw data to the socket. BooleansendEvent(VideoEvent event)Send event to the socket. Unitconnect(User connectData)Connect the user. Unitreconnect(User data, Boolean force)Reconnect the user to the socket. <ERROR CLASS>disconnect()Disconnect the socket. UnitupdateToken(String token)Update the token from the outside. -
-
Constructor Detail
-
CoordinatorSocketConnection
CoordinatorSocketConnection(String apiKey, String url, User user, String token, OkHttpClient httpClient, NetworkStateProvider networkStateProvider, CoroutineScope scope, Lifecycle lifecycle, TokenProvider tokenProvider, TokenRepository tokenRepository)
Backwards-compatible constructor for callers that still pass a fixed User.
-
-
Method Detail
-
getDeliverOnMainThread
Boolean getDeliverOnMainThread()
The callbacks are by default delivered on the main thread. Changing this property to false will deliver the callbacks on their originating threads.
Set to false for faster callback delivery on the original thread (no unnecessary context switching).
-
onConnecting
Unit onConnecting()
Invoked when the connection begins to establish and socket state changes to Connecting.
-
onConnected
Unit onConnected(ConnectedEvent event)
Invoked when we receive the first ConnectedEventType in this connection.
Note: This is not invoked when the ws connection is opened but when the ConnectedEventType is received.
- Parameters:
event- ConnectedEventType sent by server as first event once the connection is established.
-
onEvent
Unit onEvent(VideoEvent event)
Invoked when we receive any successful event.
- Parameters:
event- parsed VideoEvent received in this web socket connection.
-
onError
Unit onError(StreamWebSocketEvent.Error error)
Invoked when there is any error in this web socket connection.
- Parameters:
error- Error object with the error details.
-
onDisconnected
Unit onDisconnected(DisconnectCause cause)
Invoked when the web socket connection is disconnected.
- Parameters:
cause- DisconnectCause reason of disconnection.
-
connectionId
StateFlow<String> connectionId()
Get the connection id.
-
whenConnected
Unit whenConnected(Long connectionTimeout, SuspendFunction1<Throwable, Unit> connectionFailed, SuspendFunction1<String, Unit> connected)
When connected to the socket.
-
state
StateFlow<VideoSocketState> state()
State of the socket as StateFlow
-
events
Flow<VideoEvent> events()
Socket events as Flow
-
errors
Flow<StreamWebSocketEvent.Error> errors()
Socket errors as Flow
-
sendData
<ERROR CLASS> sendData(String data)
Send raw data to the socket. If you already have a parsed event that can be sent. Refactor later to return bool
-
sendEvent
Boolean sendEvent(VideoEvent event)
Send event to the socket.
-
disconnect
<ERROR CLASS> disconnect()
Disconnect the socket.
-
updateToken
Unit updateToken(String token)
Update the token from the outside.
-
-
-
-