Socket

class Socket(url: String, val paramsClosure: PayloadClosure, val 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. 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

Link copied to clipboard
constructor(url: String, params: Payload = mapOf(), 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. Takes a constant parameter to be sent to the server when connecting. Defaults to null if excluded.

constructor(url: String, paramsClosure: PayloadClosure, vsn: String = Defaults.VSN, encode: EncodeClosure = Defaults.encode, decode: DecodeClosure = Defaults.decode, client: OkHttpClient = OkHttpClient.Builder().build())

Properties

Link copied to clipboard
Link copied to clipboard

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

The fully qualified socket URL

Link copied to clipboard

Interval between sending a heartbeat, in ms

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

The optional function to receive logs

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Interval between socket reconnect attempts, in ms

Link copied to clipboard

Interval between channel rejoin attempts, in ms

Link copied to clipboard

Disables heartbeats from being sent. Default is false.

Link copied to clipboard

Timeout to use when opening a connection

Link copied to clipboard
val vsn: String

Functions

Link copied to clipboard
fun channel(topic: String, paramsClosure: PayloadClosure): Channel
fun channel(topic: String, params: Payload = mapOf()): Channel
Link copied to clipboard
fun connect()
Link copied to clipboard
fun disconnect(code: Int = WS_CLOSE_NORMAL, reason: String? = null, callback: () -> Unit? = null)
Link copied to clipboard
fun logItems(body: String)
Link copied to clipboard
fun off(refs: List<String>)

Removes onOpen, onClose, onError, and onMessage registrations by their ref value.

Link copied to clipboard
fun onClose(callback: () -> Unit): String
Link copied to clipboard
fun onError(callback: (Throwable, Response?) -> Unit): String
Link copied to clipboard
fun onMessage(callback: (Message) -> Unit): String
Link copied to clipboard
fun onOpen(callback: () -> Unit): String
Link copied to clipboard
fun remove(channel: Channel)
Link copied to clipboard