feat: update core files for cluster support

This commit is contained in:
langhuihui
2025-01-02 14:18:32 +08:00
parent e2d81f5fa6
commit 2fe53ce68f
4 changed files with 19 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
global:
loglevel: debug
enablelogin: true
enablelogin: false
# db:
# dbtype: mysql
# dsn: root:Monibuca#!4@tcp(sh-cynosdbmysql-grp-kxt43lv6.sql.tencentcdb.com:28520)/lkm7s_v5?parseTime=true

View File

@@ -570,6 +570,12 @@ func (p *Plugin) PublishWithConfig(ctx context.Context, streamPath string, conf
}
}
err = p.Server.Streams.AddTask(publisher, ctx).WaitStarted()
if err == nil {
publisher.OnDispose(func() {
p.sendPublishEndWebhook(publisher)
})
p.sendPublishWebhook(publisher)
}
return
}
@@ -605,6 +611,12 @@ func (p *Plugin) SubscribeWithConfig(ctx context.Context, streamPath string, con
err = subscriber.StopReason()
}
}
if err == nil {
subscriber.OnDispose(func() {
p.sendSubscribeEndWebhook(subscriber)
})
p.sendSubscribeWebhook(subscriber)
}
return
}
@@ -778,14 +790,14 @@ func (p *Plugin) sendPublishEndWebhook(pub *Publisher) {
p.SendWebhook(config.HookOnPublishEnd, p.config.Hook[config.HookOnPublishEnd], webhookData)
}
func (p *Plugin) sendSubscribeWebhook(pub *Publisher, sub *Subscriber) {
func (p *Plugin) sendSubscribeWebhook(sub *Subscriber) {
if p.config.Hook == nil {
return
}
webhookData := map[string]interface{}{
"event": "subscribe",
"streamPath": pub.StreamPath,
"publishId": pub.ID,
"streamPath": sub.StreamPath,
"publishId": sub.Publisher.ID,
"subscriberId": sub.ID,
"remoteAddr": sub.RemoteAddr,
"type": sub.Type,

View File

@@ -31,7 +31,7 @@ func (p *PushJob) Init(pusher IPusher, plugin *Plugin, streamPath string, conf c
p.Connection.Init(plugin, streamPath, conf.URL, conf.Proxy, http.Header(conf.Header))
p.pusher = pusher
if subConf == nil {
p.SubConf = plugin.GetCommonConf().Subscribe
p.SubConf = plugin.config.Subscribe
} else {
p.SubConf = *subConf
}

View File

@@ -405,6 +405,7 @@ func (s *Server) Start() (err error) {
}
if s.DB != nil {
s.DB.AutoMigrate(&PullProxy{})
s.DB.AutoMigrate(&PushProxy{})
}
for _, d := range s.PullProxy {
if d.ID != 0 {
@@ -540,6 +541,7 @@ func (s *Server) Login(ctx context.Context, req *pb.LoginRequest) (res *pb.Login
res = &pb.LoginResponse{}
if !s.ServerConfig.EnableLogin {
res.Data = &pb.LoginSuccess{
Token: "monibuca",
UserInfo: &pb.UserInfo{
Username: "anonymous",
ExpiresAt: time.Now().Add(24 * time.Hour).Unix(),