mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 16:46:58 +08:00
加入是否允许空房间的配置
This commit is contained in:
@@ -32,3 +32,7 @@ func InstallPlugin(opt *PluginConfig) {
|
|||||||
type ListenerConfig struct {
|
type ListenerConfig struct {
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var config = &struct {
|
||||||
|
EnableWaitRoom bool
|
||||||
|
}{true}
|
||||||
|
1
go.mod
1
go.mod
@@ -7,6 +7,7 @@ require (
|
|||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478
|
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478
|
||||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/shirou/gopsutil v2.20.1+incompatible
|
github.com/shirou/gopsutil v2.20.1+incompatible
|
||||||
github.com/stretchr/testify v1.5.1 // indirect
|
github.com/stretchr/testify v1.5.1 // indirect
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
|
||||||
|
2
go.sum
2
go.sum
@@ -16,6 +16,8 @@ github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6Wezm
|
|||||||
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
||||||
github.com/langhuihui/monibuca v0.4.1 h1:hR5xiVtYJM272ChQUrKdNd+AQyY98SNxVZEx2WAuNmA=
|
github.com/langhuihui/monibuca v0.4.1 h1:hR5xiVtYJM272ChQUrKdNd+AQyY98SNxVZEx2WAuNmA=
|
||||||
github.com/langhuihui/monibuca v0.4.1/go.mod h1:S4rqYUQ+bCB3WdwuXTJ92FqVRZz5Sh7zAXOJc94JqMI=
|
github.com/langhuihui/monibuca v0.4.1/go.mod h1:S4rqYUQ+bCB3WdwuXTJ92FqVRZz5Sh7zAXOJc94JqMI=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/quangngotan95/go-m3u8 v0.1.0/go.mod h1:smzfWHlYpBATVNu1GapKLYiCtEo5JxridIgvvudZ+Wc=
|
github.com/quangngotan95/go-m3u8 v0.1.0/go.mod h1:smzfWHlYpBATVNu1GapKLYiCtEo5JxridIgvvudZ+Wc=
|
||||||
|
26
hook.go
26
hook.go
@@ -42,6 +42,19 @@ func (h OnSubscribeHook) Trigger(s *OutputStream) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var OnUnSubscribeHooks = make(OnUnSubscribeHook, 0)
|
||||||
|
|
||||||
|
type OnUnSubscribeHook []func(s *OutputStream)
|
||||||
|
|
||||||
|
func (h OnUnSubscribeHook) AddHook(hook func(s *OutputStream)) {
|
||||||
|
OnUnSubscribeHooks = append(h, hook)
|
||||||
|
}
|
||||||
|
func (h OnUnSubscribeHook) Trigger(s *OutputStream) {
|
||||||
|
for _, f := range h {
|
||||||
|
f(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var OnDropHooks = make(OnDropHook, 0)
|
var OnDropHooks = make(OnDropHook, 0)
|
||||||
|
|
||||||
type OnDropHook []func(s *OutputStream)
|
type OnDropHook []func(s *OutputStream)
|
||||||
@@ -67,3 +80,16 @@ func (h OnSummaryHook) Trigger(v bool) {
|
|||||||
f(v)
|
f(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var OnRoomClosedHooks = make(OnRoomClosedHook, 0)
|
||||||
|
|
||||||
|
type OnRoomClosedHook []func(*Room)
|
||||||
|
|
||||||
|
func (h OnRoomClosedHook) AddHook(hook func(*Room)) {
|
||||||
|
OnRoomClosedHooks = append(h, hook)
|
||||||
|
}
|
||||||
|
func (h OnRoomClosedHook) Trigger(v *Room) {
|
||||||
|
for _, f := range h {
|
||||||
|
f(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -39,6 +39,12 @@ func Run(configFile string) (err error) {
|
|||||||
go Summary.StartSummary()
|
go Summary.StartSummary()
|
||||||
var cg map[string]interface{}
|
var cg map[string]interface{}
|
||||||
if _, err = toml.Decode(string(ConfigRaw), &cg); err == nil {
|
if _, err = toml.Decode(string(ConfigRaw), &cg); err == nil {
|
||||||
|
if cfg, ok := cg["Monibuca"]; ok {
|
||||||
|
b, _ := json.Marshal(cfg)
|
||||||
|
if err = json.Unmarshal(b, config); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
for name, config := range Plugins {
|
for name, config := range Plugins {
|
||||||
if cfg, ok := cg[name]; ok {
|
if cfg, ok := cg[name]; ok {
|
||||||
b, _ := json.Marshal(cfg)
|
b, _ := json.Marshal(cfg)
|
2
room.go
2
room.go
@@ -91,6 +91,7 @@ type ChangeRoomCmd struct {
|
|||||||
func (r *Room) onClosed() {
|
func (r *Room) onClosed() {
|
||||||
log.Printf("room destoryed :%s", r.StreamPath)
|
log.Printf("room destoryed :%s", r.StreamPath)
|
||||||
AllRoom.Delete(r.StreamPath)
|
AllRoom.Delete(r.StreamPath)
|
||||||
|
OnRoomClosedHooks.Trigger(r)
|
||||||
if r.Publisher != nil {
|
if r.Publisher != nil {
|
||||||
r.OnClosed()
|
r.OnClosed()
|
||||||
}
|
}
|
||||||
@@ -138,6 +139,7 @@ func (r *Room) Run() {
|
|||||||
switch v := s.(type) {
|
switch v := s.(type) {
|
||||||
case *UnSubscribeCmd:
|
case *UnSubscribeCmd:
|
||||||
delete(r.Subscribers, v.ID)
|
delete(r.Subscribers, v.ID)
|
||||||
|
OnUnSubscribeHooks.Trigger(v.OutputStream)
|
||||||
log.Printf("%s subscriber %s removed remains:%d", r.StreamPath, v.ID, len(r.Subscribers))
|
log.Printf("%s subscriber %s removed remains:%d", r.StreamPath, v.ID, len(r.Subscribers))
|
||||||
if len(r.Subscribers) == 0 && r.Publisher == nil {
|
if len(r.Subscribers) == 0 && r.Publisher == nil {
|
||||||
r.Cancel()
|
r.Cancel()
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Monibuca/engine/avformat"
|
"github.com/Monibuca/engine/avformat"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Subscriber 订阅者
|
// Subscriber 订阅者
|
||||||
@@ -55,6 +56,11 @@ func (s *OutputStream) Close() {
|
|||||||
|
|
||||||
//Play 开始订阅
|
//Play 开始订阅
|
||||||
func (s *OutputStream) Play(streamPath string) (err error) {
|
func (s *OutputStream) Play(streamPath string) (err error) {
|
||||||
|
if !config.EnableWaitRoom {
|
||||||
|
if _, ok := AllRoom.Load(streamPath); !ok {
|
||||||
|
return errors.New(fmt.Sprintf("Stream not found:%s", streamPath))
|
||||||
|
}
|
||||||
|
}
|
||||||
AllRoom.Get(streamPath).Subscribe(s)
|
AllRoom.Get(streamPath).Subscribe(s)
|
||||||
defer s.UnSubscribe(s)
|
defer s.UnSubscribe(s)
|
||||||
for {
|
for {
|
||||||
|
Reference in New Issue
Block a user