49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"hightube/internal/api"
|
|
"hightube/internal/chat"
|
|
"hightube/internal/db"
|
|
"hightube/internal/monitor"
|
|
"hightube/internal/stream"
|
|
)
|
|
|
|
func main() {
|
|
monitor.Init(2000)
|
|
monitor.Infof("Starting Hightube Server v1.0.0-Beta4.7")
|
|
|
|
// Initialize Database and run auto-migrations
|
|
db.InitDB()
|
|
|
|
// Initialize Chat WebSocket Hub
|
|
chat.InitChat()
|
|
|
|
srv := stream.NewRTMPServer()
|
|
|
|
// Start the API server in a goroutine so it doesn't block the RTMP server
|
|
go func() {
|
|
r := api.SetupRouter(srv)
|
|
httpServer := &http.Server{
|
|
Addr: ":8080",
|
|
Handler: r,
|
|
ReadHeaderTimeout: 5 * time.Second,
|
|
IdleTimeout: 60 * time.Second,
|
|
MaxHeaderBytes: 1 << 20,
|
|
}
|
|
monitor.Infof("API server listening on :8080")
|
|
monitor.Infof("Web console listening on :8080/admin")
|
|
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
monitor.Errorf("Failed to start API server: %v", err)
|
|
}
|
|
}()
|
|
|
|
// Setup and start the RTMP server
|
|
monitor.Infof("Ready to receive RTMP streams from OBS")
|
|
if err := srv.Start(":1935"); err != nil {
|
|
monitor.Errorf("Failed to start RTMP server: %v", err)
|
|
}
|
|
}
|