Пост #144490

     
сохранен 11.09.2020 11:14
Текст поста
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sub ws_feed {
  my $ws = shift;
  #~ $ws->inactivity_timeout(300);# переподключение вебсокета
  my $feed = $ws->param('feed')
    or return $ws->send("none param feed?");
  
  $ws->log->error("Client connect try feed=$feed, but feeds=[@{[ keys %{ $ws->app->feeds} ]}]");
  
  $feed = $ws->app->feeds->{$feed}
    or return $ws->send("yet none feed ".$ws->param('feed'));

  my $id = "$ws";
  $ws->log->error("Client connected: $id; to feed tx=".$feed->{tx},);
  $feed->{clients}{$id} = $ws;
  $ws->tx->with_protocols('binary');
  
  $ws->on(
    finish => sub {
      my( $ws, $code, $reason ) = @_ ;
      my $id = "$ws";
      $ws->log->error("Client disconnected: $id");
      delete $feed->{clients}{ $id };
    }
  );
}
Добавить комментарий
Автор