//$State['PlaylistXMLs'][$F[0]] = htmlspecialchars_decode($D[1]); $State['PlaylistURLs'][$F[0]] = $D[0]; $State['PlaylistXMLs'][$F[0]] = $D[1]; $musicDB = new MusicDB(); $musicDB->UpdateQueue($F[0], -1, -1, $D[0], $D[1]); $musicDB->close(); } elseif (strpos($front, "ACTION Ds/Playlist 1 Insert ") !== false) { //ACTION Ds/Playlist 1 Insert \"(\d+)\" \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" //RESPONSE \"([[:ascii:]]+?)\" $F = getParameters($front); $D = getParameters($data); $State['NewId'] = $D[0]; $State['PlaylistURLs'][$State['NewId']] = $F[1]; $State['PlaylistXMLs'][$State['NewId']] = $F[2]; $musicDB = new MusicDB(); $musicDB->UpdateQueue($D[0], -1, -1, $F[1], $F[2]); $musicDB->close(); } elseif (strpos($front, "ACTION Ds/Playlist 1 IdArray") !== false) { //ACTION Ds/Playlist 1 IdArray //RESPONSE \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" $F = getParameters($front); $D = getParameters($data); $State['IdArray_Token'] = $D[0]; $State['IdArray_base64'] = $D[1]; $State['IdArray'] = unpack("N*", base64_decode($D[1])); $musicDB = new MusicDB(); CheckPlaylist($musicDB); $musicDB->close(); } Send(""); $DataHandled = true;
public function processMessage($message) { LogWrite("LPECClientSocket::processMessage - {$message}"); $DataHandled = false; if ($DEBUG > 1) { LogWrite($message); } if (strpos($message, "ALIVE Ds") !== false) { $this->Send("SUBSCRIBE Ds/Product"); $DataHandled = true; } elseif (strpos($message, "ALIVE") !== false) { LogWrite("ALIVE ignored : " . $message); $DataHandled = true; } elseif (strpos($message, "ERROR") !== false) { LogWrite("ERROR ignored : " . $message); $DataHandled = true; } elseif (strpos($message, "SUBSCRIBE") !== false) { // SUBSCRIBE are sent by Linn when a SUBSCRIBE finishes, thus // we send the possible next command (Send) after removing // previous command. // We record the Number to Subscribe action in the array to // help do less work with the events. $front = array_shift($this->Queue); if ($DEBUG > 1) { LogWrite("Command: " . $front . " -> " . $message); } $S1 = substr($front, 10); $S2 = substr($message, 10); $this->SubscribeType[$S1] = $S2; $this->Send(""); $DataHandled = true; } elseif (strpos($message, "RESPONSE") !== false) { // RESPONSE are sent by Linn when an ACTION finishes, thus we // send the possible next command (Send) after removing // previous command. $front = array_shift($this->Queue); if ($DEBUG > 0) { LogWrite("Command: " . $front . " -> " . $message); } if (strpos($front, "ACTION Ds/Product 1 Source ") !== false) { //ACTION Ds/Product 1 Source \"(\d+)\" //RESPONSE \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" $F = getParameters($front); $D = getParameters($message); //$State['Source_SystemName'][$F[0]] = $D[0]; //$State['Source_Type'][$F[0]] = $D[1]; //$State['Source_Name'][$F[0]] = $D[2]; //$State['Source_Visible'][$F[0]] = $D[3]; $this->getState()->setStateArray('SourceName', $D[2], $F[0]); if ($D[1] == "Playlist") { // We have the Playlist service. subscribe... $this->Send("SUBSCRIBE Ds/Playlist"); //$this->Send("SUBSCRIBE Ds/Jukebox"); } elseif ($D[1] == "Radio") { // We have the Radio service. subscribe... //$this->Send("SUBSCRIBE Ds/Radio"); } } elseif (strpos($front, "ACTION Ds/Playlist 1 Read ") !== false) { //ACTION Ds/Playlist 1 Read \"(\d+)\" //RESPONSE \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" $F = getParameters($front); $D = getParameters($message); $this->getState()->setStateArray('PlaylistURLs', $F[0], $D[0]); $this->getState()->setStateArray('PlaylistXMLs', $F[0], $D[1]); $musicDB = new MusicDB(); $musicDB->UpdateQueue($F[0], -1, -1, $D[0], $D[1]); $musicDB->close(); } elseif (strpos($front, "ACTION Ds/Playlist 1 Insert ") !== false) { //ACTION Ds/Playlist 1 Insert \"(\d+)\" \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" //RESPONSE \"([[:ascii:]]+?)\" $F = getParameters($front); $D = getParameters($message); $this->getState()->setState('NewId', $D[0]); $this->getState()->setStateArray('PlaylistURLs', $D[0], $F[1]); $this->getState()->setStateArray('PlaylistXMLs', $D[0], $F[2]); $musicDB = new MusicDB(); $musicDB->UpdateQueue($D[0], -1, -1, $F[1], $F[2]); $musicDB->close(); } elseif (strpos($front, "ACTION Ds/Playlist 1 IdArray") !== false) { //ACTION Ds/Playlist 1 IdArray //RESPONSE \"([[:ascii:]]+?)\" \"([[:ascii:]]+?)\" $F = getParameters($front); $D = getParameters($message); $this->getState()->setState('IdArray_Token', $D[0]); $this->getState()->setState('IdArray_base64', $D[1]); $this->getState()->setState('IdArray', unpack("N*", base64_decode($D[1]))); $musicDB = new MusicDB(); $this->CheckPlaylist($musicDB); $musicDB->close(); } $this->Send(""); $DataHandled = true; } elseif (strpos($message, "EVENT ") !== false) { // EVENTs are sent by Your linn - those that were subscribed // to. We think the below ones are interesting.... $E = getEvent($message); if (strpos($message, "EVENT " . $this->SubscribeType['Ds/Product']) !== false) { if (strpos($message, "SourceIndex ") !== false) { $this->getState()->setState('SourceIndex', $E[SourceIndex]); } if (strpos($message, "ProductModel ") !== false) { $this->getState()->setState('ProductModel', $E[ProductModel]); } if (strpos($message, "ProductName ") !== false) { $this->getState()->setState('ProductName', $E[ProductName]); } if (strpos($message, "ProductRoom ") !== false) { $this->getState()->setState('ProductRoom', $E[ProductRoom]); } if (strpos($message, "ProductType ") !== false) { $this->getState()->setState('ProductType', $E[ProductType]); } if (strpos($message, "Standby ") !== false) { $this->getState()->setState('Standby', $E[Standby]); $musicDB = new MusicDB(); $musicDB->SetState("Standby", $E[Standby]); $musicDB->close(); } if (strpos($message, "ProductUrl ") !== false) { $this->getState()->setState('ProductUrl', $E[ProductUrl]); } if (strpos($message, "Attributes ") !== false) { $this->getState()->setState('Attributes', $E[Attributes]); if (strpos($E[Attributes], "Volume") !== false) { $this->Send("SUBSCRIBE Ds/Volume"); } if (strpos($E[Attributes], "Info") !== false) { //$this->Send("SUBSCRIBE Ds/Info"); } if (strpos($E[Attributes], "Time") !== false) { //$this->Send("SUBSCRIBE Ds/Time"); } } if (strpos($message, "SourceCount ") !== false) { for ($i = 0; $i < $E[SourceCount]; $i++) { $this->Send("ACTION Ds/Product 1 Source \"" . $i . "\""); } } $DataHandled = true; } elseif (strpos($message, "EVENT " . $this->SubscribeType['Ds/Playlist']) !== false) { if (strpos($message, "TransportState ") !== false) { $this->getState()->setState('TransportState', $E[TransportState]); $musicDB = new MusicDB(); $musicDB->SetState("TransportState", $E[TransportState]); $musicDB->close(); } if (strpos($message, "Id ") !== false) { $this->getState()->setState('Id', $E[Id]); $musicDB = new MusicDB(); $musicDB->SetState("LinnId", $E[Id]); $musicDB->close(); } if (strpos($message, "IdArray ") !== false) { $this->getState()->setState('IdArray_base64', $E[IdArray]); $this->getState()->setState('IdArray', unpack("N*", base64_decode($E[IdArray]))); $musicDB = new MusicDB(); $this->CheckPlaylist($musicDB); $musicDB->close(); } if (strpos($message, "Shuffle ") !== false) { $this->getState()->setState('Shuffle', $E[Shuffle]); } if (strpos($message, "Repeat ") !== false) { $this->getState()->setState('Repeat', $E[Repeat]); } if (strpos($message, "TrackDuration ") !== false) { $this->getState()->setState('TrackDuration', $E[TrackDuration]); } if (strpos($message, "TrackCodecName ") !== false) { $this->getState()->setState('TrackCodecName', $E[TrackCodecName]); } if (strpos($message, "TrackSampleRate ") !== false) { $this->getState()->setState('TrackSampleRate', $E[TrackSampleRate]); } if (strpos($message, "TrackBitRate ") !== false) { $this->getState()->setState('TrackBitRate', $E[TrackBitRate]); } if (strpos($message, "TrackLossless ") !== false) { $this->getState()->setState('TrackLossless', $E[TrackLossless]); } $DataHandled = true; } elseif (strpos($message, "EVENT " . $this->SubscribeType['Ds/Volume']) !== false) { if (strpos($message, "Volume ") !== false) { LogWrite("Event Volume"); $this->getState()->setState('Volume', $E[Volume]); $musicDB = new MusicDB(); $musicDB->SetState("Volume", $E[Volume]); $musicDB->close(); } if (strpos($message, "Mute ") !== false) { $this->getState()->setState('Mute', $E[Mute]); $musicDB = new MusicDB(); $musicDB->SetState("Mute", $E[Mute]); $musicDB->close(); } $DataHandled = true; } elseif (strpos($message, "EVENT " . $this->SubscribeType['Ds/Jukebox']) !== false) { if (strpos($message, "CurrentPreset ") !== false) { $this->getState()->setState('CurrentPreset', $E[CurrentPreset]); } if (strpos($message, "CurrentBookmark ") !== false) { $this->getState()->setState('CurrentBookmark', $E[CurrentBookmark]); } $DataHandled = true; } else { LogWrite("UNKNOWN : " . $message); $DataHandled = true; } } return $DataHandled; }