Skip to main content

Concept Explanation

What is a Device?

A Device is the terminal carrier for users to access the WuKongIM system, representing the specific device used by users to send and receive messages. Each device has a unique identifier and type, supporting users to simultaneously use instant messaging services on multiple devices.

Why are Devices Important?

  • Multi-device Sync: Users can log in simultaneously on multiple devices like phones, computers, and tablets with real-time message synchronization
  • Device Management: Can view and manage all user login devices, supporting remote device logout
  • Push Strategy: Adopt different message push strategies based on device type

Relationship with Other Concepts

  • User: A user can own multiple devices, each device is associated with a user ID
  • Message: Messages are synchronized to all online devices of the user
  • Connection: Each device has an independent network connection

Core Structure

Devices contain the following core attributes:
AttributeTypeDescription
cidintegerConnection unique identifier
uidstringUser ID that owns the device
device_idstringDevice unique identifier
device_flagintegerDevice type identifier
uptimestringOnline duration
idlestringIdle time

Device Example

{
  "cid": 12345,
  "uid": "user123",
  "device_id": "device_456",
  "device_flag": 1,
  "uptime": "1h30m",
  "idle": "5m"
}
EndpointMethodDescription
/user/device_quitPOSTForce device offline
/connzGETView connection information

Device Type Identifiers

Identifier ValueDevice TypeDescription
0AppAndroid, iPhone, iPad devices
1WebBrowser, Web applications
2DesktopDesktop applications

EasySDK Code Examples

Device Initialization and Configuration

import { WKIM } from 'easyjssdk';

// Device type is automatically set to Web (1) during initialization
const im = WKIM.init("ws://your-server.com:5200", {
  uid: "user123",
  token: "your_token",
  deviceId: "web_device_001"  // Optional: custom device ID
});

// EasySDK automatically handles device type, Web platform defaults to device type 1
console.log('Current platform: Web');
console.log('Device type: 1 (Web)');

Multi-device Synchronization

Important Note: EasySDK automatically handles message synchronization between multiple devices. When a user logs in on multiple devices, messages are automatically synchronized to all online devices.
// EasySDK automatically handles multi-device sync
// When receiving messages, all online devices will receive the same message

im.on(WKIMEvent.Message, (message) => {
  console.log('Received message (auto-synced to all devices):', message);
});

// Check connection status
console.log('Current device connection status:', im.isConnected());

Device Management

// EasySDK automatically manages device connections
// Each device maintains its own connection state

// Listen for connection events
im.on(WKIMEvent.Connect, (result) => {
  console.log('Device connected:', result);
});

im.on(WKIMEvent.Disconnect, (info) => {
  console.log('Device disconnected:', info);
});

// Graceful disconnect
await im.disconnect();
console.log('Device disconnected gracefully');
A user can be online on multiple devices simultaneously. EasySDK automatically handles message synchronization between multiple devices. Each device has an independent connection and device identifier.