diff --git a/models/ItemWidget.php b/models/ItemWidget.php index 2bcd4e1..9b495ee 100644 --- a/models/ItemWidget.php +++ b/models/ItemWidget.php @@ -54,6 +54,7 @@ class ItemWidget extends ActiveRecord [['value_type'], 'in', 'range' => self::getValueTypesArray()], [['name', 'item_id', 'icon', 'type'], 'required'], [['name', 'html_class', 'icon'], 'string', 'max' => 255], + [['sort_order'], 'default', 'value' => 0], [['item_id'], 'exist', 'skipOnError' => true, 'targetClass' => Item::className(), 'targetAttribute' => ['item_id' => 'id']], [['room_id'], 'exist', 'skipOnError' => true, 'targetClass' => Room::className(), 'targetAttribute' => ['room_id' => 'id']], ]; diff --git a/servers/CoreServer.php b/servers/CoreServer.php index 42a7672..566939b 100644 --- a/servers/CoreServer.php +++ b/servers/CoreServer.php @@ -160,6 +160,11 @@ class CoreServer implements MessageComponentInterface if (isset($conn->User)) { $this->logUserConnection($conn->User, false); + if (isset($this->userConnections[$conn->User->id][$conn->resourceId]) + and $this->userConnections[$conn->User->id][$conn->resourceId] instanceof ConnectionInterface) { + unset($this->userConnections[$conn->User->id][$conn->resourceId]); + } + $this->log("User [{$conn->User->id}] disconnected"); } elseif (isset($conn->Board)) { $boardId = $conn->Board->id; @@ -210,12 +215,12 @@ class CoreServer implements MessageComponentInterface } // Check if it is an API request - $api = $conn->remoteAddress == '127.0.0.1' and $conn->WebSocket->request->getHeader('Origin') == 'origin'; + $api = $conn->remoteAddress === '127.0.0.1' and $conn->WebSocket->request->getHeader('Origin') == 'origin'; // Close previous connection if it is not an API connection - if (isset($this->userConnections[$user->id]) and !$api) { - $this->userConnections[$user->id]->close(); - } +// if (!$api and isset($this->userConnections[$user->id]) and $this->userConnections[$user->id] instanceof ConnectionInterface) { +// $this->userConnections[$user->id]->close(); +// } // Regenerate auth token $user->reGenerateAuthToken(); @@ -224,7 +229,7 @@ class CoreServer implements MessageComponentInterface $conn->User = $user; $conn->api = $api; - $this->userConnections[$user->id] = $conn; + $this->userConnections[$user->id][$conn->resourceId] = $conn; // Prepare Items for User $itemModels = Item::find()->all(); @@ -507,7 +512,6 @@ class CoreServer implements MessageComponentInterface $this->sendUsers($parameters); $this->logItemValue($item, serialize($parameters)); - VarDumper::dump($parameters); $this->saveItemValue($item->id, $parameters, $item->type); break; @@ -804,8 +808,15 @@ class CoreServer implements MessageComponentInterface { $msg = Json::encode($data); - foreach ($this->userConnections as $client) { - $client->send($msg); + foreach ($this->userConnections as $userConnections) { + if (is_array($userConnections)) { + /** @var Connection[] $userConnections */ + foreach ($userConnections as $connection) { + $connection->send($msg); + } + } else { + $userConnections->send($msg); + } } }