Skip to content

Commit

Permalink
ignore rogue matrix call events; support verto.media RPC as a horribl…
Browse files Browse the repository at this point in the history
…e hack; fix NA::Matrix dep
  • Loading branch information
ara4n authored and Paul "LeoNerd" Evans committed Dec 2, 2014
1 parent 72c1cc7 commit 9f4abd5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
3 changes: 2 additions & 1 deletion contrib/vertobot/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vuc.yaml
vucbot.yaml
vertobot.yaml
49 changes: 30 additions & 19 deletions contrib/vertobot/bot.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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;
Expand Down Expand Up @@ -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}";
Expand Down Expand Up @@ -253,27 +258,33 @@ sub on_room_message
{
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}) {
Expand Down
2 changes: 1 addition & 1 deletion contrib/vertobot/cpanfile
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 9f4abd5

Please sign in to comment.