reuse the same Participant ID within the same room/session

This commit is contained in:
David Zhao
2021-01-28 01:14:06 -08:00
parent 0e48711e4b
commit fe83baa662
10 changed files with 232 additions and 17 deletions
+27 -4
View File
@@ -6,6 +6,7 @@ import (
"github.com/thoas/go-funk"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/livekit-server/proto/livekit"
)
@@ -15,14 +16,17 @@ type LocalRoomStore struct {
rooms map[string]*livekit.Room
// map of roomName => roomId
roomIds map[string]string
lock sync.RWMutex
// map of roomName => { participantName: participantId }
participantIds map[string]map[string]string
lock sync.RWMutex
}
func NewLocalRoomStore() *LocalRoomStore {
return &LocalRoomStore{
rooms: make(map[string]*livekit.Room),
roomIds: make(map[string]string),
lock: sync.RWMutex{},
rooms: make(map[string]*livekit.Room),
roomIds: make(map[string]string),
participantIds: make(map[string]map[string]string),
lock: sync.RWMutex{},
}
}
@@ -73,3 +77,22 @@ func (p *LocalRoomStore) DeleteRoom(idOrName string) error {
delete(p.roomIds, room.Name)
return nil
}
func (p *LocalRoomStore) GetParticipantId(room, name string) (string, error) {
p.lock.Lock()
defer p.lock.Unlock()
roomParticipantIds := p.participantIds[room]
if roomParticipantIds == nil {
p.participantIds[room] = make(map[string]string)
roomParticipantIds = p.participantIds[room]
}
pId := roomParticipantIds[name]
if pId == "" {
pId = utils.NewGuid(utils.ParticipantPrefix)
roomParticipantIds[name] = pId
}
return pId, nil
}