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

Pocitani poctu sledujicich

parent e09395b7
No related branches found
No related tags found
No related merge requests found
Pipeline #5830 passed
......@@ -2,7 +2,7 @@ image: docker:20.10.9
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 2.0.2
IMAGE_VER: 2.1.0
services:
- docker:20.10.9-dind
......
......@@ -77,7 +77,6 @@ sub startup {
$r->get('/streams')->to(cb => sub { shift->render('streams'); });
$r->get('/api/streams')->to('Stream#list');
$r->get('/streams/:id')->to('Stream#info');
$r->put('/streams/:id/recording')->to('Stream#recording');
$r->get('/calendar')->to(cb => sub { shift->render('calendar'); });
$r->get('/api/calendar')->to('Calendar#list');
......
......@@ -43,11 +43,6 @@ sub callback_rtmp($c) {
is_live => ( $c->param('call') =~ /done/ ) ? 'f':'t',
});
# pri zahajeni a ukonceni vysulani smazat priznak nahravani
if ( $event ne 'update' ) {
$stream->update({ recording => 'f'});
}
$pubsub->json('streams')->notify( streams => {
call => $c->param('call'),
stream_id => $stream->id,
......@@ -67,29 +62,6 @@ sub callback_recorder($c) {
});
$c->render( status => 404, text => '' ), return if ! $stream;
# aktualizace stavu streamu
# $stream->update({
# recording => 'f',
# });
#
# my $record = $stream->records(
# {
# end => undef,
# path => undef,
# },
# {
# order_by => {'-desc' => 'begin'}
# }
# )->first;
#
# if ( $record ) {
# $record->update({
# path => $c->param('path'),
# recorder => $c->param('recorder'),
# end => \'now()',
# });
# }
$stream->add_to_records({
publish_user_id => $stream->publish_user_id,
path => $c->param('path'),
......@@ -108,8 +80,8 @@ sub callback_hls($c) {
if ($c->req->headers->header('X-Original-URI') =~ HLS ) {
$c->app->log->error('>>>>>>>>>>>>'. $1
);
$c->app->log->error('>>>>>>>>>>>>'. $1);
if ( $c->session->{user} ) {
$code = 204 if $c->session->{user}{acl}{ $1 } & 4;
}
......@@ -124,8 +96,7 @@ $c->app->log->error('>>>>>>>>>>>>'. $1
$c->render( status => $code, text => '');
}
sub callback_record {
my $c = shift;
sub callback_record($c ) {
$c->app->log->debug($c->req->headers->header('X-Original-URI'));
......
......@@ -127,61 +127,6 @@ sub info {
$c->render();
}
sub recording {
my $c = shift;
# akce
if ( ! $c->param('action') || $c->param('action') !~ /(stop|start)/) {
$c->render( status => 400, text => '');
return;
}
# stream
my $stream = $c->schema->resultset('Stream')->find({
id => $c->stash->{id}
});
if ( ! $stream ) {
$c->render( status => 404, text => '');
return;
}
if ( $stream->publish_user_id != $c->session->{user}{id}) {
$c->render( status => 403, text => '');
return;
}
my $ua = Mojo::UserAgent->new;
my $res = $ua->get(sprintf(CONTROL_URL,
$c->config->{nginx}{base_url},
$c->param('action'),
$stream->key,
'all'
))->result;
my $recording = ( $c->param('action') eq 'start' ) ? 1 : 0;
if ($res->is_success) {
my $guard = $c->schema->txn_scope_guard;
$stream->update({
recording => $recording
});
if ( $recording ) {
$stream->add_to_records({
publish_user_id => $stream->publish_user_id,
path => $res->body,
});
}
$guard->commit;
}
$c->render( json => { recording => $stream->recording } );
}
1;
......
......@@ -10,6 +10,8 @@ use constant SOCKET_INACTIVITY_TIMEOUT => 300;
sub main {
my $c = shift;
my $ip = $c->tx->remote_address;
my $key = $c->req->headers->header('Sec-WebSocket-Key');
$c->inactivity_timeout(SOCKET_INACTIVITY_TIMEOUT);
......@@ -25,7 +27,13 @@ sub main {
});
$c->on(json => sub( $c, $message ) {
if ( $message->{event} eq 'KEEPALIVE' ) {
if ( $message->{stream} ) {
$c->redis->set(
join (':', ('live', $message->{stream}, $key)),
'live', 'EX', 16
);
my $count = $c->redis->keys( 'live:' . $message->{stream} . ':*' );
$c->send({json => { watchers => $count }});
}
});
......
......@@ -30,14 +30,6 @@ rtmp {
record_unique on;
record_max_size 8000m;
recorder all {
record all manual;
record_suffix -%Y%m%d-%H%M%S.flv;
record_path /records;
record_unique on;
record_max_size 4000m;
}
recorder audio {
record audio manual;
record_suffix -%Y%m%d-%H%M%S.audio.flv;
......
% layout 'default';
% title $c->stash->{stream}{name};
%= include 'includes/player', src => $url, live => 1;
<script>
function connect() {
var ws = new WebSocket('<%= $c->config->{ws_url} %>');
ws.onmessage = function (event) {
var data = JSON.parse(event.data)
if ( typeof data.watchers !== 'undefined' ) {
console.log(data);
}
else {
ws.send(JSON.stringify({
event: "watch",
stream: "<%= $c->stash->{stream}{id} %>"
}));
}
};
ws.onclose = function(e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
connect();
}, 1000);
};
ws.onerror = function(err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
connect();
</script>
......@@ -59,7 +59,6 @@ function formatterStatus(value, row) {
var ws = new WebSocket('<%= $c->config->{ws_url} %>');
ws.onmessage = function (event) {
console.log(event.data);
$('#Streams').bootstrapTable('refresh', {silent: true})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment