Skip to content

1001api/streamtab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

banner

StreamTab

A lightweight, secure WebRTC-based screen sharing application built with Go and Fiber. StreamTab enables real-time browser tab/screen sharing between a broadcaster and viewer using peer-to-peer WebRTC connections.

Features

  • WebRTC Screen Sharing: Real-time screen/tab streaming with audio support
  • Secure Authentication: Password-protected access with AES-GCM encryption
  • WebSocket Signaling: Efficient peer connection establishment
  • Modern UI: Clean, responsive interface built with Templ templates
  • Docker Support: Easy deployment with Docker and Docker Compose
  • Hot Reload: Development mode with Air for automatic recompilation
  • Security Headers: Built-in Helmet middleware for enhanced security

Tech Stack

  • Backend: Go 1.23+ with Fiber v2 web framework
  • Frontend: Vanilla JavaScript with WebRTC API
  • Templates: Templ for type-safe Go templates
  • WebSocket: Real-time bidirectional communication
  • WebRTC: Peer-to-peer media streaming with STUN/TURN support
  • Encryption: AES-GCM for secure cookie authentication

Prerequisites

  • Go 1.23 or higher
  • Docker and Docker Compose (for containerized deployment)
  • Modern web browser with WebRTC support

Installation

Local Development

  1. Clone the repository

    git clone <repository-url>
    cd streamtab
  2. Install dependencies

    go mod download
  3. Install Templ CLI (for template generation)

    go install github.com/a-h/templ/cmd/templ@latest
  4. Configure environment variables

    Fill a .env file in the project root:

    APP_PASSWORD=your-secure-password
    APP_PASSWORD_KEY=your-32-character-encryption-key
  5. Generate templates and build

    templ generate
    go build -o main main.go
  6. Run the application

    ./main

    The server will start on http://localhost:3000

Development with Hot Reload

Install Air for automatic recompilation:

go install github.com/cosmtrek/air@latest

Run with hot reload:

air

Docker Deployment

  1. Build and run with Docker Compose

    docker-compose up -d
  2. Configure environment variables in docker-compose.yml:

    environment:
      - APP_PASSWORD=your-secure-password
      - APP_PASSWORD_KEY=your-32-character-encryption-key

Usage

For Broadcasters (Streamers)

  1. Navigate to /stream after logging in
  2. Click "Start Streaming" to share your screen/tab
  3. Select the screen or browser tab you want to share
  4. The stream will be available to viewers

For Viewers

  1. Navigate to /viewer after logging in
  2. Wait for the broadcaster to start streaming
  3. Click "Play" when the stream becomes available
  4. View the shared screen in real-time

Project Structure

streamtab/
├── main.go                 # Main application entry point
├── go.mod                  # Go module dependencies
├── go.sum                  # Dependency checksums
├── .env                    # Environment configuration
├── .air.toml              # Air hot reload configuration
├── Dockerfile             # Docker container definition
├── docker-compose.yml     # Docker Compose orchestration
├── public/                # Static assets
│   ├── streaming.js       # Broadcaster WebRTC logic
│   └── viewer.js          # Viewer WebRTC logic
└── views/                 # Templ templates
    ├── IndexPage.templ    # Home page template
    ├── LoginPage.templ    # Login page template
    ├── StreamerTemplate.templ  # Broadcaster interface
    └── ViewerTemplate.templ    # Viewer interface

Configuration

Environment Variables

Variable Description Default Required
APP_PASSWORD Application access password q;j,6rDk No
APP_PASSWORD_KEY 32-byte encryption key for cookies test-key No

WebRTC Configuration

The application uses the following STUN/TURN servers:

  • Google STUN servers (stun.l.google.com)
  • Cloudflare STUN server
  • OpenRelay TURN servers (for NAT traversal)

Security Features

  • Password Authentication: Constant-time password comparison to prevent timing attacks
  • Cookie Encryption: AES-GCM encryption for authentication cookies
  • Secure Cookies: HTTPOnly and Secure flags enabled
  • Helmet Middleware: Security headers for XSS, clickjacking protection
  • 7-Day Session: Automatic session expiration

API Endpoints

Method Path Description Auth Required
GET / Home page Yes
GET /login Login page No
POST /login Authentication No
GET /stream Broadcaster interface Yes
GET /viewer Viewer interface Yes
GET /ws WebSocket signaling No
GET /static/* Static file serving No

WebSocket Signaling Protocol

The WebSocket endpoint (/ws) handles WebRTC signaling messages:

{
  "type": "offer|answer|candidate",
  "data": { /* SDP or ICE candidate data */ }
}

Message Types:

  • offer: SDP offer from broadcaster
  • answer: SDP answer from viewer
  • candidate: ICE candidate for NAT traversal

Development

Building from Source

# Generate Templ templates
templ generate

# Build the binary
go build -o main main.go

# Run
./main

Running Tests

go test ./...

Deployment

Production Considerations

  1. Set strong passwords: Use secure, randomly generated passwords
  2. Use HTTPS: Deploy behind a reverse proxy (Traefik, Nginx) with TLS
  3. Configure TURN servers: For reliable NAT traversal in production
  4. Resource limits: Set appropriate Docker resource constraints
  5. Monitoring: Implement logging and monitoring solutions

Traefik Integration

The included docker-compose.yml has Traefik labels configured:

  • Automatic HTTPS with Let's Encrypt
  • Domain: stream.hubku.com (update to your domain)
  • Network: traefik-network (external network required)

Troubleshooting

Connection Issues

  • WebSocket fails: Check firewall rules for port 3000
  • WebRTC connection fails: Ensure STUN/TURN servers are accessible
  • No audio: Browser may require user interaction before audio playback

Browser Compatibility

  • Chrome/Edge: Full support
  • Firefox: Full support
  • Safari: Requires HTTPS for WebRTC

Common Errors

"Screen sharing permission denied"

  • User declined browser permission prompt
  • Retry and accept the permission request

"Connection to viewer lost"

  • Network connectivity issues
  • Firewall blocking WebRTC traffic
  • TURN server unavailable

License

MIT Licensed

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on the repository.

About

A lightweight, secure WebRTC-based screen sharing application built with Go and Fiber

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •