class Socket : WebSocketAdapter
Socket main constructor.
This class is a thin layer above websockets. This layer provides compatibility with Phoenix Sockets. It handle heartbeat, serialization and provides a simple event based API.
When using Phoenix, you will usually not push messages directly to sockets but use Channels instead.
The url can use either the ws://
or wss://
scheme.
Message |
A raw socket message. class Message |
Options |
Socket options. class Options |
State |
Enum representing socket state enum class State |
<init> |
Socket main constructor. Socket(url: String, opts: Options = Socket.Options()) |
opts |
An var opts: Options |
url |
The full web socket URL var url: String |
channel |
Prefered constructor for channels. fun channel(topic: String, params: JSONObject = JSONObject()): Channel |
connect |
Connect the socket to the server fun connect(): Unit |
connectionState |
Returns the current socket state fun connectionState(): State |
disconnect |
Disconnect the socket. fun disconnect(callback: (() -> Unit)? = null, code: Int? = null, reason: String? = null): Unit |
endPointURL |
Returns the full endpoint URL. fun endPointURL(): URI |
isConnected |
Returns the connected state (if state is OPEN) fun isConnected(): Boolean |
log |
Log a message. fun log(tag: String, msg: String, data: Any? = null): Unit |
off |
Unregister on listeners fun off(refs: List<Ref>): Unit
Unregister on listener fun off(ref: Ref): Unit |
onClose |
Register an close callback. Multiple callbacks can be registerd. fun onClose(callback: CloseCallback): Ref |
onError |
Register an error callback. Multiple callbacks can be registerd. fun onError(callback: ErrorCallback): Ref |
onMessage |
Register an on message callback. Multiple callbacks can be registerd. fun onMessage(callback: MessageCallback): Ref |
onOpen |
Register an open callback. Multiple callbacks can be registerd. fun onOpen(callback: OpenCallback): Ref |
push |
Push a message to the socket fun push(msg: Message): Unit |
toString |
fun toString(): String |