示例#1
0
 /**
  * @param string JSON'ified string we'll receive from ZeroMQ
  */
 public function onReceiveMessage($message)
 {
     // $entryData = json_decode($entry, true);
     // // If the lookup topic object isn't set there is no one to publish to
     // if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
     //     return;
     // }
     // $topic = $this->subscribedTopics[0];
     // // re-send the data to all the clients subscribed to that category
     // $messageSentTime = microtime();
     // $timeSinceLastMessage = $messageSentTime - $this->lastMessageSentTime;
     // if ($timeSinceLastMessage)
     // {
     echo "\nReceived message:\n";
     echo $message;
     $songInfo = $this->pandoraService->parseMessage($message);
     if ($songInfo) {
         if (sizeof($songInfo) == 1) {
             $songClass = "App\\Volumio\\Pandora\\PandoraSong";
             $song = ObjectConverterUtil::arrayToObject($songInfo[0], $songClass);
             $this->songChangeNotifier->notify($song);
         }
         // foreach($this->clients as $client)
         // {
         //     $client->send(json_encode($songInfo));
         // }
     }
 }
示例#2
0
 function sendCommand($commandName, $serviceType, $song = null, $playlist = null, $query = null, $searchType = null)
 {
     if ($serviceType) {
         $playerClass = ServiceUtils::getClass($serviceType, $this->connectionService);
         $response = "";
         $songClass = "App\\Volumio\\{$serviceType}\\" . $serviceType . "Song";
         $playlistClass = "App\\Volumio\\{$serviceType}\\" . $serviceType . "Playlist";
         $song = ObjectConverterUtil::arrayToObject($song, $songClass);
         $playlist = ObjectConverterUtil::arrayToObject($playlist, $playlistClass);
     }
     switch ($commandName) {
         case "play":
             $this->stopOtherServices($serviceType);
             $response = $playerClass->{$commandName}($song);
             break;
         case "addQueue":
         case "add":
         case "image":
         case "rateUp":
         case "rateDown":
         case "removePlaylist":
         case "removeQueue":
             $response = $playerClass->{$commandName}($song);
             break;
         case "playPlaylist":
             $this->stopOtherServices($serviceType);
             $response = $playerClass->{$commandName}($playlist, $song);
             break;
         case "addPlaylist":
             $response = $playerClass->{$commandName}($playlist, $song);
             break;
         case "getPlaylist":
             $response = $playerClass->{$commandName}($playlist);
             break;
         case "search":
             $response = $playerClass->{$commandName}($query, $searchType);
             break;
         case "next":
         case "previous":
         case "stop":
         case "pause":
         case "status":
         case "shuffle":
         case "repeat":
         case "clearQueue":
         case "getPlaylists":
         case "openService":
             $response = $playerClass->{$commandName}();
             break;
         case "currentSong":
             $response = $this->currentSongService->getCurrentSong();
             if (array_key_exists("serviceType", $response)) {
                 $playerClass = ServiceUtils::getClass(ucfirst($response["serviceType"]), $this->connectionService);
                 $response = $playerClass->status();
             }
             break;
         case "getQueue":
             $response = $this->currentSongService->getCurrentSong();
             if (array_key_exists("serviceType", $response)) {
                 $playerClass = ServiceUtils::getClass(ucfirst($response["serviceType"]), $this->connectionService);
                 $response = $playerClass->getQueue();
             }
             break;
         case "getServices":
             $services = config("options.services");
             $musicServices = [];
             foreach ($services as $service) {
                 $newService["directory"] = strtoupper($service);
                 $newService["serviceType"] = strtoupper($service);
                 $newService["type"] = "Directory";
                 array_push($musicServices, $newService);
             }
             return $musicServices;
             break;
     }
     return json_encode($response);
 }