A complete real-time chat application demonstrating the Capacitor SignalR Plugin in action.
recording.mp4
- ASP.NET Core SignalR Backend - Real-time hub implementation
- Ionic Angular Mobile App - Cross-platform mobile client
- Web Test Client - Browser-based testing interface
- .NET 9.0 SDK
- Node.js 18+
- Ionic CLI
- Android Studio (for Android) or Xcode (for iOS)
git clone https://github.com/dotnetdreamer/capacitor-signalr-demo.git
cd capacitor-signalr-demo
Option 1: Using .NET CLI (Recommended)
cd web
dotnet run
Option 2: Using Visual Studio
- Open
web/web.sln
in Visual Studio - Set the
web
project as the startup project (right-click β "Set as Startup Project") - Press
F5
or click the "Start" button to run the project - Visual Studio will automatically open a browser - you can close it as we'll use the mobile app
The backend will start on http://localhost:5236
with a SignalR hub at /chatHub
.
Keep this running - the backend needs to be active for the demo to work.
Open a new terminal and run:
cd mobile
npm install
npm run build or ionic capacitor run android --livereload --external --host=0.0.0.0
npx cap sync
Now go to home.page.ts
and change the url to your ip address i.e inside setupSignalRConnection() e.g http://0.0.0.0:5236/chatHub to http://192.168.1.130:5236/chatHub
-
Find your computer's IP address:
# Windows ipconfig # macOS/Linux ifconfig
-
Edit
mobile/src/app/home/home.page.ts
and update the URL:const connectionInfo = await CapacitorSignalR.create({ url: 'http://YOUR_IP_ADDRESS:5236/chatHub', // Replace with your IP // ... other options });
Example:
url: 'http://192.168.1.100:5236/chatHub',
ionic capacitor run android --livereload --external --host=0.0.0.0
ionic capacitor run ios --livereload --external --host=0.0.0.0
Open the web-test.html
file in your browser and:
- Update the hub URL to match your IP address
- Click "Connect"
- Subscribe to "ReceiveMessage" event
- Send messages to test cross-platform communication
- β Send and receive messages instantly
- β Cross-platform messaging (mobile β web)
- β Message persistence during session
- β User identification
- β Connection state monitoring
- β Auto-reconnection with configurable delays
- β Connection error handling
- β Visual connection status indicators
- β WebSockets (preferred)
- β Server-Sent Events (fallback)
- β Long Polling (fallback)
- β Android native implementation
- β iOS native implementation
- β Web fallback using Microsoft SignalR JS client
capacitor-signalr-demo/
βββ web/ # ASP.NET Core SignalR Backend
β βββ Hubs/ChatHub.cs # SignalR Hub implementation
β βββ Program.cs # Server configuration
β βββ Controllers/ # Web controllers
β
βββ mobile/ # Ionic Angular Mobile App
β βββ src/app/home/ # Main chat interface
β βββ capacitor.config.ts # Capacitor configuration
β βββ package.json # Dependencies
β
βββ web-test.html # Standalone web test client
Problem: "Connection refused" or "Failed to connect"
- β
Ensure the backend is running (
dotnet run
in theweb
folder) - β Check the IP address in your mobile app configuration
- β Ensure your device and computer are on the same network
- β Check firewall settings (allow port 5236)
Problem: App doesn't connect on device
- β
Use your computer's IP address, not
localhost
- β
Ensure livereload is running with
--external --host=0.0.0.0
- β Check that the device is on the same WiFi network
Problem: Messages appear twice
- β This has been fixed in the latest version
- β Ensure you're using the latest plugin version
Problem: CORS errors
- β The backend is configured to allow all origins for demo purposes
- β
Check
Program.cs
for CORS configuration
The ChatHub.cs
implements the SignalR hub with methods:
SendMessage(user, message)
- Broadcasts messages to all connected clientsOnConnectedAsync()
- Handles new connectionsOnDisconnectedAsync()
- Handles disconnections
The Ionic app uses the Capacitor SignalR plugin to:
- Create and manage SignalR connections
- Send messages through hub methods
- Listen for real-time events
- Handle connection state changes
The web-test.html
demonstrates direct usage of the Microsoft SignalR JavaScript client for comparison and testing.
- Capacitor SignalR Plugin - The main plugin repository
- Microsoft SignalR Documentation - Official SignalR docs
- Ionic Framework - Mobile app framework
- Capacitor - Native bridge framework
Found a bug or have a suggestion? Please open an issue on the main plugin repository: Report Issues
This demo application is provided as-is for demonstration purposes. See the main plugin repository for licensing information.
Made with β€οΈ for the Capacitor community