Sign In Register

How can we help you today?

Start a new topic
Answered

"nonceCallback is not a function" (init)

Hi,


Trying the JS SDK for the 1st time: 

 

WebSocket onOpen: Connected [object Event]
gamesparks.js:155 WebSocket onMessage: {"@class": ".AuthenticatedConnectResponse","connectUrl": "url","requestId": "0"}
gamesparks.js:140 WebSocket onClose executed 
gamesparks.js:148 WebSocket onOpen: Connected [object Event]
gamesparks.js:155 WebSocket onMessage: {"@class":".AuthenticatedConnectResponse","nonce":"nonce","requestId":"0"}
gamesparks.js:201 Uncaught TypeError: nonceCallback is not a function

 

gamesparks.js:201 Uncaught TypeError: nonceCallback is not a function 

^ This seems to be the issue, but the options already have the callback:

 

  onNonce: "GSOnNonce",

    

 

 

function GSOnNonce(nonce)
{
    alert("Test");
    return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(nonce, "Removed Secret Key"));
}

 

 

   


Best Answer

Oh I thought I was having issues - realized pending approval oops!!


OK I think I resolved the issue. I was putting it in like JSON format and it's definitely not json, oops.  Seems to be working so far :)


gah, mod, can you delete my secret key?

Hey Dan,

If you are setting the SDK up as in the docs here, then the proper callback should be onNonce() not GSOnNonce...
So your initialization code should be as below...

//Initialse the SDK
    function init(){
        gamesparks.initPreview({
            key:document.getElementById ('apiKey').value,
            onNonce: onNonce,
            onInit:onInit,
            onMessage:onMessage,
        });
    }

    //Callback function to hmac sha256 a nonce with the secret. It's assumed you will have your own method of securing the secret;
    function onNonce(nonce)
    {
        alert("Test");
        return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(nonce, "Removed Secret Key"));
    }

 

Hope that helps,
Sean

Thank you ~


But ah I'm a bit confused: The docs implied I can enter my own function name (otherwise why would it be there under "options", awaiting a string, I must ask?).


It's not a big deal, but I may use several API that use as nonce so was trying to be consistent.


I'll give it a shot, thanks.

You can implement things that way, but you initialization would be...

    //Initialse the SDK
    function init(){
        gamesparks.initPreview({
            key:document.getElementById ('apiKey').value,
            onNonce: GSOnNonce,
            onInit:onInit,
            onMessage:onMessage,
        });
    }

    //Callback function to hmac sha256 a nonce with the secret. It's assumed you will have your own method of securing the secret;
    function GSOnNonce(nonce)
    {
        alert("Test");
        return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(nonce, "Removed Secret Key"));
    }


 

Following up with results: Same error, even after setting the onNonce prop to onNonce, and renaming the function to onNonce() -- I was fairly certain that didn't make sense (it should go to whatever function I name for onNonce: <function_name>, from my understanding.

(PS -- you added the secret key back :/ can you remove it again pls? Cheers)

Sorry spam -- to add, original post showed I used

 

onNonce: "GSOnNonce",

 But even changing them both to default still is causing this err

Hey Dylan,

I would have to see your code to see where this is going wrong.
Did you try downloading the original SDK files to see if the work? The one at the top of the JS SDK page.
This should run without any need for modification, if you can confirm that it works then we can debug from there.

Sean

 

Original SDK. Yes, the demo worked fine. My code can be found https://www.ThroneOfLies.com/js/tol-beta.js (for https://www.ThroneOfLies.com/beta.php )


You can see the code at the very bottom. The only thing not at the bottom is the init being called from $(document).ready()


I'll be checking back and forth after this, too, to see if there were no typos, but 99% of this code was copy+paste from the docs:

https://docs.gamesparks.net/sdk/javascript-sdk-setup

(PS -- Can you please remove my secret key from your quote that added it back?  Cheers)

Hm sorry if I added this 2x - didn't seem to go through 1st time:

From here : https://docs.gamesparks.net/sdk/javascript-sdk-setup


From the docs:

gamesparks.initPr
({
key:<YOUR API KEY>,
onNonce: <HMAC FUNCTION>,
onInit:<INITIALISATION CALLBACK>,
onMessage:<ASYNC MESSAGE HANDLER>,
});

Ahh -- the docs don't actually give an example -- I was putting the functions in quotes. PS: The docs and the example shows a lingering "," comma at the end .. isn't that a syntax err? Trying again..


Answer

Oh I thought I was having issues - realized pending approval oops!!


OK I think I resolved the issue. I was putting it in like JSON format and it's definitely not json, oops.  Seems to be working so far :)

Login to post a comment