Implement getServerMetadata method.

This method let the user get the unique name and public IP of its machine during a running session.
This let users implement their own communication method for Unreal app for example (using their own server to communicate with their app).

** Update readme
This commit is contained in:
Maxence Brasselet 2020-08-07 16:44:13 +02:00
Родитель 3f37eabc2e
Коммит b0a88f2945
2 изменённых файлов: 49 добавлений и 1 удалений

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

@ -133,6 +133,22 @@ player.getServerAvailability(function(data) {
}); });
``` ```
#### getServerMetadata(function(metadata) {}, function(error) {}) asynchronous function
Call this function to get unique VM informations.
This function return metadata only when a session is running.
`metadata: Object`:
- `publicIP: String` The VM public IP.
- `name: String` A unique name to identify a VM.
##### Example:
```javascript
player.getServerAvailability(function(metadata) {
console.log("Public VM IP: ", metadata.publicIP);
console.log("VM unique name: ", metadata.name);
}, function(error) {
// Treat the error.
});
```
### Methods to create your own interface ### Methods to create your own interface
Those methods let you create your own interface. Those methods let you create your own interface.

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

@ -28,7 +28,8 @@ const _eventNames = {
ON_USER_INACTIVE: "onUserInactive", ON_USER_INACTIVE: "onUserInactive",
ON_SESSION_STOPPED: "onSessionStopped", ON_SESSION_STOPPED: "onSessionStopped",
ON_STATS: "onStats", ON_STATS: "onStats",
GET_SERVER_AVAILABILITY: "getServerAvailability" GET_SERVER_AVAILABILITY: "getServerAvailability",
GET_SERVER_METADATA: "getServerMetadata",
}; };
const _qualityValues = { const _qualityValues = {
@ -205,6 +206,25 @@ module.exports = class Player {
this._getServerAvailabilityCallback(response.stats); this._getServerAvailabilityCallback(response.stats);
return; return;
case _eventNames.GET_SERVER_METADATA:
const response = e.data.value;
if (response.error) {
console.log("Error getting server metadata", response.error);
if (this._getServerMetadataErrorCallback) {
this._getServerMetadataErrorCallback(response.error);
}
return;
}
if (!this._getServerMetadataCallback) {
console.log("No success callback binded !");
return;
}
this._getServerMetadataCallback(response.metadata);
return;
case _eventNames.ERROR: case _eventNames.ERROR:
this._displayErrorMessage(e.data.value); this._displayErrorMessage(e.data.value);
return; return;
@ -366,4 +386,16 @@ module.exports = class Player {
this.embed.contentWindow.postMessage({ type: _eventNames.GET_SERVER_AVAILABILITY }, _furioosServerUrl); this.embed.contentWindow.postMessage({ type: _eventNames.GET_SERVER_AVAILABILITY }, _furioosServerUrl);
// The response will be treat in the listener below. // The response will be treat in the listener below.
} }
getServerMetadata(getServerMetadataCallback, getServerMetadataErrorCallback) {
if (!this.loaded) {
return; // Not loaded.
}
this._getServerMetadataCallback = getServerMetadataCallback;
this._getServerMetadataErrorCallback = getServerMetadataErrorCallback;
// Call the get.
this.embed.contentWindow.postMessage({ type: _eventNames.GET_SERVER_METADATA }, _furioosServerUrl);
// The response will be treat in the listener below.
}
} }