Skip to content

Commit

Permalink
Merge pull request #466 from mynaparrot/improve
Browse files Browse the repository at this point in the history
Few improvements
  • Loading branch information
jibon57 authored Apr 12, 2024
2 parents 5997a99 + 091409e commit 440064a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
14 changes: 14 additions & 0 deletions pkg/config/error_msgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package config

const (
RequestedRoomNotExist = "requested room does not exist"
OnlyAdminCanRequest = "only admin can send this request"
NoRoomIdInToken = "no roomId in token"
UserNotActive = "user isn't active now"
CanNotDemotePresenter = "can't demote current presenter"
CanNotChangeAlternativePresenter = "can't change alternative presenter"
CanNotPromoteToPresenter = "can't promote to presenter"
InvalidConsumerKey = "invalid consumer_key"
VerificationFailed = "verification failed"
UserIdOrEmailRequired = "either value of user_id or lis_person_contact_email_primary required"
)
6 changes: 3 additions & 3 deletions pkg/models/lti_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m *LTIV1) LTIV1Landing(c *fiber.Ctx, requests, signingURL string) error {
}

if userId == "" {
return errors.New("either value of user_id or lis_person_contact_email_primary required")
return errors.New(config.UserIdOrEmailRequired)
}

name := params.Get("lis_person_name_full")
Expand Down Expand Up @@ -141,7 +141,7 @@ func (m *LTIV1) VerifyAuth(requests, signingURL string) (*url.Values, error) {
}

if p.Get("oauth_consumer_key") != p.ConsumerKey {
return nil, errors.New("invalid consumer_key")
return nil, errors.New(config.InvalidConsumerKey)
}

sign, err := p.Sign()
Expand All @@ -152,7 +152,7 @@ func (m *LTIV1) VerifyAuth(requests, signingURL string) (*url.Values, error) {

if sign != providedSignature {
log.Errorln("Calculated: " + sign + " provided: " + providedSignature)
return nil, errors.New("verification failed")
return nil, errors.New(config.VerificationFailed)
}

return &params, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/room_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (am *RoomAuthModel) CreateRoom(r *plugnmeet.CreateRoomReq) (bool, string, *
roomDbInfo, _ := am.rm.GetRoomInfo(r.RoomId, "", 1)
if roomDbInfo.Id > 0 {
rf, err := am.rs.LoadRoomInfo(r.RoomId)
if err != nil && err.Error() != "requested room does not exist" {
if err != nil && err.Error() != config.RequestedRoomNotExist {
return false, "can't create room. try again", nil
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (am *RoomAuthModel) CreateRoom(r *plugnmeet.CreateRoomReq) (bool, string, *
}

if room.Sid == "" {
// without SID isn't hard to manage, if empty then we won't continue
// without SID, it is hard to manage, if empty then we won't continue
// in this case we'll end the room to clean up
_, _ = am.rs.EndRoom(r.RoomId)
return false, "Error: can't create room with empty SID", nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/room_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *RoomService) LoadRoomInfo(roomId string) (*livekit.Room, error) {
// if you change this text then make sure
// you also update: scheduler.go activeRoomChecker()
// also room_auth.go CreateRoom()
return nil, errors.New("requested room does not exist")
return nil, errors.New(config.RequestedRoomNotExist)
}

room := res.Rooms[0]
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *SchedulerModel) activeRoomChecker() {
}

fromRedis, err := s.ra.rs.LoadRoomInfo(room.RoomId)
if fromRedis == nil && err.Error() == "requested room does not exist" {
if fromRedis == nil && err.Error() == config.RequestedRoomNotExist {
_, _ = s.ra.rm.UpdateRoomStatus(&RoomInfo{
Sid: room.Sid,
IsRunning: 0,
Expand Down
18 changes: 9 additions & 9 deletions pkg/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func (u *UserModel) CommonValidation(c *fiber.Ctx) error {
isAdmin := c.Locals("isAdmin")
roomId := c.Locals("roomId")
if isAdmin != true {
return errors.New("only admin can send this request")
return errors.New(config.OnlyAdminCanRequest)
}
if roomId == "" {
return errors.New("no roomId in token")
return errors.New(config.NoRoomIdInToken)
}

return nil
Expand Down Expand Up @@ -113,7 +113,7 @@ func (u *UserModel) updateParticipantLockMetadata(um updateParticipantLockMetada
return err
}

return errors.New("user isn't active now")
return errors.New(config.UserNotActive)
}

func (u *UserModel) changeLockSettingsMetadata(service string, direction string, l *plugnmeet.LockSettings) *plugnmeet.LockSettings {
Expand Down Expand Up @@ -171,7 +171,7 @@ func (u *UserModel) MuteUnMuteTrack(r *plugnmeet.MuteUnMuteTrackReq) error {
}

if p.State != livekit.ParticipantInfo_ACTIVE {
return errors.New("user isn't active now")
return errors.New(config.UserNotActive)
}
trackSid := r.TrackSid

Expand Down Expand Up @@ -224,7 +224,7 @@ func (u *UserModel) RemoveParticipant(r *plugnmeet.RemoveParticipantReq) error {
}

if p.State != livekit.ParticipantInfo_ACTIVE {
return errors.New("user isn't active now")
return errors.New(config.UserNotActive)
}

// send message to user first
Expand Down Expand Up @@ -268,7 +268,7 @@ func (u *UserModel) SwitchPresenter(r *plugnmeet.SwitchPresenterReq) error {
m.IsPresenter = false
_, err = u.roomService.UpdateParticipantMetadataByStruct(r.RoomId, p.Identity, m)
if err != nil {
return errors.New("can't demote current presenter")
return errors.New(config.CanNotDemotePresenter)
}
}
} else if r.Task == plugnmeet.SwitchPresenterTask_DEMOTE {
Expand All @@ -278,7 +278,7 @@ func (u *UserModel) SwitchPresenter(r *plugnmeet.SwitchPresenterReq) error {
m.IsPresenter = true
_, err = u.roomService.UpdateParticipantMetadataByStruct(r.RoomId, p.Identity, m)
if err != nil {
return errors.New("can't change alternative presenter")
return errors.New(config.CanNotChangeAlternativePresenter)
}
}
}
Expand All @@ -298,13 +298,13 @@ func (u *UserModel) SwitchPresenter(r *plugnmeet.SwitchPresenterReq) error {
m.IsPresenter = true
_, err = u.roomService.UpdateParticipantMetadataByStruct(r.RoomId, p.Identity, m)
if err != nil {
return errors.New("can't promote to presenter")
return errors.New(config.CanNotPromoteToPresenter)
}
} else if r.Task == plugnmeet.SwitchPresenterTask_DEMOTE {
m.IsPresenter = false
_, err = u.roomService.UpdateParticipantMetadataByStruct(r.RoomId, p.Identity, m)
if err != nil {
return errors.New("can't demote to presenter. try again")
return errors.New(config.CanNotDemotePresenter)
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (w *webhookEvent) roomStarted() {
break
}
if list {
log.Println(event.Room.GetName(), "creation in progress, so waiting for", config.WaitDurationIfRoomInProgress)
// we'll wait
time.Sleep(config.WaitDurationIfRoomInProgress)
} else {
Expand Down
9 changes: 4 additions & 5 deletions pkg/models/webhook_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (w *WebhookNotifier) ForceToPutInQueue(event *plugnmeet.CommonNotifyEvent)
return
}
if event.Room.GetSid() == "" || event.Room.GetRoomId() == "" {
log.Errorln("empty room info for", event.GetEvent())
return
}

Expand All @@ -156,10 +157,8 @@ func (w *WebhookNotifier) ForceToPutInQueue(event *plugnmeet.CommonNotifyEvent)

if w.enabledForPerMeeting {
roomInfo, _ := w.rm.GetRoomInfo("", event.Room.GetSid(), 0)
if roomInfo != nil {
if roomInfo.WebhookUrl != "" {
urls = append(urls, roomInfo.WebhookUrl)
}
if roomInfo != nil && roomInfo.WebhookUrl != "" {
urls = append(urls, roomInfo.WebhookUrl)
}
}

Expand All @@ -176,7 +175,7 @@ func (w *WebhookNotifier) saveData(roomId string, d *webhookRedisFields) error {
return err
}

// we'll simply overrider any existing value & put new
// we'll simply override any existing value & put new
_, err = w.rc.HSet(w.ctx, WebhookRedisKey, roomId, marshal).Result()
if err != nil {
return err
Expand Down

0 comments on commit 440064a

Please sign in to comment.