Skip to content
Snippets Groups Projects
Verified Commit eb404523 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Novy format keealive

parent cb7069f8
No related branches found
No related tags found
No related merge requests found
FROM debian:buster
#FROM debian:buster-slim
FROM debian:buster-slim
RUN apt-get update && apt-get install -y \
wget \
cpanminus \
build-essential \
libcrypt-openssl-rsa-perl \
libdata-random-perl \
libdigest-sha-perl \
libdbd-pg-perl \
libdbi-perl \
libdbix-class-perl \
......
......@@ -3,6 +3,8 @@ package CF::Controller::Websockets;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Pg::PubSub;
use JSON;
use Digest::SHA qw(hmac_sha1_hex);
use feature 'signatures';
no warnings qw{ experimental::signatures };
......@@ -14,21 +16,6 @@ sub main {
$c->inactivity_timeout(SOCKET_INACTIVITY_TIMEOUT);
my $user;
if ( my $key = $c->req->headers->authorization ) {
if ( $key =~ s/Bearer\s+//i ) {
$c->oauth_token($key);
if ( $c->user ) {
$user = $c->schema->resultset('User')->find_or_create(
$c->user, { key => 'uuid'}
);
}
}
}
my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg);
$pubsub->listen(notify => sub($pubsub, $payload) {
......@@ -36,7 +23,12 @@ sub main {
});
$c->on(message => sub( $c, $message ) {
$user->update({keepalive => \'now()'}) if $user;
my $data = from_json($message);
if ($data->{payload} =~ /^\d+$/) {
my $user = $c->schama->resultset('User')->find({ id => $1 });
$user->update({keepalive => \'now()'}) if $user;
}
my $min_alive_time = "now() - '" . USER_ALIVE_TIMEOUT. " s'::interval";
......@@ -45,7 +37,11 @@ sub main {
keepalive => { '>' => \$min_alive_time },
}
);
$c->send(to_json({ event => 'online_users_updated', payload => $alive }));
$c->send(to_json({ event => 'online_users_updated', payload => {
all => $alive,
members => $alive,
}}));
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment