# 🔴 Socket.IO REAL-TIME

Live location tracking — Connect, emit events & listen to real-time updates

← Back to REST API Docs Server Status

## ⚙️ Connection

Socket.IO Server URL Bearer Token (Sanctum)
⚠️ Token Register API se milta hai → `POST /api/auth/register` → response mein `"token"` field copy karo
Disconnected

### 📤 Client → Server (Emit)

EMIT location-update Send live location ▼

Client sends current location. Server broadcasts to all circles the user is in.

Payload

    {
      "latitude": 24.8607,
      "longitude": 67.0011,
      "battery_level": 85,
      "speed": 5.2,
      "activity_type": "still",
      "is_moving": false
    }

{ "latitude": 24.8607, "longitude": 67.0011, "battery_level": 85, "speed": 0, "activity_type": "still", "is_moving": false }
EMIT join-circle Join a circle room ▼

After joining a new circle via API, emit this to join the Socket.IO room for real-time updates.

Payload

    { "circle_id": 1 }

{ "circle_id": 1 }
EMIT leave-circle Leave a circle room ▼

When user leaves a circle, emit this to stop receiving that circle's events.

Payload

    { "circle_id": 1 }

{ "circle_id": 1 }

### 📥 Server → Client (Listen)

LISTEN member-location-updated A member's location changed ▼

Received when any circle member sends a location update (via API or Socket).

Data received

    {
      "user_id": 2,
      "name": "Member Name",
      "avatar_url": null,
      "latitude": 33.6844,
      "longitude": 73.0479,
      "battery_level": 60,
      "activity_type": "driving",
      "is_moving": true,
      "updated_at": "2026-03-29T16:00:00Z"
    }

LISTEN member-joined New member joined circle ▼

When someone joins a circle using an invite code.

Data received

    {
      "circle_id": 1,
      "circle_name": "Family",
      "user_id": 3,
      "name": "New Member",
      "phone": "+923...",
      "timestamp": "2026-03-29T16:00:00Z"
    }

LISTEN member-left Member left the circle ▼

When a member voluntarily leaves a circle.

Data received

    {
      "circle_id": 1,
      "circle_name": "Family",
      "user_id": 3,
      "name": "Member Name",
      "timestamp": "..."
    }

LISTEN member-removed Member was removed by admin ▼

When circle owner removes a member.

Data received

    {
      "circle_id": 1,
      "circle_name": "Family",
      "user_id": 3,
      "removed_by": "Owner Name",
      "timestamp": "..."
    }

LISTEN circle-deleted Circle was deleted by owner ▼

When circle owner deletes the entire circle.

Data received

    {
      "circle_id": 1,
      "circle_name": "Family",
      "deleted_by": "Owner Name",
      "timestamp": "..."
    }

LISTEN member-online Member came online ▼

When a circle member opens the app and connects to Socket.IO.

Data received

    { "user_id": 2, "name": "Member", "online": true, "timestamp": "..." }

LISTEN member-offline Member went offline ▼

When a circle member closes the app or loses connection.

Data received

    { "user_id": 2, "name": "Member", "online": false, "timestamp": "..." }

### 📱 React Native Integration

CODE React Native Example Copy-paste ready ▼
Install

    npm install socket.io-client

Usage

    import { io } from 'socket.io-client';

    const socket = io('http://YOUR_SERVER:3000', {
      auth: { token: 'Bearer YOUR_SANCTUM_TOKEN' },
      transports: ['websocket'],
    });

    socket.on('connect', () => {
      console.log('Connected!', socket.id);
    });

    socket.on('member-location-updated', (data) => {
      console.log(`${data.name}: ${data.latitude}, ${data.longitude}`);
      // Update map marker
    });

    socket.on('member-joined', (data) => {
      console.log(`${data.name} joined ${data.circle_name}`);
    });

    socket.on('member-online', (data) => {
      console.log(`${data.name} is online`);
    });

    // Send location
    socket.emit('location-update', {
      latitude: 24.8607,
      longitude: 67.0011,
      battery_level: 85,
    });

    // Join new circle room
    socket.emit('join-circle', { circle_id: 1 });

    // Cleanup
    socket.disconnect();

## 📡 Live Event Log

Connect to Socket.IO server to see live events...