Setup

Before using the SDK, you will need to create a new SDK instance with your API key. Please find your account API key in the admin panel.

import EkoClient from 'eko-sdk';
const client = new EkoClient({ apiKey: 'YOUR_API_KEY' });

Authentication

In order to use any SDK feature, you must first register the current session with a userId. Sessions are not permanent, and you must do this every time on application start up.

Additionally, an optional displayName can be provided if you wish to have this user identified in push notifications.

client.registerSession({ userId: 'user1234', displayName: 'Bob Newton' });

Unregister

When the user logs out, you should also explicitly unregister the user from the SDK to prevent the current session from receiving any unnecessary or restricted data.

client.unregisterSession();

If there is a scenario where you want to switch to a different user, you can call registerSession again with a different userId. The older session will be automatically unregistered.

Connection Status

If you have any logic or UI concerning server connection status, you can use the connectionStatus property on the EkoClient instance. Note that because the SDK automatically manages network connection and queues up any requests in cases of bad connection, there should be little need to attach additional logic around this status. However, sometimes the user may want to know the exact network status to determine if actions are performed in real-time.

You can also be notified about connectionStatus changes via the connectionStatusChanged event.

// listen to connectionStatus event
client.on('connectionStatusChanged', ({ oldValue, newValue }) => {
// handle changes
});
// stop listening to connectionStatus event once you are finished
client.removeAllListeners('connectionStatusChanged');