RTSDK
    Preparing search index...

    Class World

    Create an instance of World class with a given url slug and optional attributes and session credentials.

    import { World } from "utils/topiaInit.ts";

    const world = await World.create(exampleUrlSlug, {
    attributes: { name: "Example World" },
    credentials: { interactivePublicKey: "examplePublicKey", interactiveNonce: "exampleNonce", assetId: "exampleDroppedAssetId", visitorId: 1, urlSlug: "exampleUrlSlug" }
    });

    Hierarchy (View Summary)

    Implements

    Index

    Analytics

    • Retrieve world analytics by day, week, month, quarter, or year

      Parameters

      • __namedParameters: {
            dateValue: number;
            periodType: "week" | "month" | "quarter" | "year";
            year: number;
        }

      Returns Promise<void | ResponseType>

      get, fetch, retrieve, analytics, stats, statistics, data, metrics

      const analytics = await world.fetchWorldAnalytics({
      periodType: "week",
      dateValue: 40,
      year: 2023,
      });

    Data Objects

    • Retrieves the data object for a world. Must have valid interactive credentials from a visitor in the world.

      Parameters

      • OptionalappPublicKey: string
      • OptionalappJWT: string
      • OptionalsharedAppPublicKey: string
      • OptionalsharedAppJWT: string

      Returns Promise<void | ResponseType>

      get, fetch, retrieve, load, data, object, state

      await world.fetchDataObject();
      const { dataObject } = world;
    • Increments a specific value in the data object for a world by the amount specified. Must have valid interactive credentials from a visitor in the world.

      Parameters

      • path: string
      • amount: number
      • options: {
            analytics?: AnalyticType[];
            appJWT?: string;
            appPublicKey?: string;
            lock?: { lockId: string; releaseLock?: boolean };
            sharedAppJWT?: string;
            sharedAppPublicKey?: string;
        } = {}

      Returns Promise<void | ResponseType>

      Optionally, a lock can be provided with this request to ensure only one update happens at a time between all updates that share the same lock id

      increment, increase, add, count, data, object, state

      await world.incrementDataObjectValue([`keyAssets.${keyAssetId}.totalItemsCollected.count`], 1);
      
    • Sets the data object for a user. Must have valid interactive credentials from a visitor in the world.

      Parameters

      • dataObject: undefined | null | object
      • options: {
            analytics?: AnalyticType[];
            appJWT?: string;
            appPublicKey?: string;
            lock?: { lockId: string; releaseLock?: boolean };
            sharedAppJWT?: string;
            sharedAppPublicKey?: string;
        } = {}

      Returns Promise<void | ResponseType>

      Optionally, a lock can be provided with this request to ensure only one update happens at a time between all updates that share the same lock id

      set, assign, store, save, data, object, state

       await world.setDataObject(
      {
      ...defaultGameData,
      keyAssetId: droppedAsset.id,
      },
      { lock: { lock: { lockId: `${keyAssetId}-${new Date(Math.round(new Date().getTime() / 10000) * 10000)}` }, releaseLock: true } },
      );
      const { profileMapper } = world.dataObject;
    • Updates the data object for a world. Must have valid interactive credentials from a visitor in the world.

      Parameters

      • dataObject: object
      • options: {
            analytics?: AnalyticType[];
            appJWT?: string;
            appPublicKey?: string;
            lock?: { lockId: string; releaseLock?: boolean };
            sharedAppJWT?: string;
            sharedAppPublicKey?: string;
        } = {}

      Returns Promise<void | ResponseType>

      Optionally, a lock can be provided with this request to ensure only one update happens at a time between all updates that share the same lock id

      update, modify, change, edit, alter, data, object, state

      await world.updateDataObject({
      [`keyAssets.${keyAssetId}.itemsCollectedByUser.${profileId}`]: { [dateKey]: { count: 1 }, total: 1 },
      [`profileMapper.${profileId}`]: username,
      });
      const { profileMapper } = world.dataObject;

    Dropped Assets

    • Retrieve all assets dropped in a world.

      Returns Promise<void | ResponseType>

      get, fetch, retrieve, list, current, dropped assets

      await world.fetchDroppedAssets();
      const assets = world.droppedAssets;
    • Retrieve all assets dropped in a world matching sceneDropId.

      Parameters

      • __namedParameters: { sceneDropId: string; uniqueName?: string }

      Returns Promise<DroppedAsset[]>

      Returns an array of DroppedAsset instances.

      get, fetch, retrieve, list, current, dropped assets, sceneDropId

      const droppedAssets = await world.fetchDroppedAssetsBySceneDropId({
      sceneDropId: "sceneDropIdExample",
      uniqueName: "optionalUniqueNameExample",
      });
    • Retrieve all assets dropped in a world matching uniqueName.

      Parameters

      • __namedParameters: { isPartial?: boolean; isReversed?: boolean; uniqueName: string }

      Returns Promise<DroppedAsset[]>

      Returns an array of DroppedAsset instances.

      get, fetch, retrieve, list, current, dropped assets, uniqueName

      const droppedAssets = await world.fetchDroppedAssetsWithUniqueName({ uniqueName: "exampleUniqueName", isPartial: true });
      
    • Retrieve all landmark zone assets dropped in a world.

      Parameters

      • OptionallandmarkZoneName: string
      • OptionalsceneDropId: string

      Returns Promise<DroppedAsset[]>

      Returns an array of DroppedAsset instances.

      get, fetch, retrieve, list, landmark, zones, dropped assets

      const zones = await world.fetchLandmarkZones("optionalLandmarkZoneName", "optionalSceneDropIdExample");
      
    • Update multiple custom text dropped assets with a single style while preserving text for specified dropped assets only.

      Parameters

      Returns Promise<object>

      Updates each DroppedAsset instance and world.droppedAssets map.

      update, modify, change, edit, dropped assets, custom text, style, text

      const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]];
      const style = {
      "textColor": "#abc123",
      "textFontFamily": "Arial",
      "textSize": 40,
      "textWeight": "normal",
      "textWidth": 200
      };
      await world.updateCustomText(droppedAssetsToUpdate, style);

    Other

    credentials: undefined | InteractiveCredentials
    dataObject?: null | object
    jwt?: string
    requestOptions: object
    sceneDropIds?: null | [string]
    scenes?: null | [string]
    topia: Topia
    urlSlug: string
    webhooks?: null | WorldWebhooksInterface
    • get droppedAssets(): { [key: string]: DroppedAsset }

      Returns { [key: string]: DroppedAsset }

    • Standardized error handler for all SDK operations.

      Parameters

      • __namedParameters: { error?: unknown; message?: string; params?: object; sdkMethod?: string }

      Returns {
          data: {};
          message: string;
          method: string;
          params: object;
          sdkMethod: undefined | string;
          stack: string;
          stackTrace: Error;
          status: number;
          success: boolean;
          url: string;
      }

      Standardized error object with properties: data, message, method, params, sdkMethod, stack, status, success, url

      This method processes errors from API calls and formats them consistently across the SDK. It extracts relevant error information including:

      • HTTP status codes and response data
      • Error messages from API responses
      • Stack traces for debugging
      • Request details (URL, method, parameters)

      All errors thrown by SDK methods flow through this handler to ensure consistent error format.

      error, exception, handler, debugging, api error, http error

    • Retrieves details of a world.

      Returns Promise<void | ResponseType>

      get, fetch, retrieve, details, info, information, world

      await world.fetchDetails();
      const { name } = world;
    • Returns Promise<object | ResponseType>

      { sceneDropIds: [] }
      

      Use fetchScenes instead.

      Fetch a list of all scene drop ids in a world that include at least one asset with an interactivePublicKey

      await world.fetchSceneDropIds();
      
    • Display a message via a toast to all visitors currently in a world.

      Parameters

      Returns Promise<void | ResponseType>

      Returns { success: true } or an error.

      send, display, show, toast, message, notification

      await world.fireToast({
      groupId: "custom-message",
      title: "Hello World",
      text: "Thank you for participating!",
      });
    • Returns the configured Axios instance for making API calls to Topia's Public API.

      Returns AxiosInstance

      The configured Axios client instance with authentication headers.

      All HTTP requests to the Topia API should use this method to ensure proper authentication headers and base URL configuration are applied.

      api, axios, http, request, client, public api

    • Add an activity to a world excludeFromNotification is an array of visitorIds to exclude from the notification

      Parameters

      • __namedParameters: {
            assetId: string;
            excludeFromNotification?: (string | number)[];
            type: WorldActivityType;
        }

      Returns Promise<string | ResponseType>

      Returns the activityId or an error response.

      start, trigger, activity

      await world.triggerActivity({ type: "GAME_ON", assetId: "abc123" });
      
    • Set close world settings

      Parameters

      • __namedParameters: { closeWorldDescription: string; isWorldClosed: boolean }

      Returns Promise<void | ResponseType>

      Returns { success: true } or an error.

      update, modify, change, edit, world, settings, details, close, closed

      await world.updateCloseWorldSettings({
      controls: {
      allowMuteAll: true,
      disableHideVideo: true,
      isMobileDisabled: false,
      isShowingCurrentGuests: false,
      },
      description: 'Welcome to my world.',
      forceAuthOnLogin: false,
      height: 2000,
      name: 'Example',
      spawnPosition: { x: 100, y: 100 },
      width: 2000
      });
    • Update details of a world.

      Parameters

      Returns Promise<void | ResponseType>

      update, modify, change, edit, world, settings, details

      await world.updateDetails({
      controls: {
      allowMuteAll: true,
      disableHideVideo: true,
      isMobileDisabled: false,
      isShowingCurrentGuests: false,
      },
      description: 'Welcome to my world.',
      forceAuthOnLogin: false,
      height: 2000,
      name: 'Example',
      spawnPosition: { x: 100, y: 100 },
      width: 2000
      });

      const { name, description } = world;

    Particles

    • Get all particles available

      Returns Promise<object | ResponseType>

      get, fetch, retrieve, list, particles

      await world.getAllParticles();

      @returns {Promise<ResponseType>} Returns an array of particles or an error response.
    • Trigger a particle effect at a position in the world

      Parameters

      • __namedParameters: { duration?: number; id?: string; name?: string; position?: object }

      Returns Promise<string | ResponseType>

      Returns { success: true } or a message if no particleId is found.

      trigger, start, play, particle, effect

      const droppedAsset = await DroppedAsset.get(assetId, urlSlug, { credentials });

      await world.triggerParticle({ name: "Flame", duration: 5, position: droppedAsset.position });

    Scenes

    • Drops a scene in a world and returns sceneDropId.

      Parameters

      • __namedParameters: {
            allowNonAdmins?: boolean;
            assetSuffix?: string;
            position: object;
            sceneDropId?: string;
            sceneId: string;
        }

      Returns Promise<ResponseType>

      { sceneDropId: sceneId-timestamp, success: true }
      

      drop, add, place, scene

      await world.dropScene({
      "sceneId": "string",
      "position": {
      "x": 0,
      "y": 0
      },
      "assetSuffix": "string"
      });
    • Fetch a list of all scene drop ids and dropped assets in a world

      Returns Promise<object | ResponseType>

      { "scenes": {
      "sceneDropId_1": {
      "droppedAssets": {
      "droppedAssetId_1": {
      "metaName": "hello"
      "metaNameReversed": "olleh"
      },
      "droppedAssetId_2": {
      "metaName": "world"
      "metaNameReversed": "dlorw"
      }
      }
      },
      }
      }

      get, fetch, retrieve, list, scenes

      await world.fetchScenes();
      
    • Replace the current scene of a world.

      Parameters

      • sceneId: string

      Returns Promise<void | ResponseType>

      Returns { success: true } or an error.

      replace, change, scene

      const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
      const style = {
      "textColor": "#abc123",
      "textFontFamily": "Arial",
      "textSize": 40,
      "textWeight": "normal",
      "textWidth": 200
      }
      await world.replaceScene(SCENE_ID);

    Webhooks

    • Retrieve all webhooks in a world.

      Returns Promise<void | ResponseType>

      get, fetch, retrieve, list, current, webhooks

      await world.fetchWebhooks();
      const webhooks = world.webhooks;