presence_sdk 0.1.1 copy "presence_sdk: ^0.1.1" to clipboard
presence_sdk: ^0.1.1 copied to clipboard

Dart SDK for the Presence realtime platform. Drop-in chat, notifications, and live presence with WebSocket fan-out and automatic reconnection.

presence_sdk #

Dart/Flutter SDK for the Presence realtime platform.

Drop-in chat, notifications, and live presence with zero WebSocket boilerplate.

Installation #

dependencies:
  presence_sdk: ^0.1.0
flutter pub get

Quick start #

import 'package:presence_sdk/presence_sdk.dart';

// Connect with server credentials (handles token exchange automatically)
final client = await PresenceClient.connectWithCredentials(
  endpoint: 'https://your-presence-server.com',
  clientID: 'prn_...',
  clientSecret: '...',
  subjectID: 'user-uuid',
);

// --- Chat ---
// Subscribe to a conversation room
client.chat.subscribe('conversation-uuid');

// Listen for new messages
client.chat.onMessage.listen((msg) {
  print('${msg.senderId}: ${msg.content.text}');
});

// Send a message
await client.chat.sendText('conversation-uuid', 'Hello!');

// Typing indicators
client.chat.startTyping('conversation-uuid'); // call on keypress
client.chat.onTyping.listen((event) {
  print('${event.subjectId} is typing: ${event.typing}');
});

// --- Notifications ---
client.notifications.onNotification.listen((n) {
  print('[${n.title}] ${n.body}');
});

final inbox = await client.notifications.inbox(subjectId: 'user-uuid');

// --- Presence ---
client.presence.watch(['user-a', 'user-b']);
client.presence.onOnline.listen((e) => print('${e.subjectId} came online'));
client.presence.onOffline.listen((e) => print('${e.subjectId} went offline'));

// Disconnect when done
client.disconnect();

Advanced: custom token provider #

final client = await PresenceClient.connect(
  endpoint: 'https://your-presence-server.com',
  tokenProvider: () async {
    // Return a fresh session token from your auth service
    return await myAuth.getPresenceSessionToken();
  },
);

Flutter with Provider #

class PresenceApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => PresenceProvider('my-user-id'),
      child: MaterialApp(home: HomeScreen()),
    );
  }
}

API reference #

PresenceClient #

Method Description
connectWithCredentials(...) Connect using client ID + secret. Handles two-step token exchange.
connect(endpoint, tokenProvider) Connect with a custom async token provider.
disconnect() Close the WebSocket and dispose all streams.
.chat ChatModule — messaging operations
.notifications NotificationsModule — notification operations
.presence PresenceModule — online/offline tracking

ChatModule #

Method Description
subscribe(conversationId) Join a conversation room for live events
onMessage Stream<Message> — new messages
onTyping Stream<TypingEvent> — typing events
sendText(conversationId, text) Send a text message
listMessages(conversationId) Fetch message history
markRead(conversationId, sequence) Mark messages read
createDirect(targetSubjectId) Create a direct conversation
startTyping(conversationId) / stopTyping(...) Typing indicators

NotificationsModule #

Method Description
onNotification Stream<Notification> — live notifications
inbox({subjectId}) Fetch notification inbox
markRead(notificationId) Mark a notification read

PresenceModule #

Method Description
watch(subjectIds) Subscribe to presence events for a list of subjects
onOnline Stream<PresenceEvent>
onOffline Stream<PresenceEvent>
getPresence(subjectIds) Fetch current online/offline state

Requirements #

  • Dart SDK >=3.0.0
  • A running Presence server

License #

MIT

0
likes
150
points
172
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dart SDK for the Presence realtime platform. Drop-in chat, notifications, and live presence with WebSocket fan-out and automatic reconnection.

Repository (GitHub)

License

MIT (license)

Dependencies

http, web_socket_channel

More

Packages that depend on presence_sdk