dnotifier 1.1.3
dnotifier: ^1.1.3 copied to clipboard
Real-time notification and messaging SDK for Dart and Flutter. Use in Flutter (Android, iOS, Web) or pure Dart. WebSocket & HTTP, auth, binary frames, and optional AI integration. No platform-specific [...]
DNotifier Dart SDK #
DNotifier is a real-time notification & messaging SDK for Dart and Flutter, supporting Android and iOS. It provides WebSocket and HTTP transports, binary streaming, and framed packet communication.
Features #
- WebSocket & HTTP transport support
- Secure authentication handshake
- Real-time messaging (send/receive text and binary)
- Binary data transfer (files, images, media)
- AI pipeline: send messages to AI (
sendAI), fetch AI history (fetchAIHistory) - Plan limits from auth (
getPlanLimits) - Automatic packet framing & decoding
- Handles partial packets & large payloads
- Flutter-ready: works in Flutter (Android, iOS, Web) and pure Dart; no platform-specific code in the SDK
Installation #
Add to your pubspec.yaml:
dependencies:
dnotifier:
path: . # or git: https://github.com/...
Or publish the package and use:
dependencies:
dnotifier: ^1.0.0
Then run:
# In a Dart project
dart pub get
# In a Flutter project
flutter pub get
Usage #
import 'package:dnotifier/dnotifier.dart';
void main() async {
final client = DNotifier(
appId: 'your-app-id',
secret: 'your-app-secret',
transport: 'ws',
userId: 'user-123',
onConnected: () => print('Connected'),
onMessage: (DNotifierMessage msg) {
print('Message from ${msg.metadata.sender}: ${msg.payload.toJSON()}');
},
onDisconnected: ({code, reason}) => print('Disconnected: $reason'),
);
await client.connect();
// Send a text message
client.send(
senderId: 'user-123',
receiverId: 'user-456',
data: {'text': 'Hello'},
);
// Send binary - No need to use this function. Use the send function as it gives more space and types can defined as per the use-cases.
client.sendBinary(
senderId: 'user-123',
receiverIds: ['user-456'],
buffer: [0x00, 0x01, 0x02],
);
Sending text, images, audio, documents, and other binary attachments #
The SDK supports any binary payload. The type field in data is defined by your app—use whatever values fit your logic (e.g. 'text', 'image', 'audio', 'doc'). In onMessage, branch on body['type'] (e.g. with if/else if) to handle each kind.
// Text message
notifier.send(
senderId: userId,
receiverId: userId,
data: <String, dynamic>{
'type': 'text',
'text': 'hello from dnotifier sdk!',
},
);
// Image (bytes; SDK will split into multiple messages if over plan limit)
final imagePath = File('path/to/your/image.png');
if (await imagePath.exists()) {
final imageBytes = await imagePath.readAsBytes();
notifier.send(
senderId: userId,
receiverId: userId,
data: <String, dynamic>{
'type': 'image',
'content': imageBytes,
},
);
}
// Audio (e.g. base64)
final audioPath = File('path/to/your/voice.m4a');
if (await audioPath.exists()) {
final audioBytes = await audioPath.readAsBytes();
notifier.send(
senderId: userId,
receiverId: userId,
data: <String, dynamic>{
'type': 'audio',
'content': audioBytes,
},
);
}
Use dart:convert for base64Encode. In onMessage, handle body['type'] (e.g. 'image' / 'audio') and decode or save the payload as needed.
Plan limits and AI (after connect) #
final limits = client.getPlanLimits();
if (limits != null && limits.aiEnabled) {
client.sendAI(
senderId: 'user-123',
message: {'text': 'Hello'},
);
// Or with chat history:
// client.sendAI(
// senderId: 'user-123',
// message: {
// 'messages': [
// {'role': 'system', 'content': 'You are a helpful assistant.'},
// {'role': 'user', 'content': 'Generate the plan.'},
// ],
// },
// );
client.fetchAIHistory(senderId: 'user-123');
}
API summary #
| Method / property | Description |
|---|---|
DNotifier(appId, secret, transport, userId, ...) |
Build the client. transport is 'ws' or 'http'. |
connect() |
Authenticate and connect (WebSocket handshake when using ws). |
getPlanLimits() |
Plan limits from last auth (e.g. aiEnabled, maxAIRequestsPerMonth). Throws if not connected. |
send(senderId, receiverId/receiverIds, data) |
Send a text message (JSON-serializable data). |
sendAI(senderId, message) |
Send to the AI pipeline. message is an object: {text: string} or {messages: [{role, content}, ...]}. |
fetchAIHistory(senderId) |
Fetch AI conversation history for the sender. |
fetchChatHistory(senderId, receiverIds) |
Request chat history; server responds via onMessage with the history payload. |
sendBinary(senderId, receiverIds, buffer, type?) |
Send raw bytes. |
sendWithOpenAI(senderId, message, ...) |
Deprecated: use sendAI instead. Forwards to AI pipeline. |
disconnect() |
Close the WebSocket. |
isConnected, aiEnabled |
Connection state and whether AI is enabled for the plan. |
onConnected |
Callback when connection is ready. |
onMessage |
Callback with DNotifierMessage (metadata + Payload). |
onDisconnected |
Callback when connection closes. |
Payload.raw(), .toString(), .toJSON(), .toBase64() |
Read received payload. |
DNotifierPlanLimits |
Plan limits: messagesHardLimit, maxAIRequestsPerMonth, maxAIWordsPerMonth, knowledgeBaseMaxWords, aiEnabled, maxUsers, maxRowsPerUser. |
Links #
- Product: dnotifier.com
- Docs: Product docs