public async Task Publish([FromOptionalArgument] string streamName, [FromOptionalArgument] string publishingType) { if (string.IsNullOrEmpty(streamName)) { throw new InvalidOperationException("empty publishing name"); } if (!PublishingHelpers.IsTypeSupported(publishingType)) { throw new InvalidOperationException($"not supported publishing type {publishingType}"); } _publishingType = PublishingHelpers.PublishingTypes[publishingType]; await RtmpSession.SendControlMessageAsync(new StreamIsRecordedMessage() { StreamID = MessageStream.MessageStreamId }); await RtmpSession.SendControlMessageAsync(new StreamBeginMessage() { StreamID = MessageStream.MessageStreamId }); var onStatus = RtmpSession.CreateCommandMessage <OnStatusCommandMessage>(); MessageStream.RegisterMessageHandler <DataMessage>(HandleData); MessageStream.RegisterMessageHandler <AudioMessage>(HandleAudioMessage); MessageStream.RegisterMessageHandler <VideoMessage>(HandleVideoMessage); MessageStream.RegisterMessageHandler <UserControlMessage>(HandleUserControlMessage); onStatus.InfoObject = new AmfObject { { "level", "status" }, { "code", "NetStream.Publish.Start" }, { "description", "Stream is now published." }, { "details", streamName } }; await MessageStream.SendMessageAsync(ChunkStream, onStatus); _recordFileData = new FileStream(_recordService.GetRecordFilename(streamName) + ".data", FileMode.OpenOrCreate); _recordFileData.SetLength(0); _keyframes = new AmfObject(); _keyframeTimes = new List <object>(); _keyframeFilePositions = new List <object>(); _keyframes.Add("times", _keyframeTimes); _keyframes.Add("filepositions", _keyframeFilePositions); }