rajibul/lolipop-sfu

Official Laravel SDK for Lolipop.live WebRTC SFU & PK Battle Engine

Maintainers

Package info

github.com/Rajibul-16103404/lolipop-sfu-laravel

pkg:composer/rajibul/lolipop-sfu

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-27 23:55 UTC

This package is auto-updated.

Last update: 2026-08-28 00:07:34 UTC


README

Latest Version on Packagist Total Downloads Software License

Official Laravel SDK for integrating with the high-performance Go WebRTC SFU (Selective Forwarding Unit), Coturn STUN/TURN ephemeral token builder, and Dual-Host PK Battle Engine.

๐Ÿš€ Features

  • โšก Auto-Discovery: Seamless Laravel 10 / 11 Service Provider & Lolipop Facade auto-discovery.
  • ๐Ÿ”‘ Coturn STUN/TURN Credentials: Generates ephemeral, time-limited HMAC-SHA1 tokens for symmetric NAT traversal.
  • โš”๏ธ Dual-Host PK Battle Engine: Initiate, synchronize, and track real-time dual-room PK battles.
  • ๐ŸŽ Real-Time Gift Pipeline: Credit in-stream gifts directly into PK battle scoring loops.
  • ๐Ÿ’ฌ In-Stream Messaging: Broadcast administrative notices and chat events to live rooms.
  • ๐Ÿ›ก๏ธ Robust Error Handling: Domain-specific LolipopException with full HTTP status codes and error payload inspectability.

๐Ÿ“ฆ Installation

Install via Composer:

composer require rajibul/lolipop-sfu

Publish the package configuration:

php artisan vendor:publish --tag="lolipop-config"

โš™๏ธ Configuration

Add the following environment variables to your Laravel .env file:

# SFU Server HTTP API Base URL
LOLIPOP_SERVER_URL=http://YOUR_VPS_IP:8080

# SFU WebSocket Signaling URL
LOLIPOP_WS_URL=ws://YOUR_VPS_IP:8080/ws

# Server-to-Server Secret (Optional)
LOLIPOP_API_SECRET=your_sfu_secret_key

# Coturn STUN & TURN Settings
LOLIPOP_STUN_URL=stun:YOUR_VPS_IP:3478
LOLIPOP_TURN_URL=turn:YOUR_VPS_IP:3478
LOLIPOP_TURN_SECRET=sfu_super_secret_key_2026
LOLIPOP_TURN_TTL=86400

๐Ÿ’ก Usage Examples

1. Generating Room Join Payload for Web/Mobile Clients

When a user or host enters a live room, call generateJoinPayload in your controller to supply the client with WebSocket endpoints and signed ICE/TURN credentials:

use Rajibul\LolipopSfu\Facades\Lolipop;
use Rajibul\LolipopSfu\Enums\Role;

class LivestreamController extends Controller
{
    public function joinRoom(Request $request, string $roomId)
    {
        $user = $request->user();
        $isHost = $user->isHostOf($roomId);

        $payload = Lolipop::generateJoinPayload(
            roomId: $roomId,
            peerId: "user_{$user->id}",
            role: $isHost ? Role::HOST : Role::VIEWER,
            meta: [
                'name'   => $user->name,
                'avatar' => $user->avatar_url,
            ]
        );

        return response()->json([
            'status' => 'success',
            'data'   => $payload,
        ]);
    }
}

2. Starting a Dual-Host PK Battle

Initiate a cross-room PK battle between Host A in Room A and Host B in Room B:

use Rajibul\LolipopSfu\Facades\Lolipop;

class PKBattleController extends Controller
{
    public function startBattle(Request $request)
    {
        $battle = Lolipop::startBattle(
            hostA: 'host_101',
            roomA: 'room_101',
            hostB: 'host_202',
            roomB: 'room_202',
            durationSec: 180,    // 3-minute battle
            punishmentSec: 60    // 1-minute punishment
        );

        return response()->json($battle);
    }
}

3. Sending a Live Gift (Auto-Credits PK Battle Score)

Send gifts inside a live room. If the room is in an active PK battle, the points are instantly applied to the receiver host's score and broadcast via WebRTC DataChannels:

use Rajibul\LolipopSfu\Facades\Lolipop;

class GiftController extends Controller
{
    public function send(Request $request, string $roomId)
    {
        $user = $request->user();

        $result = Lolipop::sendGift(
            roomId: $roomId,
            senderId: "user_{$user->id}",
            senderName: $user->name,
            giftId: 'rocket_99',
            giftName: 'Space Rocket',
            giftValue: 100, // 100 points
            receiverHostId: 'host_101'
        );

        return response()->json([
            'status' => 'success',
            'data'   => $result,
        ]);
    }
}

4. Broadcasting In-Stream System Notices

use Rajibul\LolipopSfu\Facades\Lolipop;

Lolipop::broadcastMessage(
    roomId: 'room_101',
    senderId: 'system',
    senderName: 'Admin',
    message: 'Stream rule notice: Be respectful in the live chat!',
    level: 'warning'
);

5. Checking SFU Server Health

use Rajibul\LolipopSfu\Facades\Lolipop;

if (Lolipop::getHealth()) {
    // SFU Media Server is healthy and accepting connections
}

๐Ÿงช Testing

composer test

๐Ÿ“„ License

The MIT License (MIT). Please see LICENSE.md for more information.