fix:更新已知bug,优化代码
This commit is contained in:
21
vendor/webman/gateway-worker/LICENSE
vendored
Normal file
21
vendor/webman/gateway-worker/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 webman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
2
vendor/webman/gateway-worker/README.md
vendored
Normal file
2
vendor/webman/gateway-worker/README.md
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# gateway-worker
|
||||
webman gateway-worker plugin
|
||||
13
vendor/webman/gateway-worker/composer.json
vendored
Normal file
13
vendor/webman/gateway-worker/composer.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "webman/gateway-worker",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"workerman/gateway-worker": "^3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\GatewayWorker\\": "src"
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/webman/gateway-worker/src/BusinessWorker.php
vendored
Normal file
27
vendor/webman/gateway-worker/src/BusinessWorker.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Webman\GatewayWorker;
|
||||
|
||||
class BusinessWorker extends \GatewayWorker\BusinessWorker
|
||||
{
|
||||
public function __construct($config)
|
||||
{
|
||||
foreach ($config as $key => $value)
|
||||
{
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function onWorkerStart()
|
||||
{
|
||||
$this->_onWorkerStart = $this->onWorkerStart;
|
||||
$this->_onWorkerReload = $this->onWorkerReload;
|
||||
$this->_onWorkerStop = $this->onWorkerStop;
|
||||
$this->onWorkerStop = array($this, 'onWorkerStop');
|
||||
$this->onWorkerStart = array($this, 'onWorkerStart');
|
||||
$this->onWorkerReload = array($this, 'onWorkerReload');
|
||||
|
||||
$args = func_get_args();
|
||||
$this->id = $args[0]->id;
|
||||
parent::onWorkerStart();
|
||||
}
|
||||
}
|
||||
65
vendor/webman/gateway-worker/src/Gateway.php
vendored
Normal file
65
vendor/webman/gateway-worker/src/Gateway.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Webman\GatewayWorker;
|
||||
|
||||
class Gateway extends \GatewayWorker\Gateway
|
||||
{
|
||||
public function __construct($config)
|
||||
{
|
||||
foreach ($config as $key => $value)
|
||||
{
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
$this->router = array("\\GatewayWorker\\Gateway", 'routerBind');
|
||||
}
|
||||
|
||||
public function onConnect($connection)
|
||||
{
|
||||
parent::onClientConnect($connection);
|
||||
}
|
||||
|
||||
public function onClose($connection)
|
||||
{
|
||||
parent::onClientClose($connection);
|
||||
}
|
||||
|
||||
public function onMessage($connection, $data)
|
||||
{
|
||||
parent::onClientMessage($connection, $data);
|
||||
}
|
||||
|
||||
public function onWorkerStart()
|
||||
{
|
||||
// 保存用户的回调,当对应的事件发生时触发
|
||||
$this->_onWorkerStart = $this->onWorkerStart;
|
||||
$this->onWorkerStart = array($this, 'onWorkerStart');
|
||||
// 保存用户的回调,当对应的事件发生时触发
|
||||
$this->_onConnect = $this->onConnect;
|
||||
$this->onConnect = array($this, 'onClientConnect');
|
||||
|
||||
// onMessage禁止用户设置回调
|
||||
$this->onMessage = array($this, 'onClientMessage');
|
||||
|
||||
// 保存用户的回调,当对应的事件发生时触发
|
||||
$this->_onClose = $this->onClose;
|
||||
$this->onClose = array($this, 'onClientClose');
|
||||
// 保存用户的回调,当对应的事件发生时触发
|
||||
$this->_onWorkerStop = $this->onWorkerStop;
|
||||
$this->onWorkerStop = array($this, 'onWorkerStop');
|
||||
|
||||
if (!is_array($this->registerAddress)) {
|
||||
$this->registerAddress = array($this->registerAddress);
|
||||
}
|
||||
|
||||
// 记录进程启动的时间
|
||||
$this->_startTime = time();
|
||||
|
||||
$args = func_get_args();
|
||||
$this->id = $args[0]->id;
|
||||
|
||||
$worker = func_get_arg(0);
|
||||
$this->_gatewayPort = substr(strrchr($worker->getSocketName(),':'),1);
|
||||
|
||||
parent::onWorkerStart();
|
||||
}
|
||||
}
|
||||
70
vendor/webman/gateway-worker/src/Install.php
vendored
Normal file
70
vendor/webman/gateway-worker/src/Install.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Webman\GatewayWorker;
|
||||
|
||||
class Install
|
||||
{
|
||||
const WEBMAN_PLUGIN = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $pathRelation = array (
|
||||
'plugin/webman/gateway' => 'plugin/webman/gateway',
|
||||
'config/plugin/webman/gateway-worker' => 'config/plugin/webman/gateway-worker',
|
||||
);
|
||||
|
||||
/**
|
||||
* Install
|
||||
* @return void
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
static::installByRelation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall
|
||||
* @return void
|
||||
*/
|
||||
public static function uninstall()
|
||||
{
|
||||
self::uninstallByRelation();
|
||||
}
|
||||
|
||||
/**
|
||||
* installByRelation
|
||||
* @return void
|
||||
*/
|
||||
public static function installByRelation()
|
||||
{
|
||||
foreach (static::$pathRelation as $source => $dest) {
|
||||
if ($pos = strrpos($dest, '/')) {
|
||||
$parent_dir = base_path().'/'.substr($dest, 0, $pos);
|
||||
if (!is_dir($parent_dir)) {
|
||||
mkdir($parent_dir, 0777, true);
|
||||
}
|
||||
}
|
||||
//symlink(__DIR__ . "/$source", base_path()."/$dest");
|
||||
copy_dir(__DIR__ . "/$source", base_path()."/$dest");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uninstallByRelation
|
||||
* @return void
|
||||
*/
|
||||
public static function uninstallByRelation()
|
||||
{
|
||||
foreach (static::$pathRelation as $source => $dest) {
|
||||
$path = base_path()."/$dest";
|
||||
if (!is_dir($path) && !is_file($path)) {
|
||||
continue;
|
||||
}
|
||||
/*if (is_link($path) {
|
||||
unlink($path);
|
||||
}*/
|
||||
remove_dir($path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
32
vendor/webman/gateway-worker/src/Register.php
vendored
Normal file
32
vendor/webman/gateway-worker/src/Register.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Webman\GatewayWorker;
|
||||
|
||||
class Register extends \GatewayWorker\Register
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function onWorkerstart()
|
||||
{
|
||||
// 设置 onMessage 连接回调
|
||||
$this->onConnect = array($this, 'onConnect');
|
||||
|
||||
// 设置 onMessage 回调
|
||||
$this->onMessage = array($this, 'onMessage');
|
||||
|
||||
// 设置 onClose 回调
|
||||
$this->onClose = array($this, 'onClose');
|
||||
|
||||
// 记录进程启动的时间
|
||||
$this->_startTime = time();
|
||||
|
||||
// 强制使用text协议
|
||||
$this->protocol = '\Workerman\Protocols\Text';
|
||||
|
||||
// reusePort
|
||||
$this->reusePort = false;
|
||||
}
|
||||
|
||||
}
|
||||
4
vendor/webman/gateway-worker/src/config/plugin/webman/gateway-worker/app.php
vendored
Normal file
4
vendor/webman/gateway-worker/src/config/plugin/webman/gateway-worker/app.php
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
37
vendor/webman/gateway-worker/src/config/plugin/webman/gateway-worker/process.php
vendored
Normal file
37
vendor/webman/gateway-worker/src/config/plugin/webman/gateway-worker/process.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Webman\GatewayWorker\Gateway;
|
||||
use Webman\GatewayWorker\BusinessWorker;
|
||||
use Webman\GatewayWorker\Register;
|
||||
|
||||
return [
|
||||
'gateway' => [
|
||||
'handler' => Gateway::class,
|
||||
'listen' => 'websocket://0.0.0.0:7272',
|
||||
'count' => cpu_count(),
|
||||
'reloadable' => false,
|
||||
'constructor' => ['config' => [
|
||||
'lanIp' => '127.0.0.1',
|
||||
'startPort' => 2300,
|
||||
'pingInterval' => 25,
|
||||
'pingData' => '{"type":"ping"}',
|
||||
'registerAddress' => '127.0.0.1:1236',
|
||||
'onConnect' => function(){},
|
||||
]]
|
||||
],
|
||||
'worker' => [
|
||||
'handler' => BusinessWorker::class,
|
||||
'count' => cpu_count()*2,
|
||||
'constructor' => ['config' => [
|
||||
'eventHandler' => plugin\webman\gateway\Events::class,
|
||||
'name' => 'ChatBusinessWorker',
|
||||
'registerAddress' => '127.0.0.1:1236',
|
||||
]]
|
||||
],
|
||||
'register' => [
|
||||
'handler' => Register::class,
|
||||
'listen' => 'text://0.0.0.0:1236',
|
||||
'count' => 1, // Must be 1
|
||||
'constructor' => []
|
||||
],
|
||||
];
|
||||
34
vendor/webman/gateway-worker/src/plugin/webman/gateway/Events.php
vendored
Normal file
34
vendor/webman/gateway-worker/src/plugin/webman/gateway/Events.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\webman\gateway;
|
||||
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
|
||||
class Events
|
||||
{
|
||||
public static function onWorkerStart($worker)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function onConnect($client_id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function onWebSocketConnect($client_id, $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function onMessage($client_id, $message)
|
||||
{
|
||||
Gateway::sendToClient($client_id, "receive message $message");
|
||||
}
|
||||
|
||||
public static function onClose($client_id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user