Re: Help in JSNI callback in javascript object

415 views
Skip to first unread message

Manuel Carrasco Moñino

unread,
Oct 2, 2012, 10:41:51 AM10/2/12
to google-we...@googlegroups.com
This is the same question than this one in stackoverflow.

- Manolo

On Fri, Sep 28, 2012 at 4:08 PM, JSNI NOOB <rpgo...@gmail.com> wrote:

Hi i need some help to do a wrapper to GWT.

in javascript i have the following:

(...)

// create a new SIP stack. Not mandatory as it's possible to reuse the same satck
        oSipStack
= new tsip_stack(txtRealm.value, txtPrivateIdentity.value, txtPublicIdentity.value)
oSipStack
.on_event_stack = onSipEventStack;
oSipStack
.on_event_dialog = onSipEventDialog;

(...)

// Callback function for SIP Stacks
function onSipEventStack
(evt) {
   
// this is a special event shared by all sessions and there is no "e_stack_type"
   
// check the 'sip/stack' code
    tsk_utils_log_info
(evt.s_phrase);
   
switch (evt.i_code) {
       
case tsip_event_code_e.STACK_STARTED:

(...)

// Callback function for all SIP dialogs (INVITE, REGISTER, INFO...)
function onSipEventDialog
(evt) {
   
// this is special event shared by all sessions and there is no "e_dialog_type"
   
// check the 'sip/dialog' code
    tsk_utils_log_info
(evt.s_phrase);
   
switch (evt.i_code) {
       
case tsip_event_code_e.DIALOG_TRANSPORT_ERROR:
       
case tsip_event_code_e.DIALOG_GLOBAL_ERROR:
       
case tsip_event_code_e.DIALOG_MESSAGE_ERROR:
       
case tsip_event_code_e.DIALOG_WEBRTC_ERROR:

So in my GWT-Wrapper using JSNI i make:

public static native JavaScriptObject tsip_stack(String s_realm,
           
String s_impi, String s_impu_uri
           
) /*-{
        return new $wnd.tsip_stack(s_realm, s_impi, s_impu_uri);
    }-*/
;

How do i make the callback and is association to the javascript object.

This project is to make an wrapper of sipml5 if someone had the wrapper it helps to

Thanks Best Regards

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/HAUjdk0kmwcJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

gpike

unread,
Oct 2, 2012, 2:33:29 PM10/2/12
to google-we...@googlegroups.com
If you want the callbacks to call into your Java methods one way to do that is to assign those methods to a globally accessible Javascript variable. Then you can register those as callbacks to your on_event calls. The example I'm showing is static but you may be able to use instance methods. Something like (keep in mind I'm writing on the fly so may not be exactly right): 

    public static void onSipEventStack(JavaScriptObject evt) { ... }
   
public static native void exportStaticMethod(JavaScriptObject tsip) /*-{
       $wnd.onSipEventStack =
          $entry(@mypackage.MySipClass::onSipEventStack(evt));
        tsip.on_event_stack = $wnd.onSipEventStack;
     }-*/;
    You could also setup a Javascript overlay object for the tsip object so you can make calls to it from you Java code. I hope that helps. 
Thanks,

Gordon Pike
Reply all
Reply to author
Forward
0 new messages