multyx-client
Version:
Framework designed to simplify the creation of multiplayer browser games by addressing the complexities of managing server-client communication, shared state, and input handling
70 lines (69 loc) • 2.21 kB
TypeScript
import { Add, Done } from './utils';
import { RawObject } from "./types";
import { Controller } from "./controller";
import { MultyxClientObject } from "./items";
import { Options } from "./options";
export default class Multyx {
ws: WebSocket;
uuid: string;
joinTime: number;
ping: number;
events: Map<string | Symbol, ((data?: any) => void)[]>;
self: RawObject;
tps: number;
all: RawObject;
space: string;
clients: {
[key: string]: MultyxClientObject;
};
teams: MultyxClientObject;
controller: Controller;
options: Options;
[Done]: ((...args: any[]) => void)[];
static Start: symbol;
static Connection: symbol;
static Disconnect: symbol;
static Edit: symbol;
static Native: symbol;
static Custom: symbol;
static Any: symbol;
constructor(options?: Options, callback?: () => void);
/**
* Listen for a message from the server
* @param name Name of the message
* @param callback Function to call when the message is received
*/
on(name: string | Symbol, callback: (data: RawObject) => any): void;
/**
* Send a message to the server
* @param name Name of the message
* @param data Data to send
*/
send(name: string, data: any): void;
/**
* Send a message to the server and wait for a response
* @param name Name of the message
* @param data Data to send
* @returns Promise that resolves when the message is received
*/
await(name: string, data?: any): Promise<unknown>;
/**
* Loop over a function
* @param callback Function to call on a loop
* @param timesPerSecond Recommended to leave blank. Number of times to loop in each second, if undefined, use requestAnimationFrame
*/
loop(callback: () => void, timesPerSecond?: number): void;
/**
* Add a function to be called after each frame
* @param callback Function to call after each frame
*/
[Add](callback: () => void): void;
/**
* Parse a native event from the server
* @param msg Message to parse
*/
private parseNativeEvent;
private initialize;
private parseSelf;
private updateSpace;
}