Create SDK debug class + update readme
This commit is contained in:
Родитель
7e65d4a787
Коммит
582ba0b39c
23
README.md
23
README.md
|
@ -1,6 +1,6 @@
|
|||
# Furioos SDK
|
||||
## Requirements
|
||||
You'll need a Business subscription on Furioos to use the SDK.
|
||||
Minimum requirements: Business subscription (or higher) on Furioos to use the SDK.
|
||||
Then choose the app you want to use with the SDK and create a SDK link.
|
||||
|
||||
## Installation
|
||||
|
@ -75,4 +75,23 @@ Bind a callback to receive messages from your application.
|
|||
|
||||
#### 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.
|
||||
- `data: JSON`: The data you want to send to your app formated in JSON.
|
||||
|
||||
## SDK Local Test Exemple
|
||||
SDKDebug class let you debug the SDK communication on your local setup.
|
||||
Requirements: The Furioos Unity SDK on your application.
|
||||
```javascript
|
||||
import { SDKDebug } from 'furioos-sdk';
|
||||
|
||||
const sdkDebug = new SDKDebug("127.0.0.1:3000");
|
||||
|
||||
sdkDebug.onReady(function() {
|
||||
// Here you know when the WS connection with your application is ready.
|
||||
sdkDebug.sendSDKMessage({ test: "test" });
|
||||
});
|
||||
|
||||
sdkDebug.onSDKMessage(function(data) {
|
||||
// Here you can manage the received data.
|
||||
console.log("Received JSON", data);
|
||||
})
|
||||
```
|
|
@ -0,0 +1,59 @@
|
|||
module.exports = class SDKLocalDebug {
|
||||
constructor(localServerAddress) {
|
||||
if (!localServerAddress) {
|
||||
throw "Bad parameters";
|
||||
}
|
||||
|
||||
// Init WS connection.
|
||||
this.ws = new WebSocket(localServerAddress);
|
||||
this.ws.binaryType = 'arraybuffer';
|
||||
this.ws.onerror = (event) => {this._wsOnError(event)};
|
||||
this.ws.onclose = (event) => {this._wsOnClose(event);}
|
||||
this.ws.onmessage = (event) => {this._wsOnMessage(event);}
|
||||
this.ws.onopen = () => {
|
||||
console.log("WS connected to: ", localServerAddress);
|
||||
if (this.onReady) {
|
||||
this.onReady()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
/// PRIVATE METHODS ///
|
||||
///////////////////////
|
||||
_wsOnError(event) {
|
||||
console.error("WS Error", event);
|
||||
}
|
||||
|
||||
_wsOnClose(event) {
|
||||
console.error("WS Close", event);
|
||||
}
|
||||
|
||||
_wsOnMessage(event) {
|
||||
this._onSDKMessageCallback(JSON.parse(event.data));
|
||||
}
|
||||
|
||||
_wsOnSendError(event) {
|
||||
console.error("WS send error", event);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
//// PUBLIC METHODS ////
|
||||
////////////////////////
|
||||
|
||||
// Binding onload callback.
|
||||
// SDK
|
||||
onSDKMessage(onSDKMessageCallback) {
|
||||
this._onSDKMessageCallback = onSDKMessageCallback;
|
||||
}
|
||||
|
||||
sendSDKMessage(data) {
|
||||
if (!this.ws || this.ws.readyState != WebSocket.OPEN) {
|
||||
console.log("Cannot send message, ws connection not open");
|
||||
return; // Not loaded.
|
||||
}
|
||||
|
||||
|
||||
this.ws.send(JSON.stringify(data),this._wsOnSendError);
|
||||
}
|
||||
}
|
4
index.js
4
index.js
|
@ -1,5 +1,7 @@
|
|||
var Player = require("./classes/Player.js");
|
||||
var SDKDebug = require("./classes/SDKDebug.js");
|
||||
|
||||
module.exports = {
|
||||
Player
|
||||
Player,
|
||||
SDKDebug
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "furioos-sdk",
|
||||
"version": "1.1.7",
|
||||
"version": "1.1.8",
|
||||
"description": "Furioos SDK: create your own furioos UI communicating with your application",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
Загрузка…
Ссылка в новой задаче