diff --git a/static/js/index.js b/static/js/index.js index f77bdd2..d478ca1 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -53,14 +53,14 @@ function loadWindowState() { } function onFullscreened() { - if (!isInGame && windowState === 'normal') { + if (!isInGame && windowState == 'normal') { storeData('windowState', 'fullscreen', null); windowState = 'fullscreen'; } } function onBoundsChanged() { - if (!isInGame && windowState === 'fullscreen') { + if (!isInGame && windowState == 'fullscreen') { storeData('windowState', 'normal', null); windowState = 'normal'; } @@ -105,7 +105,7 @@ function restoreUiAfterNaClLoad() { return; } - if (hosts[returneMdnsDiscoveredHost.serverUid] !== null) { + if (hosts[returneMdnsDiscoveredHost.serverUid] != null) { // if we're seeing a host we've already seen before, update it for the current local IP. hosts[returneMdnsDiscoveredHost.serverUid].address = returneMdnsDiscoveredHost.address; } else { @@ -255,7 +255,7 @@ function pairTo(nvhttpHost, onSuccess, onFailure) { console.log('%c[index.js]', 'color: green;', 'Sending pairing request to ' + nvhttpHost.hostname + ' with random number' + randomNumber); nvhttpHost.pair(randomNumber).then(function (paired) { if (!paired) { - if (nvhttpHost.currentGame !== 0) { + if (nvhttpHost.currentGame != 0) { $('#pairingDialogText').html('Error: ' + nvhttpHost.hostname + ' is busy. Stop streaming to pair.'); } else { $('#pairingDialogText').html('Error: failed to pair with ' + nvhttpHost.hostname + '.'); @@ -322,7 +322,7 @@ function addHost() { pairTo(_nvhttpHost, function () { // Check if we already have record of this host - if (hosts[_nvhttpHost.serverUid] !== undefined) { + if (hosts[_nvhttpHost.serverUid] != undefined) { // Just update the addresses hosts[_nvhttpHost.serverUid].address = _nvhttpHost.address; hosts[_nvhttpHost.serverUid].userEnteredAddress = _nvhttpHost.userEnteredAddress; @@ -368,7 +368,7 @@ function addHostToGrid(host, ismDNSDiscovered) { hostChosen(host); }); outerDiv.keypress(function (e) { - if (e.keyCode === 13) { + if (e.keyCode == 13) { hostChosen(host); } }); @@ -411,7 +411,7 @@ function removeClicked(host) { // not do N*N stylizations of the box art, or make the code not flow very well function stylizeBoxArt(freshApi, appIdToStylize) { let app_selector = $('#game-' + appIdToStylize); - if (freshApi.currentGame === appIdToStylize) { // stylize the currently running game + if (freshApi.currentGame == appIdToStylize) { // stylize the currently running game // destylize it, if it has the not-current-game style if (app_selector.hasClass("not-current-game")) $('#game-' + appIdToStylize).removeClass("not-current-game"); // add the current-game style @@ -448,7 +448,7 @@ function showApps(host) { appList.forEach(function (app) { host.getBoxArt(app.id).then(function (resolvedPromise) { // put the box art into the image holder - if ($('#game-' + app.id).length === 0) { + if ($('#game-' + app.id).length == 0) { // double clicking the button will cause multiple box arts to appear. // to mitigate this we ensure we don't add a duplicate. // This isn't perfect: there's lots of RTTs before the logic prevents anything @@ -476,7 +476,7 @@ function showApps(host) { startGame(host, app.id); }); $('#game-' + app.id).keypress(function (e) { - if (e.keyCode === 13) { + if (e.keyCode == 13) { startGame(host, app.id); } }); @@ -488,7 +488,7 @@ function showApps(host) { }, function (failedPromise) { console.log('%c[index.js, showApps]', 'color: green;', 'Error! Failed to retrieve box art for app ID: ' + app.id + '. Returned value was: ' + failedPromise, '\n Host object:', host, host.toString()); - if ($('#game-' + app.id).length === 0) { + if ($('#game-' + app.id).length == 0) { // double clicking the button will cause multiple box arts to appear. // to mitigate this we ensure we don't add a duplicate. // This isn't perfect: there's lots of RTTs before the logic prevents anything @@ -571,7 +571,7 @@ function startGame(host, appID) { host.refreshServerInfo().then(function (ret) { host.getAppById(appID).then(function (appToStart) { - if (host.currentGame !== 0 && host.currentGame !== appID) { + if (host.currentGame != 0 && host.currentGame != appID) { host.getAppById(host.currentGame).then(function (currentApp) { let quitAppDialog = document.querySelector('#quitAppDialog'); document.getElementById('quitAppDialogText').innerHTML = @@ -612,7 +612,7 @@ function startGame(host, appID) { $('#loadingMessage').text('Starting ' + appToStart.title + '...'); playGameMode(); - if (host.currentGame === appID) { // if user wants to launch the already-running app, then we resume it. + if (host.currentGame == appID) { // if user wants to launch the already-running app, then we resume it. return host.resumeApp(rikey, rikeyid).then(function (ret) { sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate, bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]); @@ -673,7 +673,7 @@ function fullscreenNaclModule() { } function stopGameWithConfirmation() { - if (api.currentGame === 0) { + if (api.currentGame == 0) { snackbarLog('Nothing was running'); } else { api.getAppById(api.currentGame).then(function (currentGame) { @@ -717,7 +717,7 @@ function stopGame(host, callbackFunction) { host.refreshServerInfo().then(function (ret3) { // refresh to show no app is currently running. showAppsMode(); stylizeBoxArt(host, runningApp.id); - if (typeof(callbackFunction) === "function") callbackFunction(); + if (typeof(callbackFunction) == "function") callbackFunction(); }, function (failedRefreshInfo2) { console.error('%c[index.js, stopGame]', 'color:green;', 'Failed to refresh server info! Returned error was:' + failedRefreshInfo + ' and failed server was:', host, host.toString()); }); @@ -793,20 +793,20 @@ function updateDefaultBitrate() { let res = $('#selectResolution').data('value'); let frameRate = $('#selectFramerate').data('value').toString(); - if (res === "1920:1080") { - if (frameRate === "30") { // 1080p, 30fps + if (res == "1920:1080") { + if (frameRate == "30") { // 1080p, 30fps $('#bitrateSlider')[0].MaterialSlider.change('10'); } else { // 1080p, 60fps $('#bitrateSlider')[0].MaterialSlider.change('20'); } - } else if (res === "1280:720") { - if (frameRate === "30") { // 720, 30fps + } else if (res == "1280:720") { + if (frameRate == "30") { // 720, 30fps $('#bitrateSlider')[0].MaterialSlider.change('5'); } else { // 720, 60fps $('#bitrateSlider')[0].MaterialSlider.change('10'); } - } else if (res === "3840:2160") { - if (frameRate === "30") { // 2160p, 30fps + } else if (res == "3840:2160") { + if (frameRate == "30") { // 2160p, 30fps $('#bitrateSlider')[0].MaterialSlider.change('40'); } else { // 2160p, 60fps $('#bitrateSlider')[0].MaterialSlider.change('80'); @@ -829,9 +829,9 @@ function onWindowLoad() { if (chrome.storage) { // load stored resolution prefs chrome.storage.sync.get('resolution', function (previousValue) { - if (previousValue.resolution !== null) { + if (previousValue.resolution != null) { $('.resolutionMenu li').each(function () { - if ($(this).data('value') === previousValue.resolution) { + if ($(this).data('value') == previousValue.resolution) { $('#selectResolution').text($(this).text()).data('value', previousValue.resolution); } }); @@ -840,9 +840,9 @@ function onWindowLoad() { // Load stored remote audio prefs chrome.storage.sync.get('remoteAudio', function (previousValue) { - if (previousValue.remoteAudio === null) { + if (previousValue.remoteAudio == null) { document.querySelector('#externalAudioBtn').MaterialIconToggle.uncheck(); - } else if (previousValue.remoteAudio === false) { + } else if (previousValue.remoteAudio == false) { document.querySelector('#externalAudioBtn').MaterialIconToggle.uncheck(); } else { document.querySelector('#externalAudioBtn').MaterialIconToggle.check(); @@ -851,9 +851,9 @@ function onWindowLoad() { // load stored framerate prefs chrome.storage.sync.get('frameRate', function (previousValue) { - if (previousValue.frameRate !== null) { + if (previousValue.frameRate != null) { $('.framerateMenu li').each(function () { - if ($(this).data('value') === previousValue.frameRate) { + if ($(this).data('value') == previousValue.frameRate) { $('#selectFramerate').text($(this).text()).data('value', previousValue.frameRate); } }); @@ -862,9 +862,9 @@ function onWindowLoad() { // load stored optimization prefs chrome.storage.sync.get('optimize', function (previousValue) { - if (previousValue.optimize === null) { + if (previousValue.optimize == null) { document.querySelector('#optimizeGamesBtn').MaterialIconToggle.check(); - } else if (previousValue.optimize === false) { + } else if (previousValue.optimize == false) { document.querySelector('#optimizeGamesBtn').MaterialIconToggle.uncheck(); } else { document.querySelector('#optimizeGamesBtn').MaterialIconToggle.check(); @@ -873,19 +873,19 @@ function onWindowLoad() { // load stored bitrate prefs chrome.storage.sync.get('bitrate', function (previousValue) { - $('#bitrateSlider')[0].MaterialSlider.change(previousValue.bitrate !== null ? previousValue.bitrate : '10'); + $('#bitrateSlider')[0].MaterialSlider.change(previousValue.bitrate != null ? previousValue.bitrate : '10'); updateBitrateField(); }); // load the HTTP cert if we have one. chrome.storage.sync.get('cert', function (savedCert) { - if (savedCert.cert !== null) { // we have a saved cert + if (savedCert.cert != null) { // we have a saved cert pairingCert = savedCert.cert; } }); chrome.storage.sync.get('uniqueid', function (savedUniqueid) { - if (savedUniqueid.uniqueid !== null) { // we have a saved uniqueid + if (savedUniqueid.uniqueid != null) { // we have a saved uniqueid myUniqueid = savedUniqueid.uniqueid; } else { myUniqueid = uniqueid(); @@ -895,7 +895,7 @@ function onWindowLoad() { // load previously connected hosts, which have been killed into an object, and revive them back into a class chrome.storage.sync.get('hosts', function (previousValue) { - hosts = previousValue.hosts !== null ? previousValue.hosts : {}; + hosts = previousValue.hosts != null ? previousValue.hosts : {}; for (let hostUID in hosts) { // programmatically add each new host. let revivedHost = new NvHTTP(hosts[hostUID].address, myUniqueid, hosts[hostUID].userEnteredAddress); revivedHost.serverUid = hosts[hostUID].serverUid; diff --git a/static/js/utils.js b/static/js/utils.js index e287f6a..ef48de6 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1,6 +1,6 @@ function guuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); + let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } @@ -117,7 +117,7 @@ NvHTTP.prototype = { // Poll for the app list every 10 successful serverinfo polls. // Not including the first one to avoid PCs taking a while to show // as online initially - if (this._pollCount++ % 10 === 1) { + if (this._pollCount++ % 10 == 1) { this.getAppListWithCacheFlush(); } @@ -191,18 +191,18 @@ NvHTTP.prototype = { $xml = this._parseXML(xmlStr); $root = $xml.find('root'); - if ($root.attr("status_code") !== '200') { + if ($root.attr("status_code") != '200') { return false; } - if (this.serverUid !== $root.find('uniqueid').text().trim() && this.serverUid !== "") { + if (this.serverUid != $root.find('uniqueid').text().trim() && this.serverUid != "") { // if we received a UID that isn't the one we expected, fail. return false; } console.log('%c[utils.js, _parseServerInfo]', 'color:gray;', 'Parsing server info:', $root); - this.paired = $root.find("PairStatus").text().trim() === '1'; + this.paired = $root.find("PairStatus").text().trim() == '1'; this.currentGame = parseInt($root.find("currentgame").text().trim(), 10); this.appVersion = $root.find("appversion").text().trim(); this.serverMajorVersion = parseInt(this.appVersion.substring(0, 1), 10); @@ -245,7 +245,7 @@ NvHTTP.prototype = { let retApp = null; list.some(function (app) { - if (app.id === appId) { + if (app.id == appId) { retApp = app; return true; } @@ -262,7 +262,7 @@ NvHTTP.prototype = { $xml = this._parseXML(ret); $root = $xml.find("root"); - if ($root.attr("status_code") !== '200') { + if ($root.attr("status_code") != '200') { // TODO: Bubble up an error here console.error('%c[utils.js, utils.js, getAppListWithCacheFlush]', 'color: gray;', 'Applist request failed', $root.attr("status_code")); return []; @@ -303,7 +303,7 @@ NvHTTP.prototype = { console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Not warming box art cache for unpaired host'); return; } - if (Object.keys(this._memCachedBoxArtArray).length !== 0) { + if (Object.keys(this._memCachedBoxArtArray).length != 0) { console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Box art cache already warmed'); return; } @@ -311,7 +311,7 @@ NvHTTP.prototype = { chrome.storage.local.get('boxArtCache', function (JSONCachedBoxArtArray) { let storedBoxArtArray; // load cached data if it exists - if (JSONCachedBoxArtArray.boxArtCache !== undefined) { + if (JSONCachedBoxArtArray.boxArtCache != undefined) { storedBoxArtArray = JSONCachedBoxArtArray.boxArtCache; for (let key in storedBoxArtArray) { this._memCachedBoxArtArray[key] = _base64ToArrayBuffer(storedBoxArtArray[key]); @@ -330,13 +330,13 @@ NvHTTP.prototype = { // TODO: unfortunately we do N lookups from storage cache, each of them filling up the memory cache. // once the first round of calls are all made, each subsequent request hits this and returns from memory cache - if (this._memCachedBoxArtArray[appId] === null) { + if (this._memCachedBoxArtArray[appId] == null) { // This means a previous box art request failed, don't try again return new Promise(function (resolve, reject) { console.error('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning cached box-art failure result'); reject(null); }.bind(this)); - } else if (this._memCachedBoxArtArray[appId] !== undefined) { + } else if (this._memCachedBoxArtArray[appId] != undefined) { return new Promise(function (resolve, reject) { console.log('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning memory-cached box-art'); resolve(this._memCachedBoxArtArray[appId]); @@ -350,7 +350,7 @@ NvHTTP.prototype = { chrome.storage.local.get('boxArtCache', function (JSONCachedBoxArtArray) { let storedBoxArtArray; // load cached data if it exists - if (JSONCachedBoxArtArray.boxArtCache !== undefined && JSONCachedBoxArtArray.boxArtCache[appId] !== undefined) { + if (JSONCachedBoxArtArray.boxArtCache != undefined && JSONCachedBoxArtArray.boxArtCache[appId] != undefined) { storedBoxArtArray = JSONCachedBoxArtArray.boxArtCache; storedBoxArtArray[appId] = _base64ToArrayBuffer(storedBoxArtArray[appId]); @@ -361,7 +361,7 @@ NvHTTP.prototype = { } // if we already have it, load it. - if (storedBoxArtArray[appId] !== undefined && Object.keys(storedBoxArtArray).length !== 0 && storedBoxArtArray[appId].constructor !== Object) { + if (storedBoxArtArray[appId] != undefined && Object.keys(storedBoxArtArray).length != 0 && storedBoxArtArray[appId].constructor != Object) { console.log('%c[utils.js, getBoxArt]', 'color: gray;', 'Returning strage-cached box art for app: ', appId); resolve(storedBoxArtArray[appId]); return; @@ -452,13 +452,13 @@ NvHTTP.prototype = { if (this.paired) return true; - if (this.currentGame !== 0) + if (this.currentGame != 0) return false; return sendMessage('pair', [this.serverMajorVersion.toString(), this.address, randomNumber]).then(function (pairStatus) { return sendMessage('openUrl', [this._baseUrlHttps + '/pair?uniqueid=' + this.clientUid + '&devicename=roth&updateState=1&phrase=pairchallenge', false]).then(function (ret) { $xml = this._parseXML(ret); - this.paired = $xml.find('paired').html() === "1"; + this.paired = $xml.find('paired').html() == "1"; return this.paired; }.bind(this)); }.bind(this));