Constructors

  • PushSocket constructor; Accepts a config object, params to be passed to the space, and a callback to be called when the socket is connected.

    Below is an example of importing and initalizing PushSocket.

    // as CommonJS Module
    const ps = require("pushsocket.js");
    // as ES Module
    import * as ps from "pushsocket.js";

    const socket = new ps.PushSocket(
    {
    // space_id: optional, defaults to "global"
    space_id: "<space: String>",
    // password: optional, defaults to "password"
    password: "<password: String>"
    },
    null, // null, no params to the space.
    handleConnect // will be called when the socket is connected.
    );

    Parameters

    • config: PSConfig
    • params: object
    • onConnect: Function

    Returns PushSocket

Properties

connected: boolean
connectedCallback: Function
id: string
space: string
spacePassword: string
ws: WebSocket

Accessors

  • get secureID(): string
  • secureID property; returns the secure id of the socket.

    Returns string

  • set secureID(id): void
  • Parameters

    • id: string

    Returns void

Methods

  • Connect Method; if you get disconnected from the space, you can call this method with the space id and space password again to reconnect. PARAM 1: space_id: String, the space to connect to. PARAM 2: space_password: String, the password to the space.

    Parameters

    • space_id: string = "global"
    • space_password: string = "password"
    • params: object

    Returns void

  • Observe Method; Observes a channel for message(s). Usage:

    // channel: optional, defaults to "GLOBAL"

    PushSocket.observe("<channel: String>", (msg) => {
    // ``msg.data<String>`` for the message contents.
    });

    Parameters

    • channel: string
    • callback: Function

    Returns void

  • Send Method; sends data (param 1) to a specified channel (param 2). If param 2 is not given, channel will default to "GLOBAL"

    PushSocket.send("<channel: String>", "<data: String>");
    

    Parameters

    • data: string
    • channel: string

    Returns void

Generated using TypeDoc