Class User

Summary

Create an instance of User class with optional session credentials.

Usage

await new User(topia, {
profileId: 1,
credentials: { apiKey: "exampleKey", interactiveNonce: "exampleNonce", urlSlug: "exampleWorld", visitorId: 1 }
});

Hierarchy

Implements

Constructors

Properties

credentials: undefined | InteractiveCredentials
dataObject?: null | object
jwt?: string
profile?: Record<string, any>
profileId?: null | string
requestOptions: object
topia: Topia

Accessors

  • get adminWorlds(): {
        [key: string]: World;
    }
  • Returns {
        [key: string]: World;
    }

  • get assets(): {
        [key: string]: Asset;
    }
  • Returns {
        [key: string]: Asset;
    }

  • get scenes(): {
        [key: string]: Scene;
    }
  • Returns {
        [key: string]: Scene;
    }

  • get worlds(): {
        [key: string]: World;
    }
  • Returns {
        [key: string]: World;
    }

Methods

  • Summary

    Add a new avatar

    Usage

    const animationMeta = {
    "emote": { "loop": false, "x": 0, "y": 0, "hideLoop": true }
    }

    const spriteSheetJSON = {
    "animations": {
    "emote": [
    "emote/1.png"
    ]
    },
    "frames": {
    "emote/1.png": {
    "frame": {
    "x": 1911,
    "y": 778,
    "w": 58,
    "h": 91
    },
    "rotated": true,
    "trimmed": true,
    "spriteSourceSize": {
    "x": 50,
    "y": 33,
    "w": 58,
    "h": 91
    },
    "sourceSize": {
    "w": 159,
    "h": 159
    }
    }
    },
    "spriteSheetTypeMeta": {
    "nameplate": {
    "x": 0,
    "y": -70
    }
    },
    "meta": {
    "image": "spriteSheets%2FTvHNjgoMkiErDNSrVqHU%2FspriteSheet.png?alt=media",
    "format": "RGBA8888",
    "size": {
    "w": 2006,
    "h": 1099
    },
    "scale": "1"
    }
    }

    const formData = new FormData();
    formData.append('animationMeta', animationMeta);
    formData.append('name', "ExampleAvatarName");
    formData.append('spriteSheetJSON', spriteSheetJSON);
    formData.append('expression_dance', expression_dance);
    formData.append('expression_emote', expression_emote);
    formData.append('expression_sit', expression_sit);
    formData.append('expression_stand', expression_stand);
    formData.append('expression_transport', expression_transport);
    formData.append('preview', preview);
    formData.append('spriteSheet', spriteSheet);
    formData.append('unityPackage', unityPackage);
    await user.uploadAvatarFiles("exampleAvatarId", formData);

    Parameters

    • formData: FormData

    Returns Promise<void | ResponseType>

  • Summary

    Verify user has valid interactive credentials

    Usage

    await user.checkInteractiveCredentials();
    

    Returns Promise<void | ResponseType>

  • Summary

    Update avatar and sprite sheet records and upload files to existing sprite sheet and avatar storage buckets

    Usage

    await user.deleteAvatar("exampleAvatarId");
    

    Parameters

    • avatarId: string

    Returns Promise<void | ResponseType>

  • Parameters

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

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

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

      Retrieves all worlds a user with matching API Key is an admin in, creates a new World object for each, and creates new map of Worlds accessible via user.adminWorlds.

      Usage

      await user.fetchAdminWorldsByKey();
      const adminWorlds = user.adminWorlds;

      Returns Promise<void | ResponseType>

    • Summary

      Returns all assets owned by User when an email address is provided.

      Usage

      await user.fetchAssets();
      const userAssets = user.assets;

      Returns Promise<void | ResponseType>

    • Summary

      Returns all avatars owned by User

      Usage

      const avatars = await user.fetchAvatars();
      

      Returns Promise<void | ResponseType>

    • Summary

      Retrieves the data object for a user.

      Usage

      const dataObject = await user.fetchDataObject();
      

      Returns Promise<void | ResponseType>

    • Summary

      Retrieves ids of all dropped assets in all worlds with a matching interactivePublicKey.

      Usage

      await user.fetchInteractiveWorldsByKey("interactivePublicKeyExample");
      const interactiveWorlds = user.interactiveWorlds;

      Parameters

      • interactivePublicKey: string

      Returns Promise<object | ResponseType>

    • Summary

      Returns all scenes owned by User.

      Usage

      await user.fetchScenes();
      const userScenes = user.scenes;

      Returns Promise<void | ResponseType>

    • Summary

      Retrieves all worlds owned by user with matching API Key, creates a new World object for each, and creates new map of Worlds accessible via user.worlds.

      Usage

      await user.fetchWorldsByKey();
      const userWorlds = user.worlds;

      Result

      { urlSlug: new World({ apiKey, worldArgs, urlSlug }) }
      

      Returns Promise<void | ResponseType>

    • Summary

      Increments a specific value in the data object for a user by the amount specified. Must have valid interactive credentials from a visitor in the world.

      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

      Usage

      await user.incrementDataObjectValue("key", 1);
      

      Parameters

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

      Returns Promise<void | ResponseType>

    • Summary

      Sets the data object for a user.

      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

      Usage

      await user.setDataObject({
      "exampleKey": "exampleValue",
      });

      Parameters

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

      Returns Promise<void | ResponseType>

    • Returns AxiosInstance

    • Summary

      Update avatar and sprite sheet records and upload files to existing sprite sheet and avatar storage buckets

      Usage

      const animationMeta = {
      "emote": { "loop": false, "x": 0, "y": 0, "hideLoop": true }
      }

      const spriteSheetJSON = {
      "animations": {
      "emote": [
      "emote/1.png"
      ]
      },
      "frames": {
      "emote/1.png": {
      "frame": {
      "x": 1911,
      "y": 778,
      "w": 58,
      "h": 91
      },
      "rotated": true,
      "trimmed": true,
      "spriteSourceSize": {
      "x": 50,
      "y": 33,
      "w": 58,
      "h": 91
      },
      "sourceSize": {
      "w": 159,
      "h": 159
      }
      }
      },
      "spriteSheetTypeMeta": {
      "nameplate": {
      "x": 0,
      "y": -70
      }
      },
      "meta": {
      "image": "spriteSheets%2FTvHNjgoMkiErDNSrVqHU%2FspriteSheet.png?alt=media",
      "format": "RGBA8888",
      "size": {
      "w": 2006,
      "h": 1099
      },
      "scale": "1"
      }
      }

      const formData = new FormData();
      formData.append('animationMeta', animationMeta);
      formData.append('name', "ExampleAvatarName");
      formData.append('spriteSheetJSON', spriteSheetJSON);
      formData.append('expression_dance', expression_dance);
      formData.append('expression_emote', expression_emote);
      formData.append('expression_sit', expression_sit);
      formData.append('expression_stand', expression_stand);
      formData.append('expression_transport', expression_transport);
      formData.append('preview', preview);
      formData.append('spriteSheet', spriteSheet);
      formData.append('unityPackage', unityPackage);
      await user.uploadAvatarFiles("exampleAvatarId", formData);

      Parameters

      • avatarId: string
      • formData: FormData

      Returns Promise<void | ResponseType>

    • Summary

      Updates the data object for a user.

      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

      Usage

      await user.updateDataObject({
      "exampleKey": "exampleValue",
      });

      Parameters

      • dataObject: object
      • options: {
            analytics?: AnalyticType[];
            lock?: {
                lockId: string;
                releaseLock?: boolean;
            };
        } = {}
        • Optional analytics?: AnalyticType[]
        • Optional lock?: {
              lockId: string;
              releaseLock?: boolean;
          }
          • lockId: string
          • Optional releaseLock?: boolean

      Returns Promise<void | ResponseType>