Types
StatusCode = enum scNormal = 1000, scGoingAway = 1001, scProtocolError = 1002, scUnsupported = 1003, scReserved = 1004, scNoStatus = 1005, scAbnormal = 1006, scUnsupportedData = 1007, scPolicyViolation = 1008, scTooLarge = 1009, scMissingExt = 1010, scInternalError = 1011, scRestart = 1012, scTryAgainLater = 1013, scReserved2 = 1014, scTLSHandshake = 1015
- Source Edit
MessageEvent = object of Event data*: cstring origin*: cstring
- Source Edit
CloseEvent = object of Event code*: Natural reason*: cstring wasClean*: bool
- To learn more, see here: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Properties Source Edit
ReadyState = enum Connecting = 0, Open = 1, Closing = 2, Closed = 3
- Source Edit
WebSocket = ref object of EventTarget url*: cstring protocol*: cstring readyState*: ReadyState onopen*: proc (event: Event) onclose*: proc (event: CloseEvent) onmessage*: proc (event: MessageEvent)
- Source Edit
Procs
proc openws(url: cstring): WebSocket {.
importcpp: "new WebSocket(#)", deprecated.}- Source Edit
proc openws(url: string; protocols: seq[string]): WebSocket {.
importcpp: "new WebSocket(#,@)", deprecated.}- Source Edit
proc newWebSocket(url: cstring): WebSocket {.
importcpp: "new WebSocket(#)".}- Source Edit
proc newWebSocket(url: cstring; protocol: cstring): WebSocket {.
importcpp: "new WebSocket(#,@)".}- Source Edit
proc newWebSocket(url: cstring; protocols: seq[cstring]): WebSocket {.
importcpp: "new WebSocket(#,@)".}- Source Edit
proc addEventListener[](et: EventTarget; ev: cstring; cb: proc (ev: MessageEvent | CloseEvent))
- Source Edit
proc send(socket: WebSocket; data: cstring)
- Source Edit
proc close(socket: WebSocket)
- Source Edit
proc close[](socket: WebSocket; code: StatusCode | Natural)
- Source Edit
proc close[](socket: WebSocket; code: StatusCode | Natural; reason: cstring)
- Source Edit