ScriptInjector Failure using PubNub. Expert help/advice?

86 views
Skip to first unread message

Charlie Youakim

unread,
Oct 10, 2012, 1:46:06 PM10/10/12
to google-we...@googlegroups.com
Hello Devs,

New to GWT but I love it so far.  I do have a problem that's easy to reproduce.  It is a big problem for me because I want to create a GWT Module for PubNub - a utility we use internally.

I created a demo project to test out encapsulation and I have found an interesting problem with ScriptInjector.

At first I followed the PubNub instructions.  NOTE: I have included my keys for my test account.  Feel free to use them.

Following the instructions I put these two items in the html file in the GWT project (with my keys specified):
<div pub-key="pub-b8b75fbd-c4cf-4583-bab9-424af7a7f755" sub-key="sub-5e843c94-1193-11e2-bba9-b116c93082cf" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
<script src="http://cdn.pubnub.com/pubnub-3.1.min.js"></script>

When I do this, I can use JSNI to access pubnub.  It all works great.

What doesn't work is if I delete the <script> tag here and inject the script instead with the following code.  I know the script injects because I can see the success message and I can see the script in Developer tools in Chrome.

              ScriptInjector.fromUrl("http://cdn.pubnub.com/pubnub-3.1.js").setCallback(
                      new Callback<Void, Exception>() {
                         public void onFailure(Exception reason) {
                           Window.alert("Script load failed.");
                         }
                         public void onSuccess(Void result) {
                           Window.alert("Script load success.");
                         }
                      }).inject();

I feel this must be somehow related to accessing the DOM with the delayed script, or because the script is not a part of the DOM.  It's trying to access the setup div and it's not able to...(just my guess)

Any thoughts?  I need to move the items out of the html file because I need to modularize this project for use in other larger projects.  Any help would be appreciated.

(PS, I have tried to create html widgets as well, and add them in EntryPoint.  This also adds the <script> tag to the page based on my browsing in Developer Tools in Chrome, but it fails to work just as ScriptInjector fails.)

Reply all
Reply to author
Forward
0 new messages