UNPKG

moomooio-client

Version:

MooMooIO-Client is a client-side wrapper API designed for the game MooMoo.io. This package aims to provide a simple yet powerful API for creating clones, mods, or plugins for MooMoo.io.

29 lines (27 loc) 940 B
/** * HookWebSocket * @description This function creates a custom WebSocket class that allows you to hook into the WebSocket lifecycle. * @param target The target object that will be extended with the custom WebSocket class. * @param onHook A function that will be called with the new WebSocket instance as its only argument. * @returns The extended target object. */ export default function HookWebSocket( target: { WebSocket: { new (url: string | URL, protocols?: string | string[] | undefined): WebSocket; prototype: WebSocket; readonly CONNECTING: 0; readonly OPEN: 1; readonly CLOSING: 2; readonly CLOSED: 3; }; }, onHook: (data: WebSocket) => void ) { target.WebSocket = class extends target.WebSocket { constructor(url: string | URL, protocols?: string | string[] | undefined) { super(url, protocols); onHook(this); } }; }