20. Adding New Streaming Services
This guide explains how to add support for new streaming services to docker-rtmp-multistream.
20.1 Overview
Adding a new streaming service involves two main steps:
- Service Configuration - Create nginx configs, environment variables, and pre-init scripts
- Service Testing - Add comprehensive automated tests
Both steps are required for a complete service implementation.
20.2 Service Patterns
Before implementing a new service, choose the appropriate pattern. See Service Patterns Reference for a detailed comparison of Simple Relay and Transformer patterns, including use cases, pros/cons, and examples.
20.3 Quick Start
20.3.1 1. Configuration
Follow the Service Configuration guide to:
- Create nginx RTMP configuration files (
apps/and optionallytransformers/) - Define environment variables in
Dockerfileandenv/relay.env - Add commented includes to
app.conf - Create pre-init script (
90_configure_{service}.sh) - Make script executable
20.3.2 2. Testing
Follow the Service Testing guide to:
- Add unit tests to
tests/02_unit_tests.sh(service enablement, variable replacement, security) - Add integration test to
tests/03_integration_tests.sh(container startup) - Add validation tests to
tests/00_validation_tests.sh(if new validation functions added) - Run all tests:
./tests/test.sh - Perform manual end-to-end testing
20.3.3 3. Documentation
Add service-specific documentation:
- Create
docs/services/{service}.mdwith: - Overview and configuration variables
- Quality settings and recommendations
- Troubleshooting tips
- Update
mkdocs.ymlnavigation to include your service
20.4 Implementation Checklist
Use this checklist to track your progress:
20.4.1 Configuration
- Created nginx config files (
apps/and/ortransformers/) - Added environment variables to
Dockerfile - Added environment variables to
env/relay.env - Added commented includes to
app.conf - Created pre-init script with validation
- Made script executable (
chmod +x)
20.4.2 Testing
- Added 4-5 unit tests (enable, skip, variables, security, transformer if applicable)
- Added integration test (container startup)
- Added validation tests (if new functions added)
- All tests pass:
./tests/test.shexits with code 0 - Manual end-to-end testing completed
20.4.3 Documentation
- Created service documentation page
- Updated navigation in
mkdocs.yml - Added to main README (if appropriate)
20.5 Best Practices
- Validate early: Check for required environment variables at the start of pre-init scripts
- Use validation functions: Always validate inputs using
validate_input.shto prevent injection attacks - Fail gracefully: Exit with code 0 if service shouldn't be enabled, exit with code 1 for validation errors
- Escape properly: Use
escape_for_sed()when substituting values to handle special characters safely - Log clearly: Echo meaningful messages (e.g., "SERVICE configured and enabled")
- Test thoroughly: Add tests to all relevant test suites
- Security first: Always test that malicious inputs are rejected
- Document comprehensively: Help users configure and troubleshoot your service
20.6 Examples
Study existing service implementations:
20.6.1 Simple Relay (YouTube)
- Config:
apps/youtube.conf - Script:
90_configure_youtube.sh - Docs: YouTube Configuration
20.6.2 Transformer (Twitch)
- Transformer:
transformers/twitch.conf - App:
apps/twitch.conf - Script:
90_configure_twitch.sh - Docs: Twitch Configuration
20.7 Detailed Guides
- Service Configuration - Step-by-step configuration implementation
- Service Testing - Comprehensive testing guide
20.8 See Also
- Architecture Overview - Understanding relay and transformer patterns
- Environment Variables Reference - Complete variable reference
- Security - Input validation and security features
- Testing Guide - General testing documentation