Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of https://github.com/swooletw/laravel-swoole
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
albertcht committed Jan 14, 2019
2 parents 7832737 + 0921a11 commit 210d9a2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Concerns/InteractsWithSwooleQueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace SwooleTW\Http\Concerns;

use Swoole\Table;
use SwooleTW\Http\Table\SwooleTable;

trait InteractsWithSwooleQueue
{
/**
* Indicates if a packet is swoole's queue job.
*
* @param mixed
*/
protected function isSwooleQueuePacket($packet)
{
if (! is_string($packet)) {
return false;
}

$decoded = json_decode($packet, true);

return JSON_ERROR_NONE === json_last_error() && isset($decoded['job']);
}
}
17 changes: 17 additions & 0 deletions src/Concerns/InteractsWithWebsocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ public function onClose($server, $fd, $reactorId)
}
}

/**
* Indicates if a packet is websocket push action.
*
* @param mixed
*/
protected function isWebsocketPushPacket($packet)
{
if ( !is_array($packet)) {
return false;
}

return $this->isWebsocket
&& array_key_exists('action', $packet)
&& $packet['action'] === Websocket::PUSH_ACTION;
}


/**
* Push websocket message to clients.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Server/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use SwooleTW\Http\Concerns\InteractsWithWebsocket;
use SwooleTW\Http\Concerns\InteractsWithSwooleQueue;
use SwooleTW\Http\Concerns\InteractsWithSwooleTable;
use Symfony\Component\Debug\Exception\FatalThrowableError;

Expand All @@ -28,6 +29,7 @@ class Manager
{
use InteractsWithWebsocket,
InteractsWithSwooleTable,
InteractsWithSwooleQueue,
WithApplication;

/**
Expand Down

0 comments on commit 210d9a2

Please sign in to comment.