Returns a stream object if live.

@param $channel

@return json
510451
public function streamsChannel($channel)
    {
        $response = $this->client->get(config('twitch-api.api_url') . '/kraken/streams/' . $channel);

        return $response->json();
    }
477702
public function addChannel(Channel $channel): self
    {
        $channelName = $channel->getName();

        if (!isset($this->channels[$channelName])) {
            $this->channels[$channelName] = $channel;
        }

        return $this;
    }
7125
public static function fromJson(string $json): ChannelInformation
    {
        $response = json_decode($json, true);

        if (!is_array($response)) {
            throw new NchanException('Unable to parse JSON response: ' . json_last_error_msg());
        }

        // Check if required keys exists in $response.
        if (count(array_diff_key(array_flip(self::REQUIRED_JSON_KEYS), $response)) !== 0) {
            throw new  NchanException(
                sprintf(
                    'Unable to parse JSON response: Keys "%s" are required. Keys "%s" exists.',
                    implode('", "', self::REQUIRED_JSON_KEYS),
                    implode('", "', array_keys($response))
                )
            );
        }

        return new self(
            (int)$response['messages'],
            (int)$response['requested'],
            (int)$response['subscribers'],
            (string)$response['last_message_id']
        );
    }
911158
public function getChannel(string $channelName): SocketChannelP
    {
        $persistent = $this->protocol->client->getParam(Client::PARAM_USE_PERSISTENT_CONNECTION);
        try {
            $streamSocket = new StreamSocket(
                $this->ssl === 'ssl://' ? StreamSocket::TRANSPORT_SSL : StreamSocket::TRANSPORT_TCP,
                $this->host.':'.$channelName,
                null,
                [],
                $persistent
            );
            $socket = $streamSocket->getSocket();
        } catch (\Throwable $e) {
            $logger = $this->protocol->getClient()->getLogger();
            $logger->critical(sprintf(
                '[soluble-japha] %s (%s)',
                $e->getMessage(),
                __METHOD__
            ));
            throw new ConnectionException($e->getMessage(), $e->getCode());
        }
        stream_set_timeout($socket, -1);

        return new SocketChannelP($socket, $this->host, $this->java_recv_size, $this->java_send_size);
    }
1007621
public function getRaw($stream = false)
    {
        $this->setTokenValue($this->getEntityIdName(), $this->getId());
        $uri = $this->getURI('/raw');
        $x   = $this->getSDK()->get($uri, array(), array('accept'=>'audio/*',
            'content_type'=>'audio/*', 'Range'=> 'bytes'));

        header('Content-Type: '.$x->getHeader('Content-Type')[0]);
        header('content-length: '.$x->getHeader('content-length')[0]);
        header('Accept-Ranges: '.$x->getHeader('Accept-Ranges')[0]);

        if (!$stream) {
            header('Content-Disposition: '.$x->getHeader('Content-Disposition')[0]);
        }
        echo $x->getBody();
    }
866787
private function _UnaryStreamCallFactory($channel)
    {
        if (is_a($channel, 'Grpc\Internal\InterceptorChannel')) {
            return function ($method,
                             $argument,
                             $deserialize,
                             array $metadata = [],
                             array $options = []) use ($channel) {
                return $channel->getInterceptor()->interceptUnaryStream(
                    $method,
                    $argument,
                    $deserialize,
                    $metadata,
                    $options,
                    $this->_UnaryStreamCallFactory($channel->getNext())
                );
            };
        }
        return $this->_GrpcUnaryStream($channel);
    }
777729
public function channelStatus($channel = '')
    {
        $cmd = implode(' ', array('CHANNEL', 'STATUS'));
        if ($channel !== '') {
            $cmd .= ' "' . $channel . '"';
        }
        $result = $this->send($cmd);
        return intval($result->getResult());
    }
686377
protected static function getStream($response)
    {
        $stream = 'php://memory';
        $body = $response->body();
        if (is_string($body) && strlen($body)) {
            $stream = new Stream('php://memory', 'wb');
            $stream->write($body);

            return $stream;
        }
        if (is_callable($body)) {
            $stream = new CallbackStream($body);

            return $stream;
        }
        $file = $response->getFile();
        if ($file) {
            $stream = new Stream($file->path, 'rb');

            return $stream;
        }

        return $stream;
    }
141496
public function subscribe($channel, callable $handler)
    {
        $subscription = $this->getSubscriptionForChannel($channel);

        $isSubscriptionLoopActive = true;
        $isPauseEnabled = $this->returnImmediately && ($this->returnImmediatelyPause > 0);

        while ($isSubscriptionLoopActive) {
            $messages = $subscription->pull([
                'grpcOptions' => [
                    'timeoutMillis' => null,
                ],
                'maxMessages' => $this->maxMessages,
                'returnImmediately' => $this->returnImmediately,
            ]);
            if ($isPauseEnabled && empty($messages)) {
                usleep($this->returnImmediatelyPause);
                continue;
            }
            foreach ($messages as $message) {
                /** @var Message $message */
                $payload = Utils::unserializeMessagePayload($message->data());

                if ($payload === 'unsubscribe') {
                    $isSubscriptionLoopActive = false;
                } else {
                    call_user_func($handler, $payload);
                }

                $subscription->acknowledge($message);
            }
        }
    }
1115137
public function resetChannel($channel)
    {
        $op = $this->sendResetChannelOperation($channel);

        // waiting for reset operation finishes
        $op = $this->awaitOperation($op);

        // true if succeeded
        return $op->getState() == OperationState::Succeeded;
    }
898805
public function buildChannel($channel, $max = 3, $refreshes = 'no')
    {
        $channels = $this->validateChannel($channel);

        $url = $this->getURL('channel');

        $headers = [
            'body' => [
                'private'   => $this->privateKey,
                'channel'   => $channels,
                'max'       => $max,
                'refreshes' => $refreshes
            ]
        ];

        $response = $this->processRequest($url, $headers, 'post');

        return $response;
    }
249432
public function channel($channel)
    {
        $channel = $this->validateChannel($channel, false);

        $url = $this->getURL('channel');

        $headers = [
            'body' => [
                'private' => $this->privateKey,
                'channel' => $channel
            ]
        ];

        $response = $this->processRequest($url, $headers, 'get');

        return $response;
    }
841400
public function createChannel(Channel $channel)
    {
        $op = $this->sendCreateChannelOperation($channel);

        // waiting for create operation finishes
        $op = $this->awaitOperation($op);

        if ($op->getState() != OperationState::Succeeded) {
            return null;
        }

        // get and return the createChannel
        return $this->getChannel($op->getTargetEntityId());
    }
941616
public function channelFollows($channel, $options = [])
    {
        $availableOptions = ['limit', 'offset', 'direction'];

        return $this->sendRequest('GET', 'channels/'.$channel.'/follows', false, $options, $availableOptions);
    }
980969
public function channelsVideo($channel, $options = null)
    {
        $availableOptions = ['limit', 'offset', 'broadcasts', 'hls'];

        $query = [];

        //  Filter the available options
        foreach ($availableOptions as $option) {

            if (isset($options[ $option ])) {

                $query[ $option ] = $options[ $option ];
            }
        }

        $parameters = $this->getDefaultHeaders();
        $parameters[ 'query' ] = $query;

        $response = $this->client->get('/kraken/channels/' . $channel . '/videos', $parameters);

        return $response->json();
    }
137103
public function all($channel = '')
    {
        $channel = $channel ?: static::$defaultChannel;
        return $this->channelOrFail($channel)->all($channel);
    }
1172942
public function channel($channel = null)
    {
        // If the given driver has not been created before, we will create the instances
        // here and cache it so we can return it next time very quickly. If there is
        // already a driver created by this name, we'll just return that instance.
        if (!$this->hasChannel($channel)) {
            $this->addChannel($channel, $this->createChannel($channel));
        }

        return $this->getChannel($channel);
    }