Installation
Follow the steps to set up and start using the ADK in your project.
1. Install the ADK Packages
Create a project in technology of your choice, and choose the ADK accordingly. Install the ADK package.
- JavaScript
npm install @arealtimetech/adk-js
2. Import the ADKs into your project
Import the ADK in your project files to use the features provided by ART.
- JavaScript
import Adk from '@arealtimetech/adk-js';
3. Generate Client Secret
Once after gaining access to the ART Live Dashboard, generate the Client Secret and add it in the root of your project directory. The client credential JSON will look something like this:
{
"Client-ID": "xxxxxxxxxx",
"Client-Secret": "xxxxxxxxxxx",
"Org-Title": "YOUR_ORG",
"ProjectKey": "YOUR_PROJECT_KEY",
"Environment": "YOUR_ENV_NAME"
};
The adk-service.json needs to be updated with ProjectKey and Environment, manually. To learn how to obtain the values, click here
4. Authenticate
Once the Client Credenials are added to your project, the Client needs to be authenticated. To authenticate, user needs to generate passcode
Every ADK has its built-in functions for authetication, which you can learn once you proceed with ADK of your choice.
- JavaScript
const adk = new Adk({
AuthToken: "YOUR_PASS_CODE", // Replace with your obtained passcode
Uri: "ws.arealtimetech.com", // Replace with ART server WebSocket URI
});
// Initiate the connection to the ART server
adk.connect();
5. Subscribe to Channel
A Channel is a communication pathway that provides passage for data transfer. Subscribing to channel will allow you to get started with using the realtime messaging in your application.
- JavaScript
// Subscribe to your channel
const subscription = adk.subscribe("your-channel-name");
You can learn more about Channel Configuration from here
6. Push Messages
Messages are pushed to a channel using the push() ADK method. This method allows you to send various event types with associated data, and optionally target specific users or groups within the channel for more granular delivery.
- JavaScript
// Define the message payload
const payload = { content: "Hello from ART ADK!" };
// Optionally define specific target users within the channel
const targetUsers = ["username1", "username2"];
// Push a "message" event with the payload and targeting options
subscription
.push("message", payload, {
to: targetUsers, // Target specific recipients within the channel
})
.then((response) => {
console.log("Message acknowledged by ART:", response);
// The 'response' indicates successful queuing or delivery acknowledgment
})
.catch((error) => {
console.error("Failed to push message:", error);
});
7. Listen to All Events and Messages
The listen() method allows you to capture all events and messages published within the subscribed channel.
This is a catch-all listener that delivers every incoming payload, regardless of event type.
- JavaScript
// Listen to all events and messages in the channel
subscription.listen((data) => {
console.log("Received:", data);
});
You can refer the Quick Start Guide to understand the steps better or proceed with the ADK of your interest.
