NathanaelA / nativescript-websockets

Websockets for NativeScript
83 stars 43 forks source link

Nativescript websockets and socketcluster client not playing nice #67

Closed jcjmcclean closed 4 years ago

jcjmcclean commented 5 years ago

I've got a nativescript project which needs to interface with a socketcluster server. I've already created a proof of concept in angular (without nativescript), which works perfectly using socketcluster browser client - but I can't get the nativescript angular android app to work with socketcluster (using the same browser client).

Nativescript doesn't support websockets out of the box, there's a plugin nativescript-websockets which enables websocket support. I created another proof of concept in nativescript using a vanilla websocket server and the nativescript-websockets plugin which worked perfectly again (connected, received and sent messages + disconnected).

So now I know that socketcluster.js browser client works with angular and nativescript-websockets works with nativescript. I need to combine the 2 to enable my nativescript app to connect to the socketcluster server...

I edited the socketcluster.js browser client to switch out line 1304 (WebSocket = _dereq_('ws');) for the nativescript websockets library WebSocket = require('nativescript-websockets'); hoping that would enable the socketcluster library to work with nativescript.

The response I'm getting from that is error code 4007: 'ERROR SocketProtocolError: Client connection establishment timed out'.

I can connect to the server with the same settings from the angular app and vanilla websockets works on nativescript, so something isn't playing nice between socketcluster client and nativescript-websockets.

WIRESHARK I setup wireshark to listen for websocket packets, so I can see if/when the socketcluster connection is created. It works great with the angular app and with vanilla websockets on nativescript but sees nothing at all happening when I'm using socketcluster client in the nativescript app, it's like the websocket connection isn't even being attempted.

TL;DR Trying to get socketcluster client working on a nativescript application using nativescript-websockets. Getting timeout errors. Same code works in angular app.

Question: Can you recommend a way to debug/listen to websocket connections from a nativescript application on the android emulator?

Is there any obvious reason why socketcluster browser client wouldn't work with nativescript-websockets?

jcjmcclean commented 5 years ago

For reference links to other issues also opened: SocketCluster/socketcluster#496 https://github.com/SocketCluster/socketcluster-client/issues/127

NathanaelA commented 5 years ago

Off the top of my head I can't think of any reason why it should fail. But with that said; this plugin has basically been un-maintained for years now, as I haven't needed it for any contract jobs and the community help with maintenance is virtually non-existent :frowning_face: on the vast majority of my plugins -- which means any open source time typically goes to plugins that are used by vastly more people. So, without a real client needing it, or community support... :man_shrugging:

I am very open to PR's and will give my time to review and test them, and very very very rarely actually reject a PR. I really want to encourage the community to give back... :grinning:

Now as how to debug it; the first step would be to update the demo app to use NS 5.x and verify it still works. That at least gives you an idea if under basic conditions it works. If it works, then it is a matter to figure out what the additional code in socketcluster is doing that is not working. If it doesn't work; then it is a matter of digging into the internals of the actual websocket libraries and figuring out what has broken in later versions of Android/iOS/NativeScript...

My day to day job is contract work; so if this is important to your app; and your willing to pay; I can slot this into a paid time slot and work on WebSockets. Otherwise, at this point websockets will probably continue to sit until I have a paying client that needs it or the community steps up and helps maintain it...

edusperoni commented 5 years ago

I'm using nativescript-websockets + socketcluster to develop my interface between ngrx and remote redux dev tools, and it all worked without issue.

As I'm using webpack, I just had to add this line to my webpack.config.js:

config.plugins.push(new webpack.NormalModuleReplacementPlugin(/^ws$/, "nativescript-websockets"));

The connection is done by:

        this.socket = socketCluster.connect({
            hostname: this.options.hostname,
            port: this.options.port,
            secure: !!this.options.secure,
        });

Maybe it's something specific to your implementation?

MegaGM commented 4 years ago

@NathanaelA @jcjmcclean

I've closed the original issue.

This issue could have been closed as well, I guess.