Socket

class Socket(url: String, paramsClosure: PayloadClosure, vsn: String, encode: EncodeClosure, decode: DecodeClosure, client: OkHttpClient)

A Socket which connects to a Phoenix Server. 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) })

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

client

Default OkHttpClient to connect with. You can provide your own if needed.

Constructors

Socket
Link copied to clipboard
fun Socket(url: String, params: Payload? = null, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, client: OkHttpClient = OkHttpClient.Builder().build())
A Socket which connects to a Phoenix Server.
Socket
Link copied to clipboard
fun Socket(url: String, paramsClosure: PayloadClosure, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, client: OkHttpClient = OkHttpClient.Builder().build())
Url to connect to such as https://example.

Functions

channel
Link copied to clipboard
fun channel(topic: String, params: Payload = mapOf()): Channel
connect
Link copied to clipboard
fun connect()
disconnect
Link copied to clipboard
fun disconnect(code: Int = WS_CLOSE_NORMAL, reason: String? = null, callback: () -> Unit? = null)
logItems
Link copied to clipboard
fun logItems(body: String)
off
Link copied to clipboard
fun off(refs: List<String>)
Removes onOpen, onClose, onError, and onMessage registrations by their ref value.
onClose
Link copied to clipboard
fun onClose(callback: () -> Unit): String
onError
Link copied to clipboard
fun onError(callback: (Throwable, Response?) -> Unit): String
onMessage
Link copied to clipboard
fun onMessage(callback: (Message) -> Unit): String
onOpen
Link copied to clipboard
fun onOpen(callback: () -> Unit): String
remove
Link copied to clipboard
fun remove(channel: Channel)
removeAllCallbacks
Link copied to clipboard
fun removeAllCallbacks()

Properties

connectionState
Link copied to clipboard
val connectionState: Transport.ReadyState
endpoint
Link copied to clipboard
val endpoint: String
The string WebSocket endpoint (ie "ws://example.com/socket", "wss://example.com", etc.) that was passed to the Socket during initialization.
endpointUrl
Link copied to clipboard
var endpointUrl: URL
The fully qualified socket URL
heartbeatIntervalMs
Link copied to clipboard
var heartbeatIntervalMs: Long
Interval between sending a heartbeat, in ms
isConnected
Link copied to clipboard
val isConnected: Boolean
logger
Link copied to clipboard
var logger: (String) -> Unit? = null
The optional function to receive logs
paramsClosure
Link copied to clipboard
val paramsClosure: PayloadClosure
Closure which allows to change parameters sent during connection.
protocol
Link copied to clipboard
val protocol: String
reconnectAfterMs
Link copied to clipboard
var reconnectAfterMs: (Int) -> Long
Interval between socket reconnect attempts, in ms
rejoinAfterMs
Link copied to clipboard
var rejoinAfterMs: (Int) -> Long
Interval between channel rejoin attempts, in ms
skipHeartbeat
Link copied to clipboard
var skipHeartbeat: Boolean = false
Disables heartbeats from being sent.
timeout
Link copied to clipboard
var timeout: Long
Timeout to use when opening a connection
vsn
Link copied to clipboard
val vsn: String
JSON Serializer version to use.