Types
Opcode = enum Cont = 0, ## Denotes a continuation frame. Text = 1, ## Denotes a text frame. Binary = 2, ## Denotes a binary frame. Close = 8, ## Denotes a connection close. Ping = 9, ## Denotes a ping. Pong = 10 ## Denotes a pong.
- 4 bits. Defines the interpretation of the "Payload data". Source Edit
ReadyState = enum Connecting = 0, Open = 1, Closing = 2, Closed = 3
- Source Edit
WebSocket = ref object tcpSocket*: AsyncSocket version*: int key*: string protocol*: string readyState*: ReadyState masked*: bool
- Source Edit
WebSocketClosedError = object of WebSocketError
- Source Edit
WebSocketCreationError = object of WebSocketError
- Source Edit
WebSocketError = object of IOError
- Source Edit
WebSocketFailedUpgradeError = object of WebSocketError
- Source Edit
WebSocketHandshakeError = object of WebSocketError
- Source Edit
WebSocketPacketTypeError = object of WebSocketError
- Source Edit
WebSocketProtocolMismatchError = object of WebSocketError
- Source Edit
Procs
proc close(ws: WebSocket) {....raises: [Exception, ValueError], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect].}
- Close the Socket, sends close packet. Source Edit
proc decodeBase16(str: string): string {....raises: [], tags: [].}
- Base16 decode a string. Source Edit
proc encodeBase16(str: string): string {....raises: [], tags: [].}
- Base61 encode a string. Source Edit
proc handshake(ws: WebSocket; headers: HttpHeaders): owned(Future[void]) {. ...raises: [Exception], tags: [RootEffect].}
- Handles the websocket handshake. Source Edit
proc hangup(ws: WebSocket) {....raises: [WebSocketError], tags: [RootEffect].}
- Closes the Socket without sending a close packet. Source Edit
proc newWebSocket(req: Request; protocol: string = ""): Future[WebSocket] {. ...raises: [Exception, ValueError], tags: [RootEffect].}
- Creates a new socket from a request. Source Edit
proc newWebSocket(url: string; protocol: string): Future[WebSocket] {. ...raises: [Exception, ValueError], tags: [RootEffect, ReadIOEffect, TimeEffect].}
- Source Edit
proc newWebSocket(url: string; protocols: seq[string] = @[]): Future[WebSocket] {. ...raises: [Exception, ValueError], tags: [RootEffect, ReadIOEffect, TimeEffect].}
- Creates a new WebSocket connection, protocol is optional, "" means no protocol. Source Edit
proc ping(ws: WebSocket; data = ""): owned(Future[void]) {....raises: [Exception], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect].}
- Sends a ping to the other end, both server and client can send a ping. Data is optional. Source Edit
proc receiveBinaryPacket(ws: WebSocket): Future[seq[byte]] {. ...raises: [Exception, ValueError], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect].}
- Wait only for a binary packet to come. Errors out on string packets. Source Edit
proc receivePacket(ws: WebSocket): Future[(Opcode, string)] {. ...raises: [Exception, ValueError], tags: [RootEffect].}
- Wait for a string or binary packet to come in. Source Edit
proc receiveStrPacket(ws: WebSocket): Future[string] {. ...raises: [Exception, ValueError], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect].}
- Wait only for a string packet to come. Errors out on Binary packets. Source Edit
proc send(ws: WebSocket; text: string; opcode = Opcode.Text): Future[void] {. ...raises: [Exception], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect].}
- This is the main method used to send data via this WebSocket. Source Edit
proc setupPings(ws: WebSocket; seconds: float) {. ...raises: [Exception, ValueError], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect].}
- Sets a delay on when to send pings. Source Edit