Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
piphone-front
Commits
1ac1f950
Commit
1ac1f950
authored
Aug 17, 2016
by
okhin
Browse files
FIX #4 creating the call to the backend-sip works (but we now have issues there)
parent
0898e976
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/Api.php
View file @
1ac1f950
...
...
@@ -35,6 +35,12 @@ class Api {
return
json_decode
(
$json
,
true
);
}
// Asking for a single contact
static
function
get_contact
(
$id
)
{
$json
=
Api
::
get
(
"campaigns/"
.
CAMPAIGN_ID
.
"/contacts/"
.
$id
);
return
json_decode
(
$json
,
true
);
}
// Asking for complete list of groups
static
function
get_groups
()
{
$json
=
Api
::
get
(
"campaigns/"
.
CAMPAIGN_ID
.
"/groups"
);
...
...
app/Main.php
View file @
1ac1f950
<?php
use
\
Firebase\JWT\JWT
;
use
Psr\Http\Message\ResponseInterface
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Psr7
;
use
GuzzleHttp\Exception\RequestException
;
class
Main
extends
Controller
{
/*
...
...
@@ -14,7 +18,7 @@ class Main extends Controller {
$contacts
=
$f3
->
get
(
'contacts'
);
$f3
->
set
(
'contact'
,
$contacts
[
$rand_id
]);
$f3
->
set
(
'random'
,
rand
(
0
,
2
));
$f3
->
set
(
'block_content'
,
'home.html'
);
$f3
->
set
(
'block_content'
,
'home.html'
);
}
/*
...
...
@@ -32,12 +36,6 @@ class Main extends Controller {
$contact_id
=
$f3
->
get
(
'POST.contact_id'
);
$f3
->
set
(
"contact_id"
,
$contact_id
);
// Generate a jwt token
$token
=
JWT
::
encode
(
array
(
'api'
=>
JWT_TOKEN
),
JWT_KEY
);
//TODO: create call
//TODO: start call
$f3
->
set
(
'block_content'
,
'feedbackform.html'
);
}
//POST
...
...
@@ -68,16 +66,37 @@ class Main extends Controller {
function
call
(
$f3
,
$args
)
{
//GET
if
(
$f3
->
get
(
'VERB'
)
==
'GET'
)
{
$f3
->
set
(
'contact'
,
Api
::
get_contact
());
//$args['id']
$f3
->
set
(
'contact'
,
Api
::
get_contact
(
$args
[
'id'
]));
$f3
->
set
(
'block_content'
,
'call.html'
);
}
//POST
elseif
(
$f3
->
get
(
'VERB'
)
==
'POST'
){
//GET feedbackform
$f3
->
set
(
'VERB'
,
'GET'
);
$this
->
feedbackform
(
$f3
,
$args
);
}
// Create the call
// Generate a jwt token
$token
=
JWT
::
encode
(
array
(
'api'
=>
JWT_TOKEN
),
JWT_KEY
);
// To get the callee, we have the callee_id in the form. Using that
// to load the callee and retrieve its number.
$contact
=
Api
::
get_contact
(
$args
[
'id'
]);
$f3
->
set
(
'contact'
,
$contact
);
$data
=
array
(
'api'
=>
'piphone'
,
'caller'
=>
$f3
->
get
(
'POST.phone'
),
'callee'
=>
$contact
[
'phone'
],
'token'
=>
$token
);
// We want to generate a UNIQUE-ID (doesn't need to be cryptogaphically unique though
$call_id
=
uniqid
();
$f3
->
set
(
'CALL_ID'
,
$call_id
);
// Create the call
$client
=
new
GuzzleHttp\Client
([
'base_uri'
=>
SIP_API
]);
try
{
$res
=
$client
->
post
(
"calls/
$call_id
"
,
[
'query'
=>
$data
]);
$f3
->
set
(
'call'
,
json_decode
(
$res
->
getBody
()));
$f3
->
set
(
'VERB'
,
'GET'
);
$this
->
feedbackform
(
$f3
,
$args
);
}
catch
(
RequestException
$e
)
{
echo
Psr7\str
(
$e
->
getRequest
());
if
(
$e
->
hasResponse
())
{
echo
Psr7\str
(
$e
->
getResponse
());
}
}
}
}
function
contactslist
(
$f3
,
$args
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment