Exemplo n.º 1
0
        private Task <AcknowledgeMessageExt> QueueCommandAsTask(Command command, int streamId, int messageStreamId, bool requireConnected = true)
        {
            if (requireConnected && this.IsDisconnected)
            {
                return(RtmpClient.CreateExceptedTask((Exception) new ClientDisconnectedException("disconnected")));
            }
            Task <AcknowledgeMessageExt> task = this._callbackManager.Create(command.InvokeId);

            this._writer.Queue((RtmpEvent)command, streamId, messageStreamId);
            return(task);
        }
Exemplo n.º 2
0
            public Writer(RtmpClient owner, Stream stream, SerializationContext context, CancellationToken cancellationToken)
            {
                this.owner   = owner;
                this.stream  = stream;
                this.context = context;

                this.token   = cancellationToken;
                this.reset   = new AsyncAutoResetEvent();
                this.queue   = new ConcurrentQueue <Packet>();
                this.streams = new KeyDictionary <int, ChunkStream.Snapshot>();
            }
Exemplo n.º 3
0
 void ServerMessageReceived(object sender, RemotingMessageReceivedEventArgs e)
 {
     if (ClientMessageReceived != null)
     {
         ClientMessageReceived(sender, e);
         if (e.ReturnRequired)
         {
             RtmpClient client = (RtmpClient)sender;
             client.InvokeResult(e.InvokeId, e.MessageId, e.Data);
         }
     }
 }
Exemplo n.º 4
0
        void ServerCommandReceived(object sender, CommandMessageReceivedEventArgs e)
        {
            RtmpClient client = (RtmpClient)sender;

            switch (e.Message.Operation)
            {
            case CommandOperation.Login:
                AcknowledgeMessageExt login = new AcknowledgeMessageExt
                {
                    Body          = "success",
                    CorrelationId = e.Message.MessageId,
                    MessageId     = Uuid.NewUuid(),
                    ClientId      = Uuid.NewUuid(),
                    Headers       = new AsObject
                    {
                        { "DSMessagingVersion", 1.0 },
                        { FlexMessageHeaders.FlexClientId, e.DSId }
                    }
                };

                client.InvokeResult(e.InvokeId, login);
                break;

            case CommandOperation.Subscribe:
                AcknowledgeMessageExt subscribe = new AcknowledgeMessageExt
                {
                    Body          = null,
                    CorrelationId = e.Message.MessageId,
                    MessageId     = Uuid.NewUuid(),
                    ClientId      = e.Message.ClientId
                };

                client.InvokeResult(e.InvokeId, subscribe);
                break;

            case CommandOperation.Unsubscribe:
                break;

            case CommandOperation.ClientPing:
                break;

            case CommandOperation.Logout:
                break;

            default:
                throw new NotSupportedException();
            }

            if (ClientCommandReceieved != null)
            {
                ClientCommandReceieved(sender, e);
            }
        }
Exemplo n.º 5
0
        async void OnClientAccepted(IAsyncResult ar)
        {
            TcpListener listener = ar.AsyncState as TcpListener;

            if (listener == null)
            {
                return;
            }

            try
            {
                TcpClient client = listener.EndAcceptTcpClient(ar);
                var       stream = await GetRtmpStreamAsync(client);

                // read c0+c1
                var c01 = await RtmpHandshake.ReadAsync(stream, true);

                var random      = new Random();
                var randomBytes = new byte[1528];
                random.NextBytes(randomBytes);

                // write s0+s1+s2
                var s01 = new RtmpHandshake()
                {
                    Version = 3,
                    Time    = (uint)Environment.TickCount,
                    Time2   = 0,
                    Random  = randomBytes
                };
                var s02 = s01.Clone();
                s02.Time2 = (uint)Environment.TickCount;
                await RtmpHandshake.WriteAsync(stream, s01, s02, true);

                // read c02
                var c02 = await RtmpHandshake.ReadAsync(stream, false);

                RtmpClient rtmpClient = new RtmpClient(_serverUri, _context, stream);
                rtmpClient.ServerMessageReceived += ServerMessageReceived;
                rtmpClient.ServerCommandReceived += ServerCommandReceived;
                _clients.Add(rtmpClient);
            }
            finally
            {
                listener.BeginAcceptTcpClient(OnClientAccepted, listener);
            }
        }
Exemplo n.º 6
0
            public Reader(RtmpClient owner, Stream stream, SerializationContext context, CancellationToken cancellationToken)
            {
                this.owner   = owner;
                this.stream  = stream;
                this.context = context;
                this.token   = cancellationToken;

                this.reset    = new AsyncAutoResetEvent();
                this.queue    = new ConcurrentQueue <Builder>();
                this.streams  = new KeyDictionary <int, ChunkStream.Snapshot>();
                this.messages = new KeyDictionary <(int, uint), Builder>();

                this.buffer    = new byte[DefaultBufferLength];
                this.available = 0;

                this.__readSingleFrameReader      = new AmfReader(context);
                this.__readFramesFromBufferReader = new AmfReader(context);
            }