Methods

Dive deeper into the methods at your disposal in the ALO Javascript Presence SDK.

Constructor

Presence

new Presence({
    authToken: "xxx",
    projectId: "myproject",
    userId: "alpha",
    deviceId: "device-1"
})

Once initialized, the user is automatically connected to the presence service.

Parameters:

Name

Type

Required

Description

authToken

string

yes

The ALO generated auth token to grant access to the ALO presence service.

projectId

string

yes

The unique project ID associated with your app, provided by ALO.

userId

string

yes

A unique ID to associate the online/offline events with.

deviceId

string

no

An ID to differentiate multiple sessions or devices for the same userId. Multiple clients should not specify the same userId and deviceId pair.

Methods

.hereNow()

.hereNow({ userIds: [string] });

Fetch the current online/offline status for a list of users.

Parameters:

Name

Type

Required

Description

userIds

array[string]

yes

A list of user IDs to check online/offline status of.

.subscribe()

.subscribe({ userIds: [string] });

Subscribe to online/offline events for a list of users. If called more than once it will not unsubscribe from user ids made in previous calls. It will only subscribe to the user ids not already subscribed.

Parameters:

Name

Type

Required

Description

userIds

array[string]

yes

A list of user IDs to subscribe to online/offline events.

.unsubscribeAll()

.unsubscribeAll();

Unsubscribe from all online/offline events.

.watch()

.watch(callback: function)

Register a callback function to recieve online/offline events subscribed to with .subscribe().

Parameters:

Name

Type

Required

Description

callback

function

yes

A callback function that is called when a subscribed user ID presence event occurs.

.unwatchAll()

.unwatchAll();

Unregister all callbacks registered with .watch().

.disconnect()

.disconnect()

Disconnects the user from the presence service and unsubscribes and unwatches all events.

Last updated

Logo

© Copyright 2024 ALO.ai, Inc. • All Rights Reserved