From 511a9966794b4aa2e1a4047dab4ccfbe3a1f0171 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 17 Mar 2015 17:47:34 +0100 Subject: [PATCH] Unicast messages on the signaling channel if needed Fix #99 --- vroom.pl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/vroom.pl b/vroom.pl index 9ca4f45..caa606c 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1064,12 +1064,24 @@ websocket '/socket.io/:ver/websocket/:id' => sub { # We have a message from a peer elsif ($msg->{data}->{name} eq 'message'){ $self->app->log->debug("Signaling message received from peer " . $id); - # Forward this message to all other members of the same room $msg->{data}->{args}[0]->{from} = $id; - $self->signal_broadcast_room({ - from => $id, - msg => Protocol::SocketIO::Message->new(%$msg) - }); + my $to = $msg->{data}->{args}[0]->{to}; + # Unicast message ? Check the dest is in the same room + # and send + if ($to && + $peers->{$to} && + $peers->{$to}->{room} && + $peers->{$to}->{room} eq $peers->{$id}->{room} && + $peers->{$to}->{socket}){ + $peers->{$to}->{socket}->send(Protocol::SocketIO::Message->new(%$msg)); + } + # No dest, multicast this to every memebrs of the room + else{ + $self->signal_broadcast_room({ + from => $id, + msg => Protocol::SocketIO::Message->new(%$msg) + }); + } } # When a peer share its screen elsif ($msg->{data}->{name} eq 'shareScreen'){