/// <summary> /// 配信を開始します。 /// </summary> /// <param name="yp">チャンネル情報を載せるYellowPage</param> /// <param name="channel_id">チャンネルID</param> /// <param name="channel_info">チャンネル情報</param> /// <param name="source">配信ソース</param> /// <param name="content_reader_factory">配信ソースのコンテンツを解析するIContentReaderFactory</param> /// <returns>Channelのインスタンス</returns> public Channel BroadcastChannel(IYellowPageClient yp, Guid channel_id, ChannelInfo channel_info, Uri source, IContentReaderFactory content_reader_factory) { Channel channel = null; logger.Debug("Broadcasting channel {0} from {1}", channel_id.ToString("N"), source); ISourceStreamFactory source_factory = SourceStreamFactories.FirstOrDefault(factory => source.Scheme == factory.Scheme); if (source_factory == null) { logger.Error("Protocol `{0}' is not found", source.Scheme); throw new ArgumentException(String.Format("Protocol `{0}' is not found", source.Scheme)); } channel = new Channel(this, channel_id, this.BroadcastID, source); Utils.ReplaceCollection(ref channels, orig => { var new_collection = new List <Channel>(orig); new_collection.Add(channel); return(new_collection); }); channel.ChannelInfo = channel_info; var content_reader = content_reader_factory.Create(channel); var source_stream = source_factory.Create(channel, source, content_reader); channel.Start(source_stream); if (ChannelAdded != null) { ChannelAdded(this, new ChannelChangedEventArgs(channel)); } if (yp != null) { yp.Announce(channel); } return(channel); }
/// <summary> /// 接続先を指定してチャンネルのリレーを開始します。 /// URIから接続プロトコルも判別します /// </summary> /// <param name="channel_id">リレーするチャンネルID</param> /// <param name="tracker">接続起点およびプロトコル</param> /// <returns>Channelのインスタンス</returns> public Channel RelayChannel(Guid channel_id, Uri tracker) { Channel channel = null; logger.Debug("Requesting channel {0} from {1}", channel_id.ToString("N"), tracker); ISourceStreamFactory source_factory = SourceStreamFactories.FirstOrDefault(factory => tracker.Scheme == factory.Scheme); if (source_factory == null) { logger.Error("Protocol `{0}' is not found", tracker.Scheme); throw new ArgumentException(String.Format("Protocol `{0}' is not found", tracker.Scheme)); } channel = new Channel(this, channel_id, tracker); Utils.ReplaceCollection(ref channels, orig => { var new_collection = new List <Channel>(orig); new_collection.Add(channel); return(new_collection); }); var source_stream = source_factory.Create(channel, tracker); channel.Start(source_stream); if (ChannelAdded != null) { ChannelAdded(this, new ChannelChangedEventArgs(channel)); } return(channel); }