# cp.websocket.http

Provides a full HTTP-based websocket implementation.


# 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
  • isOpen
  • open
  • send
  • status

# API Documentation

# Functions

# new

Signature cp.websocket.http.new(url, callback) -> object
Type Function
Description Creates a new websocket connection via a serial connection.
Parameters
  • url - The URL path to the websocket server.
  • callback - A function that's triggered by websocket actions.
Returns
  • The cp.websocket object
Notes
  • The callback should accept two parameters.
  • The first parameter is a cp.websocket.event value.
  • 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 src/extensions/cp/websocket/http.lua line 21

# Methods

# close

Signature cp.websocket.http:close() -> object
Type Method
Description Closes a websocket connection.
Parameters
  • None
Returns
  • The cp.websocket.serial object
Notes
  • The status may be either closing or closed after calling this method.
  • To be notified the close has completed, listen for the cp.websocket.event.closed event in the callback.
Examples None
Source src/extensions/cp/websocket/http.lua line 175

# isOpen

Signature cp.websocket.http:isOpen() -> boolean
Type Method
Description Gets whether or not the HTTP websocket is fully open.
Parameters
  • None
Returns
  • true if open, otherwise false.
Notes None
Examples None
Source src/extensions/cp/websocket/http.lua line 133

# open

Signature cp.websocket.http:open() -> cp.websocket.status
Type Method
Description Attempts to open a websocket connection with the configured HTTP connection.
Parameters
  • None
Returns
  • The cp.websocket.status after attempting to open.
Notes None
Examples None
Source src/extensions/cp/websocket/http.lua line 117

# send

Signature cp.websocket.http: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 cp.websocket.serial 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 src/extensions/cp/websocket/http.lua line 207

# status

Signature cp.websocket.http:status() -> cp.websocket.status
Type Method
Description Returns the current connection status.
Parameters
  • None
Returns
  • The current cp.websocket.status.
Notes None
Examples None
Source src/extensions/cp/websocket/http.lua line 53