/// /// import http from 'http'; import ws from 'ws'; import { EventEmitter } from 'events'; /** * World information. * @property placeId Place ID. * @property gameId Game ID. * @property jobId Job ID. * @property userId User ID. * @property userName User name. */ export declare type World = { placeId: number; gameId: number; jobId: number; userId: number; userName: string; }; /** * Node instance. * @property socket WebSocket connection. * @property emitter Event emitter. * @property info Node information. * @property info.pid Node process ID. * @property info.version Node version. * @property info.world Node world. */ export declare type Node = { socket: ws.WebSocket; emitter: EventEmitter; info?: Partial<{ pid: number; version: string; world: World; }>; }; /** * Synapse X server instance. */ export declare type SynXServer = { port: number; nodes: Node[]; http: http.Server; wss: ws.Server; emitter: EventEmitter; }; /** * Internal packet types. */ export declare enum InternalPacket { 'client-initialization' = 0, 'server-initialization' = 1, 'datamodel-start' = 2, 'execute' = 3, 'settings' = 4, 'console-output' = 5, 'console-clear' = 6, 'tab-create' = 7, 'theme' = 8, 'request-close' = 9, 'broadcast' = 10, 'broadcast-incoming' = 11, 'datamodel-update' = 12, 'lua__DEBUG__' = 13, 'close__PSEUDO__' = 1000 } /** * JSON Serializable value. */ export declare type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue; }; /** * Reports whether the node can be communicated with. * @param node The node to check. * @returns Whether the node is good. */ export declare function nodeGood(node: Node): boolean; /** * Sends a data packet to the node. * @param node The node to send to. * @param packet The packet to send. * @param object The data to send. * @returns Whether the packet was sent. */ export declare function nodeSend(node: Node, packet: keyof typeof InternalPacket, object: JSONValue): boolean; /** * Binds a callback to an node event. * @param node The node to bind to. * @param packet The packet to bind to. * @param callback The callback to bind. */ export declare function nodeBind(node: Node, packet: keyof typeof InternalPacket, callback: (object: any) => void): void; /** * Unbinds a callback from an node event. * @param node The node to unbind from. * @param packet The packet to unbind from. * @param callback The callback to unbind. */ export declare function nodeUnbind(node: Node, packet: keyof typeof InternalPacket, callback: (object: any) => void): void; /** * Bind default callbacks to an node. * @param node The node to bind to. */ export declare function nodeBindDefaults(node: Node): void; /** * Dispatch a node, which allows it to join its world. You can hold this process * indefinitely until you are fully ready to let the node join. * @param node The node to dispatch. * @param options The options to use. * @param options.initialSettings The initial settings to use. * @param options.autoexecuteFiles The files to autoexecute. * @param options.path The path to use. */ export declare function nodeDispatch(node: Node, options: { initialSettings: { [key: string]: string; }; autoexecuteFiles: string[]; path: string; }): void; /** * Create new node from socket. * @param socket The socket to create from. * @returns The new node. */ export declare function node(socket: ws.WebSocket): { socket: ws.WebSocket; emitter: EventEmitter; }; /** * Create a new Synapse X Node Server. * @param port The port to use. * @returns The new server. */ export declare function server(port?: number): SynXServer; /** * Binds a callback to a server event. * @param server The server to bind to. * @param event The event to bind to. * @param callback The callback to bind. */ export declare function serverBind(server: SynXServer, event: string, callback: (...args: any[]) => void): void; /** * Unbinds a callback from a server event. * @param server The server to unbind from. * @param event The event to unbind from. * @param callback The callback to unbind. */ export declare function serverUnbind(server: SynXServer, event: string, callback: (...args: any[]) => void): void;