From 147b4cf9f3c08d31bf89c186b98077a7ffbc49ae Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 10 Mar 2016 23:10:08 -0800 Subject: [PATCH] Add support for starting a new stream of Steam Big Picture --- static/js/index.js | 18 ++++++++++++++++-- static/js/utils.js | 33 +++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index 17f7cda..5e00dba 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -107,11 +107,25 @@ function startPushed() { console.log('startRequest:' + target + ":" + streamWidth + ":" + streamHeight + ":" + frameRate + ":" + bitrate); + var rikey = '00000000000000000000000000000000'; + var rikeyid = 0; + sendMessage('httpInit', [pairingCert.cert, pairingCert.privateKey, myUniqueid]).then(function (ret) { api = new NvHTTP(target, myUniqueid); api.init().then(function (ret) { - if (api.currentGame != 0) { - api.resumeApp('00000000000000000000000000000000', 0).then(function (ret) { + if (api.currentGame == 0) { + api.getAppByName("Steam").then(function (app) { + api.launchApp(app.id, + streamWidth + "x" + streamHeight + "x" + frameRate, + 1, // Allow GFE to optimize game settings + rikey, rikeyid, + 0, // Play audio locally too + 0x030002 // Surround channel mask << 16 | Surround channel count + ); + }); + } + else { + api.resumeApp(rikey, rikeyid).then(function (ret) { sendMessage('startRequest', [target, streamWidth, streamHeight, frameRate, bitrate.toString(), api.serverMajorVersion.toString()]); }); } diff --git a/static/js/utils.js b/static/js/utils.js index 050efcf..5f11ad2 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -47,7 +47,7 @@ NvHTTP.prototype = { }, getAppById: function (appId) { - return getAppList().then(function (list) { + return _self.getAppList().then(function (list) { var retApp = null; list.some(function (app) { @@ -63,19 +63,36 @@ NvHTTP.prototype = { }); }, + getAppByName: function (appName) { + return _self.getAppList().then(function (list) { + var retApp = null; + + list.some(function (app) { + if (app.title == appName) { + retApp = app; + return true; + } + + 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 rootElement = $xml.find("root")[0]; var appElements = rootElement.getElementsByTagName("App"); - var appList; + 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() + title: appElements[i].getElementsByTagName("AppTitle")[0].innerHTML.trim(), + id: parseInt(appElements[i].getElementsByTagName("ID")[0].innerHTML.trim(), 10), + running: (appElements[i].getElementsByTagName("IsRunning")[0].innerHTML.trim() == 1) }); } @@ -96,7 +113,7 @@ NvHTTP.prototype = { launchApp: function (appId, mode, sops, rikey, rikeyid, localAudio, surroundAudioInfo) { return sendMessage('openUrl', [ - _self.baseUrlHttps + + _self._baseUrlHttps + '/launch?' + _self._buildUidStr() + '&appid=' + appId + '&mode=' + mode + @@ -104,7 +121,7 @@ NvHTTP.prototype = { '&rikey=' + rikey + '&rikeyid=' + rikeyid + '&localAudioPlayMode=' + localAudio + - '&surroundAudioInfo=' + suroundAudioInfo + '&surroundAudioInfo=' + surroundAudioInfo ]).then(function (ret) { return true; });