YouTubePHP Documentation

ResponseStream extends EventEmitter
in package
implements ReadableStreamInterface

FinalYes

The body of a server-streamed call, as a stream of parts.

Google serves a streamed method over plain HTTP as one JSON array whose elements arrive as the server produces them, possibly hours apart. This reads the array as it comes and emits each element, hydrated, as soon as it is complete:

$youtube->liveChatMessages->stream(liveChatId: $id, part: ['snippet', 'authorDetails'])
    ->then(function (ResponseStream $stream) {
        $stream->on('data', fn (LiveChatMessageListResponse $page) => ...);
        $stream->on('close', fn () => print("the server closed the stream\n"));
    });

Events, as for any readable stream: data with each element, error with an HttpException when the server reports one mid-stream or the body is not a JSON array, end when the array closes normally, and close after either.

Tags
since
1.0.0
author

Valithor Obsidion valithor@valgorithms.com

Table of Contents

Interfaces

ReadableStreamInterface

Properties

$closed  : bool
$depth  : int
Nesting depth inside the current element; 0 between elements.
$element  : string
The current element, so far.
$endpoint  : string
$escaped  : bool
$finished  : bool
Whether the array's closing `]` has been read.
$hydrate  : Closure
$inString  : bool
$source  : ReadableStreamInterface
$started  : bool
Whether the array's opening `[` has been read.

Methods

__construct()  : mixed
close()  : void
isReadable()  : bool
pause()  : void
pipe()  : WritableStreamInterface
resume()  : void
emitElement()  : void
end()  : void
fail()  : void
feed()  : void
Reads the next piece of the body, emitting every element it completes.

Properties

$depth

Nesting depth inside the current element; 0 between elements.

private int $depth = 0

$element

The current element, so far.

private string $element = ''

$finished

Whether the array's closing `]` has been read.

private bool $finished = false

$started

Whether the array's opening `[` has been read.

private bool $started = false

Methods

__construct()

public __construct(ReadableStreamInterface $source, callable(array<string, mixed>): mixed $hydrate[, string $endpoint = '' ]) : mixed
Parameters
$source : ReadableStreamInterface
$hydrate : callable(array<string, mixed>): mixed

Turns one decoded element into what data carries.

$endpoint : string = ''

The API method, for error messages.

pipe()

public pipe(WritableStreamInterface $dest[, array<string, mixed> $options = [] ]) : WritableStreamInterface
Parameters
$dest : WritableStreamInterface
$options : array<string, mixed> = []
Return values
WritableStreamInterface

feed()

Reads the next piece of the body, emitting every element it completes.

private feed(string $chunk) : void
Parameters
$chunk : string
On this page

Search results