Concept Explanation
What is a User?
A User is the basic entity in the WuKongIM system, representing an individual or application using the instant messaging service. Each user has a unique identifier and related attributes, serving as the subject for sending and receiving messages.
Why are Users Important?
- Identity Identification: User ID is the key to uniquely identify a user in the system
- Permission Foundation: All message sending and receiving permissions are based on user identity
- Status Management: User online status determines the method and timing of message delivery
Relationship with Other Concepts
- Message: Users are the senders and receivers of messages
- Channel: Users communicate through channels; personal channel ID is the user ID
- Conversation: User conversation list shows all chats the user participates in
- Device: A user can log in and use the service on multiple devices
Core Structure
Users contain the following core attributes:
| Attribute | Type | Description |
|---|
uid | string | User unique identifier |
online | integer | Online status (0=offline, 1=online) |
device_flag | integer | Device type identifier |
Device Type Identifiers
| Value | Device Type | Description |
|---|
| 1 | iOS | iPhone, iPad devices |
| 2 | Android | Android devices |
| 3 | Web | Browser, Web applications |
| 4 | Desktop | Desktop applications |
User Example
{
"uid": "user123",
"online": 1,
"device_flag": 1
}
| Endpoint | Method | Description |
|---|
/user/onlinestatus | POST | Query user online status |
/user/token | POST | Update user token |
/user/device_quit | POST | Force device offline |
/user/systemuids | GET | Get system user list |
EasySDK Code Examples
User Initialization and Connection
import { WKIM, WKIMEvent } from 'easyjssdk';
// Initialize SDK
const im = WKIM.init("ws://your-server.com:5200", {
uid: "user123", // User unique identifier
token: "your_auth_token" // User authentication token
});
// Listen for connection status
im.on(WKIMEvent.Connect, (result) => {
console.log('User connected:', result);
});
im.on(WKIMEvent.Disconnect, (disconnectInfo) => {
console.log('User disconnected:', disconnectInfo);
});
// Connect to server
try {
await im.connect();
console.log("Connection successful!");
} catch (error) {
console.error("Connection failed:", error);
}
User Status Management
// Check connection status
const isConnected = im.isConnected();
console.log('Connection status:', isConnected);
// Disconnect
await im.disconnect();
// Listen for error events
im.on(WKIMEvent.Error, (error) => {
console.log('Error occurred:', error);
});
WuKongIM focuses on message transmission; detailed user profiles (such as nicknames, avatars, etc.) are typically managed by the application layer.