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
+26
View File
@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/livekit-server/proto/livekit"
)
@@ -17,6 +18,12 @@ const (
// hash of room_id => room name
RoomIdMap = "room_id_map"
// hash of participant_name => participant_id
// a key for each room, with expiration
RoomParticipantMapPrefix = "participant_map:room:"
participantMappingTTL = 24 * time.Hour
)
type RedisRoomStore struct {
@@ -105,7 +112,26 @@ func (p *RedisRoomStore) DeleteRoom(idOrName string) error {
pp := p.rc.Pipeline()
pp.HDel(p.ctx, RoomIdMap, room.Sid)
pp.HDel(p.ctx, RoomsKey, room.Name)
pp.HDel(p.ctx, RoomParticipantMapPrefix+room.Name)
_, err = pp.Exec(p.ctx)
return err
}
func (p *RedisRoomStore) GetParticipantId(room, name string) (string, error) {
key := RoomParticipantMapPrefix + room
pId, err := p.rc.HGet(p.ctx, key, name).Result()
if err == redis.Nil {
// create
pId = utils.NewGuid(utils.ParticipantPrefix)
pp := p.rc.Pipeline()
pp.HSet(p.ctx, key, name, pId)
pp.Expire(p.ctx, key, participantMappingTTL)
_, err = pp.Exec(p.ctx)
} else if err != nil {
return "", err
}
return pId, err
}