From 98324121f18cdb686b48b279e684d2b512a6b10f Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Wed, 21 Feb 2024 21:38:57 +0100 Subject: [PATCH] Renamed connect event to connection --- README.md | 2 +- src/WebSocketMiddleware.php | 23 +++-------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9778741..a2c429c 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ $http->listen($socket); ### Server Events -#### connect +#### connection This event is emitted when a new WebSocket request has been accepted. The `WebSocketConnection` is passed as the first argument. diff --git a/src/WebSocketMiddleware.php b/src/WebSocketMiddleware.php index fcc053d..a5da28c 100644 --- a/src/WebSocketMiddleware.php +++ b/src/WebSocketMiddleware.php @@ -14,6 +14,8 @@ use SplObjectStorage; class WebSocketMiddleware implements EventEmitterInterface { + const EVENT_CONNECTION = 'connection'; + const MAGIC = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; use EventEmitterTrait; @@ -55,7 +57,7 @@ class WebSocketMiddleware implements EventEmitterInterface }); Loop::futureTick(function () use ($websocket) { - $this->emit('connect', [ $websocket ]); + $this->emit(self::EVENT_CONNECTION, [ $websocket ]); }); return new Response( @@ -69,23 +71,4 @@ class WebSocketMiddleware implements EventEmitterInterface ); } - // private function hexdump($data): void - // { - // printf("%4d .\n", strlen($data)); - // $rows = str_split($data, 16); - // $offs = 0; - // foreach ($rows as $row) { - // $h = []; $a = []; - // for ($n = 0; $n < 16; $n++) { - // if ($n < strlen($row)) { - // $h[] = sprintf("%02x%s", ord($row[$n]), ($n==7)?" ":" "); - // $a[] = sprintf("%s%s", (ctype_print($row[$n])?$row[$n]:"."), ($n==7)?" ":""); - // } else { - // $h[] = (($n==7)?" ":" "); - // $a[] = (($n==7)?" ":" "); - // } - // } - // printf("%04x | %s | %s\n", 16 * $offs++, join("", $h), join("", $a)); - // } - // } } \ No newline at end of file