static RtmpEvent ReadCommandOrData(AmfReader r, Command command)
        {
            var methodName = (string)r.ReadAmf0Item();

            command.InvokeId = Convert.ToInt32(r.ReadAmf0Item());
            command.ConnectionParameters = r.ReadAmf0Item();

            var parameters = new List<object>();
            while (r.DataAvailable)
                parameters.Add(r.ReadAmf0Item());

            command.MethodCall = new Method(methodName, parameters.ToArray());
            return command;
        }
        Task<object> QueueCommandAsTask(Command command, int streamId, int messageStreamId)
        {
            if (IsDisconnected)
                return CreateExceptedTask(new ClientDisconnectedException("disconnected"));

            var task = callbackManager.Create(command.InvokeId);
            writer.Queue(command, streamId, messageStreamId);
            return task;
        }