On Wednesday, February 12, 2014 4:46:52 PM UTC+1, Steve wrote:
Hi,I'm currently using the Recorderjs library in my GWT project and have got the client side bits all working by writing a wrapper class using JSNI to make the calls to the library.I know want to retrieve the recorded audio and store it on the server. The library has a method which can do this which required a callback to return the result:rec.getBuffer([callback])I've created two JSNI methods to handle this, one to call getBuffer and pass the callback method:public native void StoreAudioJSNI() /*-{var audiorec = this;var storeAudioCallback = $entry(function(buffers) {audiorec.@com.example.audiorecord.client.AudioRecord ::storeAudioCallback(Lcom/ example/audiorecord/shared/ MyJSObject;)(buffers); });$wnd.audioRecorder.getBuffer(storeAudioCallback); }-*/;and the callback method to be executed:public native void storeAudioCallback(MyJSObject buffers) /*-{this.@com.example.audiorecord.client.AudioRecord:: StoreAudio(Lcom/example/ audiorecord/shared/MyJSObject; )(buffers); }-*/;
Why are you using JSNI to call StoreAudio, and/or why are you calling it from this storeAudioCallback method rather than right from your callback in StoreAudioJSNI?
(anyway, that doesn't change your issue).
Both of these methods are in my main GWT class (the one with the same name as my project containing onModuleLoad)I want the callback method storeAudioCallback to call a Java method StoreAudio which will pass the buffers object to the service by making an RPC call:public void StoreAudio(MyJSObject mjo) {AsyncCallback<Void> callback = new AsyncCallback<Void>() {public void onSuccess(Void result) {// do some UI stuff to show success}public void onFailure(Throwable caught) {// do some UI stuff to show failure}};audioRecordService.StoreAudio(mjo, callback); }I then just have some buttons on the UI that record the audio and button with a click event that calls the JSNI method StoreAudioJSNI()The JSNI methods and callback methods work fine and the buffers is passed all the way down to the final line of StoreAudio. However, when the RPC call is made, the code in my AudioRecordSeriveImpl.StoreAudio class isn't being hit (which stores the object into a HashMap on the server). It seems that because of the JavaScript callback, something is being disconnected and the RPC call doesn't get made after the JavaScript callback. I made a seperate direct call to StoreAudio within the same click event by passing null and this works fine so it only doesn't work in the following flow: StoreAudioJSNI -> StoreAudioCallback -> StoreAudio.I've also compared the value of audioRecordService when StoreAudio is called directly compared to when it is called via the callback and the data appears to be the same so not sure why the RPC call isn't being made after the callback?Hope someone can help, I've spent several hours trying to fix this.Your help will be greatly appreciated!
The problem has nothing to do with JSNI: you cannot send a JavaScriptObject through GWT-RPC. A JavaScriptObject is a "view" (a "handle", a "pointer") on an object that lives in the browser, it has no meaning on the server-side, and GWT would not know how to serialize it through GWT-RPC.
To send the audio to your server, you'll have to either use XMLHttpRequest (knowing that the "buffers" is an array of 2 Float32Arrays; you'll have to use JSNI to send them though, as com.google.gwt.xhr.client.XMLHttpRequest only allows sending a String), or convert the data to non-JavaScriptObject objects that could be sent through GWT-RPC (beware the performance! those buffers probably are huge, so GWT-RPC definitely isn't the way to go here)
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment