Socket

actual class Socket(url: String, paramsClosure: PayloadClosure, vsn: String, encode: EncodeClosure, decode: DecodeClosure, scope: CoroutineScope) : SocketCommon
expect class Socket(url: String, paramsClosure: PayloadClosure, vsn: String, encode: EncodeClosure, decode: DecodeClosure, scope: CoroutineScope) : SocketCommon

A Socket which connects to a Phoenix Socket. Takes a closure to allow for changing parameters to be sent to the server when connecting.

Example

val socket = Socket("https://example.com/socket", { mapOf("token" to mAuthToken) })
actual class Socket(url: String, paramsClosure: PayloadClosure, vsn: String, encode: EncodeClosure, decode: DecodeClosure, scope: CoroutineScope) : SocketCommon

Parameters

url

Url to connect to such as https://example.com/socket

paramsClosure

Closure which allows to change parameters sent during connection.

vsn

JSON Serializer version to use. Defaults to 2.0.0

encode

Optional. Provide a custom JSON encoding implementation

decode

Optional. Provide a custom JSON decoding implementation

Constructors

Link copied to clipboard
actual fun Socket(url: String, params: Payload?, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, scope: CoroutineScope)
expect fun Socket(url: String, params: Payload?, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, scope: CoroutineScope)
actual fun Socket(url: String, params: Payload?, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, scope: CoroutineScope)
Link copied to clipboard
actual fun Socket(url: String, paramsClosure: PayloadClosure, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, scope: CoroutineScope)
expect fun Socket(url: String, paramsClosure: PayloadClosure, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, scope: CoroutineScope)
actual fun Socket(url: String, paramsClosure: PayloadClosure, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, scope: CoroutineScope)

Functions

Link copied to clipboard
fun channel(topic: String, socket: SocketFlow, params: Payload = emptyMap()): Channel

Creates an instance of Channel bound to the specified topic and Socket, taking optional parameters.

fun channel(topic: String, socket: SocketFlow, params: Payload = emptyMap()): Channel

Creates an instance of Channel bound to the specified topic and Socket, taking optional parameters.

fun channel(topic: String, socket: SocketFlow, params: Payload = emptyMap()): Channel

Creates an instance of Channel bound to the specified topic and Socket, taking optional parameters.

Link copied to clipboard
suspend fun connect(): SocketFlow?

Connects to the Phoenix Socket. Suspends until the server acknowledges the connection.

suspend fun connect(): SocketFlow?

Connects to the Phoenix Socket. Suspends until the server acknowledges the connection.

suspend fun connect(): SocketFlow?

Connects to the Phoenix Socket. Suspends until the server acknowledges the connection.

Link copied to clipboard
fun disconnect(code: Int = WS_CLOSE_NORMAL, reason: String? = null)

Disconnects from the Phoenix Socket and resets the reconnectTimer.

fun disconnect(code: Int = WS_CLOSE_NORMAL, reason: String? = null)

Disconnects from the Phoenix Socket and resets the reconnectTimer.

fun disconnect(code: Int = WS_CLOSE_NORMAL, reason: String? = null)

Disconnects from the Phoenix Socket and resets the reconnectTimer.

Link copied to clipboard
fun remove(channel: Channel)
fun remove(channel: Channel)
fun remove(channel: Channel)

Properties

Link copied to clipboard
abstract var endpoint: String

The string WebSocket endpoint (ie "ws://example.com/socket", "wss://example.com", etc.) that was passed to the Socket during initialization. The URL endpoint will be modified by the Socket to include "/websocket" if missing.

Link copied to clipboard
open lateinit override var endpoint: String

The string WebSocket endpoint (ie "ws://example.com/socket", "wss://example.com", etc.) that was passed to the Socket during initialization. The URL endpoint will be modified by the Socket to include "/websocket" if missing.

Link copied to clipboard
open lateinit override var endpoint: String

The string WebSocket endpoint (ie "ws://example.com/socket", "wss://example.com", etc.) that was passed to the Socket during initialization. The URL endpoint will be modified by the Socket to include "/websocket" if missing.

Link copied to clipboard
abstract var endpointUrl: URL

The fully qualified socket URL

Link copied to clipboard
open lateinit override var endpointUrl: URL

The fully qualified socket URL

Link copied to clipboard
open lateinit override var endpointUrl: <ERROR CLASS>

The fully qualified socket URL

Link copied to clipboard
val isConnected: Boolean
Link copied to clipboard
val isConnected: Boolean
Link copied to clipboard
val isConnected: Boolean
Link copied to clipboard
var logger: (String) -> Unit? = null

The optional function to receive logs

Link copied to clipboard
var logger: (String) -> Unit? = null

The optional function to receive logs

Link copied to clipboard
var logger: (String) -> Unit? = null

The optional function to receive logs

Link copied to clipboard
abstract val protocol: String
Link copied to clipboard
open override val protocol: String
Link copied to clipboard
open override val protocol: String
Link copied to clipboard
var reconnectAfterMs: (Int) -> Long

Interval between Socket reconnect attempts, in ms

Link copied to clipboard
var reconnectAfterMs: (Int) -> Long

Interval between Socket reconnect attempts, in ms

Link copied to clipboard
var reconnectAfterMs: (Int) -> Long

Interval between Socket reconnect attempts, in ms

Link copied to clipboard
var rejoinAfterMs: (Int) -> Long

Interval between Channel rejoin attempts, in ms

Link copied to clipboard
var rejoinAfterMs: (Int) -> Long

Interval between Channel rejoin attempts, in ms

Link copied to clipboard
var rejoinAfterMs: (Int) -> Long

Interval between Channel rejoin attempts, in ms

Link copied to clipboard
var timeout: Long

Timeout to use when opening a connection

Link copied to clipboard
var timeout: Long

Timeout to use when opening a connection

Link copied to clipboard
var timeout: Long

Timeout to use when opening a connection