Skip to content

Commit

Permalink
JS fixes and final tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gipetto committed Jul 25, 2011
1 parent c1ac8ae commit c6143f3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .htaccess
Expand Up @@ -13,4 +13,4 @@ RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?vbxsite=$1 [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L,QSA]
#RewriteRule ^(.*) index.php/$1 [L,QSA]

ErrorDocument 404 /fallback/rewrite.php
ErrorDocument 404 /fallback/rewrite.php
6 changes: 6 additions & 0 deletions OpenVBX/controllers/iframe.php
Expand Up @@ -32,6 +32,12 @@ function index() {
'site_title' => 'OpenVBX',
'iframe_url' => site_url('/messages')
);

// if the 'last_known_url' cookie is set then we've been redirected IN to frames mode
if (!empty($_COOKIE['last_known_url'])) {
$data['iframe_url'] = $_COOKIE['last_known_url'];
setcookie('last_known_url', '', time() - 3600);
}

if (!empty($this->application_sid))
{
Expand Down
6 changes: 6 additions & 0 deletions OpenVBX/views/layout/template.php
Expand Up @@ -53,5 +53,11 @@
<?php echo $analytics; ?>
<?php $this->load->view('js-init'); ?>
<?php echo $_scripts; ?>
<script type="text/javascript">
if (window == window.top) {
$.cookie('last_known_url', window.location, null, '/');
window.location = OpenVBX.home;
}
</script>
</body>
</html>
40 changes: 38 additions & 2 deletions assets/j/client.js
Expand Up @@ -22,14 +22,16 @@ var Client = {
connection: false,

onready: function(){},

incoming_timeout: null,

options: {
cookie_name: 'vbx_client_call',
check_timeout: 5000 // how often the parent window should check client window status
},

message: function (status) {
console.log(status);
//console.log(status);
$('#client-ui-message').text(status);
},

Expand All @@ -45,6 +47,7 @@ var Client = {
});

Twilio.Device.error(function (error) {
console.log(error);
Client.error(error);
});

Expand All @@ -53,15 +56,29 @@ var Client = {
});

Twilio.Device.disconnect(function (conn) {
console.log('disconnect');
Client.disconnect(conn);
});

Twilio.Device.incoming(function (conn) {
console.log(conn);
console.log('incoming');
Client.incoming(conn);
});

Twilio.Device.cancel(function(conn) {
console.log('canceled');
Client.cancel();
});
},

setOnBeforeUnload: function(status) {
window.onbeforeunload = (status) ? this.onBeforeUnloadWarning : null;
},

onBeforeUnloadWarning: function() {
return 'You are currently on a call. Refreshing this page will cause the call to drop. Do you really want to leave this page?';
},

translateKeyCode: function (code) {
var number = code - 48;

Expand Down Expand Up @@ -97,20 +114,30 @@ var Client = {
}
},

giveUpIncoming: function() {
if (this.incoming) {
this.connection.cancel();
}
this.status.setCallStatus(false);
setTimeout('Client.ui.toggleCallView()', 1000);
},

// listeners

incoming: function (connection) {
window.focus();
this.message('Incoming call from: ' + connection.parameters.From);
if (!this.connection) {
this.connection = connection;
this.incoming_timeout = setTimeout('Client.giveUpIncoming()', 15000);
// notify user of incoming call in future versions
Client.ui.toggleCallView();
Client.ui.show('answer');
}
},

accept: function (connection) {
clearTimeout(this.incoming_timeout);
this.connection.accept();
},

Expand All @@ -125,14 +152,23 @@ var Client = {
this.ui.show('hangup');
this.status.setCallStatus(true);
this.message('Calling');
this.setOnBeforeUnload(true);
},

disconnect: function (conn) {
this.ui.endTick();
this.status.setCallStatus(false);
this.message('Call ended');
this.setOnBeforeUnload(false);
setTimeout('Client.ui.toggleCallView()', 3000);
},

cancel: function(conn) {
this.ui.endTick();
this.status.setCallStatus(false);
this.message('Call cancelled');
setTimeout('Client.ui.toggleCallView()', 1000);
},

offline: function (device) {
this.status.setCallStatus(false);
Expand Down
1 change: 1 addition & 0 deletions assets/j/flow.js
Expand Up @@ -151,6 +151,7 @@ Flows.link = {
} else {
data[this.name] = val;
}
console.log(this.name + ' :: ' + val);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion assets/j/iframe.js
Expand Up @@ -2,7 +2,7 @@ $(document).ready(function() {
$('iframe').load(function(e) {
var href = $(this).contents().attr('URL');
var title = $(this).contents().attr('title');

// Replace the current state's URL
if(history && history.replaceState) {
history.replaceState({}, title, href);
Expand Down

0 comments on commit c6143f3

Please sign in to comment.