-
- All Implemented Interfaces:
-
io.getstream.video.android.core.socket.common.SocketActions
public final class SfuSocketConnection extends SocketListener<SfuDataEvent, JoinCallResponseEvent> implements SocketActions<SfuDataRequest, SfuDataEvent, StreamWebSocketEvent.Error, SfuSocketState, String, JoinRequest>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classSfuSocketConnection.Companion
-
Field Summary
Fields Modifier and Type Field Description private final BooleandeliverOnMainThread
-
Constructor Summary
Constructors Constructor Description SfuSocketConnection(String apiKey, String url, OkHttpClient httpClient, NetworkStateProvider networkStateProvider, CoroutineScope scope, Lifecycle lifecycle, TokenProvider tokenProvider, TokenRepository tokenRepository)
-
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(JoinCallResponseEvent event)Invoked when we receive the first ConnectedEventType in this connection. UnitonEvent(SfuDataEvent 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. UnitwhenConnected(Long connectionTimeout, SuspendFunction1<Throwable, Unit> connectionFailed, SuspendFunction1<String, Unit> connected)When connected to the socket. Unitconnect(JoinRequest connectData)Connect the user. Unitdisconnect()Disconnect the socket. UnitupdateToken(String token)Update the token from the outside. Unitreconnect(JoinRequest data, Boolean force)Reconnect the user to the socket. StateFlow<SfuSocketState>state()State of the socket as StateFlow MutableSharedFlow<SfuDataEvent>events()Socket events as Flow MutableSharedFlow<StreamWebSocketEvent.Error>errors()Socket errors as Flow UnitsendData(String data)Send raw data to the socket. BooleansendEvent(SfuDataRequest event)Send event to the socket. StateFlow<String>connectionId()Get the connection id. -
-
Constructor Detail
-
SfuSocketConnection
SfuSocketConnection(String apiKey, String url, OkHttpClient httpClient, NetworkStateProvider networkStateProvider, CoroutineScope scope, Lifecycle lifecycle, TokenProvider tokenProvider, TokenRepository tokenRepository)
-
-
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(JoinCallResponseEvent 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(SfuDataEvent 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.
-
whenConnected
Unit whenConnected(Long connectionTimeout, SuspendFunction1<Throwable, Unit> connectionFailed, SuspendFunction1<String, Unit> connected)
When connected to the socket.
-
connect
Unit connect(JoinRequest connectData)
Connect the user.
-
disconnect
Unit disconnect()
Disconnect the socket.
-
updateToken
Unit updateToken(String token)
Update the token from the outside.
-
reconnect
Unit reconnect(JoinRequest data, Boolean force)
Reconnect the user to the socket.
-
state
StateFlow<SfuSocketState> state()
State of the socket as StateFlow
-
events
MutableSharedFlow<SfuDataEvent> events()
Socket events as Flow
-
errors
MutableSharedFlow<StreamWebSocketEvent.Error> errors()
Socket errors as Flow
-
sendData
Unit 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(SfuDataRequest event)
Send event to the socket.
-
connectionId
StateFlow<String> connectionId()
Get the connection id.
-
-
-
-