From 2fc55a4e5c02787962a4e77804cfb83b38c7d975 Mon Sep 17 00:00:00 2001 From: "Jibon L. Costa" Date: Thu, 12 Dec 2024 14:47:41 +0100 Subject: [PATCH] fix(bug): Ingress was not working in the new Nats solution. Ref: https://github.com/mynaparrot/plugNmeet-server/discussions/611 --- pkg/config/constants.go | 1 + pkg/models/ingress_create.go | 20 +++++++++++++++++++- pkg/models/webhook_user.go | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 66a4c4bd..722b3b62 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -5,6 +5,7 @@ import "time" const ( RecorderBot = "RECORDER_BOT" RtmpBot = "RTMP_BOT" + IngressUserIdPrefix = "ingres_" MaxPreloadedWhiteboardFileSize int64 = 5 * 1000000 // limit to 5MB // all the time.Sleep() values diff --git a/pkg/models/ingress_create.go b/pkg/models/ingress_create.go index 7ced0d6a..c481df1d 100644 --- a/pkg/models/ingress_create.go +++ b/pkg/models/ingress_create.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/livekit/protocol/livekit" "github.com/mynaparrot/plugnmeet-protocol/plugnmeet" + "github.com/mynaparrot/plugnmeet-server/pkg/config" "time" ) @@ -35,7 +36,7 @@ func (m *IngressModel) CreateIngress(r *plugnmeet.CreateIngressReq) (*livekit.In InputType: inputType, Name: fmt.Sprintf("%s:%d", r.RoomId, 1), RoomName: r.RoomId, - ParticipantIdentity: fmt.Sprintf("%d", time.Now().UnixMilli()), + ParticipantIdentity: fmt.Sprintf("%s%d", config.IngressUserIdPrefix, time.Now().UnixMilli()), ParticipantName: r.ParticipantName, } @@ -47,6 +48,23 @@ func (m *IngressModel) CreateIngress(r *plugnmeet.CreateIngressReq) (*livekit.In return nil, errors.New("invalid nil create ingress response") } + // add this user in our bucket + tr := true + fl := false + mt := plugnmeet.UserMetadata{ + IsAdmin: true, + RecordWebcam: &tr, + WaitForApproval: false, + LockSettings: &plugnmeet.LockSettings{ + LockWebcam: &fl, + LockMicrophone: &fl, + }, + } + err = m.natsService.AddUser(r.RoomId, req.ParticipantIdentity, r.ParticipantName, true, false, &mt) + if err != nil { + return nil, err + } + ingressFeatures.InputType = r.InputType ingressFeatures.Url = f.Url ingressFeatures.StreamKey = f.StreamKey diff --git a/pkg/models/webhook_user.go b/pkg/models/webhook_user.go index 79cb3342..215d9ab4 100644 --- a/pkg/models/webhook_user.go +++ b/pkg/models/webhook_user.go @@ -4,7 +4,9 @@ import ( "fmt" "github.com/livekit/protocol/livekit" "github.com/mynaparrot/plugnmeet-protocol/plugnmeet" + "github.com/mynaparrot/plugnmeet-server/pkg/config" log "github.com/sirupsen/logrus" + "strings" ) func (m *WebhookModel) participantJoined(event *livekit.WebhookEvent) { @@ -28,6 +30,13 @@ func (m *WebhookModel) participantJoined(event *livekit.WebhookEvent) { log.Errorln(err) } + if strings.HasPrefix(event.Participant.Identity, config.IngressUserIdPrefix) { + // if user was ingress user then we'll have to do it manually + // because that user will not use plugNmeet client interface + nm := NewNatsModel(m.app, m.ds, m.rs) + nm.OnAfterUserJoined(event.Room.Name, event.Participant.Identity) + } + // webhook notification m.sendToWebhookNotifier(event) } @@ -53,6 +62,13 @@ func (m *WebhookModel) participantLeft(event *livekit.WebhookEvent) { log.Errorln(err) } + if strings.HasPrefix(event.Participant.Identity, config.IngressUserIdPrefix) { + // if user was ingress user then we'll have to do it manually + // because that user did not use plugNmeet client interface + nm := NewNatsModel(m.app, m.ds, m.rs) + go nm.OnAfterUserDisconnected(event.Room.Name, event.Participant.Identity) + } + // webhook notification go m.sendToWebhookNotifier(event)