mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
Fix adding a PC that has already been paired
This commit is contained in:
parent
2167a8d94d
commit
fd3d19ca03
@ -106,47 +106,49 @@ function pairTo(host, onSuccess, onFailure) {
|
|||||||
onFailure();
|
onFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!api) {
|
api = new NvHTTP(host, myUniqueid);
|
||||||
api = new NvHTTP(host, myUniqueid);
|
api.refreshServerInfo().then(function (ret) {
|
||||||
}
|
if(api.paired) {
|
||||||
|
onSuccess();
|
||||||
if(api.paired) {
|
|
||||||
onSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ' + host + ' with random number ' + randomNumber);
|
|
||||||
|
|
||||||
api.pair(randomNumber).then(function (paired) {
|
|
||||||
if (!paired) {
|
|
||||||
if (api.currentGame != 0) {
|
|
||||||
$('#pairingDialogText').html('Error: ' + host + ' is in app. Cannot pair until the app is stopped.');
|
|
||||||
} else {
|
|
||||||
$('#pairingDialogText').html('Error: failed to pair with ' + host + '. failure reason unknown.');
|
|
||||||
}
|
|
||||||
onFailure();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snackbarLog('Pairing successful');
|
var randomNumber = String("0000" + (Math.random()*10000|0)).slice(-4);
|
||||||
pairingDialog.close();
|
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 ' + host + ' with random number ' + randomNumber);
|
||||||
|
|
||||||
var cell = document.createElement('div');
|
api.pair(randomNumber).then(function (paired) {
|
||||||
cell.className += 'mdl-cell mdl-cell--3-col';
|
if (!paired) {
|
||||||
cell.id = 'hostgrid-' + hosts[i];
|
if (api.currentGame != 0) {
|
||||||
cell.innerHTML = hosts[i];
|
$('#pairingDialogText').html('Error: ' + host + ' is in app. Cannot pair until the app is stopped.');
|
||||||
$('#host-grid').append(cell);
|
} else {
|
||||||
cell.onclick = hostChosen;
|
$('#pairingDialogText').html('Error: failed to pair with ' + host + '. failure reason unknown.');
|
||||||
|
}
|
||||||
|
onFailure();
|
||||||
|
}
|
||||||
|
|
||||||
saveHosts();
|
snackbarLog('Pairing successful');
|
||||||
onSuccess();
|
pairingDialog.close();
|
||||||
|
|
||||||
}, function (failedPairing) {
|
var cell = document.createElement('div');
|
||||||
snackbarLog('Failed pairing to: ' + host);
|
cell.className += 'mdl-cell mdl-cell--3-col';
|
||||||
console.log('pairing failed, and returned ' + failedPairing);
|
cell.id = 'hostgrid-' + host;
|
||||||
onFailure();
|
cell.innerHTML = host;
|
||||||
|
$('#host-grid').append(cell);
|
||||||
|
cell.onclick = hostChosen;
|
||||||
|
|
||||||
|
saveHosts();
|
||||||
|
onSuccess();
|
||||||
|
|
||||||
|
}, function (failedPairing) {
|
||||||
|
snackbarLog('Failed pairing to: ' + host);
|
||||||
|
console.log('pairing failed, and returned ' + failedPairing);
|
||||||
|
onFailure();
|
||||||
|
});
|
||||||
|
}, function (failedRefreshInfo) {
|
||||||
|
snackbarLog('Failed to connect to ' + host + '! Are you sure the host is on?');
|
||||||
|
console.log('Returned error was: ' + failedRefreshInfo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,11 +159,7 @@ function hostChosen(sourceEvent) {
|
|||||||
host = sourceEvent.srcElement.innerText;
|
host = sourceEvent.srcElement.innerText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api = new NvHTTP(host, myUniqueid);
|
||||||
if(!api || api.address != host) {
|
|
||||||
api = new NvHTTP(host, myUniqueid);
|
|
||||||
}
|
|
||||||
|
|
||||||
api.refreshServerInfo().then(function (ret) {
|
api.refreshServerInfo().then(function (ret) {
|
||||||
if(!api.paired) {
|
if(!api.paired) {
|
||||||
pairTo(host);
|
pairTo(host);
|
||||||
@ -169,8 +167,8 @@ function hostChosen(sourceEvent) {
|
|||||||
if(hosts.indexOf(host) < 0) { // we don't have this host in our list. add it, and save it.
|
if(hosts.indexOf(host) < 0) { // we don't have this host in our list. add it, and save it.
|
||||||
var cell = document.createElement('div');
|
var cell = document.createElement('div');
|
||||||
cell.className += 'mdl-cell mdl-cell--3-col';
|
cell.className += 'mdl-cell mdl-cell--3-col';
|
||||||
cell.id = 'hostgrid-' + hosts[i];
|
cell.id = 'hostgrid-' + host;
|
||||||
cell.innerHTML = hosts[i];
|
cell.innerHTML = host;
|
||||||
$('#host-grid').append(cell);
|
$('#host-grid').append(cell);
|
||||||
cell.onclick = hostChosen;
|
cell.onclick = hostChosen;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user