using System.IO; using System.Linq; using System.Threading.Tasks; using WingRtmpService.ChannelManagers.Messages; using WingRtmpService.ChannelManagers.Netease.Helper; using WingServerCommon.Config; using WingServerCommon.Config.Parameters; using WingServerCommon.Log; namespace WingRtmpService.ChannelManagers.Embedded { class EmbeddedChannelManager : IChannelManager { private string _url = ""; public EmbeddedChannelManager() { _url = EnvironmentConfigs.Rtmp.RTMPPushUrl; } private string GetPushUrl(string streamName) { var rtmpPrefix = _url.Replace("http://", "").Replace("https://", ""); return $"rtmp://{rtmpPrefix.TrimEnd('/')}/{streamName}"; } private string GetPullUrl(string streamName) { var rtmpPrefix = _url.Replace("http://", "").Replace("https://", ""); return $"rtmp://{rtmpPrefix.TrimEnd('/')}/{streamName}"; } private string GetHlsPullUrl(string streamName) { return $"{_url.TrimEnd('/')}/{streamName}/play.m3u8"; } private string GetHttpPullUrl(string streamName) { return $"{_url.TrimEnd('/')}/{streamName}.flv"; } public ICreateChannelResult CreateChannel(ChannelParameter channel) { if (channel.Parameter.ContainsKey(ChannelConstant.CreateChannelKey)) { var streamName = channel.Parameter[ChannelConstant.CreateChannelKey]; var channelInfo = new ChannelInfo { Cid = channel.Parameter[ChannelConstant.CreateChannelKey], PushUrl = GetPushUrl(streamName), RtmpPullUrl = GetPullUrl(streamName), HlsPullUrl = GetHlsPullUrl(streamName), HttpPullUrl = GetHttpPullUrl(streamName), }; Logger.WriteLineInfo($"RtmpService EmbeddedChannelManager CreateChannel, streamName:{streamName}"); return new CreateChannelResult { Code = (int)SendResultStatus.Success, ChannelInfo = channelInfo }; } Logger.WriteLineError("RtmpService EmbeddedChannelManager CreateChannel failed, Create channel parameter is empty."); throw new InvalidDataException(); } public Task DeleteChannelAsync(ChannelParameter channel) { return Task.FromResult(new DeleteChannelResult { Code = (int)SendResultStatus.Success }); } } }