UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

107 lines (106 loc) 3.75 kB
import { Behaviour } from "./Component.js"; /** * SyncedRoom is a behaviour that will attempt to join a networked room based on the URL parameters or a random room. * It will also create a button in the menu to join or leave the room. * You can also join a networked room by calling the core methods like `this.context.connection.joinRoom("roomName")`. * * @example Join a networked room * ```typescript * const myObject = new Object3D(); * myObject.addComponent(SyncedRoom, { roomName: "myRoom" }); * ``` * * @example Join a random networked room * ```typescript * const myObject = new Object3D(); * myObject.addComponent(SyncedRoom, { joinRandomRoom: true }); * ``` * * @example Join a random networked room with prefix - this ensures that no room name collisions happen when running multiple applications on the same server instance * ```typescript * const myObject = new Object3D(); * myObject.addComponent(SyncedRoom, { joinRandomRoom: true, roomPrefix: "myApp_" }); * ``` * * @category Networking * @group Components */ export declare class SyncedRoom extends Behaviour { /** * The name of the room to join. * @default "" */ roomName: string; /** * The URL parameter name to use for the room name. E.g. if set to "room" the URL will look like `?room=roomName`. * @default "room" */ urlParameterName: string; /** * If true, the room will be joined automatically when this component becomes active. * @default undefined which means it will join a random room if no roomName is set. */ joinRandomRoom?: boolean; /** * If true and no room parameter is found in the URL then no room will be joined. * @default false */ requireRoomParameter: boolean; /** * If true, the room will be rejoined automatically when disconnected. * @default true */ autoRejoin: boolean; /** * If true, a join/leave room button will be created in the menu. * @default true */ createJoinButton: boolean; /** * If true, a join/leave room button for the view only URL will be created in the menu. * @default false */ createViewOnlyButton: boolean; /** * Get current room name from the URL parameter or the view parameter. */ get currentRoomName(): string | null; private _lastJoinedRoom?; /** The room prefix to use for the room name. E.g. if set to "room_" and the room name is "name" the final room name will be "room_name". */ set roomPrefix(val: string); get roomPrefix(): string; private _roomPrefix; /** @internal */ awake(): void; /** @internal */ onEnable(): void; /** @internal */ onDisable(): void; /** @internal */ onDestroy(): void; /** Will generate a random room name, set it as an URL parameter and attempt to join the room */ tryJoinRandomRoom(): void; /** Try to join the currently set roomName */ tryJoinRoom(call?: number): boolean; private _lastPingTime; private _lastRoomTime; private _userWantsToBeInARoom; /** @internal */ update(): void; /** * Get the URL to view the current room in view only mode. */ getViewOnlyUrl(): string | null; private setRandomRoomUrlParameter; private generateRoomName; private _roomButton?; private _roomButtonIconJoin?; private _roomButtonIconLeave?; private createRoomButton; private updateRoomButtonState; private destroyRoomButton; private _viewOnlyButton?; private onEnableViewOnlyButton; private onDisableViewOnlyButton; private onCreateViewOnlyButton; }