Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update browser.js #315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/connection/browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var BaseConnection = module.exports = require('./base');
let BaseConnection = module.exports = require('./base');


var BrowserConnection = module.exports = function(opts) {
let BrowserConnection = module.exports = function(opts) {
BaseConnection.call(this, opts);
var connection = this;
let connection = this;
this.on('ready', function() { connection.startFocusLoop(); })
this.on('disconnect', function() { connection.stopFocusLoop(); })
}
Expand All @@ -25,8 +25,8 @@ BrowserConnection.prototype.getPort = function(){
}

BrowserConnection.prototype.setupSocket = function() {
var connection = this;
var socket = new WebSocket(this.getUrl());
let connection = this;
let socket = new WebSocket(this.getUrl());
socket.onopen = function() { connection.handleOpen(); };
socket.onclose = function(data) { connection.handleClose(data['code'], data['reason']); };
socket.onmessage = function(message) { connection.handleData(message.data) };
Expand All @@ -46,8 +46,8 @@ BrowserConnection.prototype.setupSocket = function() {

BrowserConnection.prototype.startFocusLoop = function() {
if (this.focusDetectorTimer) return;
var connection = this;
var propertyName = null;
let connection = this;
let propertyName = null;
if (typeof document.hidden !== "undefined") {
propertyName = "hidden";
} else if (typeof document.mozHidden !== "undefined") {
Expand All @@ -64,12 +64,12 @@ BrowserConnection.prototype.startFocusLoop = function() {
connection.windowVisible = propertyName === undefined ? true : document[propertyName] === false;
}

var focusListener = window.addEventListener('focus', function(e) {
let focusListener = window.addEventListener('focus', function(e) {
connection.windowVisible = true;
updateFocusState();
});

var blurListener = window.addEventListener('blur', function(e) {
let blurListener = window.addEventListener('blur', function(e) {
connection.windowVisible = false;
updateFocusState();
});
Expand All @@ -79,8 +79,8 @@ BrowserConnection.prototype.startFocusLoop = function() {
window.removeEventListener('blur', blurListener);
});

var updateFocusState = function() {
var isVisible = propertyName === undefined ? true : document[propertyName] === false;
let updateFocusState = function() {
let isVisible = propertyName === undefined ? true : document[propertyName] === false;
connection.reportFocus(isVisible && connection.windowVisible);
}

Expand Down