BrandMeister / Project-Halligan

The official BrandMeister Dashboard 2.0
http://brandmeister.network
51 stars 22 forks source link

Last-heard api?? #43

Closed programmin1 closed 3 years ago

programmin1 commented 3 years ago

Can I access your last-heard programmatically? If so, how? I tried the web socket and it doesn't get the second connection -

?php
Require_once(__DIR__.'/vendor/autoload.php'); //use Amp\Loop;
use Amp\Websocket\Client\Connection;
use Amp\Websocket\Message;
use function Amp\delay;
use function Amp\Websocket\Client\connect;

// Connects to the Kaazing echoing websocket demo.
Amp\Loop::run(function () {
    /** @var Connection $connection */
    $connection = yield connect('wss://api.brandmeister.network/infoService/?EIO=3&transport=websocket');
    //yield $connection->send("Hello!");

    $i = 0;

    while ($message = yield $connection->receive()) {
        /** @var Message $message */
        $payload = yield $message->buffer();
        printf("Received: %s\n", $payload);
        $thing = (json_decode(preg_replace('/^0/','',$payload)));
        var_dump($thing);
        if( isset($thing->sid) ) {
                $c2 = yield connect('wss://api.brandmeister.network/lh/%7D/?EIO=3&transport=websocket&sid='.$thing->
                while( $ms2 = yield $c2->receive() ) {
                        $p = yield $ms2->buffer();
                        printf("Received: %s\n", $p);

                }
        }

        if ($payload === "Goodbye!") {
            $connection->close();
            break;
        }

        yield delay(1000); // Pause the coroutine for 1 second.

        if ($i < 3) {
            yield $connection->send("Ping: " . ++$i);
        } else {
            yield $connection->send("Goodbye!");
        }
    }
});
programmin1 commented 3 years ago

I fixed my code, integrated it in an experimental callsign listener I have been working on. Please let me know what you think - https://hearham.com/help