Websockets call from javascript

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

metainilesh
Posts: 2
Joined: 03 Feb 2018, 10:46

Websockets call from javascript

Postby metainilesh » 03 Feb 2018, 13:10

Hello All,

I'm new here

I tried to call method newhttprequest using getapi() but it's always giving me error of getapi() is not defined.

Can anyone guide me how to call webmethods using websockets?

Thanks
Neel
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Websockets call from javascript

Postby Lapo » 05 Feb 2018, 08:20

Hi,
just to clarify are we talking about server side Javascript or client side?
I ask because you posted under the "Client API" section but getApi() is a method found in the server side.

Please clarify...
Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
metainilesh
Posts: 2
Joined: 03 Feb 2018, 10:46

Re: Websockets call from javascript

Postby metainilesh » 05 Feb 2018, 12:30

I'm talking about server side and below is my query

I have a below javascript server extension code

this below method i call it from the client side
function onGameDataRequest(params, sender) {
onhttpGameDataRequest();
response.putUtfString("resgamedata", resgamedata);
send("GameDataResponse", response, [sender]);
}

in this above method this below two lines are called instantly after onhttpgamedatarequest.

response.putUtfString("resgamedata", resgamedata);
send("GameDataResponse", response, [sender]);

I would like to call back after completion function httpGameDataCallback()

Like async or await or deffered in jquery we use i need something method sfs

[/b]Or something like async of httprequest or something status code i can get from httprequest object[/b]

function onhttpGameDataRequest() {
var reqParams;
var httpReq = getApi().newHttpGetRequest('http://someip/api/v1/user/getgamedata/57dd6105-b826-4f15-a247-9ae4bb6a9bed', reqParams, httpGameDataCallback)
httpReq.execute();
}


function httpGameDataCallback(result) {
if (result.error) {
resgamedata = result.error;
trace(result.error);
}
else {
resgamedata = result.html;
trace(result.html);
}
}

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: Bax and 18 guests