From 9f4abd59f53b84e18659928a7abf566995544597 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 28 Nov 2014 14:43:28 +0000 Subject: ignore rogue matrix call events; support verto.media RPC as a horrible hack; fix NA::Matrix dep --- contrib/vertobot/.gitignore | 3 ++- contrib/vertobot/bot.pl | 49 +++++++++++++++++++++++++++------------------ contrib/vertobot/cpanfile | 2 +- 3 files changed, 33 insertions(+), 21 deletions(-) mode change 100644 => 100755 contrib/vertobot/bot.pl diff --git a/contrib/vertobot/.gitignore b/contrib/vertobot/.gitignore index e501ebe177..071a780574 100644 --- a/contrib/vertobot/.gitignore +++ b/contrib/vertobot/.gitignore @@ -1 +1,2 @@ -vuc.yaml +vucbot.yaml +vertobot.yaml diff --git a/contrib/vertobot/bot.pl b/contrib/vertobot/bot.pl old mode 100644 new mode 100755 index 0c693cdc1d..0852905081 --- a/contrib/vertobot/bot.pl +++ b/contrib/vertobot/bot.pl @@ -6,7 +6,7 @@ use 5.010; # // use IO::Socket::SSL qw(SSL_VERIFY_NONE); use IO::Async::Loop; use Net::Async::WebSocket::Client; -use Net::Async::Matrix 0.11; +use Net::Async::Matrix 0.11_002; use JSON; use YAML; use Data::UUID; @@ -148,10 +148,15 @@ sub on_unknown_event } } elsif ($event->{type} eq 'm.call.hangup') { - send_verto_json_request("verto.bye", { - "dialogParams" => \%dp, - "sessid" => $bridgestate->{$room_id}->{sessid}, - })->get; + if ($bridgestate->{$room_id}->{matrix_callid} eq $event->{content}->{call_id}) { + send_verto_json_request("verto.bye", { + "dialogParams" => \%dp, + "sessid" => $bridgestate->{$room_id}->{sessid}, + })->get; + } + else { + warn "Ignoring unrecognised callid: ".$event->{content}->{call_id}; + } } else { warn "Unhandled event: $event->{type}"; @@ -253,27 +258,33 @@ exit 0; { my $json = JSON->new->decode( $_[0] ); if ($json->{method}) { - if ($json->{method} eq 'verto.answer') { + if (($json->{method} eq 'verto.answer' && $json->{params}->{sdp}) || + $json->{method} eq 'verto.media') { my $room_id = $roomid_by_callid->{$json->{params}->{callID}}; my $room = $bot_matrix_rooms{$room_id}; - # HACK HACK HACK HACK - $room->_do_POST_json( "/send/m.call.answer", { - call_id => $bridgestate->{$room_id}->{matrix_callid}, - version => 0, - answer => { - sdp => $json->{params}->{sdp}, - type => "answer", - }, - })->then( sub { - send_verto_json_response( { - method => "verto.answer", - }, $json->{id}); - })->get; + if ($json->{params}->{sdp}) { + # HACK HACK HACK HACK + $room->_do_POST_json( "/send/m.call.answer", { + call_id => $bridgestate->{$room_id}->{matrix_callid}, + version => 0, + answer => { + sdp => $json->{params}->{sdp}, + type => "answer", + }, + })->then( sub { + send_verto_json_response( { + method => $json->{method}, + }, $json->{id}); + })->get; + } } else { warn ("[Verto] unhandled method: " . $json->{method}); + send_verto_json_response( { + method => $json->{method}, + }, $json->{id}); } } elsif ($json->{result}) { diff --git a/contrib/vertobot/cpanfile b/contrib/vertobot/cpanfile index 239258d4ac..c29fcaa6f6 100644 --- a/contrib/vertobot/cpanfile +++ b/contrib/vertobot/cpanfile @@ -1,6 +1,6 @@ requires 'parent', 0; requires 'Future', '>= 0.29'; -requires 'Net::Async::Matrix', '>= 0.11'; +requires 'Net::Async::Matrix', '>= 0.11_002'; requires 'Net::Async::Matrix::Utils'; requires 'Net::Async::WebSocket::Protocol', 0; requires 'Data::UUID', 0; -- cgit 1.4.1