AccountServices

Description

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts

The AccountServices API provides functions that give information on user connectivity, visibility, and asset download progress.

Properties

Name Type Summary
username string

The user name of the user logged in. If there is no user logged in, it is "Unknown user". Read-only.

loggedIn boolean

true if the user is logged in, otherwise false. Read-only.

findableBy string

The user's visibility to other users:

  • "none" — user appears offline.
  • "friends" — user is visible only to friends.
  • "connections" — user is visible to friends and connections.
  • "all" — user is visible to everyone.
metaverseServerURL string

The metaverse server that the user is authenticated against when logged in — typically "https://metaverse.highfidelity.com". Read-only.

Methods

Name Return Value Summary
checkAndSignalForAccessToken boolean

The function returns the login status of the user and prompts the user to log in (with a login dialog) if they're not already logged in.

getDownloadInfo AccountServices.DownloadInfoResult

Gets information on the download progress of assets in the domain.

isLoggedIn boolean

Checks whether the user is logged in.

logOut None

Logs the user out.

updateDownloadInfo None

Triggers a downloadInfoChanged signal with information on the current download progress of the assets in the domain.

Signals

Name Summary
connected

Not currently used.

disconnected

Triggered when the user logs out.

downloadInfoChanged

Triggered when the download progress of the assets in the domain changes.

findableByChanged

Triggered when the user's visibility to others changes.

loggedInChanged

Triggered when the login status of the user changes.

myUsernameChanged

Triggered when the username logged in with changes, i.e., when the user logs in or out.

Type Definitions

DownloadInfoResult
Type: object

Information on the assets currently being downloaded and pending download.

Properties

Name Type Summary
downloading Array.<number>

The download percentage remaining of each asset currently downloading.

pending number

The number of assets pending download.

Method Details

(static) checkAndSignalForAccessToken( ) → {boolean}
Returns: true if the user is logged in, false if not.

The function returns the login status of the user and prompts the user to log in (with a login dialog) if they're not already logged in.

(static) getDownloadInfo( ) → {AccountServices.DownloadInfoResult}
Returns: Information on the download progress of assets.

Gets information on the download progress of assets in the domain.

(static) isLoggedIn( ) → {boolean}
Returns: true if the user is logged in, false if not.

Checks whether the user is logged in.

Example

Report whether you are logged in.

var isLoggedIn = AccountServices.isLoggedIn();
print("You are logged in: " + isLoggedIn);  // true or false
(static) logOut( )

Logs the user out.

(static) updateDownloadInfo( )

Triggers a downloadInfoChanged signal with information on the current download progress of the assets in the domain.

Signal Details

connected( )
Returns: Signal

Not currently used.

disconnected( reason )
Returns: Signal

Triggered when the user logs out.

Parameters

Name Type Description
reason string

Has the value, "logout".

downloadInfoChanged( downloadInfo )
Returns: Signal

Triggered when the download progress of the assets in the domain changes.

Parameters

Name Type Description
downloadInfo AccountServices.DownloadInfoResult

Information on the download progress of assets.

findableByChanged( findableBy )
Returns: Signal

Triggered when the user's visibility to others changes.

Parameters

Name Type Description
findableBy string

The user's visibility to other people:

  • "none" — user appears offline.
  • "friends" — user is visible only to friends.
  • "connections" — user is visible to friends and connections.
  • "all" — user is visible to everyone.
Example

Report when your visiblity changes.

AccountServices.findableByChanged.connect(function (findableBy) {
    print("Findable by changed: " + findableBy);
});

var originalFindableBy = AccountServices.findableBy;
Script.setTimeout(function () {
    // Change visiblity.
    AccountServices.findableBy = originalFindableBy === "none" ? "all" : "none";
}, 2000);
Script.setTimeout(function () {
    // Restore original visibility.
    AccountServices.findableBy = originalFindableBy;
}, 4000);
loggedInChanged( loggedIn )
Returns: Signal

Triggered when the login status of the user changes.

Parameters

Name Type Description
loggedIn boolean

true if the user is logged in, false if not.

Example

Report when your login status changes.

AccountServices.loggedInChanged.connect(function(loggedIn) {
    print("Logged in: " + loggedIn);
});
     
myUsernameChanged( username )
Returns: Signal

Triggered when the username logged in with changes, i.e., when the user logs in or out.

Parameters

Name Type Description
username string

The user name of the user logged in. If there is no user logged in, it is "".

Example

Report when your username changes.

AccountServices.myUsernameChanged.connect(function (username) {
    print("Username changed: " + username);
});