livewave/laravel-sdk
Composer 安装命令:
composer require livewave/laravel-sdk
包简介
Official Laravel SDK for LiveWave real-time events and notifications platform
README 文档
README
Optional Laravel SDK for LiveWave - A self-hosted real-time WebSocket server for Laravel applications.
Note: For basic broadcasting, you don't need this SDK! Just use standard Laravel Pusher configuration pointing to your LiveWave server. This SDK is only needed for advanced features like API management, webhooks, and notifications.
Architecture
LiveWave works like Laravel Reverb's multi-app feature - your LiveWave server acts as a central WebSocket server that multiple Laravel applications can connect to:
┌─────────────────────────────────────────────────────────┐
│ LiveWave Server (Reverb) │
│ Central WebSocket Server for All Apps │
├─────────────────────────────────────────────────────────┤
│ Team 1 (E-commerce) │ Team 2 (CRM) │ Team 3 │
│ app_id: xxx │ app_id: yyy │ app_id: zzz │
│ app_key │ app_key │ app_key │
│ app_secret │ app_secret │ app_secret │
└─────────────────────────────────────────────────────────┘
▲ ▲ ▲
│ │ │
┌────┴───┐ ┌────┴───┐ ┌────┴───┐
│ App 1 │ │ App 2 │ │ App 3 │
│ Laravel│ │ Laravel│ │ Laravel│
│(Pusher)│ │(Pusher)│ │(Pusher)│
└────────┘ └────────┘ └────────┘
Each Laravel application connects to the same LiveWave server but with its own credentials (from their Team dashboard), keeping channels isolated.
Basic Usage (No SDK Required)
Step 1: Get Credentials from LiveWave Dashboard
When you create a Team in LiveWave, you get:
app_idapp_keyapp_secret
Step 2: Configure Your Laravel App
.env file:
BROADCAST_CONNECTION=pusher PUSHER_APP_ID=your-app-id-from-livewave PUSHER_APP_KEY=your-app-key-from-livewave PUSHER_APP_SECRET=your-app-secret-from-livewave PUSHER_HOST=your-livewave-server.com PUSHER_PORT=8080 PUSHER_SCHEME=http
config/broadcasting.php:
'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ 'host' => env('PUSHER_HOST'), 'port' => env('PUSHER_PORT', 8080), 'scheme' => env('PUSHER_SCHEME', 'http'), 'useTLS' => false, ], ],
Step 3: Frontend (Laravel Echo)
npm install laravel-echo pusher-js
import Echo from "laravel-echo"; import Pusher from "pusher-js"; window.Pusher = Pusher; window.Echo = new Echo({ broadcaster: "pusher", key: import.meta.env.VITE_PUSHER_APP_KEY, wsHost: import.meta.env.VITE_PUSHER_HOST, wsPort: import.meta.env.VITE_PUSHER_PORT, forceTLS: false, disableStats: true, enabledTransports: ["ws", "wss"], });
.env:
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" VITE_PUSHER_HOST="${PUSHER_HOST}" VITE_PUSHER_PORT="${PUSHER_PORT}"
Step 4: Broadcast Events
// app/Events/MessageSent.php use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class MessageSent implements ShouldBroadcast { use InteractsWithSockets; public function __construct(public string $message) {} public function broadcastOn(): Channel { return new Channel('chat'); } } // Dispatch event(new MessageSent('Hello World!'));
That's it! No SDK needed for basic broadcasting. ✅
When to Use This SDK
This SDK is optional and only needed for:
- API Management - Create/manage channels, API keys via code
- Webhooks - Receive events from LiveWave (channel created, member joined, etc.)
- Notifications - Send rich notifications via API
- Convenience - Helper methods and facade for common operations
Installation (For Advanced Features)
composer require livewave/laravel-sdk
Then run the installation command:
php artisan livewave:install
This will:
- Publish the configuration file
- Update your
.envwith LiveWave credentials - Configure the broadcasting driver
SDK Configuration
Environment Variables
Add these to your .env file:
LIVEWAVE_APP_ID=your-app-id LIVEWAVE_APP_KEY=your-app-key LIVEWAVE_APP_SECRET=your-app-secret LIVEWAVE_HOST=your-livewave-server.com LIVEWAVE_PORT=8080
For production with SSL:
LIVEWAVE_HOST=livewave.yourapp.com LIVEWAVE_PORT=443 LIVEWAVE_USE_TLS=true LIVEWAVE_SCHEME=https LIVEWAVE_WS_SCHEME=wss
Broadcasting Configuration
Add the livewave connection to config/broadcasting.php:
'connections' => [ 'livewave' => [ 'driver' => 'livewave', ], // ... other connections ],
SDK Usage Examples
Direct Broadcasting (Using Facade)
use LiveWave\Facades\LiveWave; // Broadcast to a public channel LiveWave::broadcast('news', 'article.published', [ 'title' => 'Breaking News', 'content' => 'Something happened...', ]); // Broadcast to a private channel LiveWave::broadcastToPrivate('user.123', 'notification', [ 'message' => 'You have a new message', ]); // Broadcast to multiple channels LiveWave::broadcastToMany(['channel1', 'channel2'], 'event.name', $data);
Channel Information
// Get channel info $info = LiveWave::getChannelInfo('presence-room.1', ['user_count', 'subscription_count']); // Get all channels $channels = LiveWave::getChannels('presence-', ['user_count']); // Get presence channel users $users = LiveWave::getPresenceUsers('presence-room.1');
Webhooks
Create a route for webhooks:
Route::post('/webhooks/livewave', [WebhookController::class, 'handle']) ->middleware('livewave.webhook');
The livewave.webhook middleware automatically verifies the webhook signature.
class WebhookController extends Controller { public function handle(Request $request) { $event = $request->input('event'); $data = $request->input('data'); match($event) { 'channel.created' => $this->handleChannelCreated($data), 'channel.deleted' => $this->handleChannelDeleted($data), 'member.added' => $this->handleMemberAdded($data), 'member.removed' => $this->handleMemberRemoved($data), default => null, }; return response()->json(['status' => 'ok']); } }
Private & Presence Channels
Private Channels
use Illuminate\Broadcasting\PrivateChannel; public function broadcastOn(): PrivateChannel { return new PrivateChannel('user.' . $this->userId); }
Define authorization in routes/channels.php:
Broadcast::channel('user.{id}', function ($user, $id) { return (int) $user->id === (int) $id; });
Presence Channels
use Illuminate\Broadcasting\PresenceChannel; public function broadcastOn(): PresenceChannel { return new PresenceChannel('room.' . $this->roomId); }
Authorization with user info:
Broadcast::channel('room.{roomId}', function ($user, $roomId) { if ($user->canJoinRoom($roomId)) { return [ 'id' => $user->id, 'name' => $user->name, 'avatar' => $user->avatar_url, ]; } });
Frontend Listening
// Public channel Echo.channel("chat").listen(".message.sent", (e) => { console.log("New message:", e.message); }); // Private channel Echo.private("user." + userId).listen(".notification", (e) => { console.log("Notification:", e); }); // Presence channel Echo.join("room." + roomId) .here((users) => { console.log("Users in room:", users); }) .joining((user) => { console.log("User joined:", user); }) .leaving((user) => { console.log("User left:", user); }) .listen(".message", (e) => { console.log("Message:", e); });
Testing
Use the LiveWaveFake for testing:
use LiveWave\Testing\LiveWaveFake; use LiveWave\Facades\LiveWave; public function test_message_is_broadcast() { LiveWave::fake(); // Perform action that broadcasts $this->post('/messages', ['content' => 'Hello']); // Assert broadcast was called LiveWave::assertBroadcast('chat', 'message.sent', function ($data) { return $data['content'] === 'Hello'; }); }
Configuration Options
| Option | Description | Default |
|---|---|---|
app_id |
Your LiveWave application ID | - |
app_key |
Public key for Echo | - |
app_secret |
Secret for signing | - |
server.host |
LiveWave server host | 127.0.0.1 |
server.port |
LiveWave server port | 8080 |
server.scheme |
HTTP scheme | http |
options.use_tls |
Enable TLS | false |
options.verify_ssl |
Verify SSL certificates | true |
Changelog
See CHANGELOG.md for recent changes.
License
MIT License. See LICENSE for details.
livewave/laravel-sdk 适用场景与选型建议
livewave/laravel-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「websocket」 「notifications」 「laravel」 「pusher」 「realtime」 「Broadcasting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 livewave/laravel-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 livewave/laravel-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 livewave/laravel-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Captures outgoing SMS notifications
WebSocket view engine
Alfabank REST API integration
Laravel package to send notifications when some exceptions are thrown.
This is a PHP Framework base on Swoole
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-13