Class WispSocketInternal

The primary interface to the Websocket API

Constructors

Properties

Filesystem: FilesystemSocket
api: WispAPI
consoleCallbacks: ((message) => void)[]

Type declaration

    • (message): void
    • Parameters

      • message: string

      Returns void

detailsPreprocessor: undefined | WebsocketDetailsPreprocessor
ghToken: undefined | string
logger: any
pool: WebsocketPool
token: undefined | string
url: undefined | string

Methods

  • Adds a new callback that will run any time a console message is rececived

    Parameters

    • callback: ((message) => void)

      The callback to run, takes a single param, message, a string

        • (message): void
        • Parameters

          • message: string

          Returns void

    Returns void

  • Internal

    Creates a new Websocket Pool

    Returns void

    Throws

    Throws an error if the URL or token are not set yet

  • Internal

    Disconnects from the websocket

    Returns Promise<void>

  • Removes a previously added console message callback

    Parameters

    • callback: ((message) => void)

      The callback function that was previously added

        • (message): void
        • Parameters

          • message: string

          Returns void

    Returns void

  • Issues a correlated fs:request to the backend and awaits its outcome.

    This is the low-level entry point for the git/filesystem protocol. The client emits fs:request with a JSON-string payload ({ req, op, ...params }), and the backend replies with one of three events, all correlated by req and all carrying a JSON-string args[0]:

    • fs:result — success; resolves with the parsed data
    • fs:error — failure; rejects with an FsError (plus collected output)
    • fs:progress — streaming stdout/stderr/progress lines (collected for error context)

    Typed convenience wrappers live on GitSocket (WispSocket.Git) and FilesystemSocket (WispSocket.Filesystem); call this directly for ops that don't have a typed wrapper yet.

    Type Parameters

    • T = any

    Parameters

    • op: string

      The operation name (e.g. git-pull, list)

    • params: Record<string, any> = {}

      Additional payload fields merged into the request (e.g. { directory })

    • timeout: number = 10000

      In milliseconds, how long to wait for the result

    Returns Promise<T>

    Example

    const status = await wisp.socket.request("git-status", { directory: "/garrysmod/addons/acf-3" })
    
  • Internal

    Runs a job on an available pool worker, handing it the worker's socket and logger. Used for event-based flows (e.g. file search) that don't fit the request request/response protocol.

    Type Parameters

    • T

    Parameters

    • work: ((worker) => Promise<T>)

      The job to run; receives the worker and returns a Promise

        • (worker): Promise<T>
        • Parameters

          • worker: SocketWorker

          Returns Promise<T>

    Returns Promise<T>

  • Sends a command to the server and then waits until output with the given prefix is seen in a console message

    Parameters

    • nonce: string

      The short, unique string that your output will be prefixed with

    • command: string

      The full command string to send

    • timeout: number = 1000

      In milliseconds, how long to wait for output before timing out

    Returns Promise<any>

    Example

    Runs a custom lua command that will prefix its output with our nonce, then prints the output from that command

    -- lua/autorun/server/nonce_example.lua
    concommand.Add( "myCommand", function( ply, _, args )
    if IsValid( ply ) then return end

    local nonce = args[1]
    print( nonce .. "Command output" )
    end )
    const nonce = "abc123";
    const command = `myCommand "${nonce}"`;
    try {
    const output = await wisp.socket.sendCommandNonce(nonce, command);
    console.log("Output from command:", output);
    catch (error) {
    console.error(error);
    }

    Remarks

    ℹ️ This is useful if you run code on your Server that will print output with the same prefix, letting you run commands and also receive output for it

  • Internal

    Requests and saves the Websocket details from the API

    Returns Promise<void>

  • Sets a callback to run on the Websocket Info before saving the details.

    Parameters

    Returns void

    Example

    // Change the URL of the Websocket
    wisp.socket.setWebsocketDetailsPreprocessor((info) => {
    info.url = "wss://newurl.com"
    })

    Remarks

    ℹ️ This can be used to modify the URL or token after its retrieved from the API

  • Internal

    Sets up the console listener worker

    Returns void

  • Internal

    Verifies that the pool is created and ready to use

    Returns Promise<void>

Generated using TypeDoc