diff --git a/http.cpp b/http.cpp index 00be1b4..d35372b 100644 --- a/http.cpp +++ b/http.cpp @@ -93,7 +93,7 @@ void MoonlightInstance::NvHTTPInit(int32_t callbackId, pp::VarArray args) PostMessage(ret); } -void MoonlightInstance::NvHTTPRequest(int32_t /*result*/, int32_t callbackId, std::string url) +void MoonlightInstance::NvHTTPRequest(int32_t /*result*/, int32_t callbackId, std::string url, bool binaryResponse) { char* _url = strdup(url.c_str()); PHTTP_DATA data = http_create_data(); @@ -118,7 +118,23 @@ void MoonlightInstance::NvHTTPRequest(int32_t /*result*/, int32_t callbackId, st goto clean_data; } - { + if (binaryResponse) { + // Response data will be returned to JS as an ArrayBuffer + + pp::VarDictionary ret; + ret.Set("callbackId", pp::Var(callbackId)); + ret.Set("type", pp::Var("resolve")); + + // Construct an array buffer and copy the response data into it + pp::VarArrayBuffer arrBuf = pp::VarArrayBuffer(data->size); + memcpy(arrBuf.Map(), data->memory, data->size); + arrBuf.Unmap(); + + ret.Set("ret", arrBuf); + PostMessage(ret); + } else { + // Response data will be returned to JS as a UTF-8 string + pp::VarDictionary ret; ret.Set("callbackId", pp::Var(callbackId)); ret.Set("type", pp::Var("resolve")); diff --git a/main.cpp b/main.cpp index 5ad0e1a..e160fc6 100644 --- a/main.cpp +++ b/main.cpp @@ -240,8 +240,9 @@ void MoonlightInstance::HandleStopStream(int32_t callbackId, pp::VarArray args) void MoonlightInstance::HandleOpenURL(int32_t callbackId, pp::VarArray args) { std::string url = args.Get(0).AsString(); + bool binaryResponse = args.Get(1).AsBool(); - openHttpThread.message_loop().PostWork(m_CallbackFactory.NewCallback(&MoonlightInstance::NvHTTPRequest, callbackId, url)); + openHttpThread.message_loop().PostWork(m_CallbackFactory.NewCallback(&MoonlightInstance::NvHTTPRequest, callbackId, url, binaryResponse)); PostMessage(pp::Var (url.c_str())); } diff --git a/moonlight.hpp b/moonlight.hpp index e75671a..1810764 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -135,7 +135,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { void LoadCert(const char* certStr, const char* keyStr); void NvHTTPInit(int32_t callbackId, pp::VarArray args); - void NvHTTPRequest(int32_t, int32_t callbackId, std::string url); + void NvHTTPRequest(int32_t, int32_t callbackId, std::string url, bool binaryResponse); private: static CONNECTION_LISTENER_CALLBACKS s_ClCallbacks; diff --git a/static/js/utils.js b/static/js/utils.js index a81d9ee..e440e1a 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -46,9 +46,9 @@ function NvHTTP(address, clientUid) { NvHTTP.prototype = { refreshServerInfo: function () { - return sendMessage('openUrl', [ _self._baseUrlHttps + '/serverinfo?' + _self._buildUidStr()]).then(function(ret) { + return sendMessage('openUrl', [ _self._baseUrlHttps + '/serverinfo?' + _self._buildUidStr(), false]).then(function(ret) { if (!_self._parseServerInfo(ret)) { - return sendMessage('openUrl', [ _self._baseUrlHttp + '/serverinfo?' + _self._buildUidStr()]).then(function(retHttp) { + return sendMessage('openUrl', [ _self._baseUrlHttp + '/serverinfo?' + _self._buildUidStr(), false]).then(function(retHttp) { _self._parseServerInfo(retHttp); }); } @@ -119,7 +119,7 @@ NvHTTP.prototype = { }); } - return sendMessage('openUrl', [_self._baseUrlHttps + '/applist?' + _self._buildUidStr()]).then(function (ret) { + return sendMessage('openUrl', [_self._baseUrlHttps + '/applist?' + _self._buildUidStr(), false]).then(function (ret) { $xml = _self._parseXML(ret); var rootElement = $xml.find("root")[0]; @@ -146,10 +146,9 @@ NvHTTP.prototype = { _self._baseUrlHttps + '/appasset?'+_self._buildUidStr() + '&appid=' + appId + - '&AssetType=2&AssetIdx=0' - ]).then(function (ret) { - return ret; - }); + '&AssetType=2&AssetIdx=0', + true + ]); }, launchApp: function (appId, mode, sops, rikey, rikeyid, localAudio, surroundAudioInfo) { @@ -162,7 +161,8 @@ NvHTTP.prototype = { '&rikey=' + rikey + '&rikeyid=' + rikeyid + '&localAudioPlayMode=' + localAudio + - '&surroundAudioInfo=' + surroundAudioInfo + '&surroundAudioInfo=' + surroundAudioInfo, + false ]).then(function (ret) { return true; }); @@ -173,14 +173,15 @@ NvHTTP.prototype = { _self._baseUrlHttps + '/resume?' + _self._buildUidStr() + '&rikey=' + rikey + - '&rikeyid=' + rikeyid + '&rikeyid=' + rikeyid, + false ]).then(function (ret) { return true; }); }, quitApp: function () { - return sendMessage('openUrl', [_self._baseUrlHttps + '/cancel?' + _self._buildUidStr()]).then(function () { + return sendMessage('openUrl', [_self._baseUrlHttps + '/cancel?' + _self._buildUidStr(), false]).then(function () { _self.currentGame = 0; }); }, @@ -194,7 +195,7 @@ NvHTTP.prototype = { return false; return sendMessage('pair', [_self.serverMajorVersion, _self.address, randomNumber]).then(function (pairStatus) { - return sendMessage('openUrl', [_self._baseUrlHttps + '/pair?uniqueid=' + _self.clientUid + '&devicename=roth&updateState=1&phrase=pairchallenge']).then(function (ret) { + return sendMessage('openUrl', [_self._baseUrlHttps + '/pair?uniqueid=' + _self.clientUid + '&devicename=roth&updateState=1&phrase=pairchallenge', false]).then(function (ret) { $xml = _self._parseXML(ret); _self.paired = $xml.find('paired').html() == "1"; return _self.paired; @@ -204,7 +205,7 @@ NvHTTP.prototype = { }, unpair: function () { - return sendMessage('openUrl', [_self._baseUrlHttps + '/unpair?' + _self._buildUidStr()]); + return sendMessage('openUrl', [_self._baseUrlHttps + '/unpair?' + _self._buildUidStr(), false]); }, _buildUidStr: function () {