Skip to content

Functions

molimawka edited this page May 11, 2022 · 3 revisions

on

Return store for the specified event name

const eventName = wsocket.on(eventName: string)

emit

Local emit event by event name

wsocket.emit(eventName: string, arg: unknown)

getState

Return readable store for websocket readyState

const state = wsocket.getState()
$: $state && onStateChange()

function onStateChange() {
  console.log("New state", $state)
}

open

Open connection. If the connection was not closed (readyState !== WebSocket.CLOSE) then nothing will happen.

wsocket.open()

close

Open connection. If the connection was not opened (readyState !== WebSocket.OPEN) then nothing will happen.

wsocket.close()

send

Send data by event name. Send json {event: eventName, data: data}

wsocket.send(eventName: string, data: unknown)

sendPlainText

Send string

wsocket.sendPlainText(text: string)
Clone this wiki locally