承接 baraadark/laravelsocket 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

baraadark/laravelsocket

Composer 安装命令:

composer require baraadark/laravelsocket

包简介

BaraaDark Laravel Socket is a powerful Laravel package that simplifies the integration of real-time WebSocket functionality into your Laravel projects. With this package, you can effortlessly create and manage a Node.js WebSocket server inside your Laravel application and utilize the Elephant.io lib

README 文档

README

BaraaDark Laravel Socket is a powerful Laravel package that simplifies the integration of real-time WebSocket functionality into your Laravel projects. With this package, you can effortlessly create and manage a Node.js WebSocket server inside your Laravel application and utilize the Elephant.io library for seamless communication with Socket.io in PHP

BaraaDark/LaravelSocket Package

Installation

You can install the LaravelSocket package using Composer by running the following command:

composer require baraadark/laravelsocket:dev-master

After installation, configure the server settings by running:

php artisan socket:config

Enter the host and port for Socket event listening.

Next, initialize the Node.js server by running:

php artisan socket:init

This will set up the necessary Node.js dependencies.

Define Socket.IO Events To define Socket.IO events, you need to publish the events.php route file by running:

php artisan vendor:publish --tag=socket-route

Edit the events.php file and define your events logic as Laravel routes. Each route you define here will correspond to two Socket.IO events:

A 'fetch' event for fetching data. A 'load' event for loading data. The event names will match the route name with 'fetch/' or 'load/' prefixed to it. For example:

Route::get('students/index', [SocketController::class, 'index']);

'fetch/students/index' event for fetching data. 'load/students/index' event for loading data. Ensure that your route action returns JSON data using the response()->json() method, as this is required for Socket.IO communication. Example:

return response()->json([
    'data' => $your_data,
    // ... other JSON data
]);

Update Socket.IO Events To update your Socket.IO events based on your routes, run:

php artisan socket:events

This command will generate the necessary JavaScript code to handle the Socket.IO events.

Using LaravelSocket Facade You can use the LaravelSocket Facade object to emit events from anywhere in your code. For example, you can emit events in an observer:

use BaraaDark\LaravelSocket\Facades\LaravelSocket;

class StudentObserver
{
    // ...

    private function reloadData(): void
    {
        LaravelSocket::emit('students/index');
    }

    public function created(Student $student): void
    {
        self::reloadData();
    }

    // ...

    public function forceDeleted(Student $student): void
    {
        self::reloadData();
    }
}

You can also pass data to the emit function:

LaravelSocket::emit('your/route/endpoint', $yourDataAsArray);

This allows you to send specific data to clients when emitting events.

Feel free to customize and expand upon this package to suit your application's real-time communication needs.

baraadark/laravelsocket 适用场景与选型建议

baraadark/laravelsocket 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 baraadark/laravelsocket 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 baraadark/laravelsocket 我们能提供哪些服务?
定制开发 / 二次开发

基于 baraadark/laravelsocket 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 50
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-10-01