PDA

View Full Version : Callback from Javascript



harun
18 May 2013, 12:40 AM
Hi All,

I must communicate applet by javascript api.

If Applet has any action, applet call javascript function webphonetojs(varr);

At this point I must callback this varr from GWT method, to show user about the action.

I can send my commands to applet by (JSNI) native methods. But I couldn't get callback from applet.

I want to ask you how can I implement webphonetojs javascript method from GWT, and how can call GWT method.

Working javascript code is following:


<SCRIPT LANGUAGE="javascript">
function webphonetojs(varr)
{
alert(varr);
//todo: handle incoming calls and other events here
}




function voipRegister(username, password)
{

document.applets[0].API_Register("", username, password);
}


function voipCall(number)
{

document.applets[0].API_Call(-1, number);
}


function voipHangup()
{

document.applets[0].API_Hangup(-2);
}

</SCRIPT>

Colin Alworth
19 May 2013, 6:52 AM
At a glance, this looks like a basic JSNI question, but without more context it is hard to be sure.
https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI

If you want to enable those functions in script on the main page to work, you need to export the methods - check out this section for more info: https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI#calling

It seems reasonable that you should be able to write those functions above entirely in your GWT code using JSNI - what isn't working about the callbacks? Are you able to debug it? What did you try, and what errors do you get?

Don't forget to reference $doc and $wnd when writing JSNI instead of document and window.