2020-06-22 20:11:56 -05:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2020-10-06 01:07:09 +08: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-22 20:11:56 -05:00
|
|
|
)
|
|
|
|
|
2020-11-13 00:14:59 +01:00
|
|
|
// Start starts the router for the http, ws, and rtmp.
|
2020-06-22 20:11:56 -05:00
|
|
|
func Start() error {
|
|
|
|
// static files
|
|
|
|
http.HandleFunc("/", controllers.IndexHandler)
|
|
|
|
|
2020-11-06 15:12:35 -08:00
|
|
|
// admin static files
|
|
|
|
http.HandleFunc("/admin/", middleware.RequireAdminAuth(admin.ServeAdmin))
|
|
|
|
|
2020-06-22 20:11:56 -05:00
|
|
|
// status of the system
|
2020-09-14 16:15:53 -07:00
|
|
|
http.HandleFunc("/api/status", controllers.GetStatus)
|
2020-06-22 20:11:56 -05:00
|
|
|
|
2020-08-12 21:56:41 -07:00
|
|
|
// custom emoji supported in the chat
|
2020-09-14 16:15:53 -07:00
|
|
|
http.HandleFunc("/api/emoji", controllers.GetCustomEmoji)
|
2020-08-12 21:56:41 -07:00
|
|
|
|
2020-10-03 14:35:03 -07:00
|
|
|
// websocket chat server
|
2020-11-14 18:39:53 -08:00
|
|
|
go func() {
|
|
|
|
err := chat.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}()
|
2020-07-06 21:53:30 -07:00
|
|
|
|
2020-10-03 14:35:03 -07:00
|
|
|
// chat rest api
|
|
|
|
http.HandleFunc("/api/chat", controllers.GetChatMessages)
|
2020-06-23 15:11:01 -05:00
|
|
|
|
2020-10-03 14:35:03 -07:00
|
|
|
// web config api
|
|
|
|
http.HandleFunc("/api/config", controllers.GetWebConfig)
|
2020-08-30 16:32:09 -07:00
|
|
|
|
2020-10-03 14:35:03 -07:00
|
|
|
// chat embed
|
|
|
|
http.HandleFunc("/embed/chat", controllers.GetChatEmbed)
|
2020-08-30 16:32:09 -07:00
|
|
|
|
2020-10-03 14:35:03 -07:00
|
|
|
// video embed
|
|
|
|
http.HandleFunc("/embed/video", controllers.GetVideoEmbed)
|
2020-10-01 23:55:38 -07:00
|
|
|
|
2020-10-03 14:35:03 -07:00
|
|
|
http.HandleFunc("/api/yp", yp.GetYPResponse)
|
2020-06-28 15:10:00 -07:00
|
|
|
|
2020-10-01 18:16:58 -07:00
|
|
|
// Authenticated admin requests
|
|
|
|
|
2020-10-02 00:12:47 -07:00
|
|
|
// Current inbound broadcaster
|
2020-11-05 18:29:16 -08:00
|
|
|
http.HandleFunc("/api/admin/status", middleware.RequireAdminAuth(admin.Status))
|
2020-10-02 00:12:47 -07:00
|
|
|
|
2020-10-01 18:16:58 -07:00
|
|
|
// Disconnect inbound stream
|
2020-10-01 23:17:27 -07: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-01 18:16:58 -07:00
|
|
|
|
2020-12-29 23:03:57 +01:00
|
|
|
// Change the current streaming name in memory
|
|
|
|
http.HandleFunc("/api/admin/changename", middleware.RequireAdminAuth(admin.ChangeStreamName))
|
|
|
|
|
|
|
|
// Change the current streaming name in memory
|
|
|
|
http.HandleFunc("/api/admin/changetitle", middleware.RequireAdminAuth(admin.ChangeStreamTitle))
|
|
|
|
|
|
|
|
// Change the current streaming name in memory
|
|
|
|
http.HandleFunc("/api/admin/changetags", middleware.RequireAdminAuth(admin.ChangeStreamTags))
|
|
|
|
|
2020-10-14 09:38:48 -07:00
|
|
|
// Change the extra page content in memory
|
|
|
|
http.HandleFunc("/api/admin/changeextrapagecontent", middleware.RequireAdminAuth(admin.ChangeExtraPageContent))
|
|
|
|
|
2020-10-02 00:02:42 -07:00
|
|
|
// Server config
|
2020-10-02 00:06:14 -07: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 00:02:42 -07:00
|
|
|
|
2020-10-02 12:18:08 -07:00
|
|
|
// Get hardware stats
|
|
|
|
http.HandleFunc("/api/admin/hardwarestats", middleware.RequireAdminAuth(admin.GetHardwareStats))
|
|
|
|
|
2020-10-06 23:14:33 -07:00
|
|
|
// Get a a detailed list of currently connected clients
|
|
|
|
http.HandleFunc("/api/admin/clients", middleware.RequireAdminAuth(controllers.GetConnectedClients))
|
|
|
|
|
2020-10-29 18:17:04 -07: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-12-29 13:35:33 -08:00
|
|
|
// Get all chat messages for the admin, unfiltered.
|
|
|
|
http.HandleFunc("/api/admin/chat/messages", middleware.RequireAdminAuth(admin.GetChatMessages))
|
|
|
|
|
|
|
|
// Update chat message visibilty
|
|
|
|
http.HandleFunc("/api/admin/chat/updatemessagevisibility", middleware.RequireAdminAuth(admin.UpdateMessageVisibility))
|
|
|
|
|
2020-07-13 14:48:56 -07:00
|
|
|
port := config.Config.GetPublicWebServerPort()
|
2020-06-22 20:11:56 -05:00
|
|
|
|
2020-11-06 15:12:35 -08:00
|
|
|
log.Tracef("Web server running on port: %d", port)
|
2020-06-22 20:11:56 -05:00
|
|
|
|
|
|
|
return http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
|
|
|
|
}
|