Noah Petherbridge
d8de60c990
* Added a top panel to put your video controls in. * Broadcaster can mute or unmute their own audio input. * When viewing others' cams, buttons appear to control their video: * Their username is displayed in the corner. * Mute/unmute button to silence their audio. * "X" button to close their camera. * Button to show what viewers are currently watching your camera. * Add an "About" page and config for app branding. * Add dark theme CSS for prefers-dark browsers.
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package barertc
|
|
|
|
import (
|
|
"net/http"
|
|
"sync"
|
|
)
|
|
|
|
// Server is the primary back-end server struct for BareRTC, see main.go
|
|
type Server struct {
|
|
// HTTP router.
|
|
mux *http.ServeMux
|
|
|
|
// Max number of messages we'll buffer for a subscriber
|
|
subscriberMessageBuffer int
|
|
|
|
// Connected WebSocket subscribers.
|
|
subscribersMu sync.RWMutex
|
|
subscribers map[*Subscriber]struct{}
|
|
}
|
|
|
|
// NewServer initializes the Server.
|
|
func NewServer() *Server {
|
|
return &Server{
|
|
subscriberMessageBuffer: 16,
|
|
subscribers: make(map[*Subscriber]struct{}),
|
|
}
|
|
}
|
|
|
|
// Setup the server: configure HTTP routes, etc.
|
|
func (s *Server) Setup() error {
|
|
var mux = http.NewServeMux()
|
|
|
|
mux.Handle("/", IndexPage())
|
|
mux.Handle("/about", AboutPage())
|
|
mux.Handle("/ws", s.WebSocket())
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
|
|
|
s.mux = mux
|
|
|
|
return nil
|
|
}
|
|
|
|
// ListenAndServe starts the web server.
|
|
func (s *Server) ListenAndServe(address string) error {
|
|
return http.ListenAndServe(address, s.mux)
|
|
}
|