tropo / PhonoSDK

Phono.com - The jQuery Phone API
http://phono.com
Other
131 stars 63 forks source link

jQuery plugin, global context, etc #27

Open undsoft opened 11 years ago

undsoft commented 11 years ago

Hi guys,

I'm trying to embed phono in my embeddable widget. User copies widget code (2 lines) to his page and then widget does the rest - preloads the jquery if necessary and initializes itself.

I've faced a problem of incorporating phono to my code.

Phono depends on $ variable to be pointing to jQuery object. (ex. line 960 $(document).ready(function())

So, I have to load Phono after jQuery was loaded. This means loading Phono code in a callback.

But when placed inside of a callback, it doesn't work, presumably because phono depends on flXHR and flXHR seems to use global context a lot.

For example, this line is not nice:

// FIXME: Needed by flXHR
var flensed={base_path:"//s.phono.com/deps/flensed/1.0/"};

So, I thought that maybe I can live with adding some objects to global space of user's page. I cut out flXHR code and placed it into a global context. No errors now, flXHR used correct urls, but I never get onReady callback from phono. Network tab show continious requests being sent to 'http-bind' and console says: no requests during idle cycle, sending blank request

Does anyone have any experience in situation like this?

steely-glint commented 11 years ago

Thanks for the feedback, I don't have a solution for you, but I do have a couple of data points. 1) flXHR isn't needed on modern browsers, it is a fallback way of doing HTTP long-polls using flash where the browser does not support them natively. 2) the 'no requests' message isn't (of itself) a problem. It just means that there isn't an XMPP message to send just now.

Based on you never getting the onReady callback, I'd guess that the flash audio component (which is separate from flXHR) hasn't loaded. - You didn't remove that too did you ? (it might be interesting to see if the java audio component works - by setting audio:'java', on the phono ).

If you can give some more details, we'll look into it - javascript console logs would be great.

undsoft commented 11 years ago

Here's what I get when I wrap most of the code with (function($){})(jQuery);

Phono Logger Initialized bizzo_engine.js:1060
18:53:51.722 DEBUG - [STROPHE] CORS with Firefox/Safari/Chome bizzo_engine.js:6928
18:53:51.723 DEBUG - [INVOKE] Phono.connect() bizzo_engine.js:6928
18:53:51.724 DEBUG - [STROPHE] _throttledRequestHandler called with 1 requests bizzo_engine.js:6928
18:53:51.725 DEBUG - [STROPHE] request id 1.0 posting bizzo_engine.js:6928
18:53:51.726 DEBUG - [STROPHE] request id 1.0 state changed to 1 bizzo_engine.js:6928
18:53:51.726 DEBUG - [WIRE] (o) <body rid="1366195701" xmlns="http://jabber.org/protocol/httpbind" to="gw-v3.d.phono.com" xml:lang="en" wait="60" hold="1" content="text/xml; charset=utf-8" ver="1.6" xmpp:version="1.0" xmlns:xmpp="urn:xmpp:xbosh"/> bizzo_engine.js:6928
18:53:51.875 DEBUG - [STROPHE] request id 1.1 state changed to 2 bizzo_engine.js:6928
18:53:51.875 DEBUG - [STROPHE] request id 1.1 state changed to 3 bizzo_engine.js:6928
18:53:51.875 DEBUG - [STROPHE] request id 1.1 state changed to 4 bizzo_engine.js:6928
18:53:51.876 DEBUG - [STROPHE] removing request bizzo_engine.js:6928
18:53:51.876 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:51.876 DEBUG - [STROPHE] request id 1 should now be removed bizzo_engine.js:6928
18:53:51.876 DEBUG - [STROPHE] request id 1.1 got 200 bizzo_engine.js:6928
18:53:51.877 DEBUG - [STROPHE] _connect_cb was called bizzo_engine.js:6928
18:53:51.877 DEBUG - [WIRE] (i) <body xmlns="http://jabber.org/protocol/httpbind" xmlns:stream="http://etherx.jabber.org/streams" xmlns:xmpp="urn:xmpp:xbosh" ack="1366195701" authid="f6370876-a9f8-4051-a3c6-0673579f675e" hold="1" inactivity="30" maxpause="300" polling="5" requests="2" sid="f6370876-a9f8-4051-a3c6-0673579f675e" ver="1.6" wait="60"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism></mechanisms></stream:features></body> bizzo_engine.js:6928
18:53:51.878 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:51.980 DEBUG - [STROPHE] request id 2.0 posting bizzo_engine.js:6928
18:53:51.980 DEBUG - [STROPHE] request id 2.0 state changed to 1 bizzo_engine.js:6928
18:53:51.982 DEBUG - [WIRE] (o) <body rid="1366195702" xmlns="http://jabber.org/protocol/httpbind" sid="f6370876-a9f8-4051-a3c6-0673579f675e"><auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="ANONYMOUS"/></body> bizzo_engine.js:6928
18:53:52.130 DEBUG - [STROPHE] request id 2.1 state changed to 2 bizzo_engine.js:6928
18:53:52.130 DEBUG - [STROPHE] request id 2.1 state changed to 3 bizzo_engine.js:6928
18:53:52.131 DEBUG - [STROPHE] request id 2.1 state changed to 4 bizzo_engine.js:6928
18:53:52.131 DEBUG - [STROPHE] removing request bizzo_engine.js:6928
18:53:52.132 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:52.132 DEBUG - [STROPHE] request id 2 should now be removed bizzo_engine.js:6928
18:53:52.133 DEBUG - [STROPHE] request id 2.1 got 200 bizzo_engine.js:6928
18:53:52.133 DEBUG - [WIRE] (i) <body xmlns="http://jabber.org/protocol/httpbind"><success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/></body> bizzo_engine.js:6928
18:53:52.134 DEBUG - [STROPHE] SASL authentication succeeded. bizzo_engine.js:6928
18:53:52.134 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:52.235 DEBUG - [STROPHE] request id 3.0 posting bizzo_engine.js:6928
18:53:52.235 DEBUG - [STROPHE] request id 3.0 state changed to 1 bizzo_engine.js:6928
18:53:52.236 DEBUG - [WIRE] (o) <body rid="1366195703" xmlns="http://jabber.org/protocol/httpbind" sid="f6370876-a9f8-4051-a3c6-0673579f675e" to="gw-v3.d.phono.com" xml:lang="en" xmpp:restart="true" xmlns:xmpp="urn:xmpp:xbosh"/> bizzo_engine.js:6928
18:53:52.399 DEBUG - [STROPHE] request id 3.1 state changed to 2 bizzo_engine.js:6928
18:53:52.400 DEBUG - [STROPHE] request id 3.1 state changed to 3 bizzo_engine.js:6928
18:53:52.400 DEBUG - [STROPHE] request id 3.1 state changed to 4 bizzo_engine.js:6928
18:53:52.400 DEBUG - [STROPHE] removing request bizzo_engine.js:6928
18:53:52.401 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:52.401 DEBUG - [STROPHE] request id 3 should now be removed bizzo_engine.js:6928
18:53:52.401 DEBUG - [STROPHE] request id 3.1 got 200 bizzo_engine.js:6928
18:53:52.402 DEBUG - [WIRE] (i) <body xmlns="http://jabber.org/protocol/httpbind" xmlns:stream="http://etherx.jabber.org/streams"><stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features></body> bizzo_engine.js:6928
18:53:52.402 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:52.503 DEBUG - [STROPHE] request id 4.0 posting bizzo_engine.js:6928
18:53:52.503 DEBUG - [STROPHE] request id 4.0 state changed to 1 bizzo_engine.js:6928
18:53:52.504 DEBUG - [WIRE] (o) <body rid="1366195704" xmlns="http://jabber.org/protocol/httpbind" sid="f6370876-a9f8-4051-a3c6-0673579f675e"><iq type="set" id="_bind_auth_2" xmlns="jabber:client"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/></iq></body> bizzo_engine.js:6928
18:53:52.670 DEBUG - [STROPHE] request id 4.1 state changed to 2 bizzo_engine.js:6928
18:53:52.670 DEBUG - [STROPHE] request id 4.1 state changed to 3 bizzo_engine.js:6928
18:53:52.670 DEBUG - [STROPHE] request id 4.1 state changed to 4 bizzo_engine.js:6928
18:53:52.671 DEBUG - [STROPHE] removing request bizzo_engine.js:6928
18:53:52.671 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:52.671 DEBUG - [STROPHE] request id 4 should now be removed bizzo_engine.js:6928
18:53:52.672 DEBUG - [STROPHE] request id 4.1 got 200 bizzo_engine.js:6928
18:53:52.672 DEBUG - [WIRE] (i) <body xmlns="http://jabber.org/protocol/httpbind"><iq from="gw-v3.d.phono.com" id="_bind_auth_2" to="68b0d085-6c99-4ce3-a1d7-3d83f2ce3ac3@gw-v3.d.phono.com" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>68b0d085-6c99-4ce3-a1d7-3d83f2ce3ac3@phono2-ext.voxeolabs.net/1m30wt7m99284</jid></bind></iq></body> bizzo_engine.js:6928
18:53:52.673 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:52.774 DEBUG - [STROPHE] request id 5.0 posting bizzo_engine.js:6928
18:53:52.774 DEBUG - [STROPHE] request id 5.0 state changed to 1 bizzo_engine.js:6928
18:53:52.774 DEBUG - [WIRE] (o) <body rid="1366195705" xmlns="http://jabber.org/protocol/httpbind" sid="f6370876-a9f8-4051-a3c6-0673579f675e"><iq type="set" id="_session_auth_2" xmlns="jabber:client"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq></body> bizzo_engine.js:6928
18:53:53.016 DEBUG - [STROPHE] request id 5.1 state changed to 2 bizzo_engine.js:6928
18:53:53.017 DEBUG - [STROPHE] request id 5.1 state changed to 3 bizzo_engine.js:6928
18:53:53.017 DEBUG - [STROPHE] request id 5.1 state changed to 4 bizzo_engine.js:6928
18:53:53.017 DEBUG - [STROPHE] removing request bizzo_engine.js:6928
18:53:53.018 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:53.018 DEBUG - [STROPHE] request id 5 should now be removed bizzo_engine.js:6928
18:53:53.018 DEBUG - [STROPHE] request id 5.1 got 200 bizzo_engine.js:6928
18:53:53.019 DEBUG - [WIRE] (i) <body xmlns="http://jabber.org/protocol/httpbind"><iq from="gw-v3.d.phono.com" id="_session_auth_2" to="68b0d085-6c99-4ce3-a1d7-3d83f2ce3ac3@gw-v3.d.phono.com/1m30wt7m99284" type="result"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq></body> bizzo_engine.js:6928
18:53:53.019 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:53.020 DEBUG - [INVOKE] Phono.handleConnect() bizzo_engine.js:6928
Detecting Audio Plugin bizzo_engine.js:6173
Detected Flash bizzo_engine.js:6184
18:53:53.664 DEBUG - [STROPHE] request id 6.0 posting bizzo_engine.js:6928
18:53:53.665 DEBUG - [STROPHE] request id 6.0 state changed to 1 bizzo_engine.js:6928
18:53:53.665 DEBUG - [WIRE] (o) <body rid="1366195706" xmlns="http://jabber.org/protocol/httpbind" sid="f6370876-a9f8-4051-a3c6-0673579f675e"><iq type="set" xmlns="jabber:client"><apikey xmlns="http://phono.com/apikey">3ebe791391b8452710240e6bd7f3deb8</apikey></iq></body> bizzo_engine.js:6928
18:53:53.817 DEBUG - [STROPHE] request id 6.1 state changed to 2 bizzo_engine.js:6928
18:53:53.817 DEBUG - [STROPHE] request id 6.1 state changed to 3 bizzo_engine.js:6928
18:53:53.817 DEBUG - [STROPHE] request id 6.1 state changed to 4 bizzo_engine.js:6928
18:53:53.820 DEBUG - [STROPHE] removing request bizzo_engine.js:6928
18:53:53.820 DEBUG - [STROPHE] _throttledRequestHandler called with 0 requests bizzo_engine.js:6928
18:53:53.821 DEBUG - [STROPHE] request id 6 should now be removed bizzo_engine.js:6928
18:53:53.821 DEBUG - [STROPHE] request id 6.1 got 200 bizzo_engine.js:6928
18:53:53.821 DEBUG - [WIRE] (i) <body xmlns="http://jabber.org/protocol/httpbind"><iq from="gw-v3.d.phono.com" id="2ccda9e2-ff89-4c1d-8bc1-6f075073e699" to="68b0d085-6c99-4ce3-a1d7-3d83f2ce3ac3@gw-v3.d.phono.com/1m30wt7m99284" type="result"><apikey xmlns="http://phono.com/apikey"/></iq></body> bizzo_engine.js:6928
18:53:53.868 DEBUG - [STROPHE] no requests during idle cycle, sending blank request bizzo_engine.js:6928
18:53:53.869 DEBUG - [STROPHE] request id 7.0 posting bizzo_engine.js:6928
18:53:53.869 DEBUG - [STROPHE] request id 7.0 state changed to 1 bizzo_engine.js:6928
18:53:53.871 DEBUG - [WIRE] (o) <body rid="1366195707" xmlns="http://jabber.org/protocol/httpbind" sid="f6370876-a9f8-4051-a3c6-0673579f675e"/> 
undsoft commented 11 years ago

Hm. I used the same wrapped code, but now I put it in a separate JS file and loaded it via jQuery.getScript. Somehow it works now. Even in IE7.

QQism commented 10 years ago

@undsoft can you explain more detail about your solution, I am stuck with this issue for a whole day