Skip to content

Repository files navigation

🚀 SocketChat — Real-Time Chat Application

Real-Time Chat Interface with Offline Support

SocketChat is a single-screen (P0) real-time chat application built using Jetpack Compose, MVVM, Hilt, Room, and PieSocket WebSockets.
It supports:

✔ Live message streaming
✔ Offline queueing
✔ Automatic resend
✔ Conversations list
✔ Unread preview
✔ Full error handling

This project fulfills all required functional points from the assignment, including real-time sync, offline behavior, message reliability, and chat preview list.


📦 APK Download

👉 Download APK


🧰 Tech Stack

  • Kotlin
  • Jetpack Compose
  • MVVM Architecture
  • Hilt Dependency Injection
  • Room Database
  • WebSockets (PieSocket)
  • Coroutines + StateFlow
  • Material 3 Design

✅ Features Implemented

🔹 1. Single-Screen Chat Interface (P0)

  • Clean, real-time Compose chat UI.
  • Messages aligned left (others) / right (mine).
  • Auto-scroll to latest message.
  • Intelligent “New Messages” button when user is not at bottom.

🔹 2. Real-Time Syncing with WebSockets

  • Uses PieSocket WebSocket channel.
  • Messages appear instantly without refreshing.
  • Messages are sent as JSON:
{
  "senderId": "<device-id>",
  "content": "Hello!"
}

🔹 3. Offline Functionality (P0)

  • Detects network disconnect with NetworkMonitor.
  • Unsent messages stored in Room (Pending Messages).
  • Automatically resent on reconnection with proper JSON payload.

🔹 4. Error Handling

  • Shows Snackbars for: i) Socket failures ii) Connection drops iii) Resend failures
  • Handles empty states: ❗ No Internet ❗ No Chats Available

🔹 5. Conversations List (P1/P2)

Includes:

  • Last message preview

  • Unread message count

  • Timestamp

  • Tapping a conversation opens chat screen

  • Conversations cleared on app close (per requirement)

    🔹 6. Navigation (P2)

    Simple internal navigation between:

✔ Conversations List ✔ Chat Screen

🗂 Project Structure

com.himanshuhc.socketchat │ ├── data │ ├── local (Room) │ ├── repository (ChatRepositoryImpl) │ └── socket (PieSocketManager) │ ├── domain │ └── model (MessageModel, Conversation) │ ├── presentation │ ├── chatlist (Chat UI + ViewModel) │ └── conversation (Conversation UI + ViewModel) │ ├── core (NetworkMonitor) └── di (Hilt Modules)

⚙️ How It Works

Message Flow

  1. User sends message
  2. If online → Sent instantly through WebSocket
  3. If offline → Added to Room DB (pending queue)
  4. On reconnect → Auto resend
  5. Incoming messages update:
  • Chat UI

  • Conversations preview

  • Unread count

    📡 WebSocket Endpoint

Used as per PieSocket: wss://s15496.blr1.piesocket.com/v3/1?api_key=C7uK7TCatKTXwfSSQwcRjbVntcKN6kEvFeiNPwgM&notify_self=0

About

A real-time chat application built with Jetpack Compose, WebSockets, and offline message support. Includes conversations list, unread previews, automatic resend, and full error handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages