Basic Usage

Discover the basic functionality of the ĀLO 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

Type

Description

eventType

string (enum)

Will be either "connected" or "disconnected".

userId

string

The associated userId with the presence event.

deviceId

string

The associated deviceId with the presence event.

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