PHPackages                             alexhackney/lara-nimble - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. alexhackney/lara-nimble

ActiveLibrary[API Development](/categories/api)

alexhackney/lara-nimble
=======================

A comprehensive Laravel package for seamless integration with Nimble Streamer API. Manage streams, DVR, sessions, restreaming, and more with a clean, expressive Laravel interface.

v0.1.2(7mo ago)21[2 PRs](https://github.com/alexhackney/lara-nimble/pulls)MITPHPPHP ^8.1|^8.2|^8.3CI passing

Since Oct 10Pushed 4mo agoCompare

[ Source](https://github.com/alexhackney/lara-nimble)[ Packagist](https://packagist.org/packages/alexhackney/lara-nimble)[ Docs](https://github.com/alexhackney/lara-nimble)[ RSS](/packages/alexhackney-lara-nimble/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (9)Versions (6)Used By (0)

Laravel Nimble Package
======================

[](#laravel-nimble-package)

A comprehensive Laravel package for seamless integration with Nimble Streamer API. Manage streams, DVR, sessions, restreaming, and more with a clean, expressive Laravel interface.

**Developed by Alex Hackney**

[![Latest Version on Packagist](https://camo.githubusercontent.com/686d47685f3376918abb3c3582aa9a42010b4261dedf6b4121679af9a53e178c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c65786861636b6e65792f6c6172612d6e696d626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexhackney/lara-nimble)[![Total Downloads](https://camo.githubusercontent.com/185ffc764d9e7c0415f7a9de7a71613ac55b6bbdeb531dba8f7539752ddf8580/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c65786861636b6e65792f6c6172612d6e696d626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexhackney/lara-nimble)[![License](https://camo.githubusercontent.com/de51a04e1aa10c2d64ede1a7f926451ec10dd204c24cee7fde82ef594c5cf74d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c65786861636b6e65792f6c6172612d6e696d626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexhackney/lara-nimble)![PHP Version](https://camo.githubusercontent.com/367cc13771e87ab74b5baf17a96c3ff0668b2b0113875cf5cda0bd4b2c2cf66c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532422d626c75653f7374796c653d666c61742d737175617265)![Laravel Version](https://camo.githubusercontent.com/c1e6b486529380b445b3384d0d5e4de8b0cb4ce9d894233d6a507b350f7182e4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d313025323025374325323031312d7265643f7374796c653d666c61742d737175617265)

Features
--------

[](#features)

- ✅ **Stream Management**: Create, configure, publish/unpublish, and monitor streams
- ✅ **Session Management**: Monitor and control active client sessions
- ✅ **DVR Control**: Manage archives, recordings, and playback
- ✅ **Restreaming**: Configure and manage restream targets
- ✅ **Stream Pulling**: Pull streams from external sources
- ✅ **Server Management**: Monitor server status, reload configuration, and sync
- ✅ **Cache Control**: Manage server cache and statistics
- 🚧 **Icecast Integration**: Manage Icecast server and inject metadata (coming soon)
- 🚧 **Playlist Management**: Create and control server playlists (coming soon)
- ✅ **Real-Time Statistics**: Get live stream stats including bandwidth, resolution, codecs, and more
- ✅ **Protocol Support**: RTMP, MPEG-TS, SRT, NDI, HLS, RTSP
- ✅ **Test-Driven Development**: Comprehensive test coverage with 127 tests
- ✅ **Type Safety**: Full PHP 8.1+ type hints and enums
- ✅ **Laravel Integration**: Service provider, facade, and configuration

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10 or 11
- Nimble Streamer with API enabled
- Composer

Installation
------------

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require alexhackney/lara-nimble
```

### Step 2: Publish Configuration

[](#step-2-publish-configuration)

```
php artisan vendor:publish --provider="AlexHackney\LaraNimble\NimbleServiceProvider" --tag="nimble-config"
```

This will create a `config/nimble.php` file in your Laravel application.

### Step 3: Configure Environment Variables

[](#step-3-configure-environment-variables)

**Minimal Configuration** - Add only what you need to your `.env` file:

```
# Required: Your Nimble server hostname
NIMBLE_HOST=your-nimble-server.com

# Optional: Only if your Nimble server requires authentication
NIMBLE_TOKEN=your-secret-token
```

That's it! The package uses sensible defaults for everything else.

**Optional Overrides** - Only add these if you need to change the defaults:

```
# Connection (defaults shown)
NIMBLE_PORT=8082              # Default Nimble management port
NIMBLE_PROTOCOL=http          # Use 'https' for production

# Timeouts (in seconds)
NIMBLE_TIMEOUT=30             # Request timeout
NIMBLE_CONNECT_TIMEOUT=10     # Connection timeout

# Retry Logic
NIMBLE_RETRY_TIMES=3          # Number of retry attempts
NIMBLE_RETRY_SLEEP=100        # Milliseconds between retries

# Debug/Logging
NIMBLE_LOG_REQUESTS=false     # Enable to log all requests
NIMBLE_LOG_CHANNEL=stack      # Laravel log channel

# SSL (for self-signed certs in development only)
NIMBLE_VERIFY_SSL=true        # Set to false to disable SSL verification
```

### Step 4: Enable Nimble API

[](#step-4-enable-nimble-api)

Ensure your Nimble server has the API enabled. Edit `/etc/nimble/nimble.conf`:

```
management_port = 8082;
management_token = your-secret-token;  # Optional but recommended

```

Restart Nimble after configuration changes:

```
sudo systemctl restart nimble
```

Usage
-----

[](#usage)

### Stream Management

[](#stream-management)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// List all streams
$streams = Nimble::streams()->list();
foreach ($streams as $stream) {
    echo "Stream: {$stream->name} ({$stream->status->value})\n";
    echo "Protocol: {$stream->protocol->value}\n";
    echo "Viewers: {$stream->viewers}\n";
}

// Get a specific stream
$stream = Nimble::streams()->get('stream-123');
echo "Status: {$stream->status->value}";

// Publish a stream
if (Nimble::streams()->publish('live', 'my-stream')) {
    echo "Stream published successfully!";
} else {
    echo "Failed to publish stream";
}

// Unpublish a stream
if (Nimble::streams()->unpublish('live', 'my-stream')) {
    echo "Stream unpublished successfully!";
}

// Get stream statistics
$stats = Nimble::streams()->statistics('stream-123');
echo "Bitrate: {$stats['bitrate']} kbps\n";
echo "Viewers: {$stats['viewers']}\n";
echo "Duration: {$stats['duration']} seconds\n";
```

### Real-Time Stream Statistics

[](#real-time-stream-statistics)

Get comprehensive, real-time statistics for active streams including bandwidth, resolution, codecs, protocol information, and publisher details. Perfect for monitoring dashboards and live stream health checks.

```
use AlexHackney\LaraNimble\Facades\Nimble;

// Get real-time stats for a specific stream by stream key
$stats = Nimble::streams()->liveStatus('my-stream-key');

if ($stats) {
    echo "Stream: {$stats->streamName}\n";
    echo "Application: {$stats->application}\n";
    echo "Protocol: {$stats->protocol}\n";
    echo "Resolution: {$stats->resolution}\n";
    echo "Video Codec: {$stats->videoCodec}\n";
    echo "Audio Codec: {$stats->audioCodec}\n";
    echo "Bandwidth: " . ($stats->bandwidth / 1000000) . " Mbps\n";
    echo "Bitrate: {$stats->bitrate} kbps\n";
    echo "FPS: {$stats->fps}\n";
    echo "Viewers: {$stats->viewers}\n";
    echo "Duration: {$stats->duration} seconds\n";
    echo "Publisher IP: {$stats->publisherIp}\n";
    echo "Publisher Port: {$stats->publisherPort}\n";
    echo "Source URL: {$stats->sourceUrl}\n";
    echo "Started: {$stats->startTime}\n";
} else {
    echo "Stream is not currently live\n";
}

// Get real-time stats for ALL currently active streams
$allStreams = Nimble::streams()->allLiveStreams();

foreach ($allStreams as $stream) {
    echo "Stream: {$stream->streamName}\n";
    echo "  Protocol: {$stream->protocol}\n";
    echo "  Resolution: {$stream->resolution}\n";
    echo "  Bandwidth: " . ($stream->bandwidth / 1000000) . " Mbps\n";
    echo "  Viewers: {$stream->viewers}\n";
    echo "\n";
}

// Example: Build a real-time monitoring dashboard
$liveStreams = Nimble::streams()->allLiveStreams();

$dashboard = $liveStreams->map(function ($stream) {
    return [
        'name' => $stream->streamName,
        'app' => $stream->application,
        'status' => 'live',
        'protocol' => $stream->protocol,
        'quality' => $stream->resolution,
        'codecs' => [
            'video' => $stream->videoCodec,
            'audio' => $stream->audioCodec,
        ],
        'network' => [
            'bandwidth_mbps' => round($stream->bandwidth / 1000000, 2),
            'bitrate_kbps' => $stream->bitrate,
            'publisher_ip' => $stream->publisherIp,
        ],
        'metrics' => [
            'viewers' => $stream->viewers,
            'fps' => $stream->fps,
            'uptime_seconds' => $stream->duration,
        ],
    ];
});

return response()->json(['streams' => $dashboard]);
```

**Use Cases for Real-Time Statistics:**

- **Live Monitoring**: Display current stream health in admin dashboards
- **Quality Alerts**: Detect bitrate drops or resolution changes
- **Viewer Analytics**: Track real-time viewer counts
- **Stream Discovery**: List all currently active streams
- **Protocol Monitoring**: Track which protocols are being used (RTMP, SRT, NDI)
- **Network Analysis**: Monitor bandwidth usage and publisher connections

### Session Management

[](#session-management)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// List all active sessions
$sessions = Nimble::sessions()->list();
foreach ($sessions as $session) {
    echo "Session: {$session->id}\n";
    echo "Client IP: {$session->clientIp}\n";
    echo "Protocol: {$session->protocol}\n";
    echo "Duration: {$session->duration} seconds\n";
}

// Get a specific session
$session = Nimble::sessions()->get('session-456');
echo "Stream: {$session->streamId}";

// Terminate a session
if (Nimble::sessions()->terminate('session-456')) {
    echo "Session terminated successfully!";
}

// Get session statistics
$stats = Nimble::sessions()->statistics('session-456');
echo "Bytes transferred: {$stats['bytes_transferred']}\n";
```

### DVR Management

[](#dvr-management)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// List all DVR archives
$archives = Nimble::dvr()->listArchives();
foreach ($archives as $archive) {
    echo "Archive: {$archive->filename}\n";
    echo "Stream: {$archive->streamId}\n";
    echo "Size: {$archive->size} bytes\n";
    echo "Duration: {$archive->duration} seconds\n";
}

// Get a specific archive
$archive = Nimble::dvr()->getArchive('archive-123');
echo "Path: {$archive->path}";

// Delete an archive
if (Nimble::dvr()->deleteArchive('archive-123')) {
    echo "Archive deleted successfully!";
}

// Configure DVR settings
if (Nimble::dvr()->configure([
    'stream' => 'stream1',
    'enabled' => true,
    'path' => '/var/dvr/stream1',
    'max_duration' => 3600,
])) {
    echo "DVR configured successfully!";
}
```

### Restream Management

[](#restream-management)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// List all restream targets
$restreams = Nimble::restream()->list();
foreach ($restreams as $restream) {
    echo "Target: {$restream->targetUrl}\n";
    echo "Protocol: {$restream->protocol}\n";
    echo "Status: {$restream->status}\n";
    echo "Enabled: " . ($restream->enabled ? 'Yes' : 'No') . "\n";
}

// Get a specific restream target
$restream = Nimble::restream()->get('restream-123');
echo "Target URL: {$restream->targetUrl}";

// Add a new restream target
if (Nimble::restream()->add('stream-123', [
    'target_url' => 'rtmp://live.youtube.com/stream/key123',
    'protocol' => 'rtmp',
    'enabled' => true,
])) {
    echo "Restream target added successfully!";
}

// Update a restream target
if (Nimble::restream()->update('restream-123', [
    'enabled' => false,
])) {
    echo "Restream target updated!";
}

// Delete a restream target
if (Nimble::restream()->delete('restream-123')) {
    echo "Restream target deleted!";
}
```

### Stream Pulling

[](#stream-pulling)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// List all pull configurations
$pulls = Nimble::pull()->list();
foreach ($pulls as $pull) {
    echo "Source: {$pull->sourceUrl}\n";
    echo "Local: {$pull->localApp}/{$pull->localStream}\n";
    echo "Protocol: {$pull->protocol}\n";
    echo "Status: {$pull->status}\n";
}

// Get a specific pull configuration
$pull = Nimble::pull()->get('pull-123');
echo "Source URL: {$pull->sourceUrl}";

// Add a new pull configuration
if (Nimble::pull()->add([
    'source_url' => 'rtmp://source.com/live/stream',
    'local_app' => 'live',
    'local_stream' => 'pulled-stream',
    'protocol' => 'rtmp',
    'enabled' => true,
])) {
    echo "Pull configuration added successfully!";
}

// Update a pull configuration
if (Nimble::pull()->update('pull-123', [
    'enabled' => false,
])) {
    echo "Pull configuration updated!";
}

// Delete a pull configuration
if (Nimble::pull()->delete('pull-123')) {
    echo "Pull configuration deleted!";
}

// Get pull stream status
$status = Nimble::pull()->status('pull-123');
echo "Uptime: {$status['uptime']} seconds\n";
echo "Bitrate: {$status['bitrate']} kbps\n";
```

### Server Management

[](#server-management)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// Get server status
$status = Nimble::server()->status();
echo "Status: {$status->status}\n";
echo "Version: {$status->version}\n";
echo "Uptime: {$status->uptime} seconds\n";
echo "Connections: {$status->connections}\n";
echo "Bandwidth In: {$status->bandwidth['in']} bytes\n";
echo "Bandwidth Out: {$status->bandwidth['out']} bytes\n";

// Reload server configuration
if (Nimble::server()->reload()) {
    echo "Server configuration reloaded successfully!";
}

// Sync with WMSPanel
if (Nimble::server()->sync()) {
    echo "Synchronization completed!";
}
```

### Cache Management

[](#cache-management)

```
use AlexHackney\LaraNimble\Facades\Nimble;

// Clear all cache
if (Nimble::cache()->clear()) {
    echo "Cache cleared successfully!";
}

// Clear specific cache type
if (Nimble::cache()->clear('hls')) {
    echo "HLS cache cleared!";
}

// Get cache statistics
$stats = Nimble::cache()->statistics();
echo "Total Size: {$stats['total_size']} bytes\n";
echo "Items: {$stats['items']}\n";
echo "Hit Rate: {$stats['hit_rate']}\n";
echo "Miss Rate: {$stats['miss_rate']}\n";

// Configure cache settings
if (Nimble::cache()->configure([
    'enabled' => true,
    'max_size' => 2147483648,
    'ttl' => 3600,
])) {
    echo "Cache configured successfully!";
}
```

### Using in Controllers

[](#using-in-controllers)

```
