SDK · HarmonyOS
imcore-sdk is the HarmonyOS NEXT (API 12+, ArkTS) client SDK for the imcore
IM server: shared WebSocket protocol over @ohos.net.webSocket, auto-reconnect,
heartbeat, login lifecycle, offline send queue and DM/group/room APIs.
Commands and DTOs are generated from clients/protocol.yaml, sharing the wire
contract of the other five SDKs.
Add it
DevEco Studio → File → Import Module → the unpacked
imcore-sdk-harmony-<version>/ from the download page; or add
"imcore-sdk": "file:./imcore-sdk-harmony-<version>" to your project’s
oh-package.json5.
Usage
import { createHarmonyClient, Cmd } from 'imcore-sdk';
const client = await createHarmonyClient({
url: 'wss://your-host/acc',
token: '<jwt>',
userId: '1001',
userName: 'alice',
storageContext: this.context, // optional: persist the offline queue
storageName: 'imcore-1001',
});
client.onStatusChanged(s => console.info(`imcore: ${s}`));
const sub = client.on(Cmd.ChatMessage, p =>
console.info(`msg ${p.get('text')?.asString()}`));
await client.connect(); // resolves after the login ack; rejects on auth errors
await client.dm.send('2002', 'hello');
const history = await client.dm.history('2002', null, 20);
// Escape hatch for commands not yet wrapped:
await client.request('chat_group_create',
JsonValue.object().set('name', JsonValue.ofString('team')));
Behavior
- Every callback runs on the ArkTS single-threaded event loop (UI thread) — no marshaling needed.
sendQueuedwhile disconnected/not logged in persists to preferences and flushes automatically after the next login;account_revokedclears the queue.- The host calls
disconnect()on background andconnect()on foreground. - Non-2xx responses map to
RequestErrorwith the server code; seq correlation with a 10s default timeout.
Scope (first drop)
Protocol core (ArkTS-compatible TS subset, fully tested in CI via Node’s native type stripping) + DM/group/room APIs + the offline queue + the @ohos webSocket/preferences adapter. Not included: ArkUI TUIKit, Push Kit registration, publishing to the public ohpm registry, a DevEco sample project.