Skip to content

Instantly share code, notes, and snippets.

@m0rb
Created February 8, 2024 02:06
Show Gist options
  • Save m0rb/2f960c2d7657e5f3596f4c808bc3b7af to your computer and use it in GitHub Desktop.
Save m0rb/2f960c2d7657e5f3596f4c808bc3b7af to your computer and use it in GitHub Desktop.
bluesky websocket firehose client for perl
#!/usr/bin/perl -w
use 5.12.0;
use strict;
use warnings;
use utf8;
use AnyEvent::WebSocket::Client;
use CBOR::XS;
my $derp = AE::cv;
my $cbor = CBOR::XS->new;
my $bsky_wss = "wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos";
my $client = AnyEvent::WebSocket::Client->new;
$client->connect($bsky_wss)->cb(sub {
our $input = eval { shift->recv };
if($@) {
warn $@;
}
$input->on(each_message => sub {
my ($con,$message) = (@_);
my $body = $message->{'body'};
if ( my $got = $cbor->incr_parse_multiple($body) ) {
if ($got->{'blocks'}) {
print $got->{'blocks'};
}
}
});
});
$derp->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment