WebSocket

open class WebSocket(val url: String, val protocol: String = definedExternally) : EventTarget(source)

The WebSocket object provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.

MDN Reference

Constructors

Link copied to clipboard
constructor(url: URL, protocol: String = definedExternally)
constructor(url: String, protocols: ReadonlyArray<JsString>)
constructor(url: URL, protocols: ReadonlyArray<JsString>)
constructor(url: String, protocol: String = definedExternally)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed interface ReadyState

Properties

Link copied to clipboard

The WebSocket.binaryType property controls the type of binary data being received over the WebSocket connection.

Link copied to clipboard

The WebSocket.bufferedAmount read-only property returns the number of bytes of data that have been queued using calls to send() but not yet transmitted to the network.

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

The WebSocket.extensions read-only property returns the extensions selected by the server.

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

The WebSocket.protocol read-only property returns the name of the sub-protocol the server selected; this will be one of the strings specified in the protocols parameter when creating the WebSocket object, or the empty string if no connection is established.

Link copied to clipboard

The WebSocket.readyState read-only property returns the current state of the WebSocket connection.

Link copied to clipboard
val url: String

The WebSocket.url read-only property returns the absolute URL of the WebSocket as resolved by the constructor.

Functions

Link copied to clipboard
fun close(code: Short = definedExternally, reason: String = definedExternally)

The WebSocket.close() method closes the already CLOSED, this method does nothing.

Link copied to clipboard
Link copied to clipboard
fun send(data: ArrayBufferView<*>)
fun send(data: Blob)

fun send(data: String)

The WebSocket.send() method enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data.

Link copied to clipboard
fun <T : Event> when(type: EventType<T>, options: ObservableEventListenerOptions? = definedExternally): Observable<T>