# hs.websocket

Simple websocket client.


# API Overview

Functions - API calls offered directly by the extension

  • new

Methods - API calls which can only be made on an object returned by a constructor

  • close
  • send
  • status

# API Documentation

# Functions

# new

Signature hs.websocket.new(url, callback) -> object
Type Function
Description Creates a new websocket connection.
Parameters
  • url - The URL to the websocket
  • callback - A function that's triggered by websocket actions.
Returns
  • The hs.websocket object
Notes
  • The callback should accept two parameters.
  • The first parameter is a string with the following possible options:
  • open - The websocket connection has been opened
  • closed - The websocket connection has been closed
  • fail - The websocket connection has failed
  • received - The websocket has received a message
  • pong - A pong request has been received
  • The second parameter is a string with the received message or an error message.
  • Given a path '/mysock' and a port of 8000, the websocket URL is as follows:
  • ws://localhost:8000/mysock
  • wss://localhost:8000/mysock (if SSL enabled)
Examples None
Source extensions/websocket/libwebsocket.m line 120

# Methods

# close

Signature hs.websocket:close() -> object
Type Method
Description Closes a websocket connection.
Parameters
  • None
Returns
  • The hs.websocket object
Notes None
Examples None
Source extensions/websocket/libwebsocket.m line 230

# send

Signature hs.websocket:send(message[, isData]) -> object
Type Method
Description Sends a message to the websocket client.
Parameters
  • message - A string containing the message to send.
  • isData - An optional boolean that sends the message as binary data (defaults to true).
Returns
  • The hs.websocket object
Notes
  • Forcing a text representation by setting isData to false may alter the data if it
  • contains invalid UTF8 character sequences (the default string behavior is to make
  • sure everything is "printable" by converting invalid sequences into the Unicode
  • Invalid Character sequence).
Examples None
Source extensions/websocket/libwebsocket.m line 164

# status

Signature hs.websocket:status() -> string
Type Method
Description Gets the status of a websocket.
Parameters
  • None
Returns
  • A string containing one of the following options:
  • connecting
  • open
  • closing
  • closed
  • unknown
Notes None
Examples None
Source extensions/websocket/libwebsocket.m line 194