Ejemplo n.º 1
0
        public async Task <bool> StopTimeshiftAsync(int slotIndex)
        {
            if (TimeshiftControl == null)
            {
                return(false);
            }

            _slotContexes[slotIndex].AccessorPath = null;
            _slotContexes[slotIndex].Channel      = null;

            return(await TimeshiftControl.StopTimeshiftAsync(slotIndex));
        }
Ejemplo n.º 2
0
        internal static async Task <bool> StopTimeshiftAsync(IOwinContext context, int id, string userName)
        {
            if (!CLIENT_CHANNELS.TryRemove(userName, out ChannelInfo channel))
            {
                return(false);
            }

            if (channel != null && !CLIENT_CHANNELS.Any(c => c.Value?.ChannelId == channel.ChannelId))
            {
                if (!(await TimeshiftControl.StopTimeshiftAsync(channel.UserName, channel.SlotIndex).ConfigureAwait(false)))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        internal static async Task <MediaItem> StartTimeshiftAsync(IOwinContext context, int id, string userName)
        {
            var channel = await GetChannelAsync(id);

            if (channel == null)
            {
                return(null);
            }

            var client = CLIENT_CHANNELS.FirstOrDefault(c => c.Value.ChannelId == id);

            if (client.Value?.MediaItem != null)
            {
                //Check if already streaming
                if (client.Key == userName)
                {
                    return(client.Value.MediaItem);
                }

                //Use same stream url as other channel
                if (!CLIENT_CHANNELS.TryAdd(userName, client.Value))
                {
                    return(null);
                }
                else
                {
                    return(client.Value.MediaItem);
                }
            }

            var freeSlot = GetFreeSlot();

            if (freeSlot == null)
            {
                return(null);
            }

            var item = await TimeshiftControl.StartTimeshiftAsync(userName, freeSlot.Value, channel);

            if (!item.Success)
            {
                return(null);
            }

            //Initiate channel cache
            ChannelInfo newChannel = new ChannelInfo
            {
                SlotIndex = freeSlot.Value,
                ChannelId = id,
                MediaItem = item.Result,
                UserName  = userName
            };

            if (!CLIENT_CHANNELS.TryAdd(userName, newChannel))
            {
                await TimeshiftControl.StopTimeshiftAsync(userName, freeSlot.Value);

                return(null);
            }

            return(item.Result);
        }