Download the PHP package danilopolani/twitch-pub-sub without Composer
On this page you can find all versions of the php package danilopolani/twitch-pub-sub. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danilopolani/twitch-pub-sub
More information about danilopolani/twitch-pub-sub
Files in danilopolani/twitch-pub-sub
Package twitch-pub-sub
Short Description Integrate Twitch PubSub Web Sockets with Laravel
License MIT
Homepage https://github.com/danilopolani/twitch-pub-sub
Informations about the package twitch-pub-sub
(Laravel) Twitch PubSub
Laravel Twitch PubSub
Connect to Twitch PubSub (Web Sockets) in a Laravel application, dispatching Events whenever a message for a topic is received.
Built with Amphp with Web Socket.
Table of Contents
-
Getting Started
- Prerequisites
- Installation
-
Usage
- Topics & Events
- Reconnecting
- Callbacks
- Changelog
- Contributing
- Testing
- Security
- Credits
- License
Getting Started
The package supports Laravel 8.x
and PHP >= 7.4
.
Prerequisites
The PHP extension ext-pcntl
is required.
Installation
You can install the package via composer:
Usage
The package relies on one main function:
Argument | Description |
---|---|
array\|string $twitchAuthToken |
if string, it must be a valid Auth Token, otherwise it can be an associative array of authToken => topics[] |
array $topics |
an array of valid topics, needed only if $twitchAuthToken is a string |
Usually you would put the main function of the package inside an Artisan Command.
Now you can run your command from your terminal or a worker.
You should definitely setup Supervisor or a similar tool to keep your command alive and restart it if something goes wrong.
Finally, create a Listener to handle the incoming events.
Topics & Events
Topic | Event |
---|---|
channel-bits-events-v1.<channel_id> |
\Danilopolani\TwitchPubSub\Events\BitsDonated |
channel-bits-events-v2.<channel_id> |
\Danilopolani\TwitchPubSub\Events\BitsDonated |
channel-bits-badge-unlocks.<channel_id> |
\Danilopolani\TwitchPubSub\Events\BitsBadgeUnlocked |
channel-points-channel-v1.<channel_id> |
\Danilopolani\TwitchPubSub\Events\RewardRedeemed |
channel-subscribe-events-v1.<channel_id> |
\Danilopolani\TwitchPubSub\Events\SubscriptionReceived |
chat_moderator_actions.<user_id>.<channel_id> |
\Danilopolani\TwitchPubSub\Events\ModeratorActionSent |
whispers.<user_id> |
\Danilopolani\TwitchPubSub\Events\WhisperReceived |
Reconnection
When the connection is closed, the package itself will try to attempt a reconnection, but this would need a fresh access token, furthermore we strongly suggest you to handle the onClose
callback and exit your script. This, with a correct configuration of Supervisor, will restart the worker automatically reconnecting with a fresh token, if your code is written in that way. Below a simple example with a correct flow to demonstrate how it should work:
When exit(0)
will be executed, the script will stop, Supervisor will restart it - invoking handle
again - and refreshing the token reconnecting correctly.
Please see below for more information about callbacks.
Callbacks
The package provides several callbacks fired when something occurs. These callbacks must be put before the ::run()
method to let them work correctly.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Testing
Clone the repository and just run
With Docker (Windows):
With Docker (Linux/OSX):
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Danilo Polani
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of twitch-pub-sub with dependencies
ext-json Version *
ext-pcntl Version *
amphp/websocket-client Version ^1.0
illuminate/contracts Version ^8.0
illuminate/events Version ^8.0
illuminate/support Version ^8.0