ScalaCast is a centralized server streaming video server built with Scala, leveraging its strengths in concurrency and distributed programming. The platform provides reliable data transmission, fault tolerance, and various streaming protocols for real-time applications.
- Centralized Server Architecture: Efficient client connection handling and communication
- Reliable Data Transmission: Built-in handling for packet loss and retransmissions
- Fault-Tolerant Design: Error handling and recovery mechanisms
- Multiple Streaming Protocols:
- HLS (HTTP Live Streaming)
- DASH (Dynamic Adaptive Streaming over HTTP)
- RTMP (Real-Time Messaging Protocol)
- Adaptive Bitrate Streaming
- WebRTC Support: For direct peer-to-peer video connections
- Peer Discovery: Built-in mechanism for discovering and communicating with peers
- Real-time Monitoring: Track CPU usage, memory usage, and logs for errors
- SSL Configuration: Secure your connections with flexible SSL setup
- WebSockets: Real-time communication between server and clients
- Subtitle Support: Add subtitles to your video streams
- Microservices Architecture: Modular design for easier scaling and development
- Frontend Management Interface: Simple web interface for system management
- HTTP/HTTPS Support: Support for both protocols with automatic HTTPS redirection
- Java 11+
- Scala 2.13.12
- sbt 1.9.8
- Play Framework 2.9.0
- Akka 2.7.0
- For RTMP streaming: ffmpeg, nginx-rtmp-module
git clone https://github.com/koke1997/ScalaCast.git
cd ScalaCastOn Linux:
./scripts/install_dependencies.shOn Windows:
scripts\install_dependencies.batGenerate SSL certificates for secure connections:
./scripts/generate_certificates.sh PEM conf/certs serversbt runYou can run the application on multiple ports using the provided Python script:
python scripts/run_local.py --port1 8080 --port2 8081The project includes a GitHub Actions workflow for easy deployment to GitHub Pages:
./scripts/build_static_files.sh
git add docs
git commit -m "Update static files for GitHub Pages"
git pushThe workflow will automatically deploy to GitHub Pages on push to the main branch.
The application exposes various API endpoints for different functionalities:
-
Centralized Server
GET /api/v1/centralized-server- Get server statusPOST /api/v1/centralized-server- Start serverDELETE /api/v1/centralized-server- Stop server
-
Fault Tolerance
GET /api/v1/fault-tolerance- Get fault tolerance statusPOST /api/v1/fault-tolerance/start- Start fault tolerance servicePOST /api/v1/fault-tolerance/stop- Stop fault tolerance service
-
Monitoring
GET /api/v1/monitoring- Get monitoring statusPOST /api/v1/monitoring/cpu- Monitor CPUPOST /api/v1/monitoring/memory- Monitor memoryPOST /api/v1/monitoring/logs- Monitor logsPOST /api/v1/monitoring/restart- Restart service
-
Video Streaming
GET /api/v1/video-streaming- Get video streaming status
-
WebRTC
GET /webrtc- WebRTC interfaceGET /webrtc/test- WebRTC test pageGET /simple-cam- Simple camera testGET /file-cam- File camera approach
-
Authentication
POST /auth/login- LoginPOST /auth/refresh-token- Refresh token
-
Client Management
GET /clients- Get all clientsGET /clients/:clientId- Get client by ID
-
Configuration
GET /config/streaming-quality- Get streaming qualityPOST /config/streaming-quality- Update streaming quality
-
Webhooks
POST /webhooks- Create webhookGET /webhooks/:webhookId- Get webhook by IDDELETE /webhooks/:webhookId- Delete webhook
-
Health Check
GET /health- Get health statusGET /metrics- Get metrics
-
Analytics
GET /analytics/usage- Get usage analyticsGET /analytics/performance- Get performance analytics
The application supports WebSockets for real-time communication:
WebSocket: /ws/video-stream
This endpoint allows real-time streaming and communication between clients and the server.
The project includes a webcam testing site that allows users to test different streaming options:
- Open
/webrtc/testin your browser - Test different streaming protocols (Webcam, HLS, DASH, RTMP)
- Select different camera inputs
- Add subtitles to your stream
sbt testsbt it:testsbt coverage testThe application follows the MVC pattern with separate controllers for each functionality:
CentralizedServerController: Manages the centralized serverAuthenticationController: Handles user authenticationWebSocketController: Manages WebSocket connectionsVideoStreamingController: Controls video streamingWebRTCController: Handles WebRTC connectionsMonitoringController: Monitors system resources
The service layer contains the business logic:
CentralizedServerService: Core server functionalityReliableTransmission: Ensures reliable data transferFaultTolerance: Provides fault tolerance mechanismsVideoStreaming: Handles video streamingMonitoringService: Monitors system resourcesPeerDiscovery: Discovers and communicates with peers
The model layer defines data structures:
Client: Represents a clientPeer: Represents a discovered peerWebhook: Represents a webhook configuration
application.conf: Main application configurationroutes: Route definitionsssl.conf: SSL configurationsys.config: System configuration
Here's a sample from application.conf:
# Application settings
app.name = "ScalaCast"
app.version = "1.0.0"
app.description = "A centralized server streaming video server built with Scala."
# SSL Configuration
ssl {
certificate.path = "/path/to/ssl_certificate.pem"
certificate.key.path = "/path/to/ssl_certificate_key.pem"
protocols = ["TLSv1.2", "TLSv1.3"]
ciphers = ["ECDHE-ECDSA-AES256-GCM-SHA384", "ECDHE-RSA-AES256-GCM-SHA384"]
}
# Video streaming settings
video.streaming {
adaptive.bitrate.enabled = true
subtitle.support.enabled = true
}
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
// Start the centralized server
Await.result(CentralizedServer.startServer(8080), 5.seconds)
// Handle a client request
Await.result(CentralizedServer.handleClientRequest(clientSocket), 5.seconds)
// Stop the centralized server
Await.result(CentralizedServer.stopServer(), 5.seconds)import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
// Start adaptive bitrate streaming
Await.result(VideoStreaming.startAdaptiveBitrateStreaming("path/to/video.mp4", "path/to/output"), 5.seconds)
// Start subtitle support
Await.result(VideoStreaming.startSubtitleSupport("path/to/video.mp4", "path/to/subtitles.srt"), 5.seconds)import scala.util.{Success, Failure}
// Load a key store
val keyStore = SSLConfiguration.loadKeyStore("path/to/keystore.jks", "password", "JKS")
// Create an SSL context
val sslContext = SSLConfiguration.createSSLContext(
"path/to/keystore.jks", "password", "JKS",
"path/to/truststore.jks", "password", "JKS"
)
// Apply the SSL context
SSLConfiguration.applySSLContext(sslContext)import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
// Monitor CPU usage
Await.result(MonitoringService.monitorCPU(), 5.seconds)
// Monitor memory usage
Await.result(MonitoringService.monitorMemory(), 5.seconds)
// Monitor logs for errors
Await.result(MonitoringService.monitorLogs(), 5.seconds)Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Please ensure your code passes all tests and follows the project's coding style.
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies not installed correctly
- Solution: Run the install_dependencies script with administrator privileges
WebSocket connection issues
- Solution: Check if port 8080 is open and not blocked by firewall
SSL certificate problems
- Solution: Generate new certificates using the provided script
Camera access denied
- Solution: Ensure browser permissions for camera access are enabled
If you have any questions or suggestions, please open an issue or contact the repository owner.
Made with β€οΈ using Scala