mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2026-04-21 07:30:12 +00:00
New message handling, and new NvAPI
This commit is contained in:
5949
static/js/crypto-js.js
Normal file
5949
static/js/crypto-js.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,19 +3,19 @@ var hosts = [];
|
||||
|
||||
// Called by the common.js module.
|
||||
function attachListeners() {
|
||||
$('#startButton')[0].addEventListener('click', startPushed);
|
||||
$('#stopButton')[0].addEventListener('click', stopPushed);
|
||||
$('#pairButton')[0].addEventListener('click', pairPushed);
|
||||
$('#showAppsButton')[0].addEventListener('click', showAppsPushed);
|
||||
$('#selectResolution')[0].addEventListener('change', saveResolution);
|
||||
$('#selectFramerate')[0].addEventListener('change', saveFramerate);
|
||||
$('#bitrateSlider')[0].addEventListener('input', updateBitrateField); // input occurs every notch you slide
|
||||
$('#bitrateSlider')[0].addEventListener('change', saveBitrate); // change occurs once the mouse lets go.
|
||||
window.addEventListener("resize", fullscreenNaclModule);
|
||||
$('#startButton').on('click', startPushed);
|
||||
$('#stopButton').on('click', stopPushed);
|
||||
$('#pairButton').on('click', pairPushed);
|
||||
$('#showAppsButton').on('click', showAppsPushed);
|
||||
$('#selectResolution').on('change', saveResolution);
|
||||
$('#selectFramerate').on('change', saveFramerate);
|
||||
$('#bitrateSlider').on('input', updateBitrateField); // input occurs every notch you slide
|
||||
$('#bitrateSlider').on('change', saveBitrate); // change occurs once the mouse lets go.
|
||||
$(window).resize(fullscreenNaclModule);
|
||||
}
|
||||
|
||||
function updateBitrateField() {
|
||||
$('#bitrateField')[0].innerHTML = $('#bitrateSlider')[0].value + " Mbps"
|
||||
$('#bitrateField').html($('#bitrateSlider')[0].value + " Mbps");
|
||||
}
|
||||
|
||||
function moduleDidLoad() {
|
||||
@@ -26,9 +26,9 @@ function moduleDidLoad() {
|
||||
// but to save from the PITA of inter-chrome-app-page JS message passing,
|
||||
// I'm opting to do it in a single page, and keep the data around.
|
||||
function hideAllWorkflowDivs() {
|
||||
$('#streamSettings')[0].style.display = 'inline-block';
|
||||
$('#hostSettings')[0].style.display = 'inline-block';
|
||||
$('#gameSelection')[0].style.display = 'none';
|
||||
$('#streamSettings').css('display', 'inline-block');
|
||||
$('#hostSettings').css('display', 'inline-block');
|
||||
$('#gameSelection').css('display', 'none');
|
||||
// common.hideModule(); // do NOT hide the nacl module. you can't interact with it then
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ function showAppsPushed() {
|
||||
|
||||
function showAppsMode() {
|
||||
console.log("entering show apps mode.")
|
||||
$('#streamSettings')[0].style.display = 'none';
|
||||
$('#hostSettings')[0].style.display = 'none';
|
||||
$('#gameSelection')[0].style.display = 'inline-block';
|
||||
$("#main-content").children().not("#listener").display = "inline-block";
|
||||
document.body.style.backgroundColor = "white";
|
||||
$('#streamSettings').css('display', 'none');
|
||||
$('#hostSettings').css('display', 'none');
|
||||
$('#gameSelection').css('display', 'inline-block');
|
||||
$("#main-content").children().not("#listener").css('display', 'inline-block');
|
||||
$("body").css('backgroundColor', 'white');
|
||||
}
|
||||
|
||||
// user wants to start a stream. We need the host, game ID, and video settings(?)
|
||||
@@ -66,12 +66,17 @@ function startPushed() {
|
||||
var e = document.getElementById("selectHost");
|
||||
target = e.options[e.selectedIndex].value;
|
||||
}
|
||||
var frameRate = $("#selectFramerate")[0].value;
|
||||
var resolution = $("#selectResolution")[0].value;
|
||||
|
||||
var frameRate = $("#selectFramerate").val();
|
||||
var streamWidth = $('#selectResolution option:selected').val().split(':')[0];
|
||||
var streamHeight = $('#selectResolution option:selected').val().split(':')[1];
|
||||
// we told the user it was in Mbps. We're dirty liars and use Kbps behind their back.
|
||||
var bitrate = parseInt($("#bitrateSlider")[0].value) * 1024;
|
||||
var bitrate = parseInt($("#bitrateSlider").val()) * 1024;
|
||||
|
||||
console.log('startRequest:' + target + ":" + resolution + ":" + frameRate);
|
||||
common.naclModule.postMessage('startRequest:' + target + ":" + resolution + ":" + frameRate + ":" + bitrate + ":");
|
||||
|
||||
sendMessage('startRequest', [target, streamWidth, streamHeight, frameRate, bitrate]);
|
||||
|
||||
// we just finished the gameSelection section. only expose the NaCl section
|
||||
playGameMode();
|
||||
}
|
||||
@@ -86,8 +91,8 @@ function playGameMode() {
|
||||
}
|
||||
|
||||
function fullscreenNaclModule() {
|
||||
var streamWidth = $('#selectResolution')[0].options[$('#selectResolution')[0].selectedIndex].value.split(':')[0];
|
||||
var streamHeight = $('#selectResolution')[0].options[$('#selectResolution')[0].selectedIndex].value.split(':')[1];
|
||||
var streamWidth = $('#selectResolution option:selected').val().split(':')[0];
|
||||
var streamHeight = $('#selectResolution option:selected').val().split(':')[1];
|
||||
var screenWidth = window.innerWidth;
|
||||
var screenHeight = window.innerHeight;
|
||||
|
||||
@@ -104,46 +109,25 @@ function fullscreenNaclModule() {
|
||||
|
||||
// user pushed the stop button. we should stop.
|
||||
function stopPushed() {
|
||||
common.naclModule.postMessage('stopRequested');
|
||||
}
|
||||
|
||||
// hook from main.cpp into the javascript
|
||||
function handleMessage(msg) {
|
||||
var quitStreamString = "streamTerminated";
|
||||
var connectionEstablishedString = "Connection Established";
|
||||
console.log("message received: " + msg.data);
|
||||
if (msg.data.lastIndexOf(quitStreamString, 0) === 0) {
|
||||
console.log("Stream termination message received. returning to 'show apps' screen.")
|
||||
showAppsMode();
|
||||
} else if (msg.data.lastIndexOf(connectionEstablishedString, 0) === 0) {
|
||||
var hostSelect = $('#selectHost')[0];
|
||||
for(var i = 0; i < hostSelect.length; i++) {
|
||||
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();
|
||||
}
|
||||
//common.naclModule.postMessage('stopRequested');
|
||||
sendMessage('stopRequested');
|
||||
}
|
||||
|
||||
function storeData(key, data, callbackFunction) {
|
||||
var obj = {};
|
||||
obj[key] = data;
|
||||
chrome.storage.sync.set(obj, callbackFunction);
|
||||
if(chrome.storage)
|
||||
chrome.storage.sync.set(obj, callbackFunction);
|
||||
}
|
||||
|
||||
function saveResolution() {
|
||||
updateDefaultBitrate();
|
||||
storeData('resolution', $('#selectResolution')[0].value, null);
|
||||
storeData('resolution', $('#selectResolution').val(), null);
|
||||
}
|
||||
|
||||
function saveFramerate() {
|
||||
updateDefaultBitrate();
|
||||
storeData('frameRate', $('#selectFramerate')[0].value, null);
|
||||
storeData('frameRate', $('#selectFramerate').val(), null);
|
||||
}
|
||||
|
||||
function saveHosts() {
|
||||
@@ -151,12 +135,12 @@ function saveHosts() {
|
||||
}
|
||||
|
||||
function saveBitrate() {
|
||||
storeData('bitrate', $('#bitrateSlider')[0].value, null);
|
||||
storeData('bitrate', $('#bitrateSlider').val(), null);
|
||||
}
|
||||
|
||||
function updateDefaultBitrate() {
|
||||
var res = $('#selectResolution')[0].value;
|
||||
var frameRate = $('#selectFramerate')[0].value;
|
||||
var res = $('#selectResolution').val();
|
||||
var frameRate = $('#selectFramerate').val();
|
||||
|
||||
if (res.lastIndexOf("1920:1080", 0) === 0) {
|
||||
if (frameRate.lastIndexOf("30", 0) === 0) { // 1080p, 30fps
|
||||
@@ -177,36 +161,39 @@ function updateDefaultBitrate() {
|
||||
|
||||
function onWindowLoad(){
|
||||
// don't show the game selection div
|
||||
document.getElementById('gameSelection').style.display = 'none';
|
||||
$('#gameSelection').css('display', 'none');
|
||||
$("#bitrateField").addClass("bitrateField");
|
||||
// load stored resolution prefs
|
||||
chrome.storage.sync.get('resolution', function(previousValue) {
|
||||
$('#selectResolution')[0].remove(0);
|
||||
$('#selectResolution')[0].value = previousValue.resolution != null ? previousValue.resolution : '1280:720';
|
||||
});
|
||||
// load stored framerate prefs
|
||||
chrome.storage.sync.get('frameRate', function(previousValue) {
|
||||
$('#selectFramerate')[0].remove(0);
|
||||
$('#selectFramerate')[0].value = previousValue.frameRate != null ? previousValue.frameRate : '30';
|
||||
});
|
||||
// load previously connected hosts
|
||||
chrome.storage.sync.get('hosts', function(previousValue) {
|
||||
hosts = previousValue.hosts != null ? previousValue.hosts : [];
|
||||
if ($('#selectHost')[0].length > 0) {
|
||||
$('#selectHost')[0].remove($('#selectHost')[0].selectedIndex);
|
||||
}
|
||||
for(var i = 0; i < hosts.length; i++) { // programmatically add each new host.
|
||||
var opt = document.createElement('option');
|
||||
opt.appendChild(document.createTextNode(hosts[i]));
|
||||
opt.value = hosts[i];
|
||||
$('#selectHost')[0].appendChild(opt);
|
||||
}
|
||||
});
|
||||
// load stored bitrate prefs
|
||||
chrome.storage.sync.get('bitrate', function(previousValue) {
|
||||
$('#bitrateSlider')[0].MaterialSlider.change(previousValue.bitrate != null ? previousValue.bitrate : '15');
|
||||
updateBitrateField();
|
||||
});
|
||||
|
||||
if(chrome.storage) {
|
||||
// load stored resolution prefs
|
||||
chrome.storage.sync.get('resolution', function(previousValue) {
|
||||
$('#selectResolution')[0].remove(0);
|
||||
$('#selectResolution')[0].value = previousValue.resolution != null ? previousValue.resolution : '1280:720';
|
||||
});
|
||||
// load stored framerate prefs
|
||||
chrome.storage.sync.get('frameRate', function(previousValue) {
|
||||
$('#selectFramerate')[0].remove(0);
|
||||
$('#selectFramerate')[0].value = previousValue.frameRate != null ? previousValue.frameRate : '30';
|
||||
});
|
||||
// load previously connected hosts
|
||||
chrome.storage.sync.get('hosts', function(previousValue) {
|
||||
hosts = previousValue.hosts != null ? previousValue.hosts : [];
|
||||
if ($('#selectHost')[0].length > 0) {
|
||||
$('#selectHost')[0].remove($('#selectHost')[0].selectedIndex);
|
||||
}
|
||||
for(var i = 0; i < hosts.length; i++) { // programmatically add each new host.
|
||||
var opt = document.createElement('option');
|
||||
opt.appendChild(document.createTextNode(hosts[i]));
|
||||
opt.value = hosts[i];
|
||||
$('#selectHost')[0].appendChild(opt);
|
||||
}
|
||||
});
|
||||
// load stored bitrate prefs
|
||||
chrome.storage.sync.get('bitrate', function(previousValue) {
|
||||
$('#bitrateSlider')[0].MaterialSlider.change(previousValue.bitrate != null ? previousValue.bitrate : '15');
|
||||
updateBitrateField();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
static/js/messages.js
Normal file
24
static/js/messages.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var callbacks = {}
|
||||
var callbacks_ids = 1;
|
||||
|
||||
var sendMessage = function(method, params) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var id = callbacks_ids++;
|
||||
callbacks[id] = {'resolve': resolve, 'reject': reject};
|
||||
|
||||
common.naclModule.postMessage({
|
||||
'callbackId': id,
|
||||
'method': method,
|
||||
'params': params
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function handleMessage(msg) {
|
||||
if (msg.data.callbackId && callbacks[msg.data.callbackId]) {
|
||||
callbacks[msg.data.callbackId][msg.data.type](msg.data.ret);
|
||||
delete callbacks[msg.data.callbackId]
|
||||
} else {
|
||||
console.log(msg.data);
|
||||
}
|
||||
}
|
||||
@@ -1,243 +1,196 @@
|
||||
function getXMLString(xml, tagName) {
|
||||
var xmlDoc = xml.responseXML;
|
||||
return xmlDoc.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
|
||||
function guuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
function verifyResponseStatus(xml) {
|
||||
var responseCode = parseInt(getXMLString(xml, "status_code"));
|
||||
if (responseCode !== 200) {
|
||||
throw "Error, expected status code 200, received status code: ".concat(responseCode.toString());
|
||||
}
|
||||
String.prototype.toHex = function() {
|
||||
var hex = '';
|
||||
for(var i = 0; i < this.length; i++) {
|
||||
hex += '' + this.charCodeAt(i).toString(16);
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
function getServerInfo() {
|
||||
var connectionResp = openHttpConnectionToString(baseUrlHttps + "/serverinfo?"+buildUniqueIdUuidString(), true);
|
||||
var serverResp = getServerVersion(connectionResp);
|
||||
function NvAPI(address, clientUid) {
|
||||
this.address = address;
|
||||
this.paired = false;
|
||||
this.supports4K = false;
|
||||
this.currentGame = 0;
|
||||
this.serverMajorVersion = 0;
|
||||
this.clientUid = clientUid;
|
||||
this._baseUrlHttps = 'https://' + address + ':47984';
|
||||
this._baseUrlHttp = 'http://' + address + ':47989';
|
||||
_self = this;
|
||||
};
|
||||
|
||||
if(serverResp == 200) {
|
||||
return connectionResp;
|
||||
} else {
|
||||
if(serverResp == 401) {
|
||||
return openHttpConnectionToString(baseUrlHttp + "/serverinfo", true);
|
||||
}
|
||||
throw serverResp
|
||||
}
|
||||
//FOR TEST ONLY
|
||||
var api;
|
||||
function init() {
|
||||
api = new NvAPI('localhost', guuid());
|
||||
return sendMessage('makeCert', []).then(function (cert) {
|
||||
return sendMessage('httpInit', [cert.cert, cert.privateKey]).then(function (ret) {
|
||||
return api.pair(cert, "1234");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getComputerDetails() {
|
||||
var serverInfo = getServerInfo();
|
||||
var details = {
|
||||
name: getXMLString(serverinfo, "hostname"),
|
||||
uuid: UUID.fromString(getXmlString(serverInfo, "uniqueid").trim()),
|
||||
macAddress: getXmlString(serverInfo, "mac").trim(),
|
||||
localIPStr: getXmlString(serverInfo, "LocalIP"),
|
||||
externalIpStr: getXmlString(serverInfo, "ExternalIP"),
|
||||
pairState: parseInt(getXmlString(serverInfo, "PairStatus").trim()) == 1 ? PairState.PAIRED : PairState.NOT_PAIRED, // needs support for PiarState.FAILED
|
||||
runningGameId: getCurrentGame(serverInfo), // force to 0 if an error happens
|
||||
state: ONLINE
|
||||
};
|
||||
return details;
|
||||
}
|
||||
|
||||
function openHTTPRequest(destinationURL, enableReadTimeout, callbackFunction) {
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
if(enableReadTimeout) {
|
||||
xmlHttp.timeout = 5000;
|
||||
}
|
||||
xmlHttp.onreadystatechange = function() {
|
||||
callbackFunction(xmlHttp);
|
||||
// if (xmlHttp.readyState == 4 && xmlHttp.status == 200) callbackFunction(xmlHttp.responseText);
|
||||
}
|
||||
xmlHttp.open("GET", theUrl, true); // true for asynchronous
|
||||
xmlHttp.send(null);
|
||||
}
|
||||
|
||||
|
||||
function getServerVersion(serverInfo) {
|
||||
return getXmlString(serverInfo, "appversion");
|
||||
}
|
||||
|
||||
function getPairState() {
|
||||
return pm.getPairState(getServerInfo());
|
||||
}
|
||||
|
||||
function getPairState(serverInfo) {
|
||||
return pm.getPairState(serverInfo);
|
||||
}
|
||||
|
||||
|
||||
function getMaxLumaPixelsH264(serverInfo) {
|
||||
var str = getXmlString(serverInfo, "MaxLumaPixelsH264");
|
||||
if (str !== null) {
|
||||
return parseInt(str);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function getMaxLumaPixelsHEVC(serverInfo) {
|
||||
var str = getXmlString(serverInfo, "MaxLumaPixelsHEVC");
|
||||
if (str !== null) {
|
||||
return parseInt(str);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function getGpuType(String serverInfo) {
|
||||
return getXmlString(serverInfo, "gputype");
|
||||
}
|
||||
|
||||
public boolean supports4K(String serverInfo) throws XmlPullParserException, IOException {
|
||||
// serverinfo returns supported resolutions in descending order, so getting the first
|
||||
// height will give us whether we support 4K. If this is not present, we don't support
|
||||
// 4K.
|
||||
var heightStr = getXmlString(serverInfo, "Height");
|
||||
if (heightStr == null) {
|
||||
return false;
|
||||
}
|
||||
NvAPI.prototype = {
|
||||
init: function () {
|
||||
return sendMessage('openUrl', [_self._baseUrlHttps+'/serverinfo?'+_self._buildUidStr()]).then(function(ret) {
|
||||
$xml = _self._parseXML(ret);
|
||||
$root = $xml.find('root')
|
||||
|
||||
if($root.attr("status_code") == 200) {
|
||||
_self.pair = getXMLString(xml, "PairStatus").trim() == 1;
|
||||
_self.currentGame = getXMLString(xml, "currentgame").trim();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// GFE 2.8 released without 4K support, even though it claims to have such
|
||||
// support using the SupportedDisplayMode element. We'll use the new ServerCodecModeSupport
|
||||
// element to tell whether 4K is supported or not. For now, we just check the existence
|
||||
// of this element. I'm hopeful that the production version that ships with 4K will
|
||||
// also be the first production version that has this element.
|
||||
if (getXmlString(serverInfo, "ServerCodecModeSupport") == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parseInt(heightStr) >= 2160) {
|
||||
// Found a 4K resolution in the list
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function getCurrentGame(String serverInfo) throws IOException, XmlPullParserException {
|
||||
// GFE 2.8 started keeping currentgame set to the last game played. As a result, it no longer
|
||||
// has the semantics that its name would indicate. To contain the effects of this change as much
|
||||
// as possible, we'll force the current game to zero if the server isn't in a streaming session.
|
||||
var serverState = getXmlString(serverInfo, "state").trim();
|
||||
if (serverState != null && !serverState.match("_SERVER_AVAILABLE" + "$")) { // an endsWith implementation.
|
||||
var game = getXmlString(serverInfo, "currentgame").trim();
|
||||
return parseInt(game);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function getAppById(appId) {
|
||||
var appList = getAppList();
|
||||
for (var i = 0, len = appList.length; i < len; i++) {
|
||||
if (appList[i].getAppId() == appId) {
|
||||
return appFromList;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* NOTE: Only use this function if you know what you're doing.
|
||||
* It's totally valid to have two apps named the same thing,
|
||||
* or even nothing at all! Look apps up by ID if at all possible
|
||||
* using the above function */
|
||||
function getAppByName(appName) {
|
||||
var appList = getAppList();
|
||||
for (var i = 0, len = appList.length; i < len; i++) {
|
||||
if (appList[i].getAppName().equalsIgnoreCase(appName)) {
|
||||
return appList[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function pair(pin) {
|
||||
return pm.pair(pin);
|
||||
}
|
||||
|
||||
function getAppListByReader(xml) {
|
||||
var rootElement = xml.getElementsByTagName("root")[0];
|
||||
var appElements = rootElement.getElementsByTagName("App");
|
||||
var returnVar;
|
||||
for(var i = 0, len = appElements.length; i < len; i++) {
|
||||
returnVar.push(
|
||||
var app {
|
||||
appTitle: appElements[i].getElementsByTagName("AppTitle")[0].nodeValue;
|
||||
ID: appElements[i].getElementsByTagName("ID")[0].nodeValue;
|
||||
isRunning: appElements[i].getElementsByTagName("IsRunning")[0].nodeValue;
|
||||
getAppById: function (appId) {
|
||||
return getAppList().then(function (list) {
|
||||
var retApp = null;
|
||||
|
||||
list.some(function (app) {
|
||||
if (app.id == appId) {
|
||||
retApp = app;
|
||||
return true;
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function getAppListRaw() {
|
||||
return openHttpConnectionToString(baseUrlHttps + "/applist?" + buildUniqueIdUuidString(), true);
|
||||
}
|
||||
|
||||
function getAppList() {
|
||||
if (verbose) {
|
||||
// Use the raw function so the app list is printed
|
||||
return getAppListByReader(new StringReader(getAppListRaw()));
|
||||
}
|
||||
else {
|
||||
var resp = openHttpConnection(baseUrlHttps + "/applist?" + buildUniqueIdUuidString(), true);
|
||||
var appList = getAppListByReader(new InputStreamReader(resp.byteStream()));
|
||||
resp.close();
|
||||
return appList;
|
||||
}
|
||||
}
|
||||
|
||||
function unpair() {
|
||||
openHttpConnectionToString(baseUrlHttps + "/unpair?"+buildUniqueIdUuidString(), true);
|
||||
}
|
||||
|
||||
|
||||
function getBoxArt(app) {
|
||||
var resp = openHttpConnection(baseUrlHttps + "/appasset?"+ buildUniqueIdUuidString() + "&appid=" + app.getAppId() + "&AssetType=2&AssetIdx=0", true);
|
||||
return resp.byteStream();
|
||||
}
|
||||
|
||||
|
||||
var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "A", "B", "C", "D", "E", "F"];
|
||||
function byteToHex(b) { // thanks, https://gist.github.com/amorri40/3430429
|
||||
if (b.constructor === Array) { // if we were given an array, then return an array.
|
||||
var returnVar;
|
||||
for(var i = 0, len = b.length; i < len; i++) {
|
||||
returnVar.push(hexChar[(b[i] >> 4) & 0x0f] + hexChar[b[i] & 0x0f]);
|
||||
}
|
||||
return returnVar;
|
||||
}
|
||||
return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f];
|
||||
}
|
||||
|
||||
function launchApp(context, appId){
|
||||
var xmlStr = openHttpConnectionToString(baseUrlHttps +
|
||||
"/launch?" + buildUniqueIdUuidString() +
|
||||
"&appid=" + appId +
|
||||
"&mode=" + context.negotiatedWidth + "x" + context.negotiatedHeight + "x" + context.negotiatedFps +
|
||||
"&additionalStates=1&sops=" + (context.streamConfig.getSops() ? 1 : 0) +
|
||||
"&rikey="+bytesToHex(context.riKey.getEncoded()) +
|
||||
"&rikeyid="+context.riKeyId +
|
||||
"&localAudioPlayMode=" + (context.streamConfig.getPlayLocalAudio() ? 1 : 0) +
|
||||
"&surroundAudioInfo=" + ((context.streamConfig.getAudioChannelMask() << 16) + context.streamConfig.getAudioChannelCount()),
|
||||
false);
|
||||
var gameSession = getXmlString(xmlStr, "gamesession");
|
||||
return gameSession != null && !gameSession.equals("0");
|
||||
}
|
||||
|
||||
function resumeApp(context) {
|
||||
var xmlStr = openHttpConnectionToString(baseUrlHttps + "/resume?" + buildUniqueIdUuidString() +
|
||||
"&rikey="+bytesToHex(context.riKey.getEncoded()) +
|
||||
"&rikeyid="+context.riKeyId, false);
|
||||
var resume = getXmlString(xmlStr, "resume");
|
||||
return parseInt(resume) != 0;
|
||||
}
|
||||
|
||||
function quitApp() {
|
||||
var xmlStr = openHttpConnectionToString(baseUrlHttps + "/cancel?" + buildUniqueIdUuidString(), false);
|
||||
var cancel = getXmlString(xmlStr, "cancel");
|
||||
return parseInt(cancel) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return retApp;
|
||||
});
|
||||
},
|
||||
|
||||
getAppList: function () {
|
||||
return sendMessage('openUrl', [_self._baseUrlHttps+'/applist?'+_self._buildUidStr()]).then(function (ret) {
|
||||
$xml = _self._parseXML(ret);
|
||||
|
||||
var rootElement = xml.getElementsByTagName("root")[0];
|
||||
var appElements = rootElement.getElementsByTagName("App");
|
||||
var appList;
|
||||
|
||||
for(var i = 0, len = appElements.length; i < len; i++) {
|
||||
appList.push({
|
||||
title: appElements[i].getElementsByTagName("AppTitle")[0].nodeValue.trim(),
|
||||
id: appElements[i].getElementsByTagName("ID")[0].nodeValue.trim(),
|
||||
running: appElements[i].getElementsByTagName("IsRunning")[0].nodeValue.trim()
|
||||
});
|
||||
}
|
||||
|
||||
return appList;
|
||||
});
|
||||
},
|
||||
|
||||
getArtBox: function (appId) {
|
||||
return sendMessage('openUrl', [
|
||||
_self._baseUrlHttps+
|
||||
'/appasset?'+_self._buildUidStr()+
|
||||
'&appid=' + appId +
|
||||
'&AssetType=2&AssetIdx=0'
|
||||
]).then(function(ret) {
|
||||
return ret;
|
||||
});
|
||||
},
|
||||
|
||||
launchApp: function (context, appId) {
|
||||
return sendMessage('openUrl', [
|
||||
_self.baseUrlHttps +
|
||||
'/launch?' + _self._buildUidStr() +
|
||||
'&appid=' + appId +
|
||||
'&mode=' +
|
||||
'&additionalStates=1&sops=' +
|
||||
'&rikey' +
|
||||
'&rikeyid' +
|
||||
'&localAudioPlayMode' +
|
||||
'&surroundAudioInfo'
|
||||
]).then(function (ret) {
|
||||
return true;
|
||||
});
|
||||
},
|
||||
|
||||
resumeApp: function (context) {
|
||||
return sendMessage('openUrl', [
|
||||
_self._baseUrlHttps +
|
||||
'/resume?' + _self._buildUidStr() +
|
||||
'&rikey=' +
|
||||
'&rikeyid='
|
||||
]).then(function (ret) {
|
||||
return true;
|
||||
});
|
||||
},
|
||||
|
||||
quitApp: function () {
|
||||
return sendMessage('openUrl', [_self._baseUrlHttps+'/unpair?'+_self._buildUidStr()]);
|
||||
},
|
||||
|
||||
pair: function (cert, pin) {
|
||||
if (_self.paired)
|
||||
return $.when(false);
|
||||
|
||||
if (_self.currentGame)
|
||||
return $.when(false);
|
||||
|
||||
var salt_data = CryptoJS.lib.WordArray.random(16);
|
||||
var cert_hex = cert.cert.toHex();
|
||||
|
||||
return sendMessage('openUrl',[
|
||||
_self._baseUrlHttp+
|
||||
'/pair?'+_self._buildUidStr()+
|
||||
'&devicename=roth&updateState=1&phrase=getservercert&salt='+salt_data.toString()+
|
||||
'&clientcert='+cert_hex
|
||||
]).then(function (ret) {
|
||||
var salt_pin_hex = salt_data.toString();
|
||||
var aes_key_hash = CryptoJS.SHA1(CryptoJS.enc.Hex.parse(salt_pin_hex + salt_pin_hex.substr(0, 8)));
|
||||
|
||||
console.log(aes_key_hash);
|
||||
|
||||
var challenge_data = CryptoJS.lib.WordArray.random(16);
|
||||
var challenge_enc = CryptoJS.AES.encrypt(challenge_data, aes_key_hash, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding});
|
||||
var challange_enc_hex = challenge_enc.ciphertext.toString()
|
||||
|
||||
return sendMessage('openUrl', [
|
||||
_self._baseUrlHttp+
|
||||
'/pair?'+_self._buildUidStr()+
|
||||
'&devicename=roth&updateState=1&clientchallenge=' + challange_enc_hex
|
||||
]).then(function (ret) {
|
||||
console.log(ret);
|
||||
|
||||
$xml = _self._parseXML(ret);
|
||||
var challengeresponse = $xml.find('challengeresponse').text();
|
||||
|
||||
for (var i = 0; i < 96; i += 32) {
|
||||
var data = CryptoJS.enc.Hex.parse(challengeresponse.substr(i, 32));
|
||||
var challenge_dec = CryptoJS.AES.decrypt(data, aes_key_hash, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.NoPadding});
|
||||
console.log(challenge_dec);
|
||||
}
|
||||
|
||||
return sendMessage('openUrl', [
|
||||
_self._baseUrlHttp+
|
||||
'/pair?'+
|
||||
'&devicename=roth&updateState=1&serverchallengeresp='
|
||||
]).then(function (ret) {
|
||||
console.log(ret);
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
unpair: function () {
|
||||
return sendMessage('openUrl', [_self._baseUrlHttps+'/unpair?'+_self._buildUidStr()]);
|
||||
},
|
||||
|
||||
_buildUidStr: function () {
|
||||
return 'uniqueid=' + _self.clientUid + '&uuid=' + guuid();
|
||||
},
|
||||
|
||||
_parseXML: function (xmlData) {
|
||||
return $($.parseXML(xmlData.toString()));
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user