owncast/main.go
2020-06-01 17:42:36 -07:00

57 lines
1.1 KiB
Go

package main
import (
"net/http"
"strconv"
icore "github.com/ipfs/interface-go-ipfs-core"
log "github.com/sirupsen/logrus"
)
var ipfs icore.CoreAPI
var configuration = getConfig()
func main() {
checkConfig(configuration)
// resetDirectories()
var hlsDirectoryPath = configuration.PublicHLSPath
log.Println("Starting up. Please wait...")
if configuration.IPFS.Enabled {
hlsDirectoryPath = configuration.PrivateHLSPath
enableIPFS()
go monitorVideoContent(hlsDirectoryPath, configuration, &ipfs)
}
go startChatServer()
startRTMPService()
}
func enableIPFS() {
log.Println("Enabling IPFS support...")
ipfsInstance, node, _ := createIPFSInstance()
ipfs = *ipfsInstance
createIPFSDirectory(ipfsInstance, "./hls")
go startIPFSNode(ipfs, node)
}
func startChatServer() {
// log.SetFlags(log.Lshortfile)
// websocket server
server := NewServer("/entry")
go server.Listen()
// static files
http.Handle("/", http.FileServer(http.Dir("webroot")))
log.Printf("Starting public web server on port %d", configuration.WebServerPort)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil))
}