Ejemplo n.º 1
0
        private async Task <Channel> RequestChannel(
            StreamName stream_name,
            CancellationToken cancel_token)
        {
            Guid channel_id;

            if (!Guid.TryParse(stream_name.Name, out channel_id))
            {
                return(null);
            }
            var tracker_uri =
                stream_name.Parameters.ContainsKey("tip") ?
                OutputStreamBase.CreateTrackerUri(channel_id, stream_name.Parameters["tip"]) :
                null;
            var channel = owner.RequestChannel(channel_id, tracker_uri);

            if (channel == null)
            {
                return(null);
            }
            await Task.WhenAny(
                Task.Delay(10000),
                channel.WaitForReadyContentTypeAsync(cancel_token)).ConfigureAwait(false);

            if (channel.ChannelInfo == null ||
                String.IsNullOrEmpty(channel.ChannelInfo.ContentType) ||
                channel.ChannelInfo.ContentType != "FLV")
            {
                return(null);
            }
            return(channel);
        }
Ejemplo n.º 2
0
 private static async Task<Channel> GetChannelAsync(OwinEnvironment ctx, ParsedRequest req, CancellationToken ct)
 {
   var tip = ctx.Request.Query.Get("tip");
   var channel = ctx.GetPeerCast().RequestChannel(req.ChannelId, OutputStreamBase.CreateTrackerUri(req.ChannelId, tip), true);
   if (channel==null) {
     return null;
   }
   using (var cts=CancellationTokenSource.CreateLinkedTokenSource(ct)) {
     cts.CancelAfter(10000);
     await channel.WaitForReadyContentTypeAsync(cts.Token).ConfigureAwait(false);
   }
   return channel;
 }
Ejemplo n.º 3
0
        private Uri CreateTrackerUri(Guid channel_id, Uri request_uri)
        {
            string tip = null;

            foreach (Match param in Regex.Matches(request_uri.Query, @"(&|\?)([^&=]+)=([^&=]+)"))
            {
                if (Uri.UnescapeDataString(param.Groups[2].Value) == "tip")
                {
                    tip = Uri.UnescapeDataString(param.Groups[3].Value);
                    break;
                }
            }
            return(OutputStreamBase.CreateTrackerUri(channel_id, tip));
        }