Skip to content

Commit

Permalink
fix(bug): Ingress was not working in the new Nats solution. Ref: #611
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Dec 12, 2024
1 parent 40e8a09 commit 2fc55a4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion pkg/models/ingress_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
}

Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/models/webhook_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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)

Expand Down

0 comments on commit 2fc55a4

Please sign in to comment.