SCILLClient
This is the main entrance point in to the SCILL JavaScript SDK. Use this class to get instances of SCILL product APIs.
Initialization
Depending on the environment and programming language it’s a bit different
npm
In npm environments (NodeJS, Angular, React, Vue, etc) you can get an instance of that class in JavaScript:
const SCILL = require("@scillgame/scill-js");
const eventsApi = SCILL.getEventsApi("ai728S-1aSdgb9GP#R]Po[P!1Z(HSSTpdULDMUAlYX");
and in TypeScript:
import * as SCILL from '@scillgame/scill-js';
const eventsApi = SCILL.getEventsApi("ai728S-1aSdgb9GP#R]Po[P!1Z(HSSTpdULDMUAlYX");
scill.js
In HTML, you can directly include the scill.js
in your browser. This script will expose the SCILL
variable
into the global context. Use it like this:
<script type="text/javascript" src="https://scill-cdn.web.app/scill.js"></script>
<script type="text/javascript">
let eventsApi = SCILL.getEventsApi("ai728S-1aSdgb9GP#R]Po[P!1Z(HSSTpdULDMUAlYX");
</script>
APIs
Use the methods below to get an instance of an API class for a SCILL product. Please don’t create instances of those APIs
yourself as they are subject to change - while the SCILLClient
API will not.
getAuthApi
Initiate an instance of the AuthApi with the API key of your application. Use this API to generate an access token.
Please note: This class should not be used in client side code (i.e. in the Browser or Web Apps) as the API key might be easily captured using Web console, giving the attacker a lot of power. Use this class in a NodeJS backend, serving your client.
static AuthApi getAuthApi(apiKey);
Parameters
apiKey string
The API key for your application. You can generate an API key in the Admin Panel for your application. Please note: Don’t expose the API key in unsecure environments like Web Apps.
Returns
An instance of the AuthApi class. Setup for production use.
getEventsApi
Initiate an instance of the EventsApi with the API key of your application. It’s used to send events required for challenges and battle passes.
Please note: This class should not be used in client side code (i.e. in the Browser or Web Apps) as the API key might be easily captured using Web console, giving the attacker a lot of power. Use this class in a NodeJS backend, serving your client.
static EventsApi getEventsApi(apiKey);
Parameters
apiKey string
The API key for your application. You can generate an API key in the Admin Panel for your application. Please note: Don’t expose the API key in unsecure environments like Web Apps.
Returns
An instance of the EventsApi class. Setup for production use.
getChallengesApi
static ChallengesApi getChallengesApi(accessToken);
Parameters
accessToken string
You need to provide an access token that you previously generated with the EventsApi. Please check out the documentation about access tokens for more info.
Returns
An instance of the ChallengesApi class. Setup for production use.
getBattlePassesApi
static BattlePassesApi getBattlePassesApi(accessToken);
Parameters
accessToken string
You need to provide an access token that you previously generated with the EventsApi. Please check out the documentation about access tokens for more info.
Returns
An instance of the BattlePassesApi class. Setup for production use.
Realtime Updates
SCILL uses MQTT for implementing real time updates. MQTT is a simple, yet very powerful and efficient transport protocol. We use it to notify clients of changes in the backend in real time to make sure, that users get updates on their state in challenges and battle passes in real time.
Using our SDKs it’s very simple to use. For this, we expose two classes that handle all the heavy lifting for you. If you are interested in the details, please check out our API reference for Realtime Updates.
startMonitorChallengeUpdates
Use this function to start listening on updates on challenges for the user identified with the access token. The function
expects a callback function handler
that will be called whenever something happens on the users challenges.
static ChallengeUpdateMonitor startMonitorChallengeUpdates(accessToken, handler);
Parameters
accessToken string
You need to provide an access token that you previously generated with the EventsApi. Please check out the documentation about access tokens for more info.
handler function
The callback function that is called whener something changes in the backend for a user challenge. The callback function receives one parameter of type ChallengeWebhookPayload.
Returns
An instance of the ChallengeUpdateMonitor class. Store that instance somewhere to stop listening when you don’t need any updates anymore.
Example
Here is a simple example on how to use that function:
const monitor = SCILL.startMonitorChallengeUpdates(accessToken, (payload) => {
// payload is of type ChallengeWebhookPayload and contains the challenge in the new and the old state
// use it to update existing UI
});
// The monitor instance should be stored and can be used to stop listening on updates, for example if user changed routes
function onDestroy() {
monitor.stop();
}
startMonitorBattlePassUpdates
Use this function to start listening on updates of battle pass challenges for the user identified with the access token. The function
expects a callback function handler
that will be called whenever something happens on the users challenges.
static UserBattlePassUpdateMonitor startMonitorBattlePassUpdates(accessToken, battlePassId, handler);
Parameters
accessToken string
You need to provide an access token that you previously generated with the EventsApi. Please check out the documentation about access tokens for more info.
battlePassId function
The id of the battle pass that you want to listen for changes.
handler function
The callback function that is called whenever something changes in the backend for a users battle pass. The callback function receives one parameter of type BattlePassChallengeChangedPayload.
Returns
An instance of the [UserBattlePassUpdateMonitor](/sdks/javascript/models.html#challengeupdatemonitor class. Store that instance somewhere to stop listening when you don’t need any updates anymore.
Example
Here is a simple example on how to use that function:
const monitor = SCILL.startMonitorBattlePassUpdates(accessToken, battlePass.battle_pass_id, (payload) => {
// payload is of type BattlePassChallengeChangedPayload and contains the battle pass challenge in the new and the old state
// use it to update existing UI
});
// The monitor instance should be stored and can be used to stop listening on updates, for example if user changed routes
function onDestroy() {
monitor.stop();
}