A simple realtime chat SDK for web and mobile apps using socket.io with support for end-to-end encryption and multi-tenant backend integration.
npm install e2ee-chatThis SDK allows you to easily integrate end-to-end encrypted 1-to-1 realtime chat into your app using our hosted microservice.
---
- ๐ End-to-end AES encrypted messages
- โก๏ธ Socket-based realtime messaging
- ๐งฉ Multi-tenant DB support via apiKey
- ๐ฅ Role-based user handling (client, handler, admin)
- ๐ฅ Chat history via REST API
- ๐ Dynamic handler takeover logic
- โ
Works with Node.js, React.js, Next.js (App Router compatible)
---
``bash`
npm install e2ee-chat
---
`jsx
"use client";
import React, { useState } from "react";
import useChat from "e2ee-chat/useChat";
export default function ChatBox() {
const [input, setInput] = useState("");
const { messages, sendMessage, joined } = useChat({
serverUrl: "http://localhost:4000",
roomId: "session_abc123",
userId: "user1",
userType: "client",
secretKey: "shared-secret-123",
apiKey: "your-api-key-here",
});
return (
---
๐งฉ useChat Options
| Option | Type | Required | Description |
| ----------- | ------ | -------- | ---------------------------------- |
|
serverUrl | string | โ
| Your hosted chat server URL |
| roomId | string | โ
| Session ID for the chat |
| userId | string | โ
| Your current user's ID |
| userType | string | โ
| client, handler, or admin |
| secretKey | string | โ
| AES secret used to encrypt/decrypt |
| apiKey | string | โ
| API key to identify your org DB |---
๐ฅ Accessing Chat History
Chat history is fetched automatically when the user joins. All messages are decrypted with your
secretKey.---
๐ Admin Takeover Logic
You can trigger handler takeover:
`js
const { takeover } = useChat(...);
takeover(); // Makes current user the new handler
`---
๐ Works in:
- โ
React.js
- โ
Next.js App Router
- โ
Node.js test scripts
---
๐ Server Setup (Hosted Microservice)
To host your own server, clone chat-server and set up
.env:`env
PORT=4000
MONGO_URI=your-default-db-uri
`---
๐ง Multi-Tenant Support
Register your
apiKey and mongoUri in the Tenant` collection to isolate DB access per organization.---
For issues, contact: support@yourchatservice.com
---
MIT