public static async ValueTask <SuccessOrError <Unit> > VerifyCanSendToChatChannel(ServiceInvokerContext context,
                                                                                          ChatChannel channel)
        {
            var selector = context.Context.Resolve <IChatChannelSelector>();
            var canSend  = await selector.CanParticipantSendMessageToChannel(context.Participant, channel);

            if (!canSend)
            {
                return(ChatError.InvalidChannel);
            }

            if (channel is PrivateChatChannel)
            {
                var mediator   = context.Context.Resolve <IMediator>();
                var conference = await mediator.Send(new FindConferenceByIdRequest(context.Participant.ConferenceId));

                var options = conference.Configuration.Chat;

                if (!options.IsPrivateChatEnabled)
                {
                    return(ChatError.PrivateMessagesDisabled);
                }
            }

            return(SuccessOrError <Unit> .Succeeded(Unit.Value));
        }
        public static async ValueTask <SuccessOrError <Unit> > ValidateConferenceIsOpen(ServiceInvokerContext context)
        {
            var openConferenceRepo = context.Context.Resolve <IOpenConferenceRepository>();

            if (!await openConferenceRepo.IsOpen(context.Participant.ConferenceId))
            {
                return(ConferenceError.ConferenceNotOpen);
            }

            return(SuccessOrError <Unit> .Succeeded(Unit.Value));
        }
示例#3
0
        public static async ValueTask <SuccessOrError <Unit> > ValidateObject <T>(ServiceInvokerContext context, T obj)
        {
            if (!context.Context.TryResolve <IValidator <T> >(out var validator))
            {
                return(SuccessOrError <Unit> .Succeeded(Unit.Value));
            }

            var result = validator.Validate(obj);

            if (result.IsValid)
            {
                return(SuccessOrError <Unit> .Succeeded(Unit.Value));
            }

            return(result.ToError());
        }
示例#4
0
        public async Task <SuccessOrError <Unit> > ErrorOccurred(Error dto)
        {
            try
            {
                var(participant, _) = GetContextParticipantWithToken();

                await _mediator.Publish(new EquipmentErrorNotification(participant, Context.ConnectionId, dto));

                return(SuccessOrError <Unit> .Succeeded(Unit.Value));
            }
            catch (Exception e)
            {
                LogException(e, dto);
                return(e.ToError());
            }
        }
示例#5
0
        public async Task <SuccessOrError <Unit> > UpdateStatus(Dictionary <ProducerSource, UseMediaStateInfo> dto)
        {
            try
            {
                var(participant, _) = GetContextParticipantWithToken();

                await _mediator.Send(new UpdateStatusRequest(participant, Context.ConnectionId, dto));

                return(SuccessOrError <Unit> .Succeeded(Unit.Value));
            }
            catch (Exception e)
            {
                LogException(e, dto);
                return(e.ToError());
            }
        }
示例#6
0
        public async Task <SuccessOrError <Unit> > Initialize(InitializeEquipmentDto dto)
        {
            try
            {
                var(participant, _) = GetContextParticipantWithToken();

                await _mediator.Send(new InitializeEquipmentRequest(participant, Context.ConnectionId, dto.Name,
                                                                    dto.Devices));

                return(SuccessOrError <Unit> .Succeeded(Unit.Value));
            }
            catch (Exception e)
            {
                LogException(e, dto);
                return(e.ToError());
            }
        }
        public async Task <SuccessOrError <Unit> > Handle(ChangeBreakoutRoomsRequest request,
                                                          CancellationToken cancellationToken)
        {
            var(conferenceId, patch) = request;
            await using (var @lock = await _repository.LockBreakoutRooms(conferenceId))
            {
                var current = await _repository.Get(conferenceId);

                if (current == null)
                {
                    return(BreakoutRoomError.NotOpen);
                }

                var newState = current.Config with {
                };                                      // clone
                patch.ApplyTo(newState);

                await _mediator.Send(new ApplyBreakoutRoomRequest(conferenceId, newState, @lock));
            }

            return(SuccessOrError <Unit> .Succeeded(Unit.Value));
        }
        public static async ValueTask <SuccessOrError <Unit> > CheckPermissions(ServiceInvokerContext context,
                                                                                params PermissionDescriptor <bool>[] requiredPermissions)
        {
            if (requiredPermissions.Length == 0)
            {
                return(SuccessOrError <Unit> .Succeeded(Unit.Value));
            }

            var participantPermissions = context.Context.Resolve <IParticipantPermissions>();
            var permissions            =
                await participantPermissions.FetchForParticipant(context.Participant);

            foreach (var permission in requiredPermissions)
            {
                var permissionValue = await permissions.GetPermissionValue(permission);

                if (!permissionValue)
                {
                    return(CommonError.PermissionDenied(permission));
                }
            }

            return(SuccessOrError <Unit> .Succeeded(Unit.Value));
        }
示例#9
0
        protected override async Task <SuccessOrError <TResponse> > CreateRequest(CancellationToken token)
        {
            var request = _lazyRequest.Value;

            return(SuccessOrError <TResponse> .Succeeded(await _mediator.Send(request, token)));
        }