UNPKG

@vrspace/babylonjs

Version:

vrspace.org babylonjs client

566 lines (565 loc) 17.7 kB
/** Object ID, consisting of class name and number. */ export class ID { constructor(className: any, id: any); /** Class name */ className: any; /** Identifier (number) */ id: any; /** class name + ' ' + id */ toString(): string; } /** Rotation, FIXME: not used */ export class Rotation { x: number; y: number; z: number; angle: number; } /** Point in space, x, y, z */ export class Point { x: number; y: number; z: number; } /** Currently active animation of an object. */ export class Animation { name: any; loop: boolean; } /** Welcome message received from the server when entering a world. */ export class Welcome { client: any; permanents: any[]; } /** Basic VRObject, has the same properties as server counterpart. */ export class VRObject { /** Id, equal on server and all instances */ id: any; /** Position, Point */ position: any; /** Rotation, Point */ rotation: any; /** Scale, Point */ scale: any; /** Default false, permanent objects remain in the scene forever */ permanent: boolean; /** Everything created by guest client is by default temporary */ temporary: any; /** URL of 3D mesh */ mesh: any; /** Active i.e. online users */ active: boolean; /** Active animation */ animation: any; /** URL of dynamically loaded script TODO */ script: any; /** Custom properties of an object - shared transient object*/ properties: any; /** Event listeners. Typically world manager listens to changes, and moves objects around. */ listeners: any[]; /** Load listeners, functions that trigger after the mesh or script is loaded. Managed by WorldManager. CHECKME SoC */ loadListeners: any[]; /** Internal, set by WorldManager after the mesh/script has loaded. */ _isLoaded: boolean; /** Handy reference to VRSpace instance */ VRSPACE: any; /** Server-side class name */ className: string; /** Add a change listener to the object. */ addListener(listener: any): void; /** Add a load listener function to the object. Triggers immediatelly if mesh/script has already loaded (_isLoaded is true). */ addLoadListener(listener: any): void; /** Remove the listener. */ removeListener(listener: any): void; /** Remove a load listener. */ removeLoadListener(listener: any): void; /** Called when server sends notification that the object has changed. Notifies all listeners of object and changes. */ notifyListeners(changes: any): void; /** Triggers all load listeners */ notifyLoadListeners(): void; /** Publish the object to the server. Can be used only on new objects. */ publish(): void; getID(): ID; } /** Scene properties, same as server counterpart. */ export class SceneProperties { /** Visibility range, default 2000 */ range: number; /** Movement resolution, default 10 */ resolution: number; /** Maximum size, default 1000 */ size: number; /** Invalidation timeout in ms, default 30000 */ timeout: number; } /** Representation of a client (user, bot, remote server...). @extends VRObject */ export class Client extends VRObject { /** Client name, must be unique */ name: any; /** Scene properties */ sceneProperties: any; /** Private tokens */ tokens: any; hasAvatar: boolean; /** Handy function, returns name if not null, else class and id */ getNameOrId(): any; } /** Representation of a user. @extends Client */ export class User extends Client { /** Does this client have humanoid avatar, default true */ humanoid: boolean; /** Does this client have video avatar, default false */ video: boolean; /** Left arm position */ leftArmPos: { x: any; y: any; z: any; }; /** Right arm position */ rightArmPos: { x: any; y: any; z: any; }; /** Left arm rotation, quaternion */ leftArmRot: { x: any; y: any; z: any; w: any; }; /** Right arm rotation, quaternion */ rightArmRot: { x: any; y: any; z: any; w: any; }; /** User height, default 1.8 */ userHeight: number; } export class RemoteServer extends Client { url: any; thumbnail: any; humanoid: boolean; } /** See server side counterpart. @extends Client */ export class EventRecorder extends Client { } /** Robot base class, useful for chatbots. @extends User */ export class Bot extends User { gender: any; lang: any; } export class BotLibre extends Bot { } export class Terrain extends VRObject { } export class VRFile extends VRObject { /** Content object contains fileName, contentType, length */ content: any; } export class Background extends VRObject { texture: any; ambientIntensity: number; } export class Game extends VRObject { name: any; numberOfPlayers: number; status: any; players: any[]; } /** An event that happened to an object. @param obj VRObject instance @param changes optional object encapsulating changes to the object (field:value) */ export class VREvent { constructor(obj: any, changes: any); /** VRObject that has changed */ object: Object; changes: any; } /** A scene event - addition or removal of some objects, typically users. An object is either added or removed, the other value is null. */ export class SceneEvent { constructor(scene: any, className: any, objectId: any, added: any, removed: any); /** Class name of object added/removed */ className: any; /** Id of added/removed object */ objectId: any; /** Added object */ added: any; /** Removed object */ removed: any; /** New scene */ scene: any; } /** * Streaming session data, used to match the client avatar or other mesh to the video/audio stream. */ export class SessionData { /** * @param {String} json string representation of this object (passed along connection as user data) */ constructor(json: string); /** Client id, long */ clientId: any; /** Session name, matches either world name for public world, or world token for private world */ name: any; /** Session type - 'main' or 'screen' */ type: any; } export class UserGroup { id: any; name: any; isPublic: any; } export class GroupMember { id: any; /** @type {UserGroup} */ group: UserGroup; /** @type {Client} */ client: Client; pendingInvite: any; pendingRequest: any; /** @type {Client} */ sponsor: Client; lastUpdate: any; } export class GroupMessage { /** @type {Client} */ from: Client; /** @type {UserGroup} */ group: UserGroup; content: any; link: any; local: any; } /** Notification from a UserGroup */ export class GroupEvent { /** @type {GroupMessage} */ message: GroupMessage; /** @type {GroupMember} */ invite: GroupMember; } /** Main client API class, no external dependencies. Provides send methods to send messages to the server, to be distributed to other clients. Listeners receive remote events. */ export class VRSpace { /** Underlying websocket */ ws: WebSocket; /** Representation of own Client, available once connection is established */ me: any; /** Map containing all objects in the scene */ scene: any; /** Debug logging, default false */ debug: boolean; connectionListeners: any[]; dataListeners: any[]; sceneListeners: any[]; welcomeListeners: any[]; errorListeners: any[]; groupListeners: any[]; /** Listener to response to a command. */ responseListener: any; sharedClasses: { ID: typeof ID; Rotation: typeof Rotation; Point: typeof Point; VRObject: typeof VRObject; SceneProperties: typeof SceneProperties; Client: typeof Client; User: typeof User; RemoteServer: typeof RemoteServer; VREvent: typeof VREvent; SceneEvent: typeof SceneEvent; EventRecorder: typeof EventRecorder; Bot: typeof Bot; BotLibre: typeof BotLibre; Terrain: typeof Terrain; VRFile: typeof VRFile; Game: typeof Game; Background: typeof Background; }; messageHandlers: { object: (message: any) => void; Add: (message: any) => void; Remove: (message: any) => void; ERROR: (message: any) => void; Welcome: (message: any) => void; response: (message: any) => void; GroupEvent: (message: any) => void; }; log(msg: any): void; addListener(array: any, callback: any): any; removeListener(array: any, listener: any): void; /** Add a connection listener that gets notified when connection is activated/broken. Callback is passed boolean argument indicating connection state. */ addConnectionListener(callback: any): any; /** Add a data listener that receives everything from the server (JSON string argument) */ addDataListener(callback: any): any; /** * @callback sceneCallback * @param {SceneEvent} event */ /** Add a scene listener that gets notified when the scene is changed. Scene listeners receive SceneEvent argument for each change. @param {sceneCallback} callback */ addSceneListener(callback: (event: SceneEvent) => any): any; /** Remove a scene listener. */ removeSceneListener(callback: any): void; /** Add a Welcome listener, notified when entering a world. The listener receives Welcome object. */ addWelcomeListener(callback: any): any; /** Remove welcome listener @param callback listener to remove */ removeWelcomeListener(callback: any): void; /** Add error listener, notified when server sends error notifications. Error listener is passed the string containing the server error message, e.g. java exception. */ addErrorListener(callback: any): any; /** Remove error listener @param callback listener to remove */ removeErrorListener(callback: any): void; /** Add a group listener, notified when entering a world. The listener receives Welcome object. @param {function(GroupEvent)} callback */ addGroupListener(callback: (arg0: GroupEvent) => any): any; /** Remove group listener @param callback listener to remove */ removeGroupListener(callback: any): void; /** Return the current scene, optionally filtered @param filter string to match current members, usually class name, or function that takes VRObject as argument */ getScene(filter: any): any; /** Connect to the server, attach listeners. @param url optional websocket url, defaults to /vrspace/client on the same server */ connect(url: any): void; /** Disconnect, notify connection listeners */ disconnect(): void; /** Convert a vector to json string @param vec object having x,y,z properties */ stringifyVector(vec: any): string; /** Convert a quaternion to json string @param vec object having x,y,z,w properties */ stringifyQuaternion(quat: any): string; /** Convert a key/value pair to json string. FIXME improperly stringifies objects having properties x, _x, or w. Properties other than x,y,z,w will be ignored. See stringifyVector and stringifyQuaternion. This is essentially workaround for bablyon types, e.g. Vector3, that have _x, _y, _z properties. @param field name of the field @param value string, object or number to convert */ stringifyPair(field: any, value: any): string; /** Create a local field of an object existing on the server FIXME Obsolete */ createField(className: any, fieldName: any, callback: any): void; /** Common code for createSharedObject and createScriptedObject @param command either Add or Share @param obj the new VRObject, containing all properties @param className optional class name to create, defaults to obj.className if exists, otherwise VRObject @returns Promise with the created VRObject instance */ _createSharedObject(command: any, obj: any, className: any): Promise<any>; /** Share an object. @param obj the new VRObject, containing all properties @param className optional class name to create, defaults to obj.className if exists, otherwise VRObjects @returns Promise with the created VRObject instance */ createSharedObject(obj: any, className: any): Promise<any>; /** Create a shared scripted object. The server determines which scripts are allowed, so this sends different command than createSharedObject. @param obj the new VRObject, containing all properties @param callback called when shared object is received @param className optional class name to create, defaults to obj.className if exists, otherwise VRObjects @returns Promise with the created VRObject instance */ createScriptedObject(obj: any, className: any): Promise<any>; /** Delete a shared object. @param obj to be removed from the server @param callback optional, called after removal from the server */ deleteSharedObject(obj: any, callback: any): void; /** Send notification of own property changes @param field name of member variable that has changed @param value new field value */ sendMy(field: any, value: any): void; /** Send a command to the server @param command to execute @param args optional object with command arguments */ sendCommand(command: any, args: any): void; /** Send a command to the server @param command to execute @param callback function that's called with command return value */ callCommand(command: any, callback: any): void; /** * Set a client token e.g. required to enter a world * @param name token name * @param value token value */ setToken(name: any, value: any): void; /** Send changes to an object @param obj VRObject that changes @param changes array containing field/value pairs */ sendChanges(obj: any, changes: any): void; /** Send changes to an object @param obj VRObject that changes @param changes object containing changed fields */ sendEvent(obj: any, changes: any): void; /** Send changes to own avatar @param changes array with field/value pairs */ sendMyChanges(changes: any): void; /** Send changes to own avatar @param changes object containing changed field(s) */ sendMyEvent(changes: any): void; send(message: any): void; /** Perform a synchronous call. @param message JSON string to send @param callback function to execute upon receiving the response */ call(message: any, callback: any): void; /** Factory method @param className shared class name @returns new shared object instance */ newInstance(className: any): any; addToScene(className: any, object: any): void; addObject(obj: any): void; removeObject(objectId: any): void; /** Called when a message is received from the server. JSON message is converted to an object, then depending on object type, forwarded to one of this.messageHandlers. @param {String} message text message from the server over the websocket */ receive(message: string): void; /** * Handle event of a shared VRObject: find the object in the scene, apply changes, notify listeners. * @param {VREvent} message containing object id and changes */ handleEvent(message: VREvent): void; /** * Handle Add message: add every object to the scene, and notify listeners. Calls addObject. * @param {Add} add Add command containing addedd objects */ handleAdd(add: Add): void; /** * Handle Remove message: remove every object from the scene, and notify listeners. Calls removeObject. * @param {Remove} remove Remove command containing list of object IDs to remove */ handleRemove(remove: Remove): void; /** * Handle server error: log the error, and notify error listeners. * @param {object} error object containing error message received from the server */ handleError(error: object): void; /** * Handle Welcome message: create own user object, and notify welcome listeners. Adds all permanent objects to the scene. * @param {Welcome} welcome the Welcome message. */ handleWelcome(welcome: Welcome): void; /** * Handle response to command: if responseListener is installed, execute it with the message, ignore otherwise. * @param {object} response object containing response to the command, can be anything, depending on the command. */ handleResponse(response: object): void; /** * Handle a group event, simply forward the event to all groupListeners. * @param {GroupEvent} event */ handleGroupEvent(event: GroupEvent): void; /** * Experimental. Executes StreamingSession start command on the server that returns session token, * the executes callback, passing the token to it */ startStreaming(callback: any): Promise<any>; /** * Experimental. Executes StreamingSession stop command on the server. * CHECKME Since the server manages streaming sessions anyway, this may not be needed at all. */ stopStreaming(): void; } export const VRSPACE: VRSpace;