2020-05-24 02:57:49 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
|
2020-06-01 21:15:07 +02:00
|
|
|
icore "github.com/ipfs/interface-go-ipfs-core"
|
2020-06-01 22:28:14 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-05-24 02:57:49 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/yutopp/go-rtmp"
|
|
|
|
)
|
|
|
|
|
2020-06-01 21:15:07 +02:00
|
|
|
var ipfs icore.CoreAPI
|
2020-05-30 03:08:33 +02:00
|
|
|
|
2020-06-01 21:15:07 +02:00
|
|
|
func main() {
|
2020-05-30 03:08:33 +02:00
|
|
|
resetDirectories()
|
|
|
|
|
2020-06-01 21:15:07 +02:00
|
|
|
ipfsInstance, node, _ := createIPFSInstance()
|
|
|
|
ipfs = *ipfsInstance
|
|
|
|
|
|
|
|
createIPFSDirectory(ipfsInstance, "./hls")
|
|
|
|
// touch("hls/stream.m3u8")
|
|
|
|
|
|
|
|
go startIPFSNode(ipfs, node)
|
|
|
|
go monitorVideoContent("./hls/", ipfsInstance)
|
2020-05-24 02:57:49 +02:00
|
|
|
go startChatServer()
|
|
|
|
|
2020-06-01 21:15:07 +02:00
|
|
|
startRTMPService()
|
|
|
|
}
|
|
|
|
|
|
|
|
func startChatServer() {
|
|
|
|
// log.SetFlags(log.Lshortfile)
|
|
|
|
|
|
|
|
// websocket server
|
|
|
|
server := NewServer("/entry")
|
|
|
|
go server.Listen()
|
|
|
|
|
|
|
|
// static files
|
|
|
|
http.Handle("/", http.FileServer(http.Dir("webroot")))
|
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func startRTMPService() {
|
2020-05-24 02:57:49 +02:00
|
|
|
tcpAddr, err := net.ResolveTCPAddr("tcp", ":1935")
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("Failed: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
listener, err := net.ListenTCP("tcp", tcpAddr)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("Failed: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
srv := rtmp.NewServer(&rtmp.ServerConfig{
|
|
|
|
OnConnect: func(conn net.Conn) (io.ReadWriteCloser, *rtmp.ConnConfig) {
|
|
|
|
l := log.StandardLogger()
|
2020-06-01 22:28:14 +02:00
|
|
|
l.SetLevel(logrus.WarnLevel)
|
2020-05-24 02:57:49 +02:00
|
|
|
|
|
|
|
h := &Handler{}
|
|
|
|
|
|
|
|
return conn, &rtmp.ConnConfig{
|
|
|
|
Handler: h,
|
|
|
|
|
|
|
|
ControlState: rtmp.StreamControlStateConfig{
|
|
|
|
DefaultBandwidthWindowSize: 6 * 1024 * 1024 / 8,
|
|
|
|
},
|
|
|
|
|
|
|
|
Logger: l,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err := srv.Serve(listener); err != nil {
|
|
|
|
log.Panicf("Failed: %+v", err)
|
|
|
|
}
|
2020-05-30 03:08:33 +02:00
|
|
|
|
2020-05-24 02:57:49 +02:00
|
|
|
}
|