mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-18 00:56:38 +00:00
JS updates, courtesy of IntelliJ's recommendations
- Changed from var to let - cached a few JQuery selectors - added a few semicolons - standardized indentation back to spaces - removed dead code from utils.js - switched from == to === to eliminate coercion
This commit is contained in:
parent
e0c4c01e44
commit
c6390338e3
@ -36,7 +36,9 @@ function fullscreenChromeWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadWindowState() {
|
function loadWindowState() {
|
||||||
if (!chrome.storage) { return; }
|
if (!chrome.storage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
chrome.storage.sync.get('windowState', function (item) {
|
chrome.storage.sync.get('windowState', function (item) {
|
||||||
// load stored window state
|
// load stored window state
|
||||||
@ -51,14 +53,14 @@ function loadWindowState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onFullscreened() {
|
function onFullscreened() {
|
||||||
if (!isInGame && windowState == 'normal') {
|
if (!isInGame && windowState === 'normal') {
|
||||||
storeData('windowState', 'fullscreen', null);
|
storeData('windowState', 'fullscreen', null);
|
||||||
windowState = 'fullscreen';
|
windowState = 'fullscreen';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBoundsChanged() {
|
function onBoundsChanged() {
|
||||||
if (!isInGame && windowState == 'fullscreen') {
|
if (!isInGame && windowState === 'fullscreen') {
|
||||||
storeData('windowState', 'normal', null);
|
storeData('windowState', 'normal', null);
|
||||||
windowState = 'normal';
|
windowState = 'normal';
|
||||||
}
|
}
|
||||||
@ -72,13 +74,13 @@ function changeUiModeForNaClLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startPollingHosts() {
|
function startPollingHosts() {
|
||||||
for(var hostUID in hosts) {
|
for (let hostUID in hosts) {
|
||||||
beginBackgroundPollingOfHost(hosts[hostUID]);
|
beginBackgroundPollingOfHost(hosts[hostUID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopPollingHosts() {
|
function stopPollingHosts() {
|
||||||
for(var hostUID in hosts) {
|
for (let hostUID in hosts) {
|
||||||
stopBackgroundPollingOfHost(hosts[hostUID]);
|
stopBackgroundPollingOfHost(hosts[hostUID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,18 +94,18 @@ function restoreUiAfterNaClLoad() {
|
|||||||
|
|
||||||
findNvService(function (finder, opt_error) {
|
findNvService(function (finder, opt_error) {
|
||||||
if (finder.byService_['_nvstream._tcp']) {
|
if (finder.byService_['_nvstream._tcp']) {
|
||||||
var ips = Object.keys(finder.byService_['_nvstream._tcp']);
|
let ips = Object.keys(finder.byService_['_nvstream._tcp']);
|
||||||
for (var i in ips) {
|
for (let i in ips) {
|
||||||
var ip = ips[i];
|
let ip = ips[i];
|
||||||
if (finder.byService_['_nvstream._tcp'][ip]) {
|
if (finder.byService_['_nvstream._tcp'][ip]) {
|
||||||
var mDnsDiscoveredHost = new NvHTTP(ip, myUniqueid);
|
let mDnsDiscoveredHost = new NvHTTP(ip, myUniqueid);
|
||||||
mDnsDiscoveredHost.pollServer(function (returneMdnsDiscoveredHost) {
|
mDnsDiscoveredHost.pollServer(function (returneMdnsDiscoveredHost) {
|
||||||
// Just drop this if the host doesn't respond
|
// Just drop this if the host doesn't respond
|
||||||
if (!returneMdnsDiscoveredHost.online) {
|
if (!returneMdnsDiscoveredHost.online) {
|
||||||
return;
|
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.
|
// if we're seeing a host we've already seen before, update it for the current local IP.
|
||||||
hosts[returneMdnsDiscoveredHost.serverUid].address = returneMdnsDiscoveredHost.address;
|
hosts[returneMdnsDiscoveredHost.serverUid].address = returneMdnsDiscoveredHost.address;
|
||||||
} else {
|
} else {
|
||||||
@ -165,7 +167,7 @@ function stopBackgroundPollingOfHost(host) {
|
|||||||
|
|
||||||
function snackbarLog(givenMessage) {
|
function snackbarLog(givenMessage) {
|
||||||
console.log('%c[index.js, snackbarLog]', 'color: green;', givenMessage);
|
console.log('%c[index.js, snackbarLog]', 'color: green;', givenMessage);
|
||||||
var data = {
|
let data = {
|
||||||
message: givenMessage,
|
message: givenMessage,
|
||||||
timeout: 2000
|
timeout: 2000
|
||||||
};
|
};
|
||||||
@ -174,7 +176,7 @@ function snackbarLog(givenMessage) {
|
|||||||
|
|
||||||
function snackbarLogLong(givenMessage) {
|
function snackbarLogLong(givenMessage) {
|
||||||
console.log('%c[index.js, snackbarLog]', 'color: green;', givenMessage);
|
console.log('%c[index.js, snackbarLog]', 'color: green;', givenMessage);
|
||||||
var data = {
|
let data = {
|
||||||
message: givenMessage,
|
message: givenMessage,
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
};
|
};
|
||||||
@ -240,8 +242,8 @@ function pairTo(nvhttpHost, onSuccess, onFailure) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var randomNumber = String("0000" + (Math.random()*10000|0)).slice(-4);
|
let randomNumber = String("0000" + (Math.random() * 10000 | 0)).slice(-4);
|
||||||
var pairingDialog = document.querySelector('#pairingDialog');
|
let pairingDialog = document.querySelector('#pairingDialog');
|
||||||
$('#pairingDialogText').html('Please enter the number ' + randomNumber + ' on the GFE dialog on the computer. This dialog will be dismissed once complete');
|
$('#pairingDialogText').html('Please enter the number ' + randomNumber + ' on the GFE dialog on the computer. This dialog will be dismissed once complete');
|
||||||
pairingDialog.showModal();
|
pairingDialog.showModal();
|
||||||
|
|
||||||
@ -253,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);
|
console.log('%c[index.js]', 'color: green;', 'Sending pairing request to ' + nvhttpHost.hostname + ' with random number' + randomNumber);
|
||||||
nvhttpHost.pair(randomNumber).then(function (paired) {
|
nvhttpHost.pair(randomNumber).then(function (paired) {
|
||||||
if (!paired) {
|
if (!paired) {
|
||||||
if (nvhttpHost.currentGame != 0) {
|
if (nvhttpHost.currentGame !== 0) {
|
||||||
$('#pairingDialogText').html('Error: ' + nvhttpHost.hostname + ' is busy. Stop streaming to pair.');
|
$('#pairingDialogText').html('Error: ' + nvhttpHost.hostname + ' is busy. Stop streaming to pair.');
|
||||||
} else {
|
} else {
|
||||||
$('#pairingDialogText').html('Error: failed to pair with ' + nvhttpHost.hostname + '.');
|
$('#pairingDialogText').html('Error: failed to pair with ' + nvhttpHost.hostname + '.');
|
||||||
@ -303,7 +305,7 @@ function hostChosen(host) {
|
|||||||
// the `+` was selected on the host grid.
|
// the `+` was selected on the host grid.
|
||||||
// give the user a dialog to input connection details for the PC
|
// give the user a dialog to input connection details for the PC
|
||||||
function addHost() {
|
function addHost() {
|
||||||
var modal = document.querySelector('#addHostDialog');
|
let modal = document.querySelector('#addHostDialog');
|
||||||
modal.showModal();
|
modal.showModal();
|
||||||
|
|
||||||
// drop the dialog if they cancel
|
// drop the dialog if they cancel
|
||||||
@ -315,12 +317,12 @@ function addHost() {
|
|||||||
// try to pair if they continue
|
// try to pair if they continue
|
||||||
$('#continueAddHost').off('click');
|
$('#continueAddHost').off('click');
|
||||||
$('#continueAddHost').on('click', function () {
|
$('#continueAddHost').on('click', function () {
|
||||||
var inputHost = $('#dialogInputHost').val();
|
let inputHost = $('#dialogInputHost').val();
|
||||||
var _nvhttpHost = new NvHTTP(inputHost, myUniqueid, inputHost);
|
let _nvhttpHost = new NvHTTP(inputHost, myUniqueid, inputHost);
|
||||||
|
|
||||||
pairTo(_nvhttpHost, function () {
|
pairTo(_nvhttpHost, function () {
|
||||||
// Check if we already have record of this host
|
// Check if we already have record of this host
|
||||||
if (hosts[_nvhttpHost.serverUid] != null) {
|
if (hosts[_nvhttpHost.serverUid] !== null) {
|
||||||
// Just update the addresses
|
// Just update the addresses
|
||||||
hosts[_nvhttpHost.serverUid].address = _nvhttpHost.address;
|
hosts[_nvhttpHost.serverUid].address = _nvhttpHost.address;
|
||||||
hosts[_nvhttpHost.serverUid].userEnteredAddress = _nvhttpHost.userEnteredAddress;
|
hosts[_nvhttpHost.serverUid].userEnteredAddress = _nvhttpHost.userEnteredAddress;
|
||||||
@ -341,10 +343,22 @@ function addHost() {
|
|||||||
// host is an NvHTTP object
|
// host is an NvHTTP object
|
||||||
function addHostToGrid(host, ismDNSDiscovered) {
|
function addHostToGrid(host, ismDNSDiscovered) {
|
||||||
|
|
||||||
var outerDiv = $("<div>", {class: 'host-container mdl-card mdl-shadow--4dp', id: 'host-container-' + host.serverUid, role: 'link', tabindex: 0, 'aria-label': host.hostname });
|
let outerDiv = $("<div>", {
|
||||||
var cell = $("<div>", {class: 'mdl-card__title mdl-card--expand', id: 'hostgrid-' + host.serverUid });
|
class: 'host-container mdl-card mdl-shadow--4dp',
|
||||||
|
id: 'host-container-' + host.serverUid,
|
||||||
|
role: 'link',
|
||||||
|
tabindex: 0,
|
||||||
|
'aria-label': host.hostname
|
||||||
|
});
|
||||||
|
let cell = $("<div>", {class: 'mdl-card__title mdl-card--expand', id: 'hostgrid-' + host.serverUid});
|
||||||
$(cell).prepend($("<h2>", {class: "mdl-card__title-text", html: host.hostname}));
|
$(cell).prepend($("<h2>", {class: "mdl-card__title-text", html: host.hostname}));
|
||||||
var removalButton = $("<div>", {class: "remove-host", id: "removeHostButton-" + host.serverUid, role: 'button', tabindex: 0, 'aria-label': 'Remove host ' + host.hostname});
|
let removalButton = $("<div>", {
|
||||||
|
class: "remove-host",
|
||||||
|
id: "removeHostButton-" + host.serverUid,
|
||||||
|
role: 'button',
|
||||||
|
tabindex: 0,
|
||||||
|
'aria-label': 'Remove host ' + host.hostname
|
||||||
|
});
|
||||||
removalButton.off('click');
|
removalButton.off('click');
|
||||||
removalButton.click(function () {
|
removalButton.click(function () {
|
||||||
removeClicked(host);
|
removeClicked(host);
|
||||||
@ -354,7 +368,7 @@ function addHostToGrid(host, ismDNSDiscovered) {
|
|||||||
hostChosen(host);
|
hostChosen(host);
|
||||||
});
|
});
|
||||||
outerDiv.keypress(function (e) {
|
outerDiv.keypress(function (e) {
|
||||||
if(e.keyCode == 13) {
|
if (e.keyCode === 13) {
|
||||||
hostChosen(host);
|
hostChosen(host);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -368,7 +382,7 @@ function addHostToGrid(host, ismDNSDiscovered) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeClicked(host) {
|
function removeClicked(host) {
|
||||||
var deleteHostDialog = document.querySelector('#deleteHostDialog');
|
let deleteHostDialog = document.querySelector('#deleteHostDialog');
|
||||||
document.getElementById('deleteHostDialogText').innerHTML =
|
document.getElementById('deleteHostDialogText').innerHTML =
|
||||||
' Are you sure you want to delete ' + host.hostname + '?';
|
' Are you sure you want to delete ' + host.hostname + '?';
|
||||||
deleteHostDialog.showModal();
|
deleteHostDialog.showModal();
|
||||||
@ -383,7 +397,6 @@ function removeClicked(host) {
|
|||||||
// this means we can re-add the host, and will still be paired.
|
// this means we can re-add the host, and will still be paired.
|
||||||
$('#continueDeleteHost').off('click');
|
$('#continueDeleteHost').off('click');
|
||||||
$('#continueDeleteHost').on('click', function () {
|
$('#continueDeleteHost').on('click', function () {
|
||||||
var deleteHostDialog = document.querySelector('#deleteHostDialog');
|
|
||||||
$('#host-container-' + host.serverUid).remove();
|
$('#host-container-' + host.serverUid).remove();
|
||||||
delete hosts[host.serverUid]; // remove the host from the array;
|
delete hosts[host.serverUid]; // remove the host from the array;
|
||||||
saveHosts();
|
saveHosts();
|
||||||
@ -397,16 +410,17 @@ function removeClicked(host) {
|
|||||||
// the function was made like this so that we can remove duplicated code, but
|
// the function was made like this so that we can remove duplicated code, but
|
||||||
// not do N*N stylizations of the box art, or make the code not flow very well
|
// not do N*N stylizations of the box art, or make the code not flow very well
|
||||||
function stylizeBoxArt(freshApi, appIdToStylize) {
|
function stylizeBoxArt(freshApi, appIdToStylize) {
|
||||||
|
let app_selector = $('#game-' + app.id);
|
||||||
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
|
// destylize it, if it has the not-current-game style
|
||||||
if ($('#game-'+ appIdToStylize).hasClass("not-current-game")) $('#game-'+ appIdToStylize).removeClass("not-current-game");
|
if (app_selector.hasClass("not-current-game")) $('#game-' + appIdToStylize).removeClass("not-current-game");
|
||||||
// add the current-game style
|
// add the current-game style
|
||||||
$('#game-'+ appIdToStylize).addClass("current-game");
|
app_selector.addClass("current-game");
|
||||||
} else {
|
} else {
|
||||||
// destylize it, if it has the current-game style
|
// destylize it, if it has the current-game style
|
||||||
if ($('#game-'+ appIdToStylize).hasClass("current-game")) $('#game-'+ appIdToStylize).removeClass("current-game");
|
if (app_selector.hasClass("current-game")) $('#game-' + appIdToStylize).removeClass("current-game");
|
||||||
// add the not-current-game style
|
// add the not-current-game style
|
||||||
$('#game-'+ appIdToStylize).addClass('not-current-game');
|
app_selector.addClass('not-current-game');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,24 +447,37 @@ function showApps(host) {
|
|||||||
|
|
||||||
appList.forEach(function (app) {
|
appList.forEach(function (app) {
|
||||||
host.getBoxArt(app.id).then(function (resolvedPromise) {
|
host.getBoxArt(app.id).then(function (resolvedPromise) {
|
||||||
|
let app_selector = $('#game-' + app.id);
|
||||||
// put the box art into the image holder
|
// put the box art into the image holder
|
||||||
if ($('#game-' + app.id).length === 0) {
|
if (app_selector.length === 0) {
|
||||||
// double clicking the button will cause multiple box arts to appear.
|
// double clicking the button will cause multiple box arts to appear.
|
||||||
// to mitigate this we ensure we don't add a duplicate.
|
// 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
|
// This isn't perfect: there's lots of RTTs before the logic prevents anything
|
||||||
var imageBlob = new Blob([resolvedPromise], {type: "image/png"});
|
let imageBlob = new Blob([resolvedPromise], {type: "image/png"});
|
||||||
var outerDiv = $("<div>", {class: 'game-container mdl-card mdl-shadow--4dp', id: 'game-'+app.id, backgroundImage: URL.createObjectURL(imageBlob), role: 'link', tabindex: 0, title: app.title, 'aria-label': app.title });
|
let outerDiv = $("<div>", {
|
||||||
$(outerDiv).append($("<img \>", {src: URL.createObjectURL(imageBlob), id: 'game-'+app.id, name: app.title }));
|
class: 'game-container mdl-card mdl-shadow--4dp',
|
||||||
|
id: 'game-' + app.id,
|
||||||
|
backgroundImage: URL.createObjectURL(imageBlob),
|
||||||
|
role: 'link',
|
||||||
|
tabindex: 0,
|
||||||
|
title: app.title,
|
||||||
|
'aria-label': app.title
|
||||||
|
});
|
||||||
|
$(outerDiv).append($("<img \>", {
|
||||||
|
src: URL.createObjectURL(imageBlob),
|
||||||
|
id: 'game-' + app.id,
|
||||||
|
name: app.title
|
||||||
|
}));
|
||||||
$(outerDiv).append($("<div>", {class: "game-title", html: $("<span>", {html: app.title})}));
|
$(outerDiv).append($("<div>", {class: "game-title", html: $("<span>", {html: app.title})}));
|
||||||
$("#game-grid").append(outerDiv);
|
$("#game-grid").append(outerDiv);
|
||||||
|
|
||||||
|
|
||||||
// $("#gameList").append($("<div>", {html:$("<img \>", {src: URL.createObjectURL(imageBlob), id: 'game-'+app.id, name: app.title }), class: 'box-art mdl-cell mdl-cell--3-col'}).append($("<span>", {html: app.title, class:"game-title"})));
|
// $("#gameList").append($("<div>", {html:$("<img \>", {src: URL.createObjectURL(imageBlob), id: 'game-'+app.id, name: app.title }), class: 'box-art mdl-cell mdl-cell--3-col'}).append($("<span>", {html: app.title, class:"game-title"})));
|
||||||
$('#game-'+app.id).on('click', function () {
|
app_selector.on('click', function () {
|
||||||
startGame(host, app.id);
|
startGame(host, app.id);
|
||||||
});
|
});
|
||||||
$('#game-'+app.id).keypress(function(e){
|
app_selector.keypress(function (e) {
|
||||||
if(e.keyCode == 13) {
|
if (e.keyCode === 13) {
|
||||||
startGame(host, app.id);
|
startGame(host, app.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -466,8 +493,16 @@ function showApps(host) {
|
|||||||
// double clicking the button will cause multiple box arts to appear.
|
// double clicking the button will cause multiple box arts to appear.
|
||||||
// to mitigate this we ensure we don't add a duplicate.
|
// 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
|
// This isn't perfect: there's lots of RTTs before the logic prevents anything
|
||||||
var outerDiv = $("<div>", {class: 'game-container mdl-card mdl-shadow--4dp', id: 'game-'+app.id, backgroundImage: "static/res/no_app_image.png" });
|
let outerDiv = $("<div>", {
|
||||||
$(outerDiv).append($("<img \>", {src: "static/res/no_app_image.png", id: 'game-'+app.id, name: app.title }));
|
class: 'game-container mdl-card mdl-shadow--4dp',
|
||||||
|
id: 'game-' + app.id,
|
||||||
|
backgroundImage: "static/res/no_app_image.png"
|
||||||
|
});
|
||||||
|
$(outerDiv).append($("<img \>", {
|
||||||
|
src: "static/res/no_app_image.png",
|
||||||
|
id: 'game-' + app.id,
|
||||||
|
name: app.title
|
||||||
|
}));
|
||||||
$(outerDiv).append($("<div>", {class: "game-title", html: $("<span>", {html: app.title})}));
|
$(outerDiv).append($("<div>", {class: "game-title", html: $("<span>", {html: app.title})}));
|
||||||
$("#game-grid").append(outerDiv);
|
$("#game-grid").append(outerDiv);
|
||||||
|
|
||||||
@ -537,9 +572,9 @@ function startGame(host, appID) {
|
|||||||
host.refreshServerInfo().then(function (ret) {
|
host.refreshServerInfo().then(function (ret) {
|
||||||
host.getAppById(appID).then(function (appToStart) {
|
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) {
|
host.getAppById(host.currentGame).then(function (currentApp) {
|
||||||
var quitAppDialog = document.querySelector('#quitAppDialog');
|
let quitAppDialog = document.querySelector('#quitAppDialog');
|
||||||
document.getElementById('quitAppDialogText').innerHTML =
|
document.getElementById('quitAppDialogText').innerHTML =
|
||||||
currentApp.title + ' is already running. Would you like to quit ' +
|
currentApp.title + ' is already running. Would you like to quit ' +
|
||||||
currentApp.title + '?';
|
currentApp.title + '?';
|
||||||
@ -558,40 +593,36 @@ function startGame(host, appID) {
|
|||||||
});
|
});
|
||||||
quitAppDialog.close();
|
quitAppDialog.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
|
||||||
}, function (failedCurrentApp) {
|
}, function (failedCurrentApp) {
|
||||||
console.error('[index.js, startGame]', 'color: green;', 'Failed to get the current running app from host! Returned error was:' + failedCurrentApp, '\n Host object:', host, host.toString());
|
console.error('[index.js, startGame]', 'color: green;', 'Failed to get the current running app from host! Returned error was:' + failedCurrentApp, '\n Host object:', host, host.toString());
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var frameRate = $('#selectFramerate').data('value').toString();
|
let frameRate = $('#selectFramerate').data('value').toString();
|
||||||
var optimize = $("#optimizeGamesSwitch").parent().hasClass('is-checked') ? 1 : 0;
|
let optimize = $("#optimizeGamesSwitch").parent().hasClass('is-checked') ? 1 : 0;
|
||||||
var streamWidth = $('#selectResolution').data('value').split(':')[0];
|
let streamWidth = $('#selectResolution').data('value').split(':')[0];
|
||||||
var streamHeight = $('#selectResolution').data('value').split(':')[1];
|
let streamHeight = $('#selectResolution').data('value').split(':')[1];
|
||||||
// we told the user it was in Mbps. We're dirty liars and use Kbps behind their back.
|
// we told the user it was in Mbps. We're dirty liars and use Kbps behind their back.
|
||||||
var bitrate = parseInt($("#bitrateSlider").val()) * 1000;
|
let bitrate = parseInt($("#bitrateSlider").val()) * 1000;
|
||||||
console.log('%c[index.js, startGame]', 'color:green;', 'startRequest:' + host.address + ":" + streamWidth + ":" + streamHeight + ":" + frameRate + ":" + bitrate + ":" + optimize);
|
console.log('%c[index.js, startGame]', 'color:green;', 'startRequest:' + host.address + ":" + streamWidth + ":" + streamHeight + ":" + frameRate + ":" + bitrate + ":" + optimize);
|
||||||
|
|
||||||
var rikey = generateRemoteInputKey();
|
let rikey = generateRemoteInputKey();
|
||||||
var rikeyid = generateRemoteInputKeyId();
|
let rikeyid = generateRemoteInputKeyId();
|
||||||
|
|
||||||
$('#loadingMessage').text('Starting ' + appToStart.title + '...');
|
$('#loadingMessage').text('Starting ' + appToStart.title + '...');
|
||||||
playGameMode();
|
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) {
|
return host.resumeApp(rikey, rikeyid).then(function (ret) {
|
||||||
sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate,
|
sendMessage('startRequest', [host.address, streamWidth, streamHeight, frameRate,
|
||||||
bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]);
|
bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]);
|
||||||
}, function (failedResumeApp) {
|
}, function (failedResumeApp) {
|
||||||
console.eror('%c[index.js, startGame]', 'color:green;', 'Failed to resume the app! Returned error was' + failedResumeApp);
|
console.error('%c[index.js, startGame]', 'color:green;', 'Failed to resume the app! Returned error was' + failedResumeApp);
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var remote_audio_enabled = $("#remoteAudioEnabledSwitch").parent().hasClass('is-checked') ? 1 : 0;
|
let remote_audio_enabled = $("#remoteAudioEnabledSwitch").parent().hasClass('is-checked') ? 1 : 0;
|
||||||
|
|
||||||
host.launchApp(appID,
|
host.launchApp(appID,
|
||||||
streamWidth + "x" + streamHeight + "x" + frameRate,
|
streamWidth + "x" + streamHeight + "x" + frameRate,
|
||||||
@ -604,7 +635,6 @@ function startGame(host, appID) {
|
|||||||
bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]);
|
bitrate.toString(), rikey, rikeyid.toString(), host.appVersion]);
|
||||||
}, function (failedLaunchApp) {
|
}, function (failedLaunchApp) {
|
||||||
console.error('%c[index.js, launchApp]', 'color: green;', 'Failed to launch app width id: ' + appID + '\nReturned error was: ' + failedLaunchApp);
|
console.error('%c[index.js, launchApp]', 'color: green;', 'Failed to launch app width id: ' + appID + '\nReturned error was: ' + failedLaunchApp);
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -627,17 +657,17 @@ function playGameMode() {
|
|||||||
|
|
||||||
// Maximize the size of the nacl module by scaling and resizing appropriately
|
// Maximize the size of the nacl module by scaling and resizing appropriately
|
||||||
function fullscreenNaclModule() {
|
function fullscreenNaclModule() {
|
||||||
var streamWidth = $('#selectResolution').data('value').split(':')[0];
|
let streamWidth = $('#selectResolution').data('value').split(':')[0];
|
||||||
var streamHeight = $('#selectResolution').data('value').split(':')[1];
|
let streamHeight = $('#selectResolution').data('value').split(':')[1];
|
||||||
var screenWidth = window.innerWidth;
|
let screenWidth = window.innerWidth;
|
||||||
var screenHeight = window.innerHeight;
|
let screenHeight = window.innerHeight;
|
||||||
|
|
||||||
var xRatio = screenWidth / streamWidth;
|
let xRatio = screenWidth / streamWidth;
|
||||||
var yRatio = screenHeight / streamHeight;
|
let yRatio = screenHeight / streamHeight;
|
||||||
|
|
||||||
var zoom = Math.min(xRatio, yRatio);
|
let zoom = Math.min(xRatio, yRatio);
|
||||||
|
|
||||||
var module = $("#nacl_module")[0];
|
let module = $("#nacl_module")[0];
|
||||||
module.width = zoom * streamWidth;
|
module.width = zoom * streamWidth;
|
||||||
module.height = zoom * streamHeight;
|
module.height = zoom * streamHeight;
|
||||||
module.style.paddingTop = ((screenHeight - module.height) / 2) + "px";
|
module.style.paddingTop = ((screenHeight - module.height) / 2) + "px";
|
||||||
@ -648,7 +678,7 @@ function stopGameWithConfirmation() {
|
|||||||
snackbarLog('Nothing was running');
|
snackbarLog('Nothing was running');
|
||||||
} else {
|
} else {
|
||||||
api.getAppById(api.currentGame).then(function (currentGame) {
|
api.getAppById(api.currentGame).then(function (currentGame) {
|
||||||
var quitAppDialog = document.querySelector('#quitAppDialog');
|
let quitAppDialog = document.querySelector('#quitAppDialog');
|
||||||
document.getElementById('quitAppDialogText').innerHTML =
|
document.getElementById('quitAppDialogText').innerHTML =
|
||||||
' Are you sure you would like to quit ' +
|
' Are you sure you would like to quit ' +
|
||||||
currentGame.title + '? Unsaved progress will be lost.';
|
currentGame.title + '? Unsaved progress will be lost.';
|
||||||
@ -682,7 +712,7 @@ function stopGame(host, callbackFunction) {
|
|||||||
snackbarLog('Nothing was running');
|
snackbarLog('Nothing was running');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var appName = runningApp.title;
|
let appName = runningApp.title;
|
||||||
snackbarLog('Stopping ' + appName);
|
snackbarLog('Stopping ' + appName);
|
||||||
host.quitApp().then(function (ret2) {
|
host.quitApp().then(function (ret2) {
|
||||||
host.refreshServerInfo().then(function (ret3) { // refresh to show no app is currently running.
|
host.refreshServerInfo().then(function (ret3) { // refresh to show no app is currently running.
|
||||||
@ -704,14 +734,14 @@ function stopGame(host, callbackFunction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function storeData(key, data, callbackFunction) {
|
function storeData(key, data, callbackFunction) {
|
||||||
var obj = {};
|
let obj = {};
|
||||||
obj[key] = data;
|
obj[key] = data;
|
||||||
if (chrome.storage)
|
if (chrome.storage)
|
||||||
chrome.storage.sync.set(obj, callbackFunction);
|
chrome.storage.sync.set(obj, callbackFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveResolution() {
|
function saveResolution() {
|
||||||
var chosenResolution = $(this).data('value');
|
let chosenResolution = $(this).data('value');
|
||||||
$('#selectResolution').text($(this).text()).data('value', chosenResolution);
|
$('#selectResolution').text($(this).text()).data('value', chosenResolution);
|
||||||
storeData('resolution', chosenResolution, null);
|
storeData('resolution', chosenResolution, null);
|
||||||
updateDefaultBitrate();
|
updateDefaultBitrate();
|
||||||
@ -721,26 +751,25 @@ function saveOptimize() {
|
|||||||
// MaterialDesignLight uses the mouseup trigger, so we give it some time to change the class name before
|
// MaterialDesignLight uses the mouseup trigger, so we give it some time to change the class name before
|
||||||
// checking the new state
|
// checking the new state
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var chosenOptimize = $("#optimizeGamesSwitch").parent().hasClass('is-checked');
|
let chosenOptimize = $("#optimizeGamesSwitch").parent().hasClass('is-checked');
|
||||||
console.log('%c[index.js, saveOptimize]', 'color: green;', 'Saving optimize state : ' + chosenOptimize);
|
console.log('%c[index.js, saveOptimize]', 'color: green;', 'Saving optimize state : ' + chosenOptimize);
|
||||||
storeData('optimize', chosenOptimize, null);
|
storeData('optimize', chosenOptimize, null);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFramerate() {
|
function saveFramerate() {
|
||||||
var chosenFramerate = $(this).data('value');
|
let chosenFramerate = $(this).data('value');
|
||||||
$('#selectFramerate').text($(this).text()).data('value', chosenFramerate);
|
$('#selectFramerate').text($(this).text()).data('value', chosenFramerate);
|
||||||
storeData('frameRate', chosenFramerate, null);
|
storeData('frameRate', chosenFramerate, null);
|
||||||
updateDefaultBitrate();
|
updateDefaultBitrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// storing data in chrome.storage takes the data as an object, and shoves it into JSON to store
|
// storing data in chrome.storage takes the data as an object, and shoves it into JSON to store
|
||||||
// unfortunately, objects with function instances (classes) are stripped of their function instances when converted to a raw object
|
// unfortunately, objects with function instances (classes) are stripped of their function instances when converted to a raw object
|
||||||
// so we cannot forget to revive the object after we load it.
|
// so we cannot forget to revive the object after we load it.
|
||||||
function saveHosts() {
|
function saveHosts() {
|
||||||
for(var hostUID in hosts) {
|
for (let hostUID in hosts) {
|
||||||
// slim the object down to only store the necessary bytes, because we have limited storage
|
// slim the object down to only store the necessary bytes, because we have limited storage
|
||||||
hosts[hostUID]._prepareForStorage();
|
hosts[hostUID]._prepareForStorage();
|
||||||
}
|
}
|
||||||
@ -755,15 +784,15 @@ function saveRemoteAudio() {
|
|||||||
// MaterialDesignLight uses the mouseup trigger, so we give it some time to change the class name before
|
// MaterialDesignLight uses the mouseup trigger, so we give it some time to change the class name before
|
||||||
// checking the new state
|
// checking the new state
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var remoteAudioState = $("#remoteAudioEnabledSwitch").parent().hasClass('is-checked');
|
let remoteAudioState = $("#remoteAudioEnabledSwitch").parent().hasClass('is-checked');
|
||||||
console.log('%c[index.js, saveRemoteAudio]', 'color: green;', 'Saving remote audio state : ' + remoteAudioState);
|
console.log('%c[index.js, saveRemoteAudio]', 'color: green;', 'Saving remote audio state : ' + remoteAudioState);
|
||||||
storeData('remoteAudio', remoteAudioState, null);
|
storeData('remoteAudio', remoteAudioState, null);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDefaultBitrate() {
|
function updateDefaultBitrate() {
|
||||||
var res = $('#selectResolution').data('value');
|
let res = $('#selectResolution').data('value');
|
||||||
var frameRate = $('#selectFramerate').data('value').toString();
|
let frameRate = $('#selectFramerate').data('value').toString();
|
||||||
|
|
||||||
if (res === "1920:1080") {
|
if (res === "1920:1080") {
|
||||||
if (frameRate === "30") { // 1080p, 30fps
|
if (frameRate === "30") { // 1080p, 30fps
|
||||||
@ -801,7 +830,7 @@ function onWindowLoad(){
|
|||||||
if (chrome.storage) {
|
if (chrome.storage) {
|
||||||
// load stored resolution prefs
|
// load stored resolution prefs
|
||||||
chrome.storage.sync.get('resolution', function (previousValue) {
|
chrome.storage.sync.get('resolution', function (previousValue) {
|
||||||
if(previousValue.resolution != null) {
|
if (previousValue.resolution !== null) {
|
||||||
$('.resolutionMenu li').each(function () {
|
$('.resolutionMenu li').each(function () {
|
||||||
if ($(this).data('value') === previousValue.resolution) {
|
if ($(this).data('value') === previousValue.resolution) {
|
||||||
$('#selectResolution').text($(this).text()).data('value', previousValue.resolution);
|
$('#selectResolution').text($(this).text()).data('value', previousValue.resolution);
|
||||||
@ -812,9 +841,9 @@ function onWindowLoad(){
|
|||||||
|
|
||||||
// Load stored remote audio prefs
|
// Load stored remote audio prefs
|
||||||
chrome.storage.sync.get('remoteAudio', function (previousValue) {
|
chrome.storage.sync.get('remoteAudio', function (previousValue) {
|
||||||
if(previousValue.remoteAudio == null) {
|
if (previousValue.remoteAudio === null) {
|
||||||
document.querySelector('#externalAudioBtn').MaterialIconToggle.uncheck();
|
document.querySelector('#externalAudioBtn').MaterialIconToggle.uncheck();
|
||||||
} else if (previousValue.remoteAudio == false) {
|
} else if (previousValue.remoteAudio === false) {
|
||||||
document.querySelector('#externalAudioBtn').MaterialIconToggle.uncheck();
|
document.querySelector('#externalAudioBtn').MaterialIconToggle.uncheck();
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('#externalAudioBtn').MaterialIconToggle.check();
|
document.querySelector('#externalAudioBtn').MaterialIconToggle.check();
|
||||||
@ -823,7 +852,7 @@ function onWindowLoad(){
|
|||||||
|
|
||||||
// load stored framerate prefs
|
// load stored framerate prefs
|
||||||
chrome.storage.sync.get('frameRate', function (previousValue) {
|
chrome.storage.sync.get('frameRate', function (previousValue) {
|
||||||
if(previousValue.frameRate != null) {
|
if (previousValue.frameRate !== null) {
|
||||||
$('.framerateMenu li').each(function () {
|
$('.framerateMenu li').each(function () {
|
||||||
if ($(this).data('value') === previousValue.frameRate) {
|
if ($(this).data('value') === previousValue.frameRate) {
|
||||||
$('#selectFramerate').text($(this).text()).data('value', previousValue.frameRate);
|
$('#selectFramerate').text($(this).text()).data('value', previousValue.frameRate);
|
||||||
@ -834,9 +863,9 @@ function onWindowLoad(){
|
|||||||
|
|
||||||
// load stored optimization prefs
|
// load stored optimization prefs
|
||||||
chrome.storage.sync.get('optimize', function (previousValue) {
|
chrome.storage.sync.get('optimize', function (previousValue) {
|
||||||
if (previousValue.optimize == null) {
|
if (previousValue.optimize === null) {
|
||||||
document.querySelector('#optimizeGamesBtn').MaterialIconToggle.check();
|
document.querySelector('#optimizeGamesBtn').MaterialIconToggle.check();
|
||||||
} else if (previousValue.optimize == false) {
|
} else if (previousValue.optimize === false) {
|
||||||
document.querySelector('#optimizeGamesBtn').MaterialIconToggle.uncheck();
|
document.querySelector('#optimizeGamesBtn').MaterialIconToggle.uncheck();
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('#optimizeGamesBtn').MaterialIconToggle.check();
|
document.querySelector('#optimizeGamesBtn').MaterialIconToggle.check();
|
||||||
@ -845,19 +874,19 @@ function onWindowLoad(){
|
|||||||
|
|
||||||
// load stored bitrate prefs
|
// load stored bitrate prefs
|
||||||
chrome.storage.sync.get('bitrate', function (previousValue) {
|
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();
|
updateBitrateField();
|
||||||
});
|
});
|
||||||
|
|
||||||
// load the HTTP cert if we have one.
|
// load the HTTP cert if we have one.
|
||||||
chrome.storage.sync.get('cert', function (savedCert) {
|
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;
|
pairingCert = savedCert.cert;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.storage.sync.get('uniqueid', function (savedUniqueid) {
|
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;
|
myUniqueid = savedUniqueid.uniqueid;
|
||||||
} else {
|
} else {
|
||||||
myUniqueid = uniqueid();
|
myUniqueid = uniqueid();
|
||||||
@ -867,9 +896,9 @@ function onWindowLoad(){
|
|||||||
|
|
||||||
// load previously connected hosts, which have been killed into an object, and revive them back into a class
|
// 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) {
|
chrome.storage.sync.get('hosts', function (previousValue) {
|
||||||
hosts = previousValue.hosts != null ? previousValue.hosts : {};
|
hosts = previousValue.hosts !== null ? previousValue.hosts : {};
|
||||||
for(var hostUID in hosts) { // programmatically add each new host.
|
for (let hostUID in hosts) { // programmatically add each new host.
|
||||||
var revivedHost = new NvHTTP(hosts[hostUID].address, myUniqueid, hosts[hostUID].userEnteredAddress);
|
let revivedHost = new NvHTTP(hosts[hostUID].address, myUniqueid, hosts[hostUID].userEnteredAddress);
|
||||||
revivedHost.serverUid = hosts[hostUID].serverUid;
|
revivedHost.serverUid = hosts[hostUID].serverUid;
|
||||||
revivedHost.externalIP = hosts[hostUID].externalIP;
|
revivedHost.externalIP = hosts[hostUID].externalIP;
|
||||||
revivedHost.hostname = hosts[hostUID].hostname;
|
revivedHost.hostname = hosts[hostUID].hostname;
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
function guuid() {
|
function guuid() {
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
var 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);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function uniqueid() {
|
function uniqueid() {
|
||||||
return 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
return 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
||||||
var r = Math.random()*16|0;
|
let r = Math.random() * 16 | 0;
|
||||||
return r.toString(16);
|
return r.toString(16);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateRemoteInputKey() {
|
function generateRemoteInputKey() {
|
||||||
return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
||||||
var r = Math.random()*16|0;
|
let r = Math.random() * 16 | 0;
|
||||||
return r.toString(16);
|
return r.toString(16);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -23,14 +23,6 @@ function generateRemoteInputKeyId() {
|
|||||||
return ((Math.random() - 0.5) * 0x7FFFFFFF) | 0;
|
return ((Math.random() - 0.5) * 0x7FFFFFFF) | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
String.prototype.toHex = function() {
|
|
||||||
var hex = '';
|
|
||||||
for(var i = 0; i < this.length; i++) {
|
|
||||||
hex += '' + this.charCodeAt(i).toString(16);
|
|
||||||
}
|
|
||||||
return hex;
|
|
||||||
}
|
|
||||||
|
|
||||||
function NvHTTP(address, clientUid, userEnteredAddress = '') {
|
function NvHTTP(address, clientUid, userEnteredAddress = '') {
|
||||||
console.log('%c[utils.js, NvHTTP Object]', 'color: gray;', this);
|
console.log('%c[utils.js, NvHTTP Object]', 'color: gray;', this);
|
||||||
this.address = address;
|
this.address = address;
|
||||||
@ -55,23 +47,23 @@ function NvHTTP(address, clientUid, userEnteredAddress = '') {
|
|||||||
this._pollCompletionCallbacks = [];
|
this._pollCompletionCallbacks = [];
|
||||||
|
|
||||||
_self = this;
|
_self = this;
|
||||||
};
|
}
|
||||||
|
|
||||||
function _arrayBufferToBase64(buffer) {
|
function _arrayBufferToBase64(buffer) {
|
||||||
var binary = '';
|
let binary = '';
|
||||||
var bytes = new Uint8Array( buffer );
|
let bytes = new Uint8Array(buffer);
|
||||||
var len = bytes.byteLength;
|
let len = bytes.byteLength;
|
||||||
for (var i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
binary += String.fromCharCode(bytes[i]);
|
binary += String.fromCharCode(bytes[i]);
|
||||||
}
|
}
|
||||||
return window.btoa(binary);
|
return window.btoa(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _base64ToArrayBuffer(base64) {
|
function _base64ToArrayBuffer(base64) {
|
||||||
var binary_string = window.atob(base64);
|
let binary_string = window.atob(base64);
|
||||||
var len = binary_string.length;
|
let len = binary_string.length;
|
||||||
var bytes = new Uint8Array( len );
|
let bytes = new Uint8Array(len);
|
||||||
for (var i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
bytes[i] = binary_string.charCodeAt(i);
|
bytes[i] = binary_string.charCodeAt(i);
|
||||||
}
|
}
|
||||||
return bytes.buffer;
|
return bytes.buffer;
|
||||||
@ -125,7 +117,7 @@ NvHTTP.prototype = {
|
|||||||
// Poll for the app list every 10 successful serverinfo polls.
|
// Poll for the app list every 10 successful serverinfo polls.
|
||||||
// Not including the first one to avoid PCs taking a while to show
|
// Not including the first one to avoid PCs taking a while to show
|
||||||
// as online initially
|
// as online initially
|
||||||
if (this._pollCount++ % 10 == 1) {
|
if (this._pollCount++ % 10 === 1) {
|
||||||
this.getAppListWithCacheFlush();
|
this.getAppListWithCacheFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +125,7 @@ NvHTTP.prototype = {
|
|||||||
this.online = true;
|
this.online = true;
|
||||||
|
|
||||||
// Call all pending completion callbacks
|
// Call all pending completion callbacks
|
||||||
var completion;
|
let completion;
|
||||||
while ((completion = this._pollCompletionCallbacks.pop())) {
|
while ((completion = this._pollCompletionCallbacks.pop())) {
|
||||||
completion(this);
|
completion(this);
|
||||||
}
|
}
|
||||||
@ -143,7 +135,7 @@ NvHTTP.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call all pending completion callbacks
|
// Call all pending completion callbacks
|
||||||
var completion;
|
let completion;
|
||||||
while ((completion = this._pollCompletionCallbacks.pop())) {
|
while ((completion = this._pollCompletionCallbacks.pop())) {
|
||||||
completion(this);
|
completion(this);
|
||||||
}
|
}
|
||||||
@ -174,7 +166,7 @@ NvHTTP.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toString: function () {
|
toString: function () {
|
||||||
var string = '';
|
let string = '';
|
||||||
string += 'server address: ' + this.address + '\r\n';
|
string += 'server address: ' + this.address + '\r\n';
|
||||||
string += 'server UID: ' + this.serverUid + '\r\n';
|
string += 'server UID: ' + this.serverUid + '\r\n';
|
||||||
string += 'is paired: ' + this.paired + '\r\n';
|
string += 'is paired: ' + this.paired + '\r\n';
|
||||||
@ -185,7 +177,7 @@ NvHTTP.prototype = {
|
|||||||
string += 'gpu type: ' + this.gputype + '\r\n';
|
string += 'gpu type: ' + this.gputype + '\r\n';
|
||||||
string += 'number of apps: ' + this.numofapps + '\r\n';
|
string += 'number of apps: ' + this.numofapps + '\r\n';
|
||||||
string += 'supported display modes: ' + '\r\n';
|
string += 'supported display modes: ' + '\r\n';
|
||||||
for(var displayMode in this.supportedDisplayModes) {
|
for (let displayMode in this.supportedDisplayModes) {
|
||||||
string += '\t' + displayMode + ': ' + this.supportedDisplayModes[displayMode] + '\r\n';
|
string += '\t' + displayMode + ': ' + this.supportedDisplayModes[displayMode] + '\r\n';
|
||||||
}
|
}
|
||||||
return string;
|
return string;
|
||||||
@ -199,18 +191,18 @@ NvHTTP.prototype = {
|
|||||||
$xml = this._parseXML(xmlStr);
|
$xml = this._parseXML(xmlStr);
|
||||||
$root = $xml.find('root');
|
$root = $xml.find('root');
|
||||||
|
|
||||||
if($root.attr("status_code") != 200) {
|
if ($root.attr("status_code") !== 200) {
|
||||||
return false;
|
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.
|
// if we received a UID that isn't the one we expected, fail.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('%c[utils.js, _parseServerInfo]', 'color:gray;', 'Parsing server info:', $root);
|
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.currentGame = parseInt($root.find("currentgame").text().trim(), 10);
|
||||||
this.appVersion = $root.find("appversion").text().trim();
|
this.appVersion = $root.find("appversion").text().trim();
|
||||||
this.serverMajorVersion = parseInt(this.appVersion.substring(0, 1), 10);
|
this.serverMajorVersion = parseInt(this.appVersion.substring(0, 1), 10);
|
||||||
@ -223,9 +215,9 @@ NvHTTP.prototype = {
|
|||||||
this.numofapps = $root.find('numofapps').text().trim();
|
this.numofapps = $root.find('numofapps').text().trim();
|
||||||
// now for the hard part: parsing the supported streaming
|
// now for the hard part: parsing the supported streaming
|
||||||
$root.find('DisplayMode').each(function (index, value) { // for each resolution:FPS object
|
$root.find('DisplayMode').each(function (index, value) { // for each resolution:FPS object
|
||||||
var yres = parseInt($(value).find('Height').text());
|
let yres = parseInt($(value).find('Height').text());
|
||||||
var xres = parseInt($(value).find('Width').text());
|
let xres = parseInt($(value).find('Width').text());
|
||||||
var fps = parseInt($(value).find('RefreshRate').text());
|
let fps = parseInt($(value).find('RefreshRate').text());
|
||||||
if (!this.supportedDisplayModes[yres + ':' + xres]) {
|
if (!this.supportedDisplayModes[yres + ':' + xres]) {
|
||||||
this.supportedDisplayModes[yres + ':' + xres] = [];
|
this.supportedDisplayModes[yres + ':' + xres] = [];
|
||||||
}
|
}
|
||||||
@ -250,27 +242,10 @@ NvHTTP.prototype = {
|
|||||||
|
|
||||||
getAppById: function (appId) {
|
getAppById: function (appId) {
|
||||||
return this.getAppList().then(function (list) {
|
return this.getAppList().then(function (list) {
|
||||||
var retApp = null;
|
let retApp = null;
|
||||||
|
|
||||||
list.some(function (app) {
|
list.some(function (app) {
|
||||||
if (app.id == appId) {
|
if (app.id === appId) {
|
||||||
retApp = app;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
return retApp;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getAppByName: function (appName) {
|
|
||||||
return this.getAppList().then(function (list) {
|
|
||||||
var retApp = null;
|
|
||||||
|
|
||||||
list.some(function (app) {
|
|
||||||
if (app.title == appName) {
|
|
||||||
retApp = app;
|
retApp = app;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -287,17 +262,17 @@ NvHTTP.prototype = {
|
|||||||
$xml = this._parseXML(ret);
|
$xml = this._parseXML(ret);
|
||||||
$root = $xml.find("root");
|
$root = $xml.find("root");
|
||||||
|
|
||||||
if ($root.attr("status_code") != 200) {
|
if ($root.attr("status_code") !== 200) {
|
||||||
// TODO: Bubble up an error here
|
// TODO: Bubble up an error here
|
||||||
console.error('%c[utils.js, utils.js, getAppListWithCacheFlush]', 'color: gray;', 'Applist request failed', $root.attr("status_code"));
|
console.error('%c[utils.js, utils.js, getAppListWithCacheFlush]', 'color: gray;', 'Applist request failed', $root.attr("status_code"));
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootElement = $xml.find("root")[0];
|
let rootElement = $xml.find("root")[0];
|
||||||
var appElements = rootElement.getElementsByTagName("App");
|
let appElements = rootElement.getElementsByTagName("App");
|
||||||
var appList = [];
|
let appList = [];
|
||||||
|
|
||||||
for (var i = 0, len = appElements.length; i < len; i++) {
|
for (let i = 0, len = appElements.length; i < len; i++) {
|
||||||
appList.push({
|
appList.push({
|
||||||
title: appElements[i].getElementsByTagName("AppTitle")[0].innerHTML.trim(),
|
title: appElements[i].getElementsByTagName("AppTitle")[0].innerHTML.trim(),
|
||||||
id: parseInt(appElements[i].getElementsByTagName("ID")[0].innerHTML.trim(), 10)
|
id: parseInt(appElements[i].getElementsByTagName("ID")[0].innerHTML.trim(), 10)
|
||||||
@ -315,7 +290,6 @@ NvHTTP.prototype = {
|
|||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
console.log('%c[utils.js, utils.js]', 'color: gray;', 'Returning memory-cached apps list');
|
console.log('%c[utils.js, utils.js]', 'color: gray;', 'Returning memory-cached apps list');
|
||||||
resolve(this._memCachedApplist);
|
resolve(this._memCachedApplist);
|
||||||
return;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,23 +303,22 @@ NvHTTP.prototype = {
|
|||||||
console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Not warming box art cache for unpaired host');
|
console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Not warming box art cache for unpaired host');
|
||||||
return;
|
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');
|
console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Box art cache already warmed');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (chrome.storage) {
|
if (chrome.storage) {
|
||||||
chrome.storage.local.get('boxArtCache', function (JSONCachedBoxArtArray) {
|
chrome.storage.local.get('boxArtCache', function (JSONCachedBoxArtArray) {
|
||||||
|
|
||||||
var storedBoxArtArray; // load cached data if it exists
|
let storedBoxArtArray; // load cached data if it exists
|
||||||
if (JSONCachedBoxArtArray.boxArtCache != undefined) {
|
if (JSONCachedBoxArtArray.boxArtCache !== undefined) {
|
||||||
storedBoxArtArray = JSONCachedBoxArtArray.boxArtCache;
|
storedBoxArtArray = JSONCachedBoxArtArray.boxArtCache;
|
||||||
for (var key in storedBoxArtArray) {
|
for (let key in storedBoxArtArray) {
|
||||||
this._memCachedBoxArtArray[key] = _base64ToArrayBuffer(storedBoxArtArray[key]);
|
this._memCachedBoxArtArray[key] = _base64ToArrayBuffer(storedBoxArtArray[key]);
|
||||||
}
|
}
|
||||||
console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Box art cache warmed');
|
console.log('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'Box art cache warmed');
|
||||||
} else {
|
} else {
|
||||||
console.warn('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'No box art found in storage. Cannot warm cache!');
|
console.warn('%c[utils.js, warmBoxArtCache]', 'color: grey;', 'No box art found in storage. Cannot warm cache!');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@ -360,15 +333,13 @@ NvHTTP.prototype = {
|
|||||||
if (this._memCachedBoxArtArray[appId] === null) {
|
if (this._memCachedBoxArtArray[appId] === null) {
|
||||||
// This means a previous box art request failed, don't try again
|
// This means a previous box art request failed, don't try again
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
console.error('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning cached box-art failure result')
|
console.error('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning cached box-art failure result');
|
||||||
reject(null);
|
reject(null);
|
||||||
return;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else if (this._memCachedBoxArtArray[appId] !== undefined) {
|
} else if (this._memCachedBoxArtArray[appId] !== undefined) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
console.log('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning memory-cached box-art');
|
console.log('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning memory-cached box-art');
|
||||||
resolve(this._memCachedBoxArtArray[appId]);
|
resolve(this._memCachedBoxArtArray[appId]);
|
||||||
return;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,8 +349,8 @@ NvHTTP.prototype = {
|
|||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
chrome.storage.local.get('boxArtCache', function (JSONCachedBoxArtArray) {
|
chrome.storage.local.get('boxArtCache', function (JSONCachedBoxArtArray) {
|
||||||
|
|
||||||
var storedBoxArtArray; // load cached data if it exists
|
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 = JSONCachedBoxArtArray.boxArtCache;
|
||||||
|
|
||||||
storedBoxArtArray[appId] = _base64ToArrayBuffer(storedBoxArtArray[appId]);
|
storedBoxArtArray[appId] = _base64ToArrayBuffer(storedBoxArtArray[appId]);
|
||||||
@ -406,24 +377,23 @@ NvHTTP.prototype = {
|
|||||||
]).then(function (streamedBoxArt) {
|
]).then(function (streamedBoxArt) {
|
||||||
// the memcached data is global to all the async calls we're doing. This way there's only one array that holds everything properly.
|
// the memcached data is global to all the async calls we're doing. This way there's only one array that holds everything properly.
|
||||||
this._memCachedBoxArtArray[appId] = streamedBoxArt;
|
this._memCachedBoxArtArray[appId] = streamedBoxArt;
|
||||||
var obj = {};
|
let obj = {};
|
||||||
var arrayToStore = {}
|
let arrayToStore = {};
|
||||||
|
|
||||||
for (key in this._memCachedBoxArtArray) { // convert the arraybuffer into a string
|
for (key in this._memCachedBoxArtArray) { // convert the arraybuffer into a string
|
||||||
arrayToStore[key] = _arrayBufferToBase64(this._memCachedBoxArtArray[key]);
|
arrayToStore[key] = _arrayBufferToBase64(this._memCachedBoxArtArray[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
obj['boxArtCache'] = arrayToStore; // storage is in JSON format. JSON does not support binary data.
|
obj['boxArtCache'] = arrayToStore; // storage is in JSON format. JSON does not support binary data.
|
||||||
chrome.storage.local.set(obj, function(onSuccess) {});
|
chrome.storage.local.set(obj, function (onSuccess) {
|
||||||
|
});
|
||||||
console.log('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning streamed box art');
|
console.log('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Returning streamed box art');
|
||||||
resolve(streamedBoxArt);
|
resolve(streamedBoxArt);
|
||||||
return;
|
|
||||||
}.bind(this), function (error) {
|
}.bind(this), function (error) {
|
||||||
// Cache the failure but not persistently
|
// Cache the failure but not persistently
|
||||||
this._memCachedBoxArtArray[appId] = null;
|
this._memCachedBoxArtArray[appId] = null;
|
||||||
console.error('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Box-art request failed!', error);
|
console.error('%c[utils.js, utils.js, getBoxArt]', 'color: gray;', 'Box-art request failed!', error);
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@ -482,13 +452,13 @@ NvHTTP.prototype = {
|
|||||||
if (this.paired)
|
if (this.paired)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (this.currentGame != 0)
|
if (this.currentGame !== 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return sendMessage('pair', [this.serverMajorVersion.toString(), this.address, randomNumber]).then(function (pairStatus) {
|
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) {
|
return sendMessage('openUrl', [this._baseUrlHttps + '/pair?uniqueid=' + this.clientUid + '&devicename=roth&updateState=1&phrase=pairchallenge', false]).then(function (ret) {
|
||||||
$xml = this._parseXML(ret);
|
$xml = this._parseXML(ret);
|
||||||
this.paired = $xml.find('paired').html() == "1";
|
this.paired = $xml.find('paired').html() === "1";
|
||||||
return this.paired;
|
return this.paired;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user