Minor reformating

master
Daniel Berteaud 10 years ago
parent ff48f7ec30
commit 9a4c35de2d
  1. 29
      vroom.pl

@ -921,6 +921,9 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
$peers->{$id}->{socket} = $self->tx; $peers->{$id}->{socket} = $self->tx;
# And set the initial "last seen" flag # And set the initial "last seen" flag
$peers->{$id}->{last} = time; $peers->{$id}->{last} = time;
# Associate the unique ID and name
$peers->{$id}->{id} = $self->session('id');
$peers->{$id}->{name} = $self->session('name');
# When we recive a message, lets parse it as e Socket.IO one # When we recive a message, lets parse it as e Socket.IO one
$self->on('message' => sub { $self->on('message' => sub {
@ -972,13 +975,11 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
} }
# We have a message from a peer # We have a message from a peer
elsif ($msg->{data}->{name} eq 'message'){ elsif ($msg->{data}->{name} eq 'message'){
# We check the room this peer is in $self->app->log->debug("Signaling message received from peer " . $id);
my $room = $peers->{$id}->{room};
$self->app->log->debug("Signaling message received from " . $id);
# Forward this message to all other members of the same room # Forward this message to all other members of the same room
foreach my $peer (keys %$peers){ foreach my $peer (keys %$peers){
next if ($peer eq $id); next if ($peer eq $id);
next if $peers->{$peer}->{room} ne $room; next if $peers->{$peer}->{room} ne $peers->{$id}->{room};
# Just set who's sending it # Just set who's sending it
$msg->{data}->{args}[0]->{from} = $id; $msg->{data}->{args}[0]->{from} = $id;
$peers->{$peer}->{socket}->send( $peers->{$peer}->{socket}->send(
@ -1002,12 +1003,7 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
type => 'event', type => 'event',
data => { data => {
name => 'remove', name => 'remove',
args => [ args => [{ id => $id, type => 'screen' }]
{
id => $id,
type => 'screen'
}
]
} }
) )
); );
@ -1039,12 +1035,7 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
type => 'event', type => 'event',
data => { data => {
name => 'remove', name => 'remove',
args => [ args => [{ id => $id, type => 'video' }]
{
id => $id,
type => 'video'
}
]
} }
) )
); );
@ -1060,12 +1051,14 @@ websocket '/socket.io/:ver/websocket/:id' => sub {
# Every 3 seconds # Every 3 seconds
Mojo::IOLoop->recurring( 3 => sub { Mojo::IOLoop->recurring( 3 => sub {
foreach my $peer ( keys %$peers ) { foreach my $peer ( keys %$peers ) {
# If we had no reply from this peer in the last 15 sec # This shouldn't happen, but better to log an error and fix it rather
# (5 heartbeat without response), we consider it dead and remove it # than looping indefinitly on a bogus entry if something went wrong
if (!$peers->{$peer}->{socket}){ if (!$peers->{$peer}->{socket}){
app->log->debug("Garbage found in peers (peer $peer)\n" . Dumper($peers->{$peer})); app->log->debug("Garbage found in peers (peer $peer)\n" . Dumper($peers->{$peer}));
delete $peers->{$peer}; delete $peers->{$peer};
} }
# If we had no reply from this peer in the last 15 sec
# (5 heartbeat without response), we consider it dead and remove it
elsif ($peers->{$peer}->{last} < time - 15){ elsif ($peers->{$peer}->{last} < time - 15){
app->log->debug("Peer $peer didn't reply in 15 sec, disconnecting"); app->log->debug("Peer $peer didn't reply in 15 sec, disconnecting");
$peers->{$peer}->{socket}->finish; $peers->{$peer}->{socket}->finish;

Loading…
Cancel
Save