Set default location for server + update doc

Add setLocation function to default setup the server location to search when a session start.
Change sendData function name for "sendSDKMessage"
Add default region enum
This commit is contained in:
Maxence Brasselet 2020-02-11 15:04:24 +01:00
Родитель 6e2f0f373f
Коммит a35fa8ad4e
3 изменённых файлов: 47 добавлений и 16 удалений

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

@ -36,17 +36,19 @@ Instanciate the player for a given app.
#### onLoad(callback)
Bind a callback that will be called when the player is ready.
- `callback: Function`: Your own code to do what you want when it's ready (ex: call startSession()).
#### onSDKMessage(callback)
Bind a callback to receive messages from your application.
- `callback: Function`: Your own code to do what you want.
- `callback: Function`: Your own code to do what you want when it's ready (ex: call start()).
### Methods to create your own interface
Those methods permit you to create your own interface.
#### start()
#### setLocation(location)
setup the default location used for each start.
You should set this value before the user can start the session if you use the default Furioos' start button.
- `location: Region`: Use one of the static value : Player.regions.EUW / Player.regions.USE / Player.regions.USW / Player.regions.AUE
#### start(location)
Start streaming the app.
- `location: Region`: Use one of the static value : Player.regions.EUW / Player.regions.USE / Player.regions.USW / Player.regions.AUE
#### stop()
Stop streaming the app.
@ -71,9 +73,13 @@ Restart the application
#### restartClient()
Reload all the streaming.
### API Method
### SDK Methods
To use corectly this method, you will need to use the Furioos SDK for Unity in order to received the sended data and treat it into your app.
#### sendData(data)
#### onSDKMessage(callback)
Bind a callback to receive messages from your application.
- `callback: Function`: Your own code to do what you want.
#### sendSDKMessage(data)
Send data to your own application by using the Furioos SDK for Unity.
- `data: JSON`: The data you want to send to your app formated in JSON.

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

@ -25,6 +25,7 @@ const _eventNames = {
RESTART_APP: "restartApp",
RESTART_CLIENT: "restartClient",
SEND_DATA: "sendData",
SET_LOCATION: "setLocation"
};
const _qualityValues = {
@ -34,10 +35,18 @@ const _qualityValues = {
ULTRA: 3,
}
const _regions = {
EUW: { lat: 52.1326, lng: 5.2913 },
USW: { lat: 47.751076, lng: -120.740135 },
USE: { lat: 37.926868, lng: -78.024902 },
AUE: { lat: -33.865143, lng: 151.2099 }
}
let _furioosServerUrl = "https://portal.furioos.com"
module.exports = class Player {
static get qualityValues() { return _qualityValues };
static get regions() { return _regions };
constructor(sharedLinkID, containerId, options) {
if (!_constructorParams(sharedLinkID, containerId, options)) {
@ -127,11 +136,16 @@ module.exports = class Player {
window.addEventListener("message", (e) => {
switch(e.data.type) {
case _eventNames.LOAD:
// When the player is loaded: Set the default setted location (if setted).
if (this.location) {
this.embed.contentWindow.postMessage({ type: _eventNames.SET_LOCATION, value: this.location }, _furioosServerUrl);
}
if (this._onLoadCallback) {
this._onLoadCallback();
}
return;
case ON_SDK_MESSAGE:
case _eventNames.ON_SDK_MESSAGE:
if (this._onSDKMessageCallback) {
this._onSDKMessageCallback(e.data.value);
}
@ -172,12 +186,18 @@ module.exports = class Player {
this._onLoadCallback = onLoadCallback;
}
onSDKMessage(onSDKMessageCallback) {
this._onSDKMessageCallback = onSDKMessageCallback;
}
setDefaultLocation(location) {
this.location = location;
start() {
this.embed.contentWindow.postMessage({ type: _eventNames.START }, _furioosServerUrl);
this.embed.contentWindow.postMessage({ type: _eventNames.SET_LOCATION, value: this.location }, _furioosServerUrl);
}
start(location) {
if (!location) {
location = this.location;
}
this.embed.contentWindow.postMessage({ type: _eventNames.START, value: location }, _furioosServerUrl);
}
stop() {
@ -225,7 +245,12 @@ module.exports = class Player {
this.embed.contentWindow.postMessage({ type: _eventNames.RESTART_CLIENT }, _furioosServerUrl);
}
sendData(data) {
// SDK
onSDKMessage(onSDKMessageCallback) {
this._onSDKMessageCallback = onSDKMessageCallback;
}
sendSDKMessage(data) {
this.embed.contentWindow.postMessage({
type: _eventNames.SEND_DATA,
value: data,

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

@ -1,6 +1,6 @@
{
"name": "furioos-sdk",
"version": "1.1.5",
"version": "1.1.6",
"description": "Furioos SDK to create your own furioos viewer",
"main": "index.js",
"scripts": {