UNPKG

@plutovr/multi-app-manager

Version:
209 lines (208 loc) 7.33 kB
/** * Events that Pluto Multi App sends to all running XRPKs * Subscribe to these events with MultiAppManager.addEventListener() * PMAL -> All XRPKs */ export declare enum PMALEventType { appAdded = "plutomae-event-app-added", appRemoved = "plutomae-event-app-removed", conversationUserUpdate = "plutomae-event-conversation-user-update", promiseResponse = "plutomae-event-promise-response" } /** * Events that are sent to specific XRPKs requesting various actions * PMAL -> Specific XRPK */ export declare enum PMALAppMessageEventType { shouldPinApp = "plutomam-should-pin-app", shouldUnpinApp = "plutomam-should-unpin-app", getMATransform = "plutomam-get-ma-transform" } /** * All events from an XRPK are sent using this type * @disclaimer Not intended to be used directly. Use the provided public functions to send events to Pluto Multi App * */ export declare const XRPKEventType = "plutomae-xrpk-event"; /** * Event descriptions that can be sent to Pluto Multi App Launcher from an XRPK * @disclaimer These are not event strings, but descriptions of events. Use the provided public functions to send events to Pluto Multi App Launcher * XRPK -> PMAL */ export declare enum XRPKEventTypeDescription { launchApp = "launch-xrpk", launchAppByNameAndId = "launch-xrpk-by-name-id", launchAssetByNameAndId = "launch-asset-by-name-id", duplicateApp = "duplicate-xrpk", appIsReady = "xrpk-loaded", removeApp = "remove-xrpk", getAppList = "retrieve-app-list", didPinApp = "did-pin-app", didUnpinApp = "did-unpin-app", setPinState = "set-pin-state", currentTransform = "current-transform", canProvideTransform = "can-provide-transform", isOwner = "is-owner", getSavedApps = "get-saved-xrpks", getSavedAssets = "get-saved-assets" } interface AppAddedArgs { app: { name: string; uuid: string; deviceId: string; }; currentApps: object; } interface AppRemovedArgs { app: { name: string; uuid: string; }; currentApps: object; } interface ConversationUserUpdateArgs { conversationId: string; localUserId: string; users: [object]; } interface PinAppArgs { appId: string; } interface GetMATransformArgs { appId: string; callback: (transform?: MATransform) => void; } interface Callback { (args: AppAddedArgs | AppRemovedArgs | ConversationUserUpdateArgs | PinAppArgs | GetMATransformArgs | MATransform | null): void; } interface Vector3 { x: number; y: number; z: number; } interface Quaternion { x: number; y: number; z: number; w: number; } interface MATransform { /** A Vector3 representing the object's local position. */ position: Vector3; /** Object's local rotation. */ quaternion: Quaternion; /** The object's local scale. */ scale: Vector3; } interface AssetLoaderData { url: string; name: string; isStatic: boolean; assetType: AssetType; } export declare enum AssetType { image = "image", model = "model" } interface AppState { appId?: string; /** @deprecated in v0.9.0. Use initialTransform instead */ initialPosition?: Vector3; initialTransform?: MATransform; assetLoader?: AssetLoaderData; type?: string; xrpkpath?: string; sourceAppId?: string; } declare global { interface Window { AppState: AppState; } } /** * Pluto Multi App Event Handler * Use this class to send and receive events between a mutli app and the Pluto Multi App Launcher */ declare class MultiAppManager { private _appId?; private _eventHandler; private _openPromises; private _onProvideTransform?; /** Implement this method so that the transform can be provided when requested by an external source * @param appId The App ID of the multi app whose transform is being requested (should be your multi app) * @returns A Multi App Transform */ set onProvideTransform(func: (appId?: string) => MATransform); constructor(); /** * Add an event listenter for Pluto Multi App Manager * @param type The `PMALEventType` to subscribe to * @param callback The callback to run when the event is receieved */ addEventListener(type: PMALEventType | PMALAppMessageEventType, callback: Callback): void; /** * Request to launch an XRPK in Pluto Multi App Launcher * @param linkUrl The url of the XRPK app. Must link directly to the file (ie. .wbn file) * @param transform A transform for the Pluto Multi App Launcher to pass along to the app being launched (if supported by the app being launched) * @returns A promise once a response is receieved from Pluto Multi App */ launchXRPK(linkUrl: string, transform: MATransform): Promise<unknown>; duplicateXRPK(id: string, transform: MATransform, shouldWaitForAppReady: Boolean): Promise<unknown>; XRPKLoaded(): void; /** * Request to remove an XRPK in Pluto Multi App Launcher * @param appIdToRemove The app ID of the app to be removed * @returns A promise once a response is receieved from Pluto Multi App */ removeXRPK(appIdToRemove: string): Promise<unknown>; /** * Request to determine whether this client is the owner of this app * @returns A promise once a response is receieved from Pluto Multi App */ getOwnerData(): Promise<unknown>; /** * Get the current app list from Pluto Multi App Launcher * @returns A promise that when resolved includes the app list */ retrieveAppList(): Promise<unknown>; /** * Let Pluto Multi App Launcher know that the app has been pinned * @param transform An optional transform of where the app was pinned * @returns Returns true if a message was sent to Pluto Multi App Launcher, else false */ didPinApp(transform?: MATransform): boolean; /** * Let Pluto Multi App Launcher know that the app has been unpinned * @returns Returns true if a message was sent to Pluto Multi App Launcher, else false */ didUnpinApp(): boolean; /** * Let Pluto Multi App Launcher know pinned state of an XRPK * @param pinned True if the app is pinned, otherwise false if the app is unpinned * @returns Returns true if a message was sent to Pluto Multi App Launcher, else false */ setPinState(pinned: boolean): boolean; /** * App State is provided to every app by Pluto Multi App Launcher * @returns The App State object, or an empty object if the App State does not exist */ getAppState(): AppState; /** * Send the current transform of a multi app to the Pluto Multi App Launcher * @param transform * @returns Returns true if a message was sent to Pluto Multi App Launcher, else false */ currentMATransform(transform: MATransform): boolean; /** * Let the Pluto Multi App Launcher know that your app is capable of sending a transform * @param transform * @returns Returns true if a message was sent to Pluto Multi App Launcher, else false */ canProvideTransform(): boolean; private appMessageHandler; private handleResponse; private generateResponseId; private isXRPK; } declare const _default: MultiAppManager; export default _default;