Commit cc7cda6b authored by okhin's avatar okhin 🚴

Removing the SIP logic from the frontend

parent 13d8dc93
Pipeline #2418 passed with stages
in 10 seconds
......@@ -90,23 +90,5 @@ class Api {
$json = Api::post("campaigns/" . CAMPAIGN_ID . "/feedbacks", $data);
return json_decode($json, true);
}
// Getting a call from the SIP_API
static function get_sip_call($call_id, $token) {
$data = array('api' => JWT_TOKEN,
'token' => $token
);
$client = new GuzzleHttp\Client(['base_uri' => SIP_ARI]);
try {
$res = $client->get("calls/$call_id", ['query' => $data]);
return (GuzzleHttp\Psr7\copy_to_string($res->getBody()));
} catch (RequestException $e) {
return Psr7\str($e->getRequest());
if ($e->hasResponse()) {
echo Psr7\str($e->getResponse());
}
}
}
};
......@@ -82,21 +82,6 @@ class Main extends Controller {
// We want to generate a UNIQUE-ID (doesn't need to be cryptogaphically unique though
$call_id = str_replace('.', '-', uniqid('', true));
$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', GuzzleHttp\Psr7\copy_to_string($res->getBody()));
$f3->set('VERB', 'GET');
$this->feedbackform($f3, $args);
} catch (RequestException $e) {
$block_content = Psr7\str($e->getRequest());
if ($e->hasResponse()) {
$block_content .= Psr7\str($e->getResponse());
}
$f3->set('block_content', $block_content);
}
}
}
......
......@@ -8,7 +8,7 @@
<div class="modal-body">
<div class="row">
<div class="col-sm-10">
<h2>{{ _("Call at your expense") }}</h2>
<h2>{{ _("Call This representative") }}</h2>
<p>{{ _("Here is the number of the selected MEP - you can either dial it from your phone or push the button if any VoIP client is installed on your device.") }}</p>
<a class="btn btn-default" href="tel:{{ @contact.phone }}" target="_blank">☎ {{ @contact.phone }}</a>
</div>
......
......@@ -27,24 +27,12 @@
<span class="card-title grey-text text-darken-4">{{ @contact.first_name }} {{ @contact.last_name }}
<i class="material-icons right">close</i>
</span>
<h5>{{ _("Call for free") }}</h5>
<h5>{{ _("Call this representative" }}</h5>
<form method="post" action="/call/{{ @contact.id }}">
<input type="text" id="contact_id" name="contact_id" hidden="hidden" value="{{ @contact.id }}">
<p>{{ _("If you want to call for free, you must provide us with your phone number
(the PiPhone will call that number to initiate the communication).") }}</p>
<div class="input-field col s12">
<label for="phone">{{_("Your phone number:") }}</label>
<input type="text" name="phone" id="phone" />
</div>
<p>
{{ _('Starting with your <a href="https://en.wikipedia.org/wiki/List_of_country_calling_codes#Zones_3-4:_Europe">country code</a>, without the initial 0') }}
</p>
<input class="btn btn-default" type="submit" value="{{ _('Call me') }}" />
</form>
</div>
<div class="card-action">
<a type="button" href="#">{{ _("More info") }}</a>
<a type="button" href="tel:{{ @contact.phone }}" target="_blank">{{ @contact.phone }}</a>
<input class="btn btn-default" type="submit" value="{{ _('Make the call') }}" />
</form>
</div>
</div>
<!-- contact page -->
<!-- Let's split this page in two -->
<div class="row green accent-4">
<div class="col s12">
<h4 id="step_init" class="step_text bold center white-text">{{ _("0. Initialising the call") }}</h5>
<h4 id="step_caller" class="step_text bold center white-text">{{ _("1. Calling you") }}</h5>
<h4 id="step_wait" class="step_text bold center white-text">{{ _("2. When ready, please dial 1 on your phone") }}</h3>
<h4 id="step_callee" class="step_text bold center white-text">{{ _("3. Calling ")}}{{ @contact.full_name }}</h5>
<h4 id="step_connected" class="step_text bold center white-text">{{ _("4. Connected to ") }}{{ @contact.full_name }}</h5>
</div>
</div>
<div class="row">
<div class="container">
<div class="col s12">
<p class="bold center">When you hear the MarioBros theme on the phone, you should press 1 to initiate the call to the representative.</p>
<p class="center">The music will play until the representatives you're calling picks up. Don't worry if it plays for a long time.</p>
</div>
</div>
</div>
<div class="row">
<div class="container">
<div class="col m6 s12">
......@@ -76,73 +59,3 @@
</div>
</div>
</div>
<!-- Let's include a script -->
<script type="text/javascript">
var call = JSON.parse('{{ @call | raw }}');
var call_url = call['data']['url'];
var interval = '';
function normalize_phone(phone) {
if (phone.startsWith('+')) {
return phone.replace('+', '00');
}
return phone;
}
function update_call(response) {
var call_history = response['data']['history'];
console.log(call_history);
var call_state = call_history.sort(function(a, b) {
var date1 = new Date(a[1]);
var date2 = new Date(b[1]);
return date2 - date1;
})[0];
$('.step_text').hide();
if (call_state[0].startsWith('Created:Init')) {
$('#step_init').show();
};
if (call_state[0].startsWith('Ringing:')) {
phone = normalize_phone(call_state[0].split(':')[1]);
caller = normalize_phone(response['data']['caller']);
callee = normalize_phone(response['data']['callee']);
if ( phone === caller) {
$('#step_caller').show();
} else {
$('#step_callee').show();
};
};
if (call_state[0].startsWith('Up:')) {
// Need to check if we're caller or callee
phone = normalize_phone(call_state[0].split(':')[1]);
caller = normalize_phone(response['data']['caller']);
callee = normalize_phone(response['data']['callee']);
if ( phone === caller) {
$('#step_wait').show();
} else {
$('#step_callee').show();
};
};
if (call_state[0].startsWith('Down:')) {
// The call as ended
clearInterval(interval);
};
console.log(call_state[0]);
};
function fetch() {
$.ajax({
method: 'GET',
url: call_url,
dataType: 'json',
complete: function(xhr, status) {
update_call(xhr.responseJSON);
}
});
};
$(document).ready(function() {
update_call(call);
interval = window.setInterval(fetch, 3000);
$('select').material_select();
});
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment