@globaljustice.us/gjs-chat-client
v1.0.0-beta.3
Published
A browser chat client to connect to GJS chat
Downloads
59
Readme
@globaljustice.us/gjs-chat-client
A browser chat client to connect to GJS chat using Azure Communication Services.
📦 Installation
npm install @globaljustice.us/gjs-chat-client🚀 Usage
Initialize
import { ACSChatClient } from '@globaljustice.us/gjs-chat-client';
// Example: URL and token from your backend
const SERVICE_URL = 'https://acs-backend-service.com';
const USER_TOKEN = 'user-access-token';
async function startChatClient() {
const chatClient = ACSChatClient.getInstance();
// Initialize the chat client
await chatClient.initialize(SERVICE_URL, USER_TOKEN);
// Subscribe to chat events
chatClient.on('chatMessageReceived', (event) => {
console.log('[Chat Message Received]:', event);
});
chatClient.on('chatMessageDeleted', (event) => {
console.log('[Chat Message Deleted]:', event);
});
// Handle token refresh if needed
setInterval(async () => {
const newToken = await fetchNewTokenFromBackend();
await chatClient.refreshToken(newToken);
}, 1000 * 60 * 25); // Refresh every 25 minutes
}
startChatClient();
// Dummy function: Replace with real backend call
async function fetchNewTokenFromBackend() {
return 'new-user-access-token';
}Clean up
async function cleanupChatClient() {
const chatClient = ACSChatClient.getInstance();
// Stop real-time notifications and reset client
await chatClient.reset();
console.log('Chat client cleaned up.');
}🧩 Features
Singleton chat client
Auto token refresh
Typed chat events
