2020-06-23 03:11:56 +02:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2020-10-05 19:07:09 +02:00
|
|
|
"github.com/owncast/owncast/config"
|
|
|
|
"github.com/owncast/owncast/controllers"
|
|
|
|
"github.com/owncast/owncast/controllers/admin"
|
|
|
|
"github.com/owncast/owncast/core/chat"
|
|
|
|
"github.com/owncast/owncast/router/middleware"
|
|
|
|
"github.com/owncast/owncast/yp"
|
2020-06-23 03:11:56 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
//Start starts the router for the http, ws, and rtmp
|
|
|
|
func Start() error {
|
|
|
|
// static files
|
|
|
|
http.HandleFunc("/", controllers.IndexHandler)
|
|
|
|
|
|
|
|
// status of the system
|
2020-09-15 01:15:53 +02:00
|
|
|
http.HandleFunc("/api/status", controllers.GetStatus)
|
2020-06-23 03:11:56 +02:00
|
|
|
|
2020-08-13 06:56:41 +02:00
|
|
|
// custom emoji supported in the chat
|
2020-09-15 01:15:53 +02:00
|
|
|
http.HandleFunc("/api/emoji", controllers.GetCustomEmoji)
|
2020-08-13 06:56:41 +02:00
|
|
|
|
2020-10-03 23:35:03 +02:00
|
|
|
// websocket chat server
|
|
|
|
go chat.Start()
|
2020-07-07 06:53:30 +02:00
|
|
|
|
2020-10-03 23:35:03 +02:00
|
|
|
// chat rest api
|
|
|
|
http.HandleFunc("/api/chat", controllers.GetChatMessages)
|
2020-06-23 22:11:01 +02:00
|
|
|
|
2020-10-03 23:35:03 +02:00
|
|
|
// web config api
|
|
|
|
http.HandleFunc("/api/config", controllers.GetWebConfig)
|
2020-08-31 01:32:09 +02:00
|
|
|
|
2020-10-03 23:35:03 +02:00
|
|
|
// chat embed
|
|
|
|
http.HandleFunc("/embed/chat", controllers.GetChatEmbed)
|
2020-08-31 01:32:09 +02:00
|
|
|
|
2020-10-03 23:35:03 +02:00
|
|
|
// video embed
|
|
|
|
http.HandleFunc("/embed/video", controllers.GetVideoEmbed)
|
2020-10-02 08:55:38 +02:00
|
|
|
|
2020-10-03 23:35:03 +02:00
|
|
|
http.HandleFunc("/api/yp", yp.GetYPResponse)
|
2020-06-29 00:10:00 +02:00
|
|
|
|
2020-10-02 03:16:58 +02:00
|
|
|
// Authenticated admin requests
|
|
|
|
|
2020-10-02 09:12:47 +02:00
|
|
|
// Current inbound broadcaster
|
2020-11-06 03:29:16 +01:00
|
|
|
http.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(admin.Status))
|
2020-10-02 09:12:47 +02:00
|
|
|
|
2020-10-02 03:16:58 +02:00
|
|
|
// Disconnect inbound stream
|
2020-10-02 08:17:27 +02:00
|
|
|
http.HandleFunc("/api/admin/disconnect", middleware.RequireAdminAuth(admin.DisconnectInboundConnection))
|
|
|
|
|
|
|
|
// Change the current streaming key in memory
|
|
|
|
http.HandleFunc("/api/admin/changekey", middleware.RequireAdminAuth(admin.ChangeStreamKey))
|
2020-10-02 03:16:58 +02:00
|
|
|
|
2020-10-14 18:38:48 +02:00
|
|
|
// Change the extra page content in memory
|
|
|
|
http.HandleFunc("/api/admin/changeextrapagecontent", middleware.RequireAdminAuth(admin.ChangeExtraPageContent))
|
|
|
|
|
2020-10-02 09:02:42 +02:00
|
|
|
// Server config
|
2020-10-02 09:06:14 +02:00
|
|
|
http.HandleFunc("/api/admin/serverconfig", middleware.RequireAdminAuth(admin.GetServerConfig))
|
|
|
|
|
|
|
|
// Get viewer count over time
|
|
|
|
http.HandleFunc("/api/admin/viewersOverTime", middleware.RequireAdminAuth(admin.GetViewersOverTime))
|
2020-10-02 09:02:42 +02:00
|
|
|
|
2020-10-02 21:18:08 +02:00
|
|
|
// Get hardware stats
|
|
|
|
http.HandleFunc("/api/admin/hardwarestats", middleware.RequireAdminAuth(admin.GetHardwareStats))
|
|
|
|
|
2020-10-07 08:14:33 +02:00
|
|
|
// Get a a detailed list of currently connected clients
|
|
|
|
http.HandleFunc("/api/admin/clients", middleware.RequireAdminAuth(controllers.GetConnectedClients))
|
|
|
|
|
2020-10-30 02:17:04 +01:00
|
|
|
// Get all logs
|
|
|
|
http.HandleFunc("/api/admin/logs", middleware.RequireAdminAuth(admin.GetLogs))
|
|
|
|
|
|
|
|
// Get warning/error logs
|
|
|
|
http.HandleFunc("/api/admin/logs/warnings", middleware.RequireAdminAuth(admin.GetWarnings))
|
|
|
|
|
2020-07-13 23:48:56 +02:00
|
|
|
port := config.Config.GetPublicWebServerPort()
|
2020-06-23 03:11:56 +02:00
|
|
|
|
2020-07-07 06:27:31 +02:00
|
|
|
log.Infof("Web server running on port: %d", port)
|
2020-06-23 03:11:56 +02:00
|
|
|
|
|
|
|
return http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
|
|
|
|
}
|