SDK · Dart/Flutter
Pure-Dart client SDK for the imcore IM server. WebSocket + JSON; works in
Flutter (iOS/Android/desktop), Dart CLI/server, and Dart web. Only runtime
dependency: web_socket_channel.
Add it
# pubspec.yaml
dependencies:
imcore_sdk:
path: ../path/to/clients/dart/imcore_sdk # or a git/hosted ref
Usage
import 'package:imcore_sdk/imcore_sdk.dart';
final im = ImcoreClient(
url: 'wss://your-host/acc',
auth: AuthConfig(
token: '<jwt>', // or tokenProvider: () async => ...
login: LoginPayload(userId: '1001', userName: 'alice'),
),
// heartbeatInterval / requestTimeout / reconnect / clock / socketFactory are optional.
);
im.onStatus((s) => print('status $s')); // idle/connecting/open/authenticated/closed
im.on('chat_message', (payload) => print('msg $payload'));
im.onReconnected(() {
// Optional: re-pull conversation lists + cursor history for stricter reconciliation.
});
// connect() resolves AFTER the server acknowledges login, and THROWS if login
// is refused (e.g. bad token) — always guard it.
try {
await im.connect();
} on RequestError catch (e) {
print('login failed: $e');
}
await im.dm.send(targetUserId: '1002', text: 'hi');
final queued = await im.dm.sendQueued(targetUserId: '1002', text: 'works offline');
print('${queued.status} ${queued.tempId}');
final history = await im.dm.history(targetUserId: '1002', limit: 20);
final cached = await im.cache.getMessages('dm:1001:1002');
await im.push.register(
deviceId: '<stable-device-id>',
platform: 'ios',
pushToken: '<apns-or-fcm-token>',
vendor: 'apns',
appId: '<bundle-id>',
);
// Escape hatch for any command not yet wrapped:
await im.request<Map<String, dynamic>>('chat_group_create', {'name': 'team'});
im.send('chat_dm_typing', {'targetUserID': '1002'});
Scope (v1)
Transport core + seq-correlated request/response + login-ack-gated auto-login + typed DM/group/room/community send/receive/history + local message/conversation cache + tempID-backed offline send queue + push device registration wrapper. Not included: media upload helpers, E2EE, Flutter widgets.
Development
dart pub get
dart test # unit tests (fake socket + fake clock, no server needed)
dart analyze # lints + type check
# Integration test against a live server:
IMCORE_TEST_WS_URL=wss://host/acc IMCORE_TEST_WS_TOKEN=<jwt> \
IMCORE_TEST_USER_ID=1001 IMCORE_TEST_PEER_ID=1002 dart test test/integration_test.dart