Exemplo n.º 1
0
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     try
     {
         await base.RunAsync(cancellationToken);
     }
     finally
     {
         _context.Sessions.Remove(Id);
         if (IsPlaying)
         {
             _context.RemovePlayer(IsPublishing ? PublishStream.Path : PlayStream.Path, Id);
         }
         else if (IsPublishing)
         {
             _context.RemovePublisher(PublishStream.Path);
         }
     }
 }
        private async Task HandleDeleteStreamAsync(AmfCommandMessage command)
        {
            if (_session.IsPlaying)
            {
                _context.RemovePlayer(_session.PlayStream.Path, _session.Id);
                _logger.LogInformation($@"[rtmp play] Close stream. id ={_session.Id}
                streamPath ={_session.PlayStream.Path}
                streamId =${ _session.PlayStream.Id}");
                await SendStatusMessageAsync(_session.PlayStream.Id, "status", "NetStream.Play.Stop", "Stopped playing stream.");
            }
            if (_session.IsPublishing)
            {
                var stream = _session.PublishStream;
                _logger.LogInformation($@"[rtmp publish] Close stream. id ={_session.Id}
                streamPath ={stream.Path} streamId ={stream.Id}");
                await SendStatusMessageAsync(stream.Id, "status", "NetStream.Unpublish.Success", $"{stream.Path} is now unpublished.");

                await _session.SendStopToAllPlayersAsync();

                _session.PublishStream = null;
                _context.RemovePublisher(stream.Path);
            }
        }