Basic Usage

Discover the basic functionality of the ALO Javascript Presence SDK.

Initialize a Connection to the Presence Service

Once the Presence class is initialized, a connection will be automatically established and a connected event will be fired to all subscribers of the specified userId.

import Presence from '@aloai/alo-presence-js';

const client = new Presence({
    userId: "1",
    deviceId: "1a",
    authToken: "xxx"
})

Listening for Changes in Presence

Use watch and subscribe to listen for any connected or disconnected events associated with a list of userIds.

client.watch(({ eventType, userId, deviceId }) => {
    // handle presence events
})

client.subscribe({ userIds: ["b", "c"] });Response Props

Response Props

Get Presence On-Demand

The hereNow function lets you specify which userIds you want to are online and which devices along with each device's last_active.

last_active is never greater than 300 seconds (5 minutes) ago.

import Presence from '@aloai/alo-presence-js';

const client = new Presence({
    userId: "alpha",
    deviceId: "android",
    authToken: "xxx"
})

client.hereNow({ userIds: ["bravo", "charlie"] })
    .then(function({ status, response }) {
        /*
            status = {
                error: false,
                errorData: {
                    statusCode<Integer>,
                    message<String>
                },
            }
            response = {
                users: [
                    {
                        id: "bravo",
                        online: true,
                        devices: [{
                            id: "iphone",
                            last_active: 1594233694373 // Unix Timestamp in MS
                        }]
                    },
                    {
                        id: "charlie",
                        online: false,
                        devices: []
                    }
                ]
            }
        */
    });

Last updated

Logo

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