Esempio n. 1
0
        public async ValueTask InvalidateTalkingSceneWithLockAcquired(string conferenceId, string roomId)
        {
            var scenes =
                await _mediator.FetchSynchronizedObject <SynchronizedScene>(conferenceId,
                                                                            SynchronizedScene.SyncObjId(roomId));

            var talkingStickScene = GetTalkingStickScene(scenes);

            if (talkingStickScene == null)
            {
                return;
            }

            var rooms = await _mediator.FetchSynchronizedObject <SynchronizedRooms>(conferenceId,
                                                                                    SynchronizedRooms.SyncObjId);

            var currentSpeaker = await _repository.GetCurrentSpeaker(conferenceId, roomId);

            currentSpeaker = await VerifyCurrentSpeakerInRoom(currentSpeaker, roomId, rooms);

            if (currentSpeaker == null)
            {
                await ElectNewCurrentSpeaker(conferenceId, roomId, rooms, talkingStickScene.Mode);
            }
        }
Esempio n. 2
0
        public async Task <Unit> Handle(TalkingStickPassRequest request, CancellationToken cancellationToken)
        {
            var(participant, roomId, failIfHasSpeaker) = request;

            await using (await _repository.LockRoom(participant.ConferenceId, roomId))
            {
                await _mediator.Send(new ClearCacheRequest());

                if (failIfHasSpeaker)
                {
                    var currentSpeaker = await _repository.GetCurrentSpeaker(participant.ConferenceId, roomId);

                    if (currentSpeaker != null)
                    {
                        throw SceneError.AlreadyHasSpeaker.ToException();
                    }
                }

                if (!await CheckParticipantIsInRoom(participant, roomId))
                {
                    throw new ParticipantNotFoundException(participant);
                }

                await _repository.SetCurrentSpeakerAndRemoveFromQueue(participant, roomId);

                await _modeHandler.InvalidateTalkingSceneWithLockAcquired(participant.ConferenceId, roomId);
            }

            await _mediator.Send(new UpdateSynchronizedObjectRequest(participant.ConferenceId,
                                                                     SynchronizedSceneTalkingStick.SyncObjId(roomId)));

            return(Unit.Value);
        }
Esempio n. 3
0
        public async Task <Unit> Handle(TalkingStickReturnRequest request, CancellationToken cancellationToken)
        {
            var participant = request.Participant;

            var rooms = await _mediator.FetchSynchronizedObject <SynchronizedRooms>(participant.ConferenceId,
                                                                                    SynchronizedRooms.SyncObjId);

            if (!rooms.Participants.TryGetValue(participant.Id, out var roomId))
            {
                throw SceneError.RoomNotFound.ToException();
            }

            await using (await _repository.LockRoom(participant.ConferenceId, roomId))
            {
                var currentSpeaker = await _repository.GetCurrentSpeaker(participant.ConferenceId, roomId);

                if (currentSpeaker != null && currentSpeaker.Value.Equals(participant))
                {
                    await _repository.RemoveCurrentSpeaker(currentSpeaker.Value.ConferenceId, roomId);

                    await _modeHandler.InvalidateTalkingSceneWithLockAcquired(currentSpeaker.Value.ConferenceId,
                                                                              roomId);
                }
                else
                {
                    return(Unit.Value);
                }
            }

            await _mediator.Send(new UpdateSynchronizedObjectRequest(participant.ConferenceId,
                                                                     SynchronizedSceneTalkingStick.SyncObjId(roomId)));

            return(Unit.Value);
        }
        protected override async ValueTask <SynchronizedSceneTalkingStick> InternalFetchValue(string conferenceId,
                                                                                              string roomId)
        {
            var currentSpeaker = await _repository.GetCurrentSpeaker(conferenceId, roomId);

            var queue = await _repository.FetchQueue(conferenceId, roomId);

            return(new SynchronizedSceneTalkingStick(currentSpeaker?.Id, queue));
        }