Keep connections alive

This commit is contained in:
Robin Linus 2015-12-31 00:42:53 +01:00
parent 3b4784e8eb
commit 00aa38564c
2 changed files with 80 additions and 94 deletions

View file

@ -23,7 +23,6 @@
}.bind(this); }.bind(this);
}, },
initialize: function() { initialize: function() {
if (window.isActive) {
clearInterval(this.reconnectTimer); clearInterval(this.reconnectTimer);
this.reconnectTimer = undefined; this.reconnectTimer = undefined;
var options; var options;
@ -65,7 +64,6 @@
return; return;
} }
}.bind(this)); }.bind(this));
}
}, },
connect: function(c) { connect: function(c) {

View file

@ -9,23 +9,12 @@
</template> </template>
<script> <script>
'use strict'; 'use strict';
window.isActive = true;
window.onfocus = function() {
window.isActive = true;
};
window.onblur = function() {
window.isActive = false;
};
Polymer({ Polymer({
is: 'web-socket', is: 'web-socket',
attached: function() { attached: function() {
this.init(); this.init();
}, },
init: function() { init: function() {
if (window.isActive) {
clearInterval(this.reconnectTimer); clearInterval(this.reconnectTimer);
this.reconnectTimer = undefined; this.reconnectTimer = undefined;
var websocketUrl = (window.debug ? 'ws://' + window.location.hostname + ':3002' : 'wss://snapdrop.net') + '/binary'; var websocketUrl = (window.debug ? 'ws://' + window.location.hostname + ':3002' : 'wss://snapdrop.net') + '/binary';
@ -70,7 +59,6 @@
this.client.on('close', function(e) { this.client.on('close', function(e) {
this._reconnect(e); this._reconnect(e);
}.bind(this)); }.bind(this));
}
}, },
_sendFile: function(toPeer, file) { _sendFile: function(toPeer, file) {
console.log('send file via WebSocket', file); console.log('send file via WebSocket', file);