Installation:
composer require darkanakin41/stream-bundle darkanakin41/core-bundle
(Note: The core-bundle dependency must also be installed as it’s required.)
Configuration:
php bin/console darkanakin41:core:install
config/packages/darkanakin41_stream.yaml:
darkanakin41_stream:
platforms:
twitch:
enabled: true
api_key: '%env(TWITCH_API_KEY)%'
First Use Case:
// Example: Create a migration to seed enabled platforms
Schema::create('stream_platforms', function (Blueprint $table) {
$table->id();
$table->string('name'); // e.g., 'twitch'
$table->boolean('enabled')->default(true);
$table->timestamps();
});
php bin/console darkanakin41:stream:retrieve
Stream Retrieval:
retrieve command to fetch streams from enabled platforms (e.g., Twitch) based on configured categories.* * * * * cd /path-to-project && php artisan darkanakin41:stream:retrieve).Stream Refresh:
darkanakin41:stream:refresh to update existing streams (e.g., check if a stream is still live).Platform-Specific Logic:
StreamPlatformInterface and registering it in the bundle’s configuration.// src/Service/TwitchStreamService.php
class TwitchStreamService implements StreamPlatformInterface {
public function fetchStreams(): array {
// Use Twitch API to fetch live streams
return $this->twitchClient->getLiveStreams();
}
}
Database Integration:
$liveStreams = Stream::where('is_live', true)->get();
StreamCreated, StreamEnded) to trigger actions (e.g., notifications).Event Handling:
StreamEnded events to clean up dead streams automatically:
// Event subscriber
public function onStreamEnded(StreamEnded $event) {
$event->getStream()->delete(); // Or mark as inactive
}
Dependency on Core Bundle:
darkanakin41/core-bundle will cause runtime errors. Always install both packages together.API Key Management:
.env:
TWITCH_API_KEY=your_api_key_here
config/packages/darkanakin41_stream.yaml:
api_key: '%env(TWITCH_API_KEY)%'
Rate Limiting:
GuzzleHttp with retry logic:
$client = new Client([
'timeout' => 10,
'delay' => 200, // 200ms delay between requests
]);
Database Schema Assumptions:
stream_platforms table exists. If migrating an existing project, ensure compatibility or extend the schema:
// Example: Custom migration for platform-specific fields
Schema::table('stream_platforms', function (Blueprint $table) {
$table->string('category')->nullable();
});
Event Dispatching:
StreamEnded may not fire if the refresh command fails silently. Add logging:
try {
$this->refreshStreams();
} catch (\Exception $e) {
\Log::error("Stream refresh failed: " . $e->getMessage());
}
Custom Platforms:
YouTubeStreamService and register it in the bundle’s config:
darkanakin41_stream:
platforms:
youtube:
enabled: true
service: App\Service\YouTubeStreamService
Testing:
$this->mock(TwitchClient::class, function ($mock) {
$mock->shouldReceive('getLiveStreams')->andReturn([/* mock data */]);
});
Debugging:
php bin/console darkanakin41:stream:retrieve --verbose
Performance:
Stream::chunk(100, function ($streams) {
foreach ($streams as $stream) {
$stream->refresh();
}
});
Extension Points:
services.yaml:
services:
App\Model\Stream:
tags: ['darkanakin41.stream.model']
How can I help you explore Laravel packages today?