triniwiz / nativescript-socketio

Socket.IO for nativescript
Apache License 2.0
71 stars 31 forks source link

[android] EVENT_TRANSPORT is prevent event triggering #82

Closed gogoout closed 5 years ago

gogoout commented 5 years ago

First of all, thanks for the new version. After upgrade to the latest version(3.3.0), I found my socket.on('connect',callback) is not getting called.

And I find that

 _this.socket.io().on(io.socket.client.Manager.EVENT_TRANSPORT, new io.socket.emitter.Emitter.Listener({
                    call: function (transportArgs) {
                        var transports = transportArgs[0];
                        if (transports) {
                      console.log('on EVENT_TRANSPORT');
                            transports.on(io.socket.engineio.client.Transport.EVENT_REQUEST_HEADERS, new io.socket.emitter.Emitter.Listener({
                                call: function (requestArgs) {
                                  console.log('on EVENT_REQUEST_HEADERS');
                                    var cookies = options_1['cookie'];
                                    if (cookies) {
                                        var headers = requestArgs[0];
                                        var list = new java.util.ArrayList();
                                        list.add(cookies);
                                        headers.put('Cookie', list);
                                    }
                                }
                            }))
                        }
                    }
                }));

If I comment out these lines, everything starting to working again. I haven't digged deep to figure out the reason tough.


Another thing is I found that I have to manually convert js transports to java Array to make it work. Not sure if everyone is the same cause I'm running on old nativescript v4.2.0

 if (Array.isArray(transports) && transports.length > 0) {
                          var list = new java.util.ArrayList();
                          transports.forEach(each => list.add(each));
                          opts.transports = list.toArray();
                        }
triniwiz commented 5 years ago

Fixed https://github.com/triniwiz/nativescript-socketio/commit/fc38b426e3c39ee799fbc8a4a2d3a68bcd85d029