@voxasphere/messenger-kit
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

React Web Sdk

Overview

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.

Features

  • 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.

Installation

To install the web-sdk package, use npm or yarn:

npm install @voxasphere/web-sdk

or

yarn add @voxasphere/web-sdk

Usage

Initializing the 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'
});

Socket Handling

The SDK provides easy-to-use methods for handling socket connections:

Connecting to the Socket

sdk.socket.connect();

Sending Data through Socket

sdk.socket.send('event-name', { key: 'value' });

Receiving Data from Socket

sdk.socket.on('event-name', (data) => {
  console.log('Received data:', data);
});

Disconnecting from the Socket

sdk.socket.disconnect();

Messenger Functionality

The SDK includes robust messaging features:

Sending a Message

sdk.messenger.sendMessage({
  to: 'recipient-id',
  message: 'Hello, this is a test message!'
});

Receiving Messages

sdk.messenger.onMessage((message) => {
  console.log('New message received:', message);
});

Fetching Message History

sdk.messenger.getHistory('conversation-id').then((messages) => {
  console.log('Message history:', messages);
});

Configuration Options

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'
});

API Reference

sdk.socket

  • 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.

sdk.messenger

  • 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.

Contributing

We welcome contributions! Please read our contributing guidelines for more details.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For questions or feedback, please contact us at support@voxasphere.com.


Package Sidebar

Install

npm i @voxasphere/messenger-kit

Weekly Downloads

0

Version

0.0.4

License

none

Unpacked Size

1.41 MB

Total Files

65

Last publish

Collaborators

  • voxasphere