MT#19795 API improvements RTC sessions and networks

- the connector name is properly set when creating a reseller
- the network tag defaults to just (sip,xmpp,webrtc,...)
- rtcsessions doesn't accept network tag anymore
- an rtc-account is created for every network of the rtc-user
- the identifier in the rtc-account is set according to the specific connector
- api-rtc-full.t has been simplified for the user (no more need for domain_id)
- update available networks (in reseller api)

Change-Id: I2700c646726a06569cc5a70a5a30d4cb67eb1c80
changes/32/6332/4
Gerhard Jungwirth 9 years ago
parent 9f892f5fe2
commit 13e5e31de4

@ -25,10 +25,10 @@ has_field 'rtc_networks' => (
required => '0',
widget => 'CheckboxGroup',
options => [
{ value => 'sip', label => 'SIP Only' },
{ value => 'xmpp', label => 'XMPP Only' },
{ value => 'sipwise', label => 'SIP and XMPP' },
{ value => 'webrtc', label => 'WebRTC Only' },
{ value => 'sip', label => 'SIP' },
{ value => 'xmpp', label => 'XMPP' },
{ value => 'webrtc', label => 'WebRTC' },
{ value => 'conference', label => 'Conference' },
],
element_attr => {
rel => ['tooltip'],

@ -37,8 +37,27 @@ sub login {
return;
}
# outdated: only one account (with one network) for the session
sub create_session_and_account {
my ($self, $appid, $network, $identifier, $accessToken, $owner, $account_config) = @_;
my ($self, $appid, $network_tag, $identifier, $access_token, $owner, $account_config) = @_;
my $session = $self->create_session($appid, $owner);
$session->{data}{accounts} = [] if($session->{data});
my $account = $self->create_account(
$session->{data}{id},
$owner,
$identifier,
$network_tag,
$access_token,
$account_config );
push @{ $session->{data}{accounts} }, $account->{data};
return $session;
}
sub create_session {
my ($self, $appid, $owner) = @_;
my $ua = $self->ua;
my $session_content = encode_json({
app => $appid,
@ -47,35 +66,27 @@ sub create_session_and_account {
my $session = $self->_create_response(
$ua->post($self->host . '/sessions', 'Content-Type' => 'application/json', Content => $session_content),
);
return $session;
}
sub create_account {
my ($self, $session_id, $owner, $identifier, $network_tag, $access_token, $account_config) = @_;
my $ua = $self->ua;
my $account_content = encode_json({
session => $session->{data}{id},
network => $network,
session => $session_id,
network => $network_tag,
identifier => $identifier,
accessToken => $accessToken,
accessToken => $access_token,
owner => $owner,
$account_config ? (config => encode_json($account_config)) : (),
});
#p $account_content;
my $account = $self->_create_response(
$ua->post($self->host . '/accounts', 'Content-Type' => 'application/json', Content => $account_content),
);
$account->{data}{session} = $session->{data};
return $account;
}
sub create_session {
my ($self, $appid, $owner) = @_;
my $ua = $self->ua;
my $session_content = encode_json({
app => $appid,
owner => $owner,
});
my $session = $self->_create_response(
$ua->post($self->host . '/sessions', 'Content-Type' => 'application/json', Content => $session_content),
);
return $session;
}
sub create_network {
my ($self, $tag, $connector, $config, $owner) = @_;
my $ua = $self->ua;

@ -116,9 +116,15 @@ sub _create_rtc_user {
# 5. create related networks
for my $n (@{ $rtc_networks }) {
my $connector;
if ($n =~ m/^(sip|xmpp)$/) {
$connector = "$n-connector";
} else {
$connector = $n;
}
my $n_response = $comx->create_network(
$reseller_name . "_$n",
$n . '-connector',
$n,
$connector,
{xms => JSON::false},
$user->{data}{id},
);
@ -520,31 +526,47 @@ sub create_rtc_session {
}
my $comx_networks = $comx->get_networks_by_user_id($rtc_user->rtc_user_id);
my $comx_network;
if ($comx_networks->{data} && @{ $comx_networks->{data} }){
($comx_network) = grep { $_->{tag} eq $resource->{rtc_network_tag} } @{ $comx_networks->{data} };
}
unless ($comx_network) {
my $comx_network_tags = [];
if ($comx_networks->{data} && 'ARRAY' eq ref $comx_networks->{data}) {
$comx_network_tags = [ map { $_->{tag} } @{ $comx_networks->{data} } ];
} else {
return unless &{$err_code}(
'create_rtc_session: Could not find network with specified tag.');
'create_rtc_session: Could not fetch networks for given rtc user.');
}
my $account = $comx->create_session_and_account(
my $session = $comx->create_session(
$comx_app->{id},
$resource->{rtc_network_tag},
'sip:' . $subscriber_item->username . '@' . $subscriber_item->domain->domain,
$subscriber_item->provisioning_voip_subscriber->password,
$rtc_user->rtc_user_id,
{xms => JSON::false},
);
if ($account->{code} != 201) {
if ($session->{code} != 201) {
return unless &{$err_code}(
'Creating rtc session and account failed. Error code: ' . $account->{code});
'Creating rtc session failed. Error code: ' . $session->{code});
}
for my $n (@{ $comx_networks->{data} }) {
my $identifier;
if ($n->{connector} eq "sip-connector") {
$identifier = 'sip:' . $subscriber_item->username . '@' . $subscriber_item->domain->domain;
} elsif ($n->{connector} eq "xmpp-connector") {
$identifier = 'xmpp:' . $subscriber_item->username . '@' . $subscriber_item->domain->domain;
} else { # webrtc, ...
$identifier = $subscriber_item->username;
}
my $account = $comx->create_account(
$session->{data}{id},
$rtc_user->rtc_user_id,
$identifier,
$n->{tag},
$subscriber_item->provisioning_voip_subscriber->password,
{xms => JSON::false},
);
if ($account->{code} != 201) {
return unless &{$err_code}(
"Creating rtc account ($n->{tag}) failed. Error code: " . $account->{code});
}
}
my $rtc_session_item = $subscriber_item->provisioning_voip_subscriber->create_related('rtc_session', {
rtc_network_tag => $resource->{rtc_network_tag},
rtc_session_id => $account->{data}{session}{id},
rtc_session_id => $session->{data}{id},
});
return $rtc_session_item;
}

@ -16,11 +16,14 @@ unless ($ENV{TEST_RTC}) {
exit 0;
}
my $domain_id = $ENV{TEST_RTC_DOMAIN_ID} // 3;
my $uri = $ENV{CATALYST_SERVER} || ('https://'.hostfqdn.':4443');
my ($netloc) = ($uri =~ m!^https?://(.*)/?.*$!);
my $domain_name = $ENV{TEST_RTC_DOMAIN};
unless ($domain_name) {
($domain_name) = ($uri =~ m!^https?://([^/:]*)(:[0-9]+)?/?.*$!);
}
my ($ua, $req, $res, $data);
$ua = LWP::UserAgent->new;
@ -32,6 +35,23 @@ my $user = $ENV{API_USER} // 'administrator';
my $pass = $ENV{API_PASS} // 'administrator';
$ua->credentials($netloc, "api_admin_http", $user, $pass);
my ($domain_id);
{
$req = HTTP::Request->new('GET', "$uri/api/domains/?domain=$domain_name");
$res = $ua->request($req);
is($res->code, 200, "GET search domain");
$data = JSON::from_json($res->decoded_content);
ok($data->{total_count}, "got at least one domain") || die "we can't continue without domain";
my $selected_domain = ( 'ARRAY' eq ref $data->{_embedded}{'ngcp:domains'} )
? $data->{_embedded}{'ngcp:domains'}[0]
: $data->{_embedded}{'ngcp:domains'};
$domain_id = $selected_domain->{id};
$domain_name = $selected_domain->{domain};
diag("domain: $selected_domain->{domain} ($domain_id)");
}
my ($contract_id, $reseller_id, $customer_id, $bprof_id, $customercontact_id, $network_tag);
{
@ -57,7 +77,7 @@ my ($contract_id, $reseller_id, $customer_id, $bprof_id, $customercontact_id, $n
name => 'rtc test reseller ' . time,
enable_rtc => JSON::true,
status => 'active',
rtc_networks => ['sip'],
rtc_networks => ['sip','xmpp','webrtc'],
}));
$res = $ua->request($req);
is($res->code, 201, "POST create reseller");
@ -77,7 +97,7 @@ my ($contract_id, $reseller_id, $customer_id, $bprof_id, $customercontact_id, $n
is($data->{networks}[0]{connector}, 'sip-connector', "rtcnetwork exists");
$network_tag = $data->{networks}[0]{tag};
diag("reseller id: $reseller_id , network_tag: $network_tag");
diag("reseller id: $reseller_id , first network_tag: $network_tag");
$req = HTTP::Request->new('POST', $uri.'/api/billingprofiles/');
$req->header('Content-Type' => 'application/json');
@ -152,7 +172,7 @@ my ($sub1_id, $sub1_name, $sub2_id, $sub2_name);
$res = $ua->request($req);
is($res->code, 200, "PATCH set subscriberpreferences sub1");
diag("subscriber $sub1_name: $sub1_id");
diag("subscriber $sub1_name\@$domain_name (pass: $sub1_name, id: $sub1_id)");
$req = HTTP::Request->new('POST', $uri.'/api/subscribers/');
$req->header('Content-Type' => 'application/json');
@ -179,7 +199,11 @@ my ($sub1_id, $sub1_name, $sub2_id, $sub2_name);
$res = $ua->request($req);
is($res->code, 200, "PATCH set subscriberpreferences sub2");
diag("subscriber $sub2_name: $sub2_id");
diag("subscriber $sub2_name\@$domain_name (pass: $sub2_name, id: $sub2_id)");
diag("you can now create new session using:");
my $noport_uri = ($uri =~ s/:[0-9]+//r);
diag(" curl -XPOST -v -k --user $sub1_name\@$domain_name:$sub1_name -H'Content-Type: application/json' $noport_uri/api/rtcsessions/ --data-binary '{}'");
diag(" curl -XPOST -v -k --user $sub2_name\@$domain_name:$sub2_name -H'Content-Type: application/json' $noport_uri/api/rtcsessions/ --data-binary '{}'");
}
done_testing;
done_testing;

Loading…
Cancel
Save