mkuklis / phonegap-websocket

Websocket PhoneGap plugin for Android
203 stars 78 forks source link

Cordova 3.3.0 support #37

Closed rreghin closed 10 years ago

rreghin commented 10 years ago

Is there any chance to add Cordova 3.3.0+ support for you plugin? I just can't make it work, neither if I try to use the 2.x.x version.

I'm doing this (on both Windows and MacOSX):

First: Install NodeJS Download and install/prepare the Android SDK Fix environment PATH (for both nodejs and android sdk)

Then: npm install -g cordova cd /dev/workspace cordova create wstest com.wstest WSTest cd wstest cordova platform add android cordova platform add ios cordova plugin add https://github.com/mkuklis/phonegap-websocket cordova build

All gets compiled and deployed correctly, but I just can't get the "new WebSocket(...)" to work.

On my index.html I added:

    <script>
        if( (typeof(WebSocket) === 'function') || ('WebSocket' in window) ) {
            alert("SUCCESS! Your browser DOES support HTML5 Web Sockets.");
        }
        else {
            alert("Error. Your browser does NOT support HTML5 Web Sockets.");
        }
    </script>

Am I doing something wrong?

I also tried to add the code from WebSocket.org's echo test, and it worked on IOS and Android 4.4.x, because both of them have native WebSockets support. But on Android 2.3 and 4.0, just don't work at all. =(

What am I missing??

mkuklis commented 10 years ago

These steps look good to me. Can you post your setup somewhere so I can get a closer look at it?

jlertle commented 10 years ago

Great plugin but I'm having the same issue on 3.3.1

mkuklis commented 10 years ago

@jlertle how about pre 3.3.1? Also are you testing on the emulator or real device? What version of android? thx.

jlertle commented 10 years ago

I did not try this plugin until now... let me look into setting up an older Cordova.

Do I need to add anything to config.xml though?

mkuklis commented 10 years ago

Oh I see. No I don't think anything has to be added to config.xml. I was just curious to hear if you tried with the older version. Is there anyway I could look at your current setup? Are you testing it on emulator or real device? What version of android do you use? Thx.

jlertle commented 10 years ago

Real devices: Xoom with 4.1.2 and Evo4G with 2.3.5.

Using Android SDK 4.4.2 API19

Let me commit and I'll send you the repo.

Thx!

mkuklis commented 10 years ago

@jlertle awesome thank you! Having access to the code would be very helpful.

jlertle commented 10 years ago

https://github.com/jlertle/jlertle/

Thanks for looking! ;-)

mkuklis commented 10 years ago

Thanks I will take a look at it right now.

rreghin commented 10 years ago

Hi guys!

As I told in my first post, I've tried the version 2.x.x of your plugin as well (using Cordova 2.9.7), but with the same results (nothing happens).

I also have tried on both virtual and real devices. The real ones are Android 2.3.6 and 4.0.3; and the virtual ones are 4.0.3 and 2.3.7.

Have you had any luck simulating the problem?

mkuklis commented 10 years ago

@jlertle it looks like the problem is related to the window.open. When you open a new window with window.open the context from the parent is not accessible via child's window object. You can try reference the parent window in your chat.js with opener

https://developer.mozilla.org/en-US/docs/Web/API/Window.opener

So your condition could look like this:

  if ((typeof(window.opener.WebSocket) === 'function') || ('WebSocket' in window.opener) ) {
    alert("SUCCESS! Your browser DOES support HTML5 Web Sockets.");
  }
  else {
    alert("Error. Your browser does NOT support HTML5 Web Sockets.");
  }

I would personally avoid using open.window and just include your chat.js file in cordova project or load it via script.src in a similar fashion to this:

https://bitbucket.org/mkuklis/phonegap-websocket-demo/src/e6a874f8280900c0273af552c4970232d27c38b5/client/www/index.html?at=master#cl-15

jlertle commented 10 years ago

Ah, I was hoping websockets would be provided to inappbrowser. I really just want to wrap a site but I'll look at using cordova directly.

Thx for looking!

-Sent from my TRS-80 On Jan 7, 2014 9:29 PM, "Michał Kuklis" notifications@github.com wrote:

@jlertle https://github.com/jlertle it looks like the problem is related to the window.open. When you open a new window with window.openthe context from the parent is not accessible via child's window object. You can try reference the parent window in your chat.jswith opener

https://developer.mozilla.org/en-US/docs/Web/API/Window.opener

So your condition could look like this:

if ((typeof(window.opener.WebSocket) === 'function') || ('WebSocket' in window.opener) ) { alert("SUCCESS! Your browser DOES support HTML5 Web Sockets."); } else { alert("Error. Your browser does NOT support HTML5 Web Sockets."); }

I would personally avoid using open.window and just include your chat.jsfile in cordova project or load it via script.src in a similar fashion to this:

https://bitbucket.org/mkuklis/phonegap-websocket-demo/src/e6a874f8280900c0273af552c4970232d27c38b5/client/www/index.html?at=master#cl-15

— Reply to this email directly or view it on GitHubhttps://github.com/mkuklis/phonegap-websocket/issues/37#issuecomment-31800792 .

rreghin commented 10 years ago

@mkuklis could you also have a look to my code, please??

I have it at https://github.com/rreghin/IntraChatClientMobile/tree/master/webclient

Thanks a lot!!

mkuklis commented 10 years ago

@rreghin yes will take a look today.

mkuklis commented 10 years ago

@rreghin it looks like you are trying to get access to the WebSocket constructor before Cordova and all plugins are being initialized:

https://github.com/rreghin/IntraChatClientMobile/blob/master/webclient/www/index.html#L43

Please try to move your condition here:

https://github.com/rreghin/IntraChatClientMobile/blob/master/webclient/www/js/index.js#L36

and things should work correctly.

rreghin commented 10 years ago

Thank you so much!!! You were right!! Just moved the "checking" code to the proper place and it worked right away!! =D

mkuklis commented 10 years ago

@rreghin great! I'm glad it works for you now. Cheers.

FatemaBhadka commented 10 years ago

hey how do i add your plugin to my project since i am using phonegap cloud build. Also i dont intented to use socket io

khizarsonu commented 10 years ago

PhoneGap Build service, support a limited set of plugins https://build.phonegap.com/docs/plugins. You will not be able to import this plugin with PhoneGap build.

On Thu, Sep 4, 2014 at 4:00 PM, FatemaBhadka notifications@github.com wrote:

hey how do i add your plugin to my project since i am using phonegap cloud build. Also i dont intented to use socket io

Reply to this email directly or view it on GitHub https://github.com/mkuklis/phonegap-websocket/issues/37#issuecomment-54448953 .

Have A Nice Day! -- khizar

FatemaBhadka commented 10 years ago

Oops! Can you tel me the steps i need to follow in order to get this working. Thanks :)

khizarsonu commented 10 years ago

hi,

you need to setup local build, if you switch to building locally, this will invariably split your code into multiple projects, You can create symlinks to keep www assets in a single location, but native code will be split (including your plugins)

As you mention you don't intend to use socket.io its upto you, its just js library, nothing to do with cordova/phoegap

Hope this helps

On Thu, Sep 4, 2014 at 5:26 PM, FatemaBhadka notifications@github.com wrote:

Oops! Can you tel me the steps i need to follow in order to get this working. Thanks :)

Reply to this email directly or view it on GitHub https://github.com/mkuklis/phonegap-websocket/issues/37#issuecomment-54460873 .

Have A Nice Day! -- khizar

shadimsaleh commented 9 years ago

hello , I try to build it at the first I faced an error in building and I solved by it by changing the config.xml to "android-minSdkVersion" value="17" but now i can build but when the app is run on emulator i get an error anther question how I can send photo or video via this plugin thank in advance