@vrspace/babylonjs
Version:
vrspace.org babylonjs client
140 lines (139 loc) • 5.39 kB
TypeScript
/**
* Class to execute REST API calls, singleton.
* By default, we're making API calls to the same server that serves the content.
* This can be changed by providing different apiBase URL to the constructor.
* All methods are asynchronous but blocking calls.
*/
export class VRSpaceAPI {
static instance: any;
/**
* Returns VRSpaceAPI instance, creates one if required.
* @param {String|null} [apiBase] API URL base
* @param {String|null} [apiPath] API URL path
* @returns {VRSpaceAPI}
*/
static getInstance(apiBase?: string | null, apiPath?: string | null): VRSpaceAPI;
/**
* @param {string} [apiBase=""] Base URL for all API endpoint, origin (protocol+host)
* @param {string} [apiPath="/vrspace/api"] Path component of the API URL
*/
constructor(apiBase?: string, apiPath?: string);
base: string;
apiClient: ApiClient;
endpoint: {
/** @type {WorldsApi} */
worlds: WorldsApi;
oauth2: string;
files: string;
/** @type {UsersApi} */
user: UsersApi;
/** @type {GroupsApi} */
groups: GroupsApi;
/** @type {WebPushApi} */
webpush: WebPushApi;
/** @type {ServerInfoApi} */
server: ServerInfoApi;
/** @type {SketchfabApi} */
sketchfab: SketchfabApi;
/** @type {WorldObjectsApi} */
objects: WorldObjectsApi;
};
/**
* Verify if given user name is valid, i.e. we can create user with that name.
* @param {String} name user name
* @returns {boolean} true if user name is available
*/
verifyName(name: string): boolean;
/**
* Returns current user name associated with the session.
* @returns {String|null} current user name, or null if user is anonymous (not logged in yet)
*/
getUserName(): string | null;
/**
* Returns true if the user is authanticated
* @returns {Promise<boolean>}
*/
getAuthenticated(): Promise<boolean>;
/**
* Initiates OAuth2 login with the server - opens login form with Oauth provider.
* Requires Oauth2 provider id as returned by listOAuthProviders().
* @param {String} providerId Oauth provider as defined on the server
* @param {String} userName user name
* @param {String} [avatarUrl] optional Avatar URL
*/
oauth2login(providerId: string, userName: string, avatarUrl?: string): Promise<void>;
/** Returns object of provider id: name (e.g. github: GitHub) */
listOAuthProviders(): Promise<any>;
/**
* Returns User object of the current user, or null for anonymous users
* @returns {Promise< User|null >}
*/
getUserObject(): Promise<User | null>;
/**
* Create a world from template
* @returns token required to access the world
* @param {String} worldName unique world name
* @param {String|undefined} templateName optional template name, a world with this name must exist on the server
* @param {boolean} [isPublic=false] false means only invited users (having the token) can enter
* @param {boolean} [isTemporary=true] true means world is deleted once the last user exits
*/
createWorldFromTemplate(worldName: string, templateName: string | undefined, isPublic?: boolean, isTemporary?: boolean): Promise<string>;
/**
* Internally used helper method
* @private
*/
private getJson;
/**
* Internally used helper method
* @private
*/
private getText;
/**
* Upload a file on a position/rotation.
* @param {File} file Local file object to upload
* @param position an object containing x,y,z (Vector3)
* @param rotation an object containing x,y,z (Vector3)
*/
upload(file: File, position: any, rotation: any): void;
/**
* Internal used by webpushSubscribe
* @private
*/
private unregisterSubscription;
/**
* Internal used by webpushSubscribe
* @private
*/
private registerSubscription;
/**
* Internal used by webpushSubscribe
* @private
*/
private createSubscription;
/**
* Internal used by webpushSubscribe
* @private
*/
private urlBase64ToUint8Array;
/**
* Subcribe to web push, if available on the server. Requires existing service worker,
* registered in main html file onload function. Fails silently if the registration does not exist.
* @param {String} clientUrl path to serviceworker.js
*/
webpushSubscribe(clientUrl: string): void;
/**
* Unsubcribe from web push notifications, if available and subscribed. Requires existing service worker,
* registered in main html file onload function. Fails silently if the not subscribed.
* @param {String} clientUrl path to serviceworker.js
*/
webpushUnsubscribe(clientUrl: string): void;
}
import { ApiClient } from './openapi/ApiClient.js';
import { WorldsApi } from './openapi/api/WorldsApi.js';
import { UsersApi } from './openapi/api/UsersApi.js';
import { GroupsApi } from './openapi/api/GroupsApi.js';
import { WebPushApi } from './openapi/api/WebPushApi.js';
import { ServerInfoApi } from './openapi/api/ServerInfoApi.js';
import { SketchfabApi } from './openapi/api/SketchfabApi.js';
import { WorldObjectsApi } from './openapi/api/WorldObjectsApi.js';
import { User } from './openapi/model/User.js';