Overview
The FindMe WebSocket API provides real-time communication capabilities for the FindMe application using Socket.IO. The API is organized into four namespaces:
/presence - User online/offline status and activity tracking
/chat - Real-time messaging and conversations
/location - Location updates and sharing
/interactions - User interactions (waves, connections, nearby users, profiles)
Server Configuration
| Environment | Host | Protocol |
| Development | localhost:3000 | ws |
| Production | api.findme.app | wss |
Authentication
All WebSocket connections require JWT authentication. Pass the token in the connection handshake:
const socket = io('/presence', {
auth: {
token: 'Bearer YOUR_JWT_TOKEN'
}
});
Or via headers:
const socket = io('/presence', {
extraHeaders: {
Authorization: 'Bearer YOUR_JWT_TOKEN'
}
});
Namespaces Overview
| Namespace |
Purpose |
Events |
/presence |
Track user online/offline status globally |
6 events |
/chat |
Messaging, conversations, typing indicators |
28+ events |
/location |
Location updates and sharing |
4 events |
Presence Namespace /presence
Tracks user online/offline status globally across the application.
Connection
const presenceSocket = io('/presence', {
auth: { token: 'Bearer YOUR_JWT_TOKEN' }
});
Events
| Event |
Direction |
Description |
ping |
SEND |
Keep connection alive, update activity |
pong |
RECEIVE |
Server response with timestamp |
status:update |
SEND |
Update user's presence status |
user:online |
RECEIVE |
Another user came online |
user:offline |
RECEIVE |
Another user went offline |
presence:connected |
RECEIVE |
Confirmation of connection with userId |
Example
// Ping to keep alive
presenceSocket.emit('ping');
presenceSocket.on('pong', (data) => {
console.log('Server time:', data.timestamp);
});
// Listen for other users' presence
presenceSocket.on('user:online', ({ userId, status }) => {
console.log(`User ${userId} is now ${status}`);
});
Chat Namespace /chat
Handles all messaging functionality including direct messages, group conversations, typing indicators, and message receipts.
Connection
const chatSocket = io('chat', {
auth: { token: 'Bearer YOUR_JWT_TOKEN' }
});
Conversation Events
| Event |
Direction |
Description |
conversation:create | SEND | Create a new conversation |
conversation:created | RECEIVE | Confirmation of created conversation |
conversation:join | SEND | Join a conversation room |
conversation:joined | RECEIVE | Confirmation of joining |
conversation:leave | SEND | Leave a conversation room |
conversation:left | RECEIVE | Confirmation of leaving |
conversation:get | SEND | Get all user's conversations |
conversation:list | RECEIVE | List of conversations |
conversation:update | RECEIVE | Updated conversations list |
conversation:read | RECEIVE | Conversation marked as read |
Message Events
| Event |
Direction |
Description |
message:send | SEND | Send a message to a conversation |
message:sendToUser | SEND | Send a message directly to a user |
message:sent | RECEIVE | Confirmation message was sent |
message:new | RECEIVE | New message received |
message:get | SEND | Get messages in a conversation |
message:list | RECEIVE | List of messages |
message:edit | SEND | Edit a message |
message:edited | RECEIVE | Message was edited |
message:delete | SEND | Delete a message |
message:deleted | RECEIVE | Message was deleted |
message:notification | RECEIVE | Notification of new message |
Receipt Events
| Event |
Direction |
Description |
message:markDelivered | SEND | Mark a message as delivered |
message:delivered | RECEIVE | Delivery confirmation |
message:markRead | SEND | Mark a message as read |
message:read | RECEIVE | Read confirmation |
message:markAllRead | SEND | Mark all messages in conversation as read |
Typing Events
| Event |
Direction |
Description |
typing:start | SEND | User started typing |
typing:started | RECEIVE | Someone started typing |
typing:stop | SEND | User stopped typing |
typing:stopped | RECEIVE | Someone stopped typing |
Schemas
SendMessageDto
conversationId
string (uuid)
required
content
string
required
messageType
enum: text | image | file | audio | video
default: text
mediaUrl
string (url)
nullable
replyToMessageId
string (uuid)
nullable
CreateConversationDto
type
enum: direct | group
required
participantIds
array of uuid
required
title
string
nullable, for group conversations
Location Namespace /location
Handles location updates and sharing.
Connection
const locationSocket = io('/location', {
auth: { token: 'Bearer YOUR_JWT_TOKEN' }
});
Events
| Event |
Direction |
Description |
updateLocation | SEND | Update user's location |
locationUpdated | RECEIVE | Location update confirmation |
ping | SEND | Keep connection alive |
pong | RECEIVE | Server response |
Example
// Update location
locationSocket.emit('updateLocation', {
latitude: 37.7749,
longitude: -122.4194
});
locationSocket.on('locationUpdated', (user) => {
console.log('Location updated for:', user.email);
});
Interactions Namespace /interactions
Handles user interactions including waves, connection requests, nearby user discovery, and profile viewing.
Connection
const interactionsSocket = io('/interactions', {
auth: {
token: 'Bearer YOUR_JWT_TOKEN'
}
});
Events
| Event |
Direction |
Description |
nearbyUsers:get | SEND | Get nearby users based on location |
nearbyUsers:list | RECEIVE | List of nearby users |
waves:get | SEND | Get waves by tab (sent/received) |
waves:list | RECEIVE | List of waves |
wave:send | SEND | Send a wave to another user |
wave:sent | RECEIVE | Wave sent confirmation |
wave:received | RECEIVE | Received a wave from another user |
connections:get | SEND | Get connections by tab |
connections:list | RECEIVE | List of connections |
connection:request | SEND | Send connection request |
connection:requested | RECEIVE | Connection request sent confirmation |
connection:received | RECEIVE | Received connection request |
connection:accept | SEND | Accept connection request |
connection:accepted | RECEIVE | Connection accepted confirmation |
connection:acceptedByUser | RECEIVE | Another user accepted your connection |
connection:decline | SEND | Decline connection request |
connection:declined | RECEIVE | Connection declined confirmation |
connection:declinedByUser | RECEIVE | Another user declined your connection |
connection:withdraw | SEND | Withdraw connection request |
connection:withdrawn | RECEIVE | Connection withdrawn confirmation |
profiles:get | SEND | Get user profiles by device IDs |
profiles:list | RECEIVE | List of profiles |
profile:view | SEND | View another user's profile |
profile:viewed | RECEIVE | Profile data |
ping | SEND | Keep connection alive |
pong | RECEIVE | Server response |
interactions:connected | RECEIVE | Connected to interactions namespace |
interactions:error | RECEIVE | Error event |
Example
// Get nearby users
interactionsSocket.emit('nearbyUsers:get', {
latitude: '37.7749',
longitude: '-122.4194',
radius: '5',
page: 1,
limit: 10
});
interactionsSocket.on('nearbyUsers:list', (response) => {
console.log('Nearby users:', response.data);
});
// Send a wave
interactionsSocket.emit('wave:send', {
targetUserId: 'user-uuid-here'
});
interactionsSocket.on('wave:sent', (data) => {
console.log('Wave sent:', data);
});
// Listen for received waves
interactionsSocket.on('wave:received', (data) => {
console.log('Received wave from:', data.from);
});
// Send connection request
interactionsSocket.emit('connection:request', {
targetUserId: 'user-uuid-here'
});
interactionsSocket.on('connection:requested', (data) => {
console.log('Connection requested:', data);
});
// Listen for connection accepted by other user
interactionsSocket.on('connection:acceptedByUser', (data) => {
console.log('User accepted your connection:', data);
});
Usage Examples
Complete Chat Flow
// 1. Connect to chat namespace
const chatSocket = io('chat', {
auth: { token: 'Bearer YOUR_JWT_TOKEN' }
});
// 2. Create a conversation
chatSocket.emit('conversation:create', {
type: 'direct',
participantIds: ['user-uuid-here']
});
chatSocket.on('conversation:created', ({ conversation }) => {
// 3. Join the conversation
chatSocket.emit('conversation:join', {
conversationId: conversation.id
});
});
// 4. Send a message
chatSocket.emit('message:send', {
conversationId: 'conv-uuid-here',
content: 'Hello!',
messageType: 'text'
});
// 5. Receive messages
chatSocket.on('message:new', ({ message, conversationId }) => {
console.log(`New message: ${message.content}`);
});
// 6. Typing indicators
chatSocket.emit('typing:start', { conversationId: 'conv-uuid-here' });
chatSocket.on('typing:started', ({ conversationId, userId }) => {
console.log(`User ${userId} is typing...`);
});
Error Handling
chatSocket.on('error', (error) => {
console.error('Chat error:', error.message);
});