1.4.6 • Published 1 year ago
realtimesdk-new v1.4.6
Real-time Chat SDK
Overview
The Real-time Chat SDK is a JavaScript package that allows you to easily integrate real-time chat functionality into your web applications. It provides a simple interface for connecting to a chat server via WebSocket, sending messages, and handling incoming messages.
Installation
You can install the Real-time Chat SDK package via npm:
npm install realtime-chat-sdk
Usage
- Import the
RealtimeChatSDK
class into your JavaScript file. - Create a new instance of the
RealtimeChatSDK
class with the appropriate configuration. - Connect to the chat server using the
connect()
method. - Send messages using the
sendMessage()
method. - Register message handlers using the
handleMessage()
method to handle incoming messages.
const RealtimeChatSDK = require('realtime-chat-sdk');
// Create a new instance of RealtimeChatSDK
const chatSDK = new RealtimeChatSDK({
endpoint: 'ws://example.com/chat', // WebSocket endpoint
});
// Connect to the chat server
chatSDK.connect();
// Send a message
chatSDK.sendMessage({ text: 'Hello, world!' });
// Register a message handler
chatSDK.handleMessage((message) => {
console.log('Received message:', message);
});
Configuration
endpoint
(String): The WebSocket endpoint URL of the chat server.
API Reference
connect()
: Connects to the chat server.sendMessage(message)
: Sends a message to the chat server.handleMessage(handler)
: Registers a message handler to handle incoming messages.
License
This package is licensed under the MIT License. See the LICENSE file for details.