|
|
|
@ -2,28 +2,32 @@
|
|
|
|
|
|
|
|
|
|
namespace websocket; |
|
|
|
|
|
|
|
|
|
include __DIR__ . '/../Providers/Positus.php'; |
|
|
|
|
|
|
|
|
|
use app\Middleware\ApiAgente; |
|
|
|
|
use app\Models\Atendimento; |
|
|
|
|
use Ratchet\ConnectionInterface; |
|
|
|
|
use Ratchet\MessageComponentInterface; |
|
|
|
|
use SplObjectStorage; |
|
|
|
|
|
|
|
|
|
class Servidorsocket implements MessageComponentInterface |
|
|
|
|
{ |
|
|
|
|
public $clients; |
|
|
|
|
/** @var ApiAgente $api api das função do agente */ |
|
|
|
|
protected $api; |
|
|
|
|
|
|
|
|
|
/** @var SplObjectStorage $clients api das função do agente */ |
|
|
|
|
protected $clients; |
|
|
|
|
|
|
|
|
|
/** @var Atendimento $atendimento api das função do agente */ |
|
|
|
|
protected $atendimento; |
|
|
|
|
|
|
|
|
|
public $connection = []; |
|
|
|
|
public $shell = []; |
|
|
|
|
public $conectado = []; |
|
|
|
|
public $idConexion = []; |
|
|
|
|
public $clientes = []; |
|
|
|
|
public $api; |
|
|
|
|
public $atendimento; |
|
|
|
|
|
|
|
|
|
public function __construct() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
$this->clients = new \SplObjectStorage(); |
|
|
|
|
$this->clients = new SplObjectStorage(); |
|
|
|
|
$this->api = new ApiAgente(); |
|
|
|
|
$this->atendimento = new Atendimento(); |
|
|
|
|
} |
|
|
|
@ -52,7 +56,6 @@ class Servidorsocket implements MessageComponentInterface
|
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
$mensagem = json_decode($msg, true); |
|
|
|
|
logger('ws')->debug(var_export($mensagem, true)); |
|
|
|
|
if ($mensagem['matricula']) { |
|
|
|
|
$this->clientes[$from->resourceId]['matricula'] = $mensagem['matricula']; |
|
|
|
|
} else { |
|
|
|
@ -70,10 +73,13 @@ class Servidorsocket implements MessageComponentInterface
|
|
|
|
|
|
|
|
|
|
public function onClose(ConnectionInterface $conn) |
|
|
|
|
{ |
|
|
|
|
// The connection is closed, remove it, as we can no longer send it messages |
|
|
|
|
$this->conectado[$conn->resourceId] = false; |
|
|
|
|
$this->clients->detach($conn); |
|
|
|
|
$this->api->logoff($this->clientes[$conn->resourceId], false); |
|
|
|
|
try { |
|
|
|
|
$this->conectado[$conn->resourceId] = false; |
|
|
|
|
$this->clients->detach($conn); |
|
|
|
|
$this->api->logoff($this->clientes[$conn->resourceId], false); |
|
|
|
|
} catch (\Exception $th) { |
|
|
|
|
logger('ws:onClose')->debug($th->getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function onError(ConnectionInterface $conn, \Exception $e) |
|
|
|
|