More channel call operations available

 Prevent two user create call in a channel at the same time
This commit is contained in:
2024-07-17 11:03:35 +08:00
parent 7e03eeee38
commit 2486b317e3
5 changed files with 88 additions and 5 deletions

View File

@ -66,6 +66,16 @@ func GetOngoingCall(channel models.Channel) (models.Call, error) {
}
}
func GetCallParticipants(call models.Call) ([]*livekit.ParticipantInfo, error) {
res, err := Lk.ListParticipants(context.Background(), &livekit.ListParticipantsRequest{
Room: call.ExternalID,
})
if err != nil {
return nil, err
}
return res.Participants, nil
}
func NewCall(channel models.Channel, founder models.ChannelMember) (models.Call, error) {
call := models.Call{
ExternalID: channel.Alias,
@ -94,7 +104,7 @@ func NewCall(channel models.Channel, founder models.ChannelMember) (models.Call,
} else if err = database.C.Where(models.ChannelMember{
ChannelID: call.ChannelID,
}).Preload("Account").Find(&members).Error; err == nil {
channel := call.Channel
channel = call.Channel
call, _ = GetCall(call.Channel, call.ID)
for _, member := range members {
if member.ID != call.Founder.ID {
@ -146,6 +156,14 @@ func EndCall(call models.Call) (models.Call, error) {
return call, nil
}
func KickParticipantInCall(call models.Call, username string) error {
_, err := Lk.RemoveParticipant(context.Background(), &livekit.RoomParticipantIdentity{
Room: call.ExternalID,
Identity: username,
})
return err
}
func EncodeCallToken(user models.Account, call models.Call) (string, error) {
isAdmin := false
if user.ID == call.FounderID || user.ID == call.Channel.AccountID {