Class PersistentSocket
-
- All Implemented Interfaces:
public class PersistentSocket<T extends Object> extends WebSocketListenerPersistentSocket architecture
Healthmonitor 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)
-
-
Field Summary
Fields Modifier and Type Field Description private LongreconnectTimeoutprivate final MutableSharedFlow<VideoEvent>eventsprivate final MutableSharedFlow<Throwable>errorsprivate final MutableStateFlow<SocketState>_connectionStateprivate final StateFlow<SocketState>connectionStateprivate StringconnectionIdprivate Continuation<T>connected
-
Constructor Summary
Constructors Constructor Description PersistentSocket(String url, OkHttpClient httpClient, NetworkStateProvider networkStateProvider, CoroutineScope scope)
-
Method Summary
Modifier and Type Method Description final LonggetReconnectTimeout()final UnitsetReconnectTimeout(Long reconnectTimeout)final MutableSharedFlow<VideoEvent>getEvents()flow with all the events, listen to this final MutableSharedFlow<Throwable>getErrors()flow with temporary and permanent errors final MutableStateFlow<SocketState>get_connectionState()final StateFlow<SocketState>getConnectionState()the current connection state of the socket final StringgetConnectionId()the connection id final UnitsetConnectionId(String connectionId)the connection id final Continuation<T>getConnected()Continuation if the socket successfully connected and we've authenticated final UnitsetConnected(Continuation<T> connected)Continuation if the socket successfully connected and we've authenticated final Tconnect()Connect the socket, authenticate, start the healthmonitor and see if the network is online final Unitcleanup()final Unitdisconnect()Disconnect the socket final Unitreconnect(Long timeout)Increment the reconnection attempts, disconnect and reconnect Unitauthenticate()final UnitonInternetConnected()final UnitonInternetDisconnected()final WebSocketcreateSocket()UnitonOpen(WebSocket webSocket, Response response)UnitonMessage(WebSocket webSocket, String text)Invoked when a text (type 0x1) message has been received.UnitonMessage(WebSocket webSocket, ByteString bytes)Invoked when a binary (type 0x2) message has been received.UnitonClosing(WebSocket webSocket, Integer code, String reason)Invoked when the remote peer has indicated that no more incoming messages will be transmitted. UnitonClosed(WebSocket webSocket, Integer code, String reason)Invoked when both peers have indicated that no more messages will be transmitted and the connection has been successfully released. UnitonFailure(WebSocket webSocket, Throwable t, Response response)Invoked when a web socket has been closed due to an error reading from or writing to the network. -
-
Constructor Detail
-
PersistentSocket
PersistentSocket(String url, OkHttpClient httpClient, NetworkStateProvider networkStateProvider, CoroutineScope scope)
-
-
Method Detail
-
getReconnectTimeout
final Long getReconnectTimeout()
-
setReconnectTimeout
final Unit setReconnectTimeout(Long reconnectTimeout)
-
getEvents
final MutableSharedFlow<VideoEvent> getEvents()
flow with all the events, listen to this
-
get_connectionState
final MutableStateFlow<SocketState> get_connectionState()
-
getConnectionState
final StateFlow<SocketState> getConnectionState()
the current connection state of the socket
-
getConnectionId
final String getConnectionId()
the connection id
-
setConnectionId
final Unit setConnectionId(String connectionId)
the connection id
-
getConnected
final Continuation<T> getConnected()
Continuation if the socket successfully connected and we've authenticated
-
setConnected
final Unit setConnected(Continuation<T> connected)
Continuation if the socket successfully connected and we've authenticated
-
connect
final T connect()
Connect the socket, authenticate, start the healthmonitor and see if the network is online
-
disconnect
final Unit disconnect()
Disconnect the socket
-
reconnect
final Unit reconnect(Long timeout)
Increment the reconnection attempts, disconnect and reconnect
-
authenticate
Unit authenticate()
-
onInternetConnected
final Unit onInternetConnected()
-
onInternetDisconnected
final Unit onInternetDisconnected()
-
createSocket
final WebSocket createSocket()
-
onMessage
Unit onMessage(WebSocket webSocket, String text)
Invoked when a text (type
0x1) message has been received.
-
onMessage
Unit onMessage(WebSocket webSocket, ByteString bytes)
Invoked when a binary (type
0x2) message has been received.
-
onClosing
Unit onClosing(WebSocket webSocket, Integer code, String reason)
Invoked when the remote peer has indicated that no more incoming messages will be transmitted.
-
onClosed
Unit onClosed(WebSocket webSocket, Integer code, String reason)
Invoked when both peers have indicated that no more messages will be transmitted and the connection has been successfully released. No further calls to this listener will be made.
-
-
-
-