I am trying to make a service for connection to GameSparks like so:
import { Injectable } from '@angular/core';
var gamesparks = new GameSparks();
var gsKey = "XXXXXXXXXX";
var gsSecret = "XXXXXXXXXXXXXXXXXXXX";
var gsCredentials = "";
@Injectable({
providedIn: 'root'
})
export class GamesparksService {
isLive = false;
init() {
if (this.isLive) {
gamesparks.initLive({
key: gsKey,
secret: gsSecret,
//credential: gsCredentials,
onNonce: this.onNonce,
onInit: this.onInit,
onMessage: this.onMessage,
logger: console.log,
});
} else {
gamesparks.initPreview({
key: gsKey,
secret: gsSecret,
//credential: gsCredentials,
onNonce: this.onNonce,
onInit: this.onInit,
onMessage: this.onMessage,
logger: console.log,
});
}
}
//Callback function to hmac sha256 a nonce with the secret. It's assumed you will have your own method of securing the secret;
onNonce(nonce) {
return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(nonce, gsSecret));
}
//Callback to handle when the SDK is initialised and ready to go
onInit() {
console.log("Initialised");
}
//Callback to handle async messages from the gamesparks platform
onMessage(message) {
console.log("onMessage: " + JSON.stringify(message["scriptData"]));
}
}
Now, the script does not know what GameSparks() and CryptoJS is and I guess it doesn't recognize the GameSparks SDK.
The SDK is placed in this folder:
./assets/gamesparks/gamesparks.js
./assets/gamesparks/gamesparks-functions.js
./assets/gamesparks/hmac-sha256.js
Now my service script above is placed here:
./app/services/gamesparks.service.ts
How do I implement the SDK into the service script?
Hoping for help and thanks in advance :-)