بهزودی. Abrova Chat بهزودی فعال میشود. این صفحه توضیح میدهد چطور کار خواهد کرد؛ هنوز قابل استفاده نیست.
این صفحه هنوز ترجمه نشده — نسخهی انگلیسی نمایش داده میشود. English
Realtime Events
Subscribe to Abrova Chat realtime events — messages, read receipts, typing, presence, reactions, edits, deletes, pins — over a WebSocket connection with automatic reconnect and event recovery.
بهروزرسانی: ۵ آبان ۱۴۰۵
Realtime events over a WebSocket connection with automatic reconnect and event recovery.
Event Types
- Messages — new message arrives
- Read Receipts — recipient marks the room as read
- Typing — start/stop typing in a room
- Presence — user online/offline transitions
- Deletions — message deleted
- Edits — message edited
- Reactions — emoji added/removed
- Pins — message pinned/unpinned
Subscribe & Listen to Events#
Subscribe to a room and listen to its realtime stream. Unsubscribe when the user leaves the screen to stop receiving events.
Flutter
// Subscribe to room channels (auto-done when using UI kit)
await client.subscribeRoom(room.id);
// Listen to realtime streams
client.onMessage.listen((message) {
print('New message: ${message.content}');
});
client.onReadReceipt.listen((receipt) {
print('${receipt.userId} read at ${receipt.readAt}');
});
client.onTypingEvent.listen((event) {
print('${event.userId} ${event.isTyping ? "started" : "stopped"} typing');
});
client.onPresenceChange.listen((event) {
print('${event.userId} is ${event.isOnline ? "online" : "offline"}');
});
client.onReactionEvent.listen((event) {
print('${event.userId} ${event.added ? "added" : "removed"} ${event.emoji}');
});
client.onMessageEdited.listen((event) {
print('Message ${event.messageId} edited to: ${event.content}');
});
client.onMessagePinChanged.listen((event) {
print('Message ${event.messageId} ${event.pinned ? "pinned" : "unpinned"}');
});
// Send typing indicator
await client.publishTyping(room.id);
// Check presence in a room
final onlineUsers = await client.getRoomPresence(room.id);
// Unsubscribe when done
await client.unsubscribeRoom(room.id);iOS
// Subscribe to room events
client.subscribeRoom(room.id)
// Listen to realtime events using Combine
client.onMessage
.sink { message in print("New message: \(message.content)") }
.store(in: &cancellables)
client.onReadReceipt
.sink { event in print("\(event.userId) read at \(event.readAt)") }
.store(in: &cancellables)
client.onTypingEvent
.sink { event in print("\(event.userId) is \(event.isTyping ? "typing" : "not typing")") }
.store(in: &cancellables)
client.onPresenceChange
.sink { event in print("\(event.userId) is \(event.isOnline ? "online" : "offline")") }
.store(in: &cancellables)
client.onReactionEvent
.sink { event in print("\(event.userId) \(event.added ? "added" : "removed") \(event.emoji)") }
.store(in: &cancellables)
client.onMessageEdited
.sink { event in print("Message \(event.messageId) edited") }
.store(in: &cancellables)
client.onMessageDeleted
.sink { event in print("Message \(event.messageId) deleted") }
.store(in: &cancellables)
// Send typing indicator
client.publishTyping(room.id)
// Check presence in a room
let onlineUsers = try await client.getRoomPresence(room.id)
// Unsubscribe when done
client.unsubscribeRoom(room.id)Android
// Subscribe to room events
client.subscribeRoom(room.id)
// Listen to realtime events using Kotlin Flow
lifecycleScope.launch {
client.onMessage.collect { message ->
println("New message: ${message.content}")
}
}
lifecycleScope.launch {
client.onReadReceipt.collect { event ->
println("${event.userId} read at ${event.readAt}")
}
}
lifecycleScope.launch {
client.onTypingEvent.collect { event ->
println("${event.userId} is ${if (event.isTyping) "typing" else "not typing"}")
}
}
lifecycleScope.launch {
client.onPresenceChange.collect { event ->
println("${event.userId} is ${if (event.isOnline) "online" else "offline"}")
}
}
lifecycleScope.launch {
client.onReactionEvent.collect { event ->
println("${event.userId} ${if (event.added) "added" else "removed"} ${event.emoji}")
}
}
lifecycleScope.launch {
client.onMessageEdited.collect { event ->
println("Message ${event.messageId} edited")
}
}
lifecycleScope.launch {
client.onMessageDeleted.collect { event ->
println("Message ${event.messageId} deleted")
}
}
// Send typing indicator
client.publishTyping(room.id)
// Check presence in a room
val onlineUsers = client.getRoomPresence(room.id)
// Unsubscribe when done
client.unsubscribeRoom(room.id)React Native
// Subscribe to room events
client.subscribeToRoom(roomId);
// Listen to realtime events
client.on('message', (event) => {
console.log('New message:', event.message.content);
});
client.on('readReceipt', (event) => {
console.log(`${event.userId} read up to ${event.readAt}`);
});
client.on('typing', (event) => {
console.log(`${event.userId} is typing in room ${event.roomId}`);
});
client.on('presence', (event) => {
console.log(`${event.userId} is ${event.isOnline ? 'online' : 'offline'}`);
});
client.on('reaction', (event) => {
console.log(`${event.userId} ${event.added ? 'added' : 'removed'} ${event.emoji}`);
});
client.on('messageEdited', (event) => {
console.log(`Message ${event.messageId} edited to: ${event.content}`);
});
client.on('messageDeleted', (event) => {
console.log(`Message ${event.messageId} deleted`);
});
// Send typing indicator
await client.publishTyping(roomId);
// Check presence in a room
const onlineUsers = await client.getRoomPresence(roomId);
// Unsubscribe when done
client.unsubscribeFromRoom(roomId);Web
// Subscribe to room events
client.subscribeToRoom(roomId);
// Listen to realtime events
client.on('message', (event) => {
console.log('New message:', event.message.content);
});
client.on('readReceipt', (event) => {
console.log(`${event.userId} read up to ${event.readAt}`);
});
client.on('typing', (event) => {
console.log(`${event.userId} is typing in room ${event.roomId}`);
});
client.on('presence', (event) => {
console.log(`${event.userId} is ${event.isOnline ? 'online' : 'offline'}`);
});
client.on('reaction', (event) => {
console.log(`${event.userId} ${event.added ? 'added' : 'removed'} ${event.emoji}`);
});
client.on('messageEdited', (event) => {
console.log(`Message ${event.messageId} edited to: ${event.content}`);
});
client.on('messageDeleted', (event) => {
console.log(`Message ${event.messageId} deleted`);
});
// Send typing indicator
await client.publishTyping(roomId);
// Check presence in a room
const onlineUsers = await client.getRoomPresence(roomId);
// Unsubscribe when done
client.unsubscribeFromRoom(roomId);Node.js (Token Generation)
Node.js is a server-side SDK — no WebSocket connection. Use it to mint the user tokens your client apps return from their tokenProvider (see Authentication). The client SDKs use the same token for REST calls and the WebSocket connection.
// Generate a user token for a user
const { token, expiresAt } = await abrovaChat.users.createToken({
userId: 'user-123',
info: { displayName: 'Alice' },
});
// Example Express.js endpoint — requireLogin is YOUR auth middleware.
// The client app's tokenProvider calls it and returns `token`.
app.get('/api/chat-token', requireLogin, async (req, res) => {
const { token, expiresAt } = await abrovaChat.users.createToken({
userId: req.user.id,
info: { displayName: req.user.name },
});
res.json({ token, expiresAt });
});REST API
# Get a user token (also valid for the WebSocket connection)
curl -X POST "https://chat.abrova.ir/api/v1/users/token" \
-H "X-API-Key: ab_live_your_api_key" -H "X-Server-Secret: $ABROVA_SERVER_SECRET" \
-H "Content-Type: application/json" \
-d '{"userId": "buyer-2", "info": {"displayName": "Alice"}}'
# Live events are delivered through the client SDKs (see above).این صفحه مفید بود؟
گزارش مشکل