Reinstate signed in message.

Fix multiple attempted reconnects issue.
This commit is contained in:
burke.davey
2011-05-16 03:02:33 +00:00
parent 6f0d6f2030
commit df5ab94edb
3 changed files with 13 additions and 5 deletions

View File

@@ -38,6 +38,10 @@ body, td {
if (oauth.hasToken()) {
document.getElementById('sign_in_out_div').innerHTML =
'<a href="help.html" onclick="chrome.extension.getBackgroundPage().closeBrowserChannel(); oauth.clearTokens()">' + chrome.i18n.getMessage('sign_out_message');
if (document.location.hash == '#just_signed_in') {
document.getElementById('just_signed_in_div').innerHTML = '<p><b><font color="#00A000">' +
chrome.i18n.getMessage('signed_in_message') + '</font></b></p>';
}
} else {
var sign_in_message = chrome.i18n.getMessage('sign_in_message');
sign_in_message = sign_in_message.substring(0, 1).toUpperCase() + sign_in_message.substring(1); // TODO: Get a new title case string translated
@@ -53,6 +57,8 @@ body, td {
<b><div id="msg"></div></b><a id="signout" href="#" style="color: gray;"></a></p>
<h1><img src="icon_128.png" width="64" height="64" valign="bottom">&nbsp;Google Chrome to Phone Extension</h1>
<div id="just_signed_in_div"></div>
<h2 style="padding-left: 10px"><script>document.write(chrome.i18n.getMessage('about_title_message'));</script></h2>
<p style="padding-left: 10px"><script>document.write(chrome.i18n.getMessage('about_message'));</script></p>

View File

@@ -44,7 +44,7 @@ body {
// End of the oauth request flow, get access token
oauth.initOAuthFlow(function(token, secret) {
chrome.extension.getBackgroundPage().initializeBrowserChannel();
window.location = 'help.html';
window.location = 'help.html#just_signed_in';
});
} else {
oauth.initOAuthFlow(function(token, secret) {

View File

@@ -119,6 +119,7 @@ function initializeBrowserChannel() {
if (req.status == 200) {
var channelId = req.responseText.substring(3).trim(); // expect 'OK <id>';
channel = new goog.appengine.Channel(channelId);
console.log(new Date().toTimeString() + ' Opening channel...');
socket = channel.open();
socket.onopen = function() {
console.log(new Date().toTimeString() + ' Browser channel initialized');
@@ -126,17 +127,18 @@ function initializeBrowserChannel() {
socket.onclose = function() {
console.log(new Date().toTimeString() + ' Browser channel closed');
if (!socketCloseRequested) {
console.log(new Date().toTimeString() + ' Reconnecting...');
setTimeout('initializeBrowserChannel()', 0);
}
}
socket.onerror = function(error) {
if (error.code == 401) { // token expiry
console.log(new Date().toTimeString() + ' Browser channel token expired - reconnecting');
// Reconnects in onclose()
console.log(new Date().toTimeString() + ' Browser channel token expired');
} else {
console.log(new Date().toTimeString() + ' Browser channel error - reconnecting');
setTimeout('initializeBrowserChannel()', 0);
console.log(new Date().toTimeString() + ' Browser channel error');
socket.close();
}
// Reconnects in onclose()
}
socket.onmessage = function(evt) {
console.log("Onmessage " + evt.data);