]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
MQTT: Add is_active and is _playing
authoraaronk6 <aaronk6@users.noreply.github.com>
Sat, 16 Mar 2024 16:40:59 +0000 (17:40 +0100)
committeraaronk6 <aaronk6@users.noreply.github.com>
Tue, 24 Sep 2024 18:32:08 +0000 (20:32 +0200)
mqtt.c

diff --git a/mqtt.c b/mqtt.c
index f662009d6578f45f3f6211ad453cef0162795d00..fd172161f8087ec663fe567009e0c9baed5c390a 100644 (file)
--- a/mqtt.c
+++ b/mqtt.c
@@ -21,6 +21,10 @@ struct mosquitto *global_mosq = NULL;
 char *topic = NULL;
 int connected = 0;
 
+// track active/playing state
+int is_active = 0;
+int is_playing = 0;
+
 // mosquitto logging
 void _cb_log(__attribute__((unused)) struct mosquitto *mosq, __attribute__((unused)) void *userdata,
              int level, const char *str) {
@@ -167,12 +171,16 @@ void mqtt_process_metadata(uint32_t type, uint32_t code, char *data, uint32_t le
     } else if (type == 'ssnc') {
       switch (code) {
       case 'abeg':
+        is_active = 1;
+        mqtt_publish("is_active", "1", 1);
         mqtt_publish("active_start", data, length);
         break;
       case 'acre':
         mqtt_publish("active_remote_id", data, length);
         break;
       case 'aend':
+        is_active = 0;
+        mqtt_publish("is_active", "0", 1);
         mqtt_publish("active_end", data, length);
         break;
       case 'asal':
@@ -210,9 +218,13 @@ void mqtt_process_metadata(uint32_t type, uint32_t code, char *data, uint32_t le
         mqtt_publish("output_frame_rate", data, length);
         break;
       case 'pbeg':
+        is_playing = 1;
+        mqtt_publish("is_playing", "1", 1);
         mqtt_publish("play_start", data, length);
         break;
       case 'pend':
+        is_playing = 0;
+        mqtt_publish("is_playing", "0", 1);
         mqtt_publish("play_end", data, length);
         break;
       case 'pfls':
@@ -224,6 +236,8 @@ void mqtt_process_metadata(uint32_t type, uint32_t code, char *data, uint32_t le
         }
         break;
       case 'prsm':
+        is_playing = 1;
+        mqtt_publish("is_playing", "1", 1);
         mqtt_publish("play_resume", data, length);
         break;
       case 'pvol':