owncast/main.go

84 lines
1.6 KiB
Go
Raw Normal View History

2020-05-24 02:57:49 +02:00
package main
import (
"encoding/json"
2020-05-24 02:57:49 +02:00
"net/http"
2020-06-02 01:53:31 +02:00
"strconv"
2020-05-24 02:57:49 +02:00
log "github.com/sirupsen/logrus"
)
var storage ChunkStorage
2020-06-02 01:53:31 +02:00
var configuration = getConfig()
var server *Server
var online = false
var usingExternalStorage = false
2020-05-30 03:08:33 +02:00
func main() {
2020-06-02 01:53:31 +02:00
log.Println("Starting up. Please wait...")
2020-06-09 10:52:15 +02:00
resetDirectories(configuration)
checkConfig(configuration)
2020-06-02 01:53:31 +02:00
if configuration.IPFS.Enabled {
storage = &IPFSStorage{}
2020-06-03 10:34:05 +02:00
usingExternalStorage = true
} else if configuration.S3.Enabled {
storage = &S3Storage{}
usingExternalStorage = true
}
2020-06-03 10:34:05 +02:00
if usingExternalStorage {
storage.Setup(configuration)
2020-06-09 10:52:15 +02:00
// hlsDirectoryPath = configuration.PrivateHLSPath
go monitorVideoContent(configuration.PrivateHLSPath, configuration, storage)
2020-06-02 01:53:31 +02:00
}
2020-05-24 02:57:49 +02:00
go startChatServer()
startRTMPService()
}
func startChatServer() {
// log.SetFlags(log.Lshortfile)
// websocket server
server = NewServer("/entry")
go server.Listen()
// static files
http.Handle("/", http.FileServer(http.Dir("webroot")))
http.HandleFunc("/status", getStatus)
log.Printf("Starting public web server on port %d", configuration.WebServerPort)
2020-06-02 01:53:31 +02:00
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil))
}
func getStatus(w http.ResponseWriter, r *http.Request) {
status := Status{
Online: online,
ViewerCount: server.ClientCount(),
}
json.NewEncoder(w).Encode(status)
}
func streamConnected() {
online = true
chunkPath := configuration.PublicHLSPath
if usingExternalStorage {
chunkPath = configuration.PrivateHLSPath
}
startThumbnailGenerator(chunkPath)
}
func streamDisconnected() {
online = false
}
func viewerAdded() {
}
func viewerRemoved() {
}