Fix returning binary data for box art

This commit is contained in:
Cameron Gutman 2016-07-04 14:18:01 -07:00
parent 9546e5fee1
commit 7392ea4ad7
4 changed files with 34 additions and 16 deletions

View File

@ -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"));

View File

@ -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()));
}

View File

@ -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;

View File

@ -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 () {