예제 #1
0
        public virtual void HandleRequest(RemoveFromPlaylistGroupRequest request, IGroupStateContext context, GroupStateType prevState, SessionInfo session, CancellationToken cancellationToken)
        {
            bool playingItemRemoved;

            if (request.ClearPlaylist)
            {
                context.ClearPlayQueue(request.ClearPlayingItem);
                playingItemRemoved = request.ClearPlayingItem;
            }
            else
            {
                playingItemRemoved = context.RemoveFromPlayQueue(request.PlaylistItemIds);
            }

            var playQueueUpdate = context.GetPlayQueueUpdate(PlayQueueUpdateReason.RemoveItems);
            var update          = context.NewSyncPlayGroupUpdate(GroupUpdateType.PlayQueue, playQueueUpdate);

            context.SendGroupUpdate(session, SyncPlayBroadcastType.AllGroup, update, cancellationToken);

            if (playingItemRemoved && !context.PlayQueue.IsItemPlaying())
            {
                _logger.LogDebug("Play queue in group {GroupId} is now empty.", context.GroupId.ToString());

                IGroupState idleState = new IdleGroupState(LoggerFactory);
                context.SetState(idleState);
                var stopRequest = new StopGroupRequest();
                idleState.HandleRequest(stopRequest, context, Type, session, cancellationToken);
            }
        }