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

Commit

Permalink
modify socket disconnect function
Browse files Browse the repository at this point in the history
  • Loading branch information
dxue committed May 29, 2015
1 parent 7d71321 commit c1de921
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pcsyncclient/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ <h1 data-l10n-id="content-region-header"></h1>
</p>
</section>
<menu>
<button id="accept-button" type="button" data-l10n-id="accept"></button>
<button id="reject-button" type="button" data-l10n-id="reject"></button>
<button id="accept-button" type="button" data-l10n-id="accept"></button>
</menu>
</form>
</section>
Expand Down
2 changes: 1 addition & 1 deletion pcsyncclient/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ App.prototype.getWifiCode = function() {
this.wifiEnabled = false;
this.uiManager.updateWifiCode(this.ipAddress);
this.uiManager.loading(false);
}.bind(this), 10000);
}.bind(this), 30000);
};

exports.App = App;
Expand Down
32 changes: 25 additions & 7 deletions pcsyncclient/js/server_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,34 @@ ServerManager.prototype.init = function() {
this.createServer();
};

ServerManager.prototype.restart = function() {
ServerManager.prototype.disconnect = function() {
if (this.dataSocketWrapper) {
this.dataSocketWrapper.socket.close();
this.dataSocketWrapper = null;
} else {
if (this.mainSocketWrapper) {
this.mainSocketWrapper.socket.close();
this.mainSocketWrapper = null;
}
this.app.uiManager.showConnectedPage(false);
this.app.handlersManager.reset();
}
};

ServerManager.prototype.reject = function() {
if (this.mainSocketWrapper) {
this.mainSocketWrapper.socket.close();
this.mainSocketWrapper = null;
}
this.app.uiManager.showConnectedPage(false);
};

ServerManager.prototype.restart = function() {
if (this.server) {
this.server.close();
this.server = null;
}
this.createServer();
this.app.uiManager.showConnectedPage(false);
this.app.handlersManager.reset();
};

ServerManager.prototype.createServer = function() {
Expand All @@ -60,12 +72,14 @@ ServerManager.prototype.createServer = function() {
onerror: function() {
console.log('Error occured in main socket.');
this.mainSocketWrapper = null;
this.restart();
this.dataSocketWrapper = null;
this.disconnect();
}.bind(this),
onclose: function() {
console.log('Main socket closed.');
this.mainSocketWrapper = null;
this.restart();
this.dataSocketWrapper = null;
this.disconnect();
}.bind(this)
});

Expand All @@ -87,12 +101,16 @@ ServerManager.prototype.createServer = function() {
onerror: function() {
console.log('Error occured in data socket.');
this.dataSocketWrapper = null;
this.restart();
if (this.mainSocketWrapper) {
this.mainSocketWrapper.socket.close();
}
}.bind(this),
onclose: function() {
console.log('Data socket closed.');
this.dataSocketWrapper = null;
this.restart();
if (this.mainSocketWrapper) {
this.mainSocketWrapper.socket.close();
}
}.bind(this),
onmessage:
this.app.handlersManager.handleMessage.bind(this.app.handlersManager)
Expand Down
6 changes: 4 additions & 2 deletions pcsyncclient/js/ui_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ UIManager.prototype.init = function() {

var disconnectButton = document.getElementById('button-disconnect');
disconnectButton.onclick = function(event) {
this.app.reset();
document.getElementById('button-disconnect').disabled = true;
this.app.serverManager.disconnect();
}.bind(this);

var reconnectButton = document.getElementById('button-restart-service');
Expand All @@ -48,6 +49,7 @@ UIManager.prototype.init = function() {
};

document.getElementById('accept-button').onclick = function () {
document.getElementById('button-disconnect').disabled = false;
document.getElementById('custom-confirm').classList.add('hidden');
var dataJson = {
id: CMD_ID.app_accepted,
Expand All @@ -65,7 +67,7 @@ UIManager.prototype.init = function() {
datalength: 0
};
this.app.serverManager.mainSocketWrapper.send(dataJson, null);
this.app.serverManager.restart();
this.app.serverManager.reject();
}.bind(this);

this.showConnectedPage(false);
Expand Down
4 changes: 2 additions & 2 deletions pcsyncclient/locales/pcsyncclient.en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ help-usb-link=http://os.firefox.com.cn/pcsync.html
unconnect-view-version = Version: 3.2
access_confirm=Allow remote app to access your device
accept=Accept
reject=Reject
accept=Allow
reject=Don't allow

0 comments on commit c1de921

Please sign in to comment.