Skip to content

Commit

Permalink
fixed: max_participants value was not considered
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Sep 25, 2024
1 parent 644fe66 commit 54ef007
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/jordic/lti v0.0.0-20160211051708-2c756eacbab9
github.com/livekit/protocol v1.21.0
github.com/livekit/server-sdk-go/v2 v2.2.1
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20240916153048-d72bf01c12fc
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20240925105738-164834b6cbc4
github.com/nats-io/jwt/v2 v2.7.0
github.com/nats-io/nats.go v1.37.0
github.com/nats-io/nkeys v0.4.7
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20240916153048-d72bf01c12fc h1:V75DG+KfPXg2goGSs7LXYPPxdNrqxnEVs5oZWGJPcek=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20240916153048-d72bf01c12fc/go.mod h1:oXYXVoAr5AQAO785GGRZdaF2Pn1t8PZsjoIs3cGcSJY=
github.com/nats-io/jwt/v2 v2.6.0 h1:yXoBTdEotZw3NujMT+Nnu1UPNlFWdKQ3d0JJF/+pJag=
github.com/nats-io/jwt/v2 v2.6.0/go.mod h1:ZdWS1nZa6WMZfFwwgpEaqBV8EPGVgOTDHN/wTbz0Y5A=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20240925105738-164834b6cbc4 h1:s0TYHSJGMmUc8cYqND/iebsILZMa7umrwvGH5NT+2JY=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20240925105738-164834b6cbc4/go.mod h1:oXYXVoAr5AQAO785GGRZdaF2Pn1t8PZsjoIs3cGcSJY=
github.com/nats-io/jwt/v2 v2.7.0 h1:J+ZnaaMGQi3xSB8iOhVM5ipiWCDrQvgEoitTwWFyOYw=
github.com/nats-io/jwt/v2 v2.7.0/go.mod h1:ZdWS1nZa6WMZfFwwgpEaqBV8EPGVgOTDHN/wTbz0Y5A=
github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE=
Expand Down
6 changes: 5 additions & 1 deletion pkg/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,18 @@ func HandleVerifyToken(c *fiber.Ctx) error {
}

m := models.NewRoomModel(nil, nil, nil)
rr, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
rr, roomDbInfo, rInfo, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: roomId.(string),
})

if !rr.GetIsActive() {
// prevent joining if room status is not created or active
return utils.SendCommonProtobufResponse(c, false, rr.Msg)
}
// now check MaxParticipants configuration
if rInfo.MaxParticipants > 0 && roomDbInfo.JoinedParticipants >= int64(rInfo.MaxParticipants) {
return utils.SendCommonProtobufResponse(c, false, "notifications.max-num-participates-exceeded")
}

v := version.Version
rId := roomId.(string)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/bbb.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func HandleBBBIsMeetingRunning(c *fiber.Ctx) error {
}

m := models.NewRoomModel(nil, nil, nil)
res, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
res, _, _, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: q.MeetingID,
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/lti_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func HandleLTIV1IsRoomActive(c *fiber.Ctx) error {
roomId := c.Locals("roomId")

m := models.NewRoomModel(nil, nil, nil)
res, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
res, _, _, _ := m.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: roomId.(string),
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func HandleIsRoomActive(c *fiber.Ctx) error {
}

m := models.NewRoomModel(nil, nil, nil)
res, _ := m.IsRoomActive(req)
res, _, _, _ := m.IsRoomActive(req)
return utils.SendProtoJsonResponse(c, res)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/lti_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func (m *LtiV1Model) LTIV1JoinRoom(c *plugnmeet.LtiClaims) (string, error) {
res, _ := m.rm.IsRoomActive(&plugnmeet.IsRoomActiveReq{
res, _, _, _ := m.rm.IsRoomActive(&plugnmeet.IsRoomActiveReq{
RoomId: c.RoomId,
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/room_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (m *RoomModel) CreateRoom(r *plugnmeet.CreateRoomReq) (*plugnmeet.ActiveRoo
}

// now create room bucket
err = m.natsService.AddRoom(roomDbInfo.ID, r.RoomId, sId, r.EmptyTimeout, r.Metadata)
err = m.natsService.AddRoom(roomDbInfo.ID, r.RoomId, sId, r.EmptyTimeout, r.MaxParticipants, r.Metadata)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/models/room_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
natsservice "github.com/mynaparrot/plugnmeet-server/pkg/services/nats"
)

func (m *RoomModel) IsRoomActive(r *plugnmeet.IsRoomActiveReq) (*plugnmeet.IsRoomActiveRes, *plugnmeet.RoomMetadata) {
func (m *RoomModel) IsRoomActive(r *plugnmeet.IsRoomActiveReq) (*plugnmeet.IsRoomActiveRes, *dbmodels.RoomInfo, *plugnmeet.NatsKvRoomInfo, *plugnmeet.RoomMetadata) {
// check first
m.CheckAndWaitUntilRoomCreationInProgress(r.GetRoomId())

Expand All @@ -19,18 +19,18 @@ func (m *RoomModel) IsRoomActive(r *plugnmeet.IsRoomActiveReq) (*plugnmeet.IsRoo
if err != nil {
res.Status = false
res.Msg = err.Error()
return res, nil
return res, nil, nil, nil
}
if roomDbInfo == nil || roomDbInfo.ID == 0 {
return res, nil
return res, nil, nil, nil
}

// let's make sure room actually active
rInfo, meta, err := m.natsService.GetRoomInfoWithMetadata(r.RoomId)
if err != nil {
res.Status = false
res.Msg = err.Error()
return res, nil
return res, nil, nil, nil
}

if rInfo == nil || meta == nil {
Expand All @@ -39,15 +39,15 @@ func (m *RoomModel) IsRoomActive(r *plugnmeet.IsRoomActiveReq) (*plugnmeet.IsRoo
RoomId: r.RoomId,
IsRunning: 0,
})
return res, nil
return res, nil, nil, nil
}

if rInfo.Status == natsservice.RoomStatusCreated || rInfo.Status == natsservice.RoomStatusActive {
res.IsActive = true
res.Msg = "room is active"
}

return res, meta
return res, roomDbInfo, rInfo, meta
}

func (m *RoomModel) GetActiveRoomInfo(r *plugnmeet.GetActiveRoomInfoReq) (bool, string, *plugnmeet.ActiveRoomWithParticipant) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/services/nats/room_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func (s *NatsService) GetRoomInfo(roomId string) (*plugnmeet.NatsKvRoomInfo, err
info.EmptyTimeout = parseUint
}
}
if maxParticipants, err := kv.Get(s.ctx, RoomMaxParticipants); err == nil && maxParticipants != nil {
if parseUint, err := strconv.ParseUint(string(maxParticipants.Value()), 10, 64); err == nil {
info.MaxParticipants = parseUint
}
}
if metadata, err := kv.Get(s.ctx, RoomMetadataKey); err == nil && metadata != nil {
info.Metadata = string(metadata.Value())
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/services/nats/room_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
RoomIdKey = "room_id"
RoomSidKey = "room_sid"
RoomEmptyTimeoutKey = "empty_timeout"
RoomMaxParticipants = "max_participants"
RoomStatusKey = "status"
RoomMetadataKey = "metadata"
RoomCreatedKey = "created_at"
Expand All @@ -26,7 +27,7 @@ const (
RoomStatusEnded = "ended"
)

func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeout *uint32, metadata *plugnmeet.RoomMetadata) error {
func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeout, maxParticipants *uint32, metadata *plugnmeet.RoomMetadata) error {
kv, err := s.js.CreateOrUpdateKeyValue(s.ctx, jetstream.KeyValueConfig{
Replicas: s.app.NatsInfo.NumReplicas,
Bucket: fmt.Sprintf(RoomInfoBucket, roomId),
Expand All @@ -49,6 +50,7 @@ func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeo
RoomIdKey: roomId,
RoomSidKey: roomSid,
RoomEmptyTimeoutKey: fmt.Sprintf("%d", *emptyTimeout),
RoomMaxParticipants: fmt.Sprintf("%d", *maxParticipants),
RoomStatusKey: RoomStatusCreated,
RoomCreatedKey: fmt.Sprintf("%d", time.Now().UTC().Unix()), // in seconds
RoomMetadataKey: mt,
Expand Down

0 comments on commit 54ef007

Please sign in to comment.