Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Online State Bug Fix and User Simulring #147

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions OpenVBX/models/vbx_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ static function search($search_options = array(), $limit = -1, $offset = 0)
foreach($users as $i => $user)
{
$users[$i]->devices = VBX_Device::search(array('user_id' => $user->id), 100);
}

if ($users[$i]->online) {
array_unshift($users[$i]->devices, new VBX_Device((object) array(
if ($users[$i]->online && $users[$i]->online != 9) {
array_unshift($users[$i]->devices, new VBX_Device((object) array(
'id' => 0,
'name' => 'client',
'value' => 'client:'.$users[$i]->id,
Expand All @@ -102,6 +101,7 @@ static function search($search_options = array(), $limit = -1, $offset = 0)
'is_active' => 1,
'user_id' => $users[$i]->id
)));
}
}

if($limit == 1
Expand Down
49 changes: 31 additions & 18 deletions plugins/standard/applets/dial/TwimlDial.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ public function dial($device_or_user) {

return $dialed;
}

protected function createDial($number = NULL, $append_to_response = true) {
if (empty($this->dial)) {
$this->dial = new Dial($number, array(
'action' => current_url(),
'callerId' => $this->callerId
));
}

if ($append_to_response)
$this->appendDial();

return $this->dial;
}

protected function appendDial() {
if (!empty($this->dial) && empty($this->dial_appended)) {
$this->response->append($this->dial);
$this->dial_appended = true;
}
}

/**
* Add a device to the Dialer
Expand All @@ -76,19 +97,15 @@ public function dialDevice($device) {
'url' => site_url('twiml/whisper?name='.urlencode($user->first_name)),
);

$dial = new Dial(NULL, array(
'action' => current_url(),
'callerId' => $this->callerId
));
$this->createDial();

if (strpos($device->value, 'client:') !== false) {
$dial->addClient(str_replace('client:', '', $device->value), $call_opts);
$this->dial->addClient(str_replace('client:', '', $device->value), $call_opts);
}
else {
$dial->addNumber($device->value, $call_opts);
$this->dial->addNumber($device->value, $call_opts);
}

$this->response->append($dial);
$dialed = true;
}
return $dialed;
Expand All @@ -105,10 +122,7 @@ public function dialUser($user) {
// get users devices and add all active devices to do simultaneous dialing
$dialed = false;
if (count($user->devices)) {
$dial = new Dial(NULL, array(
'action' => current_url(),
'callerId' => $this->callerId
));
$this->createDial(NULL, false);

$call_opts = array(
'url' => site_url('twiml/whisper?name='.urlencode($user->first_name)),
Expand All @@ -117,19 +131,18 @@ public function dialUser($user) {
foreach ($user->devices as $device) {
if ($device->is_active) {
if (strpos($device->value, 'client:') !== false) {
$dial->addClient(str_replace('client:', '', $device->value), $call_opts);
$this->dial->addClient(str_replace('client:', '', $device->value), $call_opts);
}
else {
$dial->addNumber($device->value, $call_opts);
$this->dial->addNumber($device->value, $call_opts);
}
$dialed = true;
break;
}
}
}

if ($dialed) {
$this->response->append($dial);
$this->appendDial();
}
return $dialed;
}
Expand All @@ -141,8 +154,8 @@ public function dialUser($user) {
* @return bool
*/
public function dialNumber($number) {
$dialed = false;
$this->response->addDial($number);
$this->createDial($number);

return true;
}

Expand Down Expand Up @@ -328,4 +341,4 @@ public function save_state() {
}
}

?>
?>
14 changes: 7 additions & 7 deletions plugins/standard/applets/dial/twiml.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
do {
$to_dial = $dial_list->next();
if ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device) {
$dialed = $dialer->dial($to_dial);
if ($dialed) {
$dialer->state = $dial_list->get_state();
}
$dialed = $dialer->dial($to_dial) || $dialed;
}
} while(!$dialed && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device));
} while((!$dialed || $dial_list instanceof DialListUser) && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device));

if (!$dialed) {
if ($dialed) {
$dialer->state = $dial_list->get_state();
}
else {
// nobody to call, push directly to voicemail
$dialer->noanswer();
}
Expand Down Expand Up @@ -72,7 +72,7 @@
$dialer->state = $dial_list->get_state();
}
}
} while(!$dialed && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device));
} while((!$dialed || $dial_list instanceof DialListUser) && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device));

if (!$dialed) {
// no users left see what next action is, or go to voicemail
Expand Down