瀏覽代碼

Merge branch 'send-message' of https://github.com/SuperBFG7/ympd into SuperBFG7-send-message

Andrew Karpow 6 年之前
父節點
當前提交
ba4322c684
共有 4 個文件被更改,包括 38 次插入0 次删除
  1. 5 0
      htdocs/index.html
  2. 10 0
      htdocs/js/mpd.js
  3. 22 0
      src/mpd_client.c
  4. 1 0
      src/mpd_client.h

+ 5 - 0
htdocs/index.html

@@ -56,6 +56,11 @@
             </button>
           </div>
           <div class="btn-group">
+            <button id="btnlove" type="button" class="btn btn-default" onclick="clickLove();">
+              <span class="glyphicon glyphicon-heart"></span>
+            </button>
+          </div>
+          <div class="btn-group">
             <div class="btn btn-toolbar btn-default">
               <span id="volume-icon" class="glyphicon glyphicon-volume-up"></span>
               <div id="volumeslider"></div>

+ 10 - 0
htdocs/js/mpd.js

@@ -517,6 +517,8 @@ function webSocketConnect() {
                     $('#album').text("");
                     $('#artist').text("");
 
+					$('#btnlove').removeClass("active");
+
                     $('#currenttrack').text(" " + obj.data.title);
                     var notification = "<strong><h4>" + obj.data.title + "</h4></strong>";
 
@@ -679,6 +681,14 @@ function basename(path) {
     return path.split('/').reverse()[0];
 }
 
+function clickLove() {
+    socket.send("MPD_API_SEND_MESSAGE,mpdas," + ($('#btnlove').hasClass('active') ? "unlove" : "love"));
+	if ( $('#btnlove').hasClass('active') )
+		$('#btnlove').removeClass("active");
+	else
+		$('#btnlove').addClass("active");
+}
+
 $('#btnrandom').on('click', function (e) {
     socket.send("MPD_API_TOGGLE_RANDOM," + ($(this).hasClass('active') ? 0 : 1));
 

+ 22 - 0
src/mpd_client.c

@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <libgen.h>
 #include <mpd/client.h>
+#include <mpd/message.h>
 
 #include "mpd_client.h"
 #include "config.h"
@@ -241,6 +242,27 @@ out_save_queue:
 out_search:
             free(p_charbuf);
             break;
+        case MPD_API_SEND_MESSAGE:
+            p_charbuf = strdup(c->content);
+            if(strcmp(strtok(p_charbuf, ","), "MPD_API_SEND_MESSAGE"))
+				goto out_send_message;
+
+            if((token = strtok(NULL, ",")) == NULL)
+                goto out_send_message;
+
+			free(p_charbuf);
+            p_charbuf = strdup(get_arg1(c->content));
+
+            if ( strtok(p_charbuf, ",") == NULL )
+                goto out_send_message;
+
+            if ( (token = strtok(NULL, ",")) == NULL )
+                goto out_send_message;
+
+			mpd_run_send_message(mpd.conn, p_charbuf, token);
+out_send_message:
+            free(p_charbuf);
+            break;
 #ifdef WITH_MPD_HOST_CHANGE
         /* Commands allowed when disconnected from MPD server */
         case MPD_API_SET_MPDHOST:

+ 1 - 0
src/mpd_client.h

@@ -50,6 +50,7 @@
     X(MPD_API_RM_ALL) \
     X(MPD_API_MOVE_TRACK) \
     X(MPD_API_SEARCH) \
+    X(MPD_API_SEND_MESSAGE) \
     X(MPD_API_SET_VOLUME) \
     X(MPD_API_SET_PAUSE) \
     X(MPD_API_SET_PLAY) \