nya / chat
基于swoole的laravel聊天插件
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/nya/chat
This package is not auto-updated.
Last update: 2025-09-28 11:03:28 UTC
README
依赖
- laravel
- swoole扩展
安装
composer require nya/chat
添加命令到app/console/Kernel.php
use Nya\Chat\Coo; ... protected $commands = [ Coo::class ];
配置文件config/nya.php
<?php return [ 'host' =>'0.0.0.0', 'port'=>2333, 'class' => 'App\Nya', 'pid_file' => storage_path('/logs/swoole.pid'), 'use_ssl' => false, 'ssl_key_file' => '/data/ssl/vgamer.im/vgamer.im.key', 'ssl_cert_file' => '/data/ssl/vgamer.im/vgamer.im_bundle.crt', 'message' => 'message_', 'open' => 'open', 'close' => 'close', 'type' => 'type', 'data' => 'data' ];
其中message以下都有默认
使用
新建示例类app/Nya.php
<?php namespace App; class Nya{ public function message_say($fd, $type){ $this->nya->push($fd, 'nya?'); } // 非必要 public function open($fd){ $this->nya->push($fd, 'link'); } public function close($fd){ // ... } }
开启聊天服务:php artisan nya start
stop可以停止
前台websocket连接端口2333
,返回 'link'
发送
{ "type": "say", "data": "nyanyanya" }
后台返回'nya?'