Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 210d9a2

Browse files
committed
Merge branch 'develop' of https://github.com/swooletw/laravel-swoole into develop
2 parents 7832737 + 0921a11 commit 210d9a2

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace SwooleTW\Http\Concerns;
4+
5+
use Swoole\Table;
6+
use SwooleTW\Http\Table\SwooleTable;
7+
8+
trait InteractsWithSwooleQueue
9+
{
10+
/**
11+
* Indicates if a packet is swoole's queue job.
12+
*
13+
* @param mixed
14+
*/
15+
protected function isSwooleQueuePacket($packet)
16+
{
17+
if (! is_string($packet)) {
18+
return false;
19+
}
20+
21+
$decoded = json_decode($packet, true);
22+
23+
return JSON_ERROR_NONE === json_last_error() && isset($decoded['job']);
24+
}
25+
}

src/Concerns/InteractsWithWebsocket.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ public function onClose($server, $fd, $reactorId)
151151
}
152152
}
153153

154+
/**
155+
* Indicates if a packet is websocket push action.
156+
*
157+
* @param mixed
158+
*/
159+
protected function isWebsocketPushPacket($packet)
160+
{
161+
if ( !is_array($packet)) {
162+
return false;
163+
}
164+
165+
return $this->isWebsocket
166+
&& array_key_exists('action', $packet)
167+
&& $packet['action'] === Websocket::PUSH_ACTION;
168+
}
169+
170+
154171
/**
155172
* Push websocket message to clients.
156173
*

src/Server/Manager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Illuminate\Contracts\Container\Container;
1919
use Illuminate\Contracts\Debug\ExceptionHandler;
2020
use SwooleTW\Http\Concerns\InteractsWithWebsocket;
21+
use SwooleTW\Http\Concerns\InteractsWithSwooleQueue;
2122
use SwooleTW\Http\Concerns\InteractsWithSwooleTable;
2223
use Symfony\Component\Debug\Exception\FatalThrowableError;
2324

@@ -28,6 +29,7 @@ class Manager
2829
{
2930
use InteractsWithWebsocket,
3031
InteractsWithSwooleTable,
32+
InteractsWithSwooleQueue,
3133
WithApplication;
3234

3335
/**

0 commit comments

Comments
 (0)