The web-sdk
package provides a comprehensive solution for real-time communication and messaging functionality. It includes both socket handling and messenger code, making it easy to integrate real-time features into your web application.
- Real-Time Communication: Utilize sockets for real-time data exchange.
- Messaging: Send and receive messages with ease.
- Scalable: Designed to handle high-traffic environments.
- Easy Integration: Simple API for quick setup and usage.
To install the web-sdk
package, use npm or yarn:
npm install @voxasphere/web-sdk
or
yarn add @voxasphere/web-sdk
First, import and initialize the SDK in your application:
import WebSDK from '@voxasphere/web-sdk';
const sdk = new WebSDK({
socketUrl: 'wss://your-socket-server.com',
messengerUrl: 'https://your-messenger-api.com'
});
The SDK provides easy-to-use methods for handling socket connections:
sdk.socket.connect();
sdk.socket.send('event-name', { key: 'value' });
sdk.socket.on('event-name', (data) => {
console.log('Received data:', data);
});
sdk.socket.disconnect();
The SDK includes robust messaging features:
sdk.messenger.sendMessage({
to: 'recipient-id',
message: 'Hello, this is a test message!'
});
sdk.messenger.onMessage((message) => {
console.log('New message received:', message);
});
sdk.messenger.getHistory('conversation-id').then((messages) => {
console.log('Message history:', messages);
});
When initializing the SDK, you can pass several configuration options:
-
socketUrl
: The URL of the socket server. -
messengerUrl
: The URL of the messenger API.
Example:
const sdk = new WebSDK({
socketUrl: 'wss://your-socket-server.com',
messengerUrl: 'https://your-messenger-api.com'
});
-
connect()
: Connects to the socket server. -
disconnect()
: Disconnects from the socket server. -
send(event: string, data: object)
: Sends data to the socket server. -
on(event: string, callback: function)
: Listens for events from the socket server.
-
sendMessage({ to: string, message: string })
: Sends a message to a recipient. -
onMessage(callback: function)
: Listens for incoming messages. -
getHistory(conversationId: string)
: Fetches the message history for a given conversation.
We welcome contributions! Please read our contributing guidelines for more details.
This project is licensed under the MIT License. See the LICENSE file for more details.
For questions or feedback, please contact us at support@voxasphere.com.