Fix callback getServerAbvailability

- Not possible to parse function throught postMessage. Implement message back to get the response.
This commit is contained in:
Maxence Brasselet 2020-05-19 21:24:18 +02:00
Родитель 1bd7044d2f
Коммит a5319f4e45
1 изменённых файлов: 26 добавлений и 3 удалений

Просмотреть файл

@ -186,6 +186,25 @@ module.exports = class Player {
this._onStatsCallback();
}
return;
case _eventNames.GET_SERVER_AVAILABILITY:
const response = e.data.value;
if (response.error) {
console.log("Error getting server availability", response.error);
if (this.getServerAvailabilityErrorCallback) {
this.getServerAvailabilityErrorCallback(response.error);
}
return;
}
if (!this.getServerAvailabilityCallback) {
console.log("No success callback binded !");
return;
}
this.getServerAvailabilityCallback(response.stats);
return;
case _eventNames.ERROR:
this._displayErrorMessage(e.data.value);
return;
@ -336,11 +355,15 @@ module.exports = class Player {
this.sendSDKMessage({ "userActive": true });
}
getServerAvailability(callback) {
getServerAvailability(getServerAvailabilityCallback, getServerAvailabilityErrorCallback) {
if (!this.loaded) {
return; // Not loaded.
}
}
this._getServerAvailabilityCallback = getServerAvailabilityCallback;
this._getServerAvailabilityErrorCallback = getServerAvailabilityErrorCallback;
this.embed.contentWindow.postMessage({ type: _eventNames.GET_SERVER_AVAILABILITY, value: callback }, _furioosServerUrl);
// Call the get.
this.embed.contentWindow.postMessage({ type: _eventNames.GET_SERVER_AVAILABILITY }, _furioosServerUrl);
// The response will be treat in the listener below.
}
}