FindMe WebSocket API

Real-time messaging, presence, and location services

Overview

The FindMe WebSocket API provides real-time communication capabilities for the FindMe application using Socket.IO. The API is organized into four namespaces:

Server Configuration

EnvironmentHostProtocol
Developmentlocalhost:3000ws
Productionapi.findme.appwss

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:createSENDCreate a new conversation
conversation:createdRECEIVEConfirmation of created conversation
conversation:joinSENDJoin a conversation room
conversation:joinedRECEIVEConfirmation of joining
conversation:leaveSENDLeave a conversation room
conversation:leftRECEIVEConfirmation of leaving
conversation:getSENDGet all user's conversations
conversation:listRECEIVEList of conversations
conversation:updateRECEIVEUpdated conversations list
conversation:readRECEIVEConversation marked as read

Message Events

Event Direction Description
message:sendSENDSend a message to a conversation
message:sendToUserSENDSend a message directly to a user
message:sentRECEIVEConfirmation message was sent
message:newRECEIVENew message received
message:getSENDGet messages in a conversation
message:listRECEIVEList of messages
message:editSENDEdit a message
message:editedRECEIVEMessage was edited
message:deleteSENDDelete a message
message:deletedRECEIVEMessage was deleted
message:notificationRECEIVENotification of new message

Receipt Events

Event Direction Description
message:markDeliveredSENDMark a message as delivered
message:deliveredRECEIVEDelivery confirmation
message:markReadSENDMark a message as read
message:readRECEIVERead confirmation
message:markAllReadSENDMark all messages in conversation as read

Typing Events

Event Direction Description
typing:startSENDUser started typing
typing:startedRECEIVESomeone started typing
typing:stopSENDUser stopped typing
typing:stoppedRECEIVESomeone 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
updateLocationSENDUpdate user's location
locationUpdatedRECEIVELocation update confirmation
pingSENDKeep connection alive
pongRECEIVEServer 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:getSENDGet nearby users based on location
nearbyUsers:listRECEIVEList of nearby users
waves:getSENDGet waves by tab (sent/received)
waves:listRECEIVEList of waves
wave:sendSENDSend a wave to another user
wave:sentRECEIVEWave sent confirmation
wave:receivedRECEIVEReceived a wave from another user
connections:getSENDGet connections by tab
connections:listRECEIVEList of connections
connection:requestSENDSend connection request
connection:requestedRECEIVEConnection request sent confirmation
connection:receivedRECEIVEReceived connection request
connection:acceptSENDAccept connection request
connection:acceptedRECEIVEConnection accepted confirmation
connection:acceptedByUserRECEIVEAnother user accepted your connection
connection:declineSENDDecline connection request
connection:declinedRECEIVEConnection declined confirmation
connection:declinedByUserRECEIVEAnother user declined your connection
connection:withdrawSENDWithdraw connection request
connection:withdrawnRECEIVEConnection withdrawn confirmation
profiles:getSENDGet user profiles by device IDs
profiles:listRECEIVEList of profiles
profile:viewSENDView another user's profile
profile:viewedRECEIVEProfile data
pingSENDKeep connection alive
pongRECEIVEServer response
interactions:connectedRECEIVEConnected to interactions namespace
interactions:errorRECEIVEError 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);
});
↑ Top