2020-06-23 04:11:56 +03:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2020-10-05 20:07:09 +03: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/core/rtmp"
|
|
|
|
"github.com/owncast/owncast/router/middleware"
|
|
|
|
"github.com/owncast/owncast/yp"
|
2020-06-23 04:11:56 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
//Start starts the router for the http, ws, and rtmp
|
|
|
|
func Start() error {
|
|
|
|
// start the rtmp server
|
|
|
|
go rtmp.Start()
|
|
|
|
|
|
|
|
// static files
|
|
|
|
http.HandleFunc("/", controllers.IndexHandler)
|
|
|
|
|
|
|
|
// status of the system
|
2020-09-15 02:15:53 +03:00
|
|
|
http.HandleFunc("/api/status", controllers.GetStatus)
|
2020-06-23 04:11:56 +03:00
|
|
|
|
2020-08-13 07:56:41 +03:00
|
|
|
// custom emoji supported in the chat
|
2020-09-15 02:15:53 +03:00
|
|
|
http.HandleFunc("/api/emoji", controllers.GetCustomEmoji)
|
2020-08-13 07:56:41 +03:00
|
|
|
|
2020-10-04 00:35:03 +03:00
|
|
|
// websocket chat server
|
|
|
|
go chat.Start()
|
2020-07-07 07:53:30 +03:00
|
|
|
|
2020-10-04 00:35:03 +03:00
|
|
|
// chat rest api
|
|
|
|
http.HandleFunc("/api/chat", controllers.GetChatMessages)
|
2020-06-23 23:11:01 +03:00
|
|
|
|
2020-10-04 00:35:03 +03:00
|
|
|
// web config api
|
|
|
|
http.HandleFunc("/api/config", controllers.GetWebConfig)
|
2020-08-31 02:32:09 +03:00
|
|
|
|
2020-10-04 00:35:03 +03:00
|
|
|
// chat embed
|
|
|
|
http.HandleFunc("/embed/chat", controllers.GetChatEmbed)
|
2020-08-31 02:32:09 +03:00
|
|
|
|
2020-10-04 00:35:03 +03:00
|
|
|
// video embed
|
|
|
|
http.HandleFunc("/embed/video", controllers.GetVideoEmbed)
|
2020-10-02 09:55:38 +03:00
|
|
|
|
2020-10-04 00:35:03 +03:00
|
|
|
http.HandleFunc("/api/yp", yp.GetYPResponse)
|
2020-06-29 01:10:00 +03:00
|
|
|
|
2020-10-02 04:16:58 +03:00
|
|
|
// Authenticated admin requests
|
|
|
|
|
2020-10-02 10:12:47 +03:00
|
|
|
// Current inbound broadcaster
|
|
|
|
http.HandleFunc("/api/admin/broadcaster", middleware.RequireAdminAuth(admin.GetInboundBroadasterDetails))
|
|
|
|
|
2020-10-02 04:16:58 +03:00
|
|
|
// Disconnect inbound stream
|
2020-10-02 09:17:27 +03: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 04:16:58 +03:00
|
|
|
|
2020-10-02 10:02:42 +03:00
|
|
|
// Server config
|
2020-10-02 10:06:14 +03: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 10:02:42 +03:00
|
|
|
|
2020-10-02 22:18:08 +03:00
|
|
|
// Get hardware stats
|
|
|
|
http.HandleFunc("/api/admin/hardwarestats", middleware.RequireAdminAuth(admin.GetHardwareStats))
|
|
|
|
|
2020-07-14 00:48:56 +03:00
|
|
|
port := config.Config.GetPublicWebServerPort()
|
2020-06-23 04:11:56 +03:00
|
|
|
|
2020-07-07 07:27:31 +03:00
|
|
|
log.Infof("Web server running on port: %d", port)
|
2020-06-23 04:11:56 +03:00
|
|
|
|
|
|
|
return http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
|
|
|
|
}
|