code: function visibilityChange(ev) {  // {{{2
    var that = this;
  
    if (this.visibilityTimeout) {
      clearTimeout(this.visibilityTimeout);
      this.visibilityTimeout = undefined;
    }
  
    switch (document.visibilityState) {
    case 'hidden':
  //    console.log('DOCUMENT HIDE');
  
      // Wait 10 seconds before peer disconnect.
      this.visibilityTimeout = setTimeout(function() {
        that.visibilityTimeout = undefined;
        O.gw.disconnect();
      }, 10 * 1000);
      return;
    case 'visible':
  //    console.log('DOCUMENT SHOW');
  
      if (! O.gw.isConnected()) {
        O.gw.connect();
      }
      return;
    }
  }
docs: Event handlers {{{1