+void MasterVolume::onClientConnected()
+{
+ // Subscribe to 4a events
+ m_client.call("ahl-4a", "subscribe", QJsonValue(), [this](bool r, const QJsonValue&) {
+ if (r) qDebug() << "MasterVolume::onClientConnected - subscribed to 4a events!";
+ else qCritical () << "MasterVolume::onClientConnected - Failed to subscribe to 4a events!";
+ });
+}
+
+void MasterVolume::onClientDisconnected()
+{
+ qDebug() << "MasterVolume::onClientDisconnected!";
+ QTimer::singleShot(1000, this, SLOT(TryOpen()));
+}
+
+void MasterVolume::onClientError(QAbstractSocket::SocketError se)
+{
+ qDebug() << "MasterVolume::onClientError: " << se;
+}
+
+void MasterVolume::onClientEventReceived(QString name, const QJsonValue& data)
+{
+ qDebug() << "MasterVolume::onClientEventReceived[" << name << "]: " << data;
+ if (name == "ahl-4a/volume_changed")
+ {
+ QJsonObject arg = data.toObject();
+ bool active = arg["active"].toBool();
+ if (active)
+ {
+ // QString role = arg["role"].toString();
+ int volume = arg["volume"].toInt();
+ if (m_volume != volume)
+ {
+ m_volume = volume;
+ emit VolumeChanged();
+ }
+ }
+ }