0.1.1 • Published 4 months ago
livechat-widget v0.1.1
LiveChat Widget
A customizable real-time chat widget for Next.js applications, built with React and TypeScript. This widget provides seamless integration for live chat functionality during streaming events.
Features
- Real-time messaging - Instant message delivery via WebSockets
- Customizable UI - Easily adapt the widget to match your brand
- Responsive design - Works on desktop and mobile devices
- Secure authentication - Uses App ID for seamless authentication
- Easy integration - Simple to add to any Next.js application
Installation
# Using npm
npm install livechat-widget
# Using yarn
yarn add livechat-widget
# Using pnpm
pnpm add livechat-widget
Usage
Basic Usage
import { ChatWidgetClient } from 'livechat-widget';
function MyApp() {
return (
<div>
<h1>My Streaming App</h1>
<ChatWidgetClient
appId="your-app-id"
roomCode="room-123"
apiUrl="https://your-api-url.com"
wsUrl="wss://your-websocket-url.com"
userInfo={{
username: "User123",
profile_image: "/path/to/profile.png"
}}
/>
</div>
);
}
Advanced Configuration
You can customize the appearance and behavior of the chat widget:
import { ChatWidgetClient } from 'livechat-widget';
function MyApp() {
return (
<ChatWidgetClient
appId="your-app-id"
roomCode="room-123"
roomName="Live Stream Chat"
apiUrl="https://your-api-url.com"
wsUrl="wss://your-websocket-url.com"
userInfo={{
username: "User123",
profile_image: "/path/to/profile.png"
}}
// Customize appearance
theme="dark"
bgColor="#1a1a1a"
textColor="#ffffff"
bgInput="#2a2a2a"
textInputColor="#ffffff"
currentUserColor="#4caf50"
// Customize dimensions
width="400px"
height="600px"
// Customize border
hasBorder={true}
borderWidth="1px"
borderColor="#333333"
borderRadius="8px"
/>
);
}
Props
Prop | Type | Default | Description |
---|---|---|---|
roomCode | string | Required | Unique identifier for the chat room |
appId | string | Required | Application ID for authentication |
roomName | string | "Chat Room" | Display name for the chat room |
theme | 'light' | 'dark' | 'light' | Color theme of the widget |
bgColor | string | - | Background color of the chat widget |
textColor | string | - | Text color for messages |
bgInput | string | - | Background color of the input field |
textInputColor | string | - | Text color for the input field |
currentUserColor | string | - | Color for the current user's name |
userInfo | UserInfo | - | User information object |
userCode | string | - | Unique identifier for the user |
width | string | number | "100%" | Width of the chat widget |
height | string | number | "400px" | Height of the chat widget |
hasBorder | boolean | false | Whether to show border |
borderWidth | string | number | "1px" | Width of the border |
borderColor | string | - | Color of the border |
borderRadius | string | number | "4px" | Border radius of the widget |
apiUrl | string | - | Base URL for the API endpoints |
wsUrl | string | - | WebSocket server URL |
Types
interface UserInfo {
username: string;
profile_image?: string;
}
interface ChatMessage {
id: string;
room_code: string;
app_id: string;
user_code: string;
username: string;
profile_image?: string;
message: string;
created_at: string;
}
Backend Requirements
This widget requires a compatible backend server that provides:
RESTful API endpoints for:
- Creating/joining chat rooms
- Fetching message history
- User authentication
WebSocket server for real-time messaging
License
MIT
0.1.1
4 months ago