Skip to content

iamfaruk01/Meshage

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

70 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฑ Meshage - Decentralized P2P Messaging App

A serverless, peer-to-peer messaging application built with React Native

Chat without internet infrastructure โ€ข No central servers โ€ข True mesh networking

React Native TypeScript Android


๐ŸŒŸ What is Meshage?

Meshage is a decentralized messaging application that enables direct device-to-device communication without requiring internet connectivity or central servers. Using Google Nearby Connections API, devices form a mesh network where messages are automatically routed through intermediate peers to reach their destination.

Key Features

  • ๐Ÿ”— True P2P Communication - Direct device-to-device messaging
  • ๐ŸŒ Mesh Network Routing - Messages hop through peers to reach distant devices
  • ๐Ÿ”’ Privacy-First - No data stored on external servers
  • ๐Ÿ’ฌ Broadcast & Direct Messages - Public chat room and private conversations
  • ๐Ÿ‘ฅ Friend System - Add friends with persistent IDs across sessions
  • ๐Ÿ’พ Persistent Chat History - Messages saved locally per conversation
  • ๐Ÿ“ก Offline-First - Works without internet or cellular connection
  • ๐Ÿ”„ Auto-Discovery - Automatically finds nearby devices
  • ๐ŸŽจ Modern UI - Clean, dark-themed interface

๐Ÿ—๏ธ Architecture

Technology Stack

  • Frontend: React Native + TypeScript
  • Navigation: React Navigation
  • Storage: AsyncStorage (persistent local storage)
  • Networking: Google Nearby Connections API (Android)
  • State Management: React Hooks (custom hooks pattern)

Project Structure

meshage/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ screens/
โ”‚   โ”‚   โ”œโ”€โ”€ OnboardingScreen.tsx          # Username setup
โ”‚   โ”‚   โ”œโ”€โ”€ BroadcastScreen.tsx               # Broadcast chat screen
โ”‚   โ”‚   โ”œโ”€โ”€ FriendsScreen.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ ChatListScreen.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ ChatDetailsScreen.tsx
โ”‚   โ”‚   โ””โ”€โ”€ SettingsScreen.tsx            # App settings
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ AddFriendBanner.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ ChatItem.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ Header.tsx
โ”‚   โ”‚   โ””โ”€โ”€ NearbyDeviceModal.tsx            # App settings
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ””โ”€โ”€ navigation.ts             # TypeScript interfaces
โ”‚   โ””โ”€โ”€ android/
โ”‚       โ””โ”€โ”€ app/src/main/java/com/meshage/
โ”‚           โ””โ”€โ”€ MeshNetworkModule.kt  # Native Android module
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • React Native CLI installed globally
  • Android Studio with Android SDK
  • JDK 17 or higher
  • Physical Android device (Nearby Connections requires real hardware)

Note: Mesh networking features require physical Android devices. Emulators cannot test P2P connectivity.

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/meshage.git
    cd meshage
  2. Install dependencies

    npm install
    # or
    yarn install
  3. Install Android dependencies

    cd android
    ./gradlew clean
    cd ..
  4. Start Metro bundler

    npm start
    # or
    yarn start
  5. Build and run on Android

    npm run android
    # or
    yarn android

Required Permissions

The app requires the following Android permissions:

  • ACCESS_FINE_LOCATION - For Nearby Connections discovery
  • BLUETOOTH_ADVERTISE - For advertising device presence
  • BLUETOOTH_CONNECT - For connecting to peers
  • BLUETOOTH_SCAN - For discovering nearby devices
  • NEARBY_WIFI_DEVICES - For WiFi Direct connections

๐Ÿ“– How It Works

1. Device Discovery

When you open the app, your device:

  • Broadcasts its presence with format: "Username|PersistentID"
  • Scans for other nearby Meshage devices
  • Automatically connects to discovered peers

2. Mesh Network Formation

Device A โ†โ†’ Device B โ†โ†’ Device C
    โ†“           โ†“
Device D    Device E

Devices form a mesh where:

  • Each device maintains multiple connections
  • Messages are forwarded through intermediate peers
  • Network self-heals when devices disconnect

3. Message Routing

Broadcast Messages:

User A sends "Hello World"
  โ†“
Message format: "deviceID|||username|||Hello World"
  โ†“
Forwarded to all connected peers
  โ†“
Each peer forwards to their connections (except sender)
  โ†“
Deduplication prevents message loops

Direct Messages (Friends):

User A โ†’ Friend B (not directly connected)
  โ†“
Message format: "DIRECT_MSG:friendID:message"
  โ†“
Broadcast to mesh network
  โ†“
Only Friend B displays the message
  โ†“
Other devices forward but don't show it

4. Friend System

  • Each device has a Persistent ID (UUID)
  • Friend requests include: FRIEND_REQUEST:senderID:username
  • Accepted friends are stored locally
  • Personal chats use persistent IDs to target messages

5. Message Deduplication

To prevent infinite message loops:

val messageHash = "$senderID:$messageContent".hashCode()
if (seenMessages.contains(messageHash)) {
    return // Already seen, don't forward
}
seenMessages[messageHash] = currentTime
forwardToOtherPeers(message)

๐Ÿ’ก Features in Detail

๐Ÿ“ข Broadcast Chat

  • Public chat room visible to all connected devices
  • Messages show sender's username
  • Real-time message delivery
  • Auto-scroll to latest messages

๐Ÿ‘ฅ Friends System

  • Send friend requests using persistent IDs
  • Accept/reject incoming requests
  • Friends list persists across app restarts
  • See online/offline status

๐Ÿ’ฌ Personal Chats

  • One-on-one conversations with friends
  • Messages stored locally per friend
  • Chat history persists across sessions
  • Works even when friend is not directly connected (via mesh routing)

๐Ÿ” Privacy & Security

  • No central server - all data stays on device
  • Messages not stored on intermediate devices
  • Each user has a unique persistent ID
  • Friend system prevents spam

๐Ÿ› ๏ธ Development

Code Organization

The project follows separation of concerns pattern:

UI Components (*.tsx)

  • Pure presentational components
  • No business logic
  • Imports hooks and styles

Custom Hooks (use*.ts)

  • State management
  • Business logic
  • Event listeners
  • Network operations

Styles (*.styles.ts)

  • StyleSheet definitions
  • Separated from components
  • Reusable style objects

Types (types/index.ts)

  • Centralized TypeScript interfaces
  • Shared across the app
  • Type-safe development

Key Files

Native Module (MeshNetworkModule.kt)

  • Implements Google Nearby Connections API
  • Handles device discovery and connections
  • Manages message sending/receiving
  • Forwards messages in mesh network

Storage Service (utils/storage.ts)

  • AsyncStorage wrapper
  • Manages persistent data
  • Friend list storage
  • Chat history per friend

Main Hook (useChatScreen.ts)

  • Manages broadcast chat logic
  • Handles peer connections
  • Processes incoming messages
  • Friend request system

๐Ÿ“ฑ Screens

1. Onboarding Screen

  • First-time setup
  • Enter username
  • Generates persistent ID
  • One-time process

2. Chats Screen (Broadcast)

  • Main chat room
  • See all connected peers
  • Send broadcast messages
  • Add friends from peer list

3. Friends Screen

  • List of added friends
  • Online/offline indicators
  • Tap to open personal chat
  • Pending friend requests

4. Personal Chat Screen

  • One-on-one conversation
  • Message history
  • Send direct messages
  • Connection status indicator

5. Settings Screen

  • View your username
  • View persistent ID
  • App information
  • Clear data options

๐Ÿ”ง Configuration

Message Format

Broadcast Message:

"senderEndpointID|||senderUsername|||messageText"

Direct Message:

"DIRECT_MSG:targetPersistentID:messageText"

Friend Request:

"FRIEND_REQUEST:senderPersistentID:senderUsername"

Friend Accept:

"FRIEND_ACCEPT:senderPersistentID:senderUsername"

Storage Keys

@meshage_username           // User's display name
@meshage_persistent_id      // Unique device ID
@meshage_friends            // Friends list (JSON array)
@meshage_friend_requests    // Pending requests (JSON array)
@meshage_chat_<friendID>    // Chat history per friend
@meshage_onboarding_complete // Onboarding status

๐Ÿงช Testing

Testing Mesh Network

  1. Install app on 3+ physical Android devices
  2. Open app on all devices
  3. Devices should auto-discover each other
  4. Send message from Device A
  5. Verify Device B and C receive it
  6. Move Device C out of range of Device A
  7. Verify Device C still receives messages via Device B (mesh routing)

Testing Personal Chats

  1. Add Device B as friend from Device A
  2. Accept friend request on Device B
  3. Open personal chat on Device A
  4. Send message
  5. Verify message appears on Device B
  6. Close and reopen app
  7. Verify chat history persists

๐Ÿ› Troubleshooting

Devices not discovering each other

  • Ensure Location is enabled (required for Nearby Connections)
  • Grant all required permissions
  • Check that devices are within 100 meters
  • Restart the app on both devices
  • Check Android version (requires Android 6.0+)

Messages not being received

  • Check if devices are connected (peer list)
  • Verify network status in app
  • Check logs for errors: adb logcat | grep Meshage
  • Ensure message format is correct

App crashes on startup

  • Clear app data: Settings โ†’ Apps โ†’ Meshage โ†’ Clear Data
  • Reinstall the app
  • Check Android version compatibility
  • Review logcat for native errors

Friend requests not working

  • Verify both devices have unique persistent IDs
  • Check that devices are connected to mesh
  • Ensure friend request message format is correct
  • Check AsyncStorage for corrupted data

๐Ÿ“Š Performance

  • Discovery Time: 2-5 seconds
  • Connection Time: 1-3 seconds per peer
  • Message Latency: <100ms (direct), <500ms (via mesh)
  • Max Peers: ~8 simultaneous connections per device
  • Range: Up to 100 meters (WiFi Direct)
  • Battery Impact: Moderate (continuous scanning/advertising)

๐Ÿ”ฎ Future Enhancements

  • End-to-end encryption
  • File/image sharing
  • Group chats
  • Voice messages
  • Message reactions
  • Read receipts
  • Typing indicators
  • iOS support (using MultipeerConnectivity)
  • Message search
  • Export chat history
  • Custom themes
  • Profile pictures

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ‘จโ€๐Ÿ’ป Author

Your Name


๐Ÿ™ Acknowledgments

  • Google Nearby Connections API - For P2P connectivity
  • React Native Community - For the amazing framework
  • AsyncStorage - For persistent local storage
  • All contributors and testers

๐Ÿ“š Learn More

React Native Resources

Nearby Connections

Mesh Networking


Built with โค๏ธ using React Native

Empowering communication without boundaries

About

P2P Messaging App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 91.6%
  • Kotlin 6.3%
  • Other 2.1%