diff --git a/index.html b/index.html index f7269a6..5cd081a 100644 --- a/index.html +++ b/index.html @@ -77,6 +77,8 @@ + +

Pairing

diff --git a/libgamestream/pairing.c b/libgamestream/pairing.c index 1a795ee..7ecb31a 100644 --- a/libgamestream/pairing.c +++ b/libgamestream/pairing.c @@ -233,10 +233,6 @@ int gs_pair(int serverMajorVersion, const char* address, const char* pin) { if ((ret = http_request(url, data)) != GS_OK) goto cleanup; - sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", address, g_UniqueId); - if ((ret = http_request(url, data)) != GS_OK) - goto cleanup; - cleanup: http_free_data(data); diff --git a/main.cpp b/main.cpp index 5318fc5..de1e3df 100644 --- a/main.cpp +++ b/main.cpp @@ -227,7 +227,7 @@ void MoonlightInstance::PairCallback(int32_t /*result*/, int32_t callbackId, pp: pp::VarDictionary ret; ret.Set("callbackId", pp::Var(callbackId)); - ret.Set("type", err ? pp::Var("reject") : pp::Var("resolve")); + ret.Set("type", pp::Var("resolve")); ret.Set("ret", pp::Var(err)); PostMessage(ret); } diff --git a/manifest.json b/manifest.json index 69b3145..fe68d00 100644 --- a/manifest.json +++ b/manifest.json @@ -16,9 +16,13 @@ "scripts": ["static/js/jquery-2.2.0.min.js", "static/js/material.min.js", "static/js/common.js", "static/js/background.js"] } }, + "sockets": { + "udp": { "bind": "*", "send": "*" } + }, "permissions": [ "storage", "pointerLock", + "system.network", "fullscreen", { "socket": [ "tcp-connect", diff --git a/static/js/index.js b/static/js/index.js index d9f17db..b260457 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -31,7 +31,7 @@ function snackbarLog(givenMessage) { } function updateBitrateField() { - $('#bitrateField').html($('#bitrateSlider')[0].value + " Mbps"); + $('#bitrateField').html($('#bitrateSlider').val() + " Mbps"); } function moduleDidLoad() { @@ -60,10 +60,13 @@ function moduleDidLoad() { // because the user can change the target host at any time, we continually have to check function updateTarget() { - target = $('#GFEHostIPField')[0].value; + target = $('#GFEHostIPField').val(); if (target == null || target == "") { - var e = $("#selectHost")[0]; - target = e.options[e.selectedIndex].value; + target = $("#selectHost option:selected").val(); + } + + if(api && api.address != target) { + api = new NvHTTP(target, myUniqueid); } } @@ -80,70 +83,57 @@ function hideAllWorkflowDivs() { // pair button was pushed. pass what the user entered into the GFEHostIPField. function pairPushed() { updateTarget(); + if(!pairingCert) { snackbarLog('ERROR: cert has not been generated yet. Is NaCL initialized?'); console.log("User wants to pair, and we still have no cert. Problem = very yes."); return; } - if(!api || !api.paired) { + + if(!api) { api = new NvHTTP(target, myUniqueid); } - - - api.refreshServerInfoUnpaired().then(function (ret) { - - if(api.currentGame != 0) { // make sure host isn't already in a game - snackbarLog(target + ' is already in game. Cannot pair!'); + + if(api.paired) { + return; + } + + $('#pairButton').html('Pairing...'); + snackbarLog('Attempting pair to: ' + target); + var randomNumber = String("0000" + (Math.random()*10000|0)).slice(-4); + var 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'); + pairingDialog.showModal(); + console.log('sending pairing request to ' + target + ' with random number ' + randomNumber); + + api.pair(randomNumber).then(function (paired) { + if (!paired) { + snackbarLog('Pairing failed'); + $('#pairButton').html('Pairing Failed'); + $('#pairingDialogText').html('Error: Pairing failed'); + if (api.currentGame != 0) + snackbarLog(target + ' is already in game. Cannot pair!'); return; } + + $('#pairButton').html('Paired'); + snackbarLog('Pairing successful'); + pairingDialog.close(); + + var hostSelect = $('#selectHost')[0]; + for(var i = 0; i < hostSelect.length; i++) { // check if we already have the host. + if (hostSelect.options[i].value == target) return; + } - api.refreshServerInfo().then(function (ret) { - if(api.paired) { // don't pair if you don't have to - snackbarLog('already paired with ' + target + '!'); - return; - } else { // we're not already paired. pair now. - - $('#pairButton')[0].innerHTML = 'Pairing...'; - snackbarLog('Attempting pair to: ' + target); - var randomNumber = String("0000" + (Math.random()*10000|0)).slice(-4); - var pairingDialog = document.querySelector('#pairingDialog'); - document.getElementById('pairingDialogText').innerHTML = - 'Please enter the number ' + randomNumber + ' on the GFE dialog on the computer. This dialog will be dismissed once complete'; - pairingDialog.showModal(); - console.log('sending pairing request to ' + target + ' with random number ' + randomNumber); - - sendMessage('pair', [api.serverMajorVersion, target, randomNumber]).then(function (ret3) { - console.log('"pair" call returned.'); - console.log(ret3); - if (ret3 === 0) { // pairing was successful. save this host. - $('#pairButton')[0].innerHTML = 'Paired'; - snackbarLog('Pairing successful'); - pairingDialog.close(); - var hostSelect = $('#selectHost')[0]; - for(var i = 0; i < hostSelect.length; i++) { // check if we already have the host. - if (hostSelect.options[i].value == target) return; - } - - var opt = document.createElement('option'); - opt.appendChild(document.createTextNode(target)); - opt.value = target; - $('#selectHost')[0].appendChild(opt); - hosts.push(target); - saveHosts(); - // move directly on to retrieving the apps list. - showAppsPushed(); - } else { - snackbarLog('Pairing failed'); - $('#pairButton')[0].innerHTML = 'Pairing Failed'; - document.getElementById('pairingDialogText').innerHTML = 'Error: Pairing failed with code: ' + ret3; - } - console.log("pairing attempt returned: " + ret3); - }); - - } - }); + var opt = document.createElement('option'); + opt.appendChild(document.createTextNode(target)); + opt.value = target; + $('#selectHost')[0].appendChild(opt); + hosts.push(target); + saveHosts(); + + showAppsPushed(); }); - } function pairingPopupCanceled() { @@ -155,30 +145,32 @@ function pairingPopupCanceled() { // otherwise, we assume they selected from the host history dropdown. function showAppsPushed() { updateTarget(); + if(!api || !api.paired) { - api = new NvHTTP(target, myUniqueid); + return; } - api.refreshServerInfo().then(function (ret) { - api.getAppList().then(function (appList) { - if ($('#selectGame').has('option').length > 0 ) { - // there was already things in the dropdown. Clear it, then add the new ones. - // Most likely, the user just hit the 'retrieve app list' button again - $('#selectGame').empty(); - } - for(var i = 0; i < appList.length; i++) { // programmatically add each app - var opt = document.createElement('option'); - opt.appendChild(document.createTextNode(appList[i])); - opt.value = appList[i].id; - opt.innerHTML = appList[i].title; - $('#selectGame')[0].appendChild(opt); - } - $("#selectGame").html($("#selectGame option").sort(function (a, b) { // thanks, http://stackoverflow.com/a/7466196/3006365 - return a.text.toUpperCase() == b.text.toUpperCase() ? 0 : a.text.toUpperCase() < b.text.toUpperCase() ? -1 : 1 - })); - if (api.currentGame != 0) $('#selectGame')[0].value = api.currentGame; - gameSelectUpdated(); // default the button to 'Resume Game' if one is running. + + api.getAppList().then(function (appList) { + if ($('#selectGame').has('option').length > 0 ) { + // there was already things in the dropdown. Clear it, then add the new ones. + // Most likely, the user just hit the 'retrieve app list' button again + $('#selectGame').empty(); + } + + appList.forEach(function (app) { + $('#selectGame').append($('