Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/tpy/src/ws.ts>TpyWs#on

🔑 A strongly typed Pylon API client.
Latest
method TpyWs.prototype.on
import { TpyWs } from "https://deno.land/x/tpy@v1.0.0-RC/src/ws.ts";

Adds an event listener to WebSocket events.

Parameters

type: "open"

Fired when the WebSocket is (re)opened.

callback: (data: Event) => void

A callback function to invoke when this event is fired.

Adds an event listener to WebSocket events.

Parameters

type: "close"

Fired when the WebSocket is closed.

callback: (data: CloseEvent) => void

A callback function to invoke when this event is fired.

Adds an event listener to WebSocket events.

Parameters

type: "error"

Fired when the WebSocket captures an error.

callback: (data: ErrorEvent | Event) => void

A callback function to invoke when this event is fired.

Notice!

This event is fired every time the WebSocket is closed. This is an action of the Pylon backend marking closed connections as errors.

Adds an event listener to WebSocket events.

Type Parameters

T extends unknown[]

The type of the data object inside PylonWebSocket.Response.

Parameters

type: "message"

Fired when the WebSocket recieves a message.

callback: (data: Unpacked<PylonWebSocket.Response<T>>) => void

A callback function to invoke when this event is fired.