Refactor ChatConnect and related classes to use dynamic typing for properties and method parameters. Update event handling to use a consistent naming convention for emitted events. Adjust WebSocket message handling methods to accept event arrays instead of specific data structures. Update configuration for Swoole to increase ping intervals and timeouts.

This commit is contained in:
li
2026-01-29 03:04:40 +08:00
parent b8cd0c9418
commit ca996c227c
27 changed files with 441 additions and 148 deletions
+11 -11
View File
@@ -14,14 +14,14 @@ class Snowflake
private const DATACENTER_ID_BITS = 5;
private const SEQUENCE_BITS = 12;
private int $workerId;
private int $datacenterId;
private int $sequence = 0;
private int $lastTimestamp = -1;
private $workerId;
private $datacenterId;
private $sequence = 0;
private $lastTimestamp = -1;
private static ?Snowflake $instance = null;
private static $instance = null;
public function __construct(int $workerId = 1, int $datacenterId = 1)
public function __construct($workerId = 1, $datacenterId = 1)
{
$this->workerId = $workerId & 0x1F;
$this->datacenterId = $datacenterId & 0x1F;
@@ -30,7 +30,7 @@ class Snowflake
/**
* 获取单例实例
*/
public static function getInstance(): Snowflake
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self(1, 1);
@@ -41,7 +41,7 @@ class Snowflake
/**
* 生成下一个ID
*/
public function nextId(): int
public function nextId()
{
$timestamp = $this->currentTimeMillis();
@@ -65,17 +65,17 @@ class Snowflake
/**
* 生成字符串ID
*/
public function nextIdString(): string
public function nextIdString()
{
return (string)$this->nextId();
}
private function currentTimeMillis(): int
private function currentTimeMillis()
{
return (int)(microtime(true) * 1000);
}
private function waitNextMillis(int $lastTimestamp): int
private function waitNextMillis($lastTimestamp)
{
$timestamp = $this->currentTimeMillis();
while ($timestamp <= $lastTimestamp) {