Advertisement
Krokit

Untitled

Jul 1st, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. require __DIR__ . '/vendor/autoload.php';
  4.  
  5. $loop = React\EventLoop\Factory::create();
  6. $reactConnector = new React\Socket\Connector($loop, [
  7.     'dns' => '1.1.1.1',
  8.     'timeout' => 10
  9.         ]);
  10. $connector = new Ratchet\Client\Connector($loop, $reactConnector, ['verify_peer_name' => false, 'allow_self_signed' => true]);
  11.  
  12. $connector('wss://playradioapp.dev.icbtech.rs:21718/ws')
  13.         ->then(function(Ratchet\Client\WebSocket $conn) {
  14.             $conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
  15.                 $title = json_decode($msg)->nowPlaying->artist . " - " . json_decode($msg)->nowPlaying->title . "";
  16.                 echo $title;
  17.                 $conn->close();
  18.             });
  19.         }, function(\Exception $e) use ($loop) {
  20.             echo "Could not connect: {$e->getMessage()}\n";
  21.             $loop->stop();
  22.         });
  23.  
  24. $loop->run();
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement