Skip to main content
Module

x/tpy/mod.ts>TpyWs

🔑 A strongly typed Pylon API client.
Go to Latest
class TpyWs
import { TpyWs } from "https://deno.land/x/tpy@v1.0.0-pre-release-11/mod.ts";

An EventEmitter forwarder that keeps an emitter alive while a WebSocket reconnects. Listens to a deployment's console output.

This class creates a parent emitter over a child WebSocket emitter, forwarding events and persists when the child emitter terminates, maintaining active listeners and allowing reconnection with customizable timeouts.

Constructors

new
TpyWs(
tpyInstance: Tpy,
deploymentID: string,
reconnectionTimeout?,
)

Properties

private
optional
_websocket: WebSocket
private
deploymentID: string
private
reconnectionTimout: number
private
tpyClient: Tpy
private
tryToConnect: boolean
eventEmitter: EventEmitter

The proxy stream that ensures the process (or at least the stream) is not terminated.

readonly
messageTypes:
| "message"
| "open"
| "close"
| "error"
[]
readonly
websocket

The raw WebSocket object.

Methods

Closes the WebSocket connection, reconnection will not be attempted.

Retrieves the workbench URL and ties the WebSocket events to an event emitter.

on(type: "open", callback: (data: Event) => void): EventEmitter

Adds an event listener to WebSocket events.

on(type: "close", callback: (data: CloseEvent) => void): EventEmitter

Adds an event listener to WebSocket events.

on(type: "error", callback: (data: ErrorEvent | Event) => void): EventEmitter

Adds an event listener to WebSocket events.

on<T extends unknown[]>(type: "message", callback: (data: Unpacked<PylonWebSocket.Response<T>>) => void): EventEmitter

Adds an event listener to WebSocket events.

Runs the connect method after the specified reconnection timeout.