Skip to main content

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:
AttributeTypeDescription
uidstringUser unique identifier
onlineintegerOnline status (0=offline, 1=online)
device_flagintegerDevice type identifier

Device Type Identifiers

ValueDevice TypeDescription
1iOSiPhone, iPad devices
2AndroidAndroid devices
3WebBrowser, Web applications
4DesktopDesktop applications

User Example

{
  "uid": "user123",
  "online": 1,
  "device_flag": 1
}
EndpointMethodDescription
/user/onlinestatusPOSTQuery user online status
/user/tokenPOSTUpdate user token
/user/device_quitPOSTForce device offline
/user/systemuidsGETGet 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.