visibility api

box-drawing
Ondřej Hruška 7 years ago
parent b51a2d1b54
commit 865efe41f7
  1. 19
      js/term_conn.js

@ -19,15 +19,16 @@ module.exports = class TermConnection extends EventEmitter {
this.pageShown = false this.pageShown = false
window.addEventListener('focus', () => { document.addEventListener('visibilitychange', () => {
console.info('Window got focus, re-connecting') if (document.hidden === true) {
this.init() console.info('Window lost focus, freeing socket')
}) this.closeSocket()
window.addEventListener('blur', () => { clearTimeout(this.heartbeatTimeout)
console.info('Window lost focus, freeing socket') } else {
this.closeSocket() console.info('Window got focus, re-connecting')
clearTimeout(this.heartbeatTimeout) this.init()
}) }
}, false)
} }
onWSOpen (evt) { onWSOpen (evt) {

Loading…
Cancel
Save