nativescript-socket.io icon indicating copy to clipboard operation
nativescript-socket.io copied to clipboard

use with feathersjs

Open bzd2000 opened this issue 6 years ago • 1 comments

Hello,

I would like to use this plugin with feathersjs. the connection with feathers works, but when using it with the @feathersjs/authentication-client plugin, I run into the following issue.

At some point it calls the following function:

const socketUpgradeHandler = () => {
      socket.io.engine.on('upgrade', () => {
        debug('Socket upgrading');

        // If socket was already authenticated then re-authenticate
        // it with the server automatically.
        if (socket.authenticated) {
          const data = {
            strategy: this.options.jwtStrategy,
            accessToken: app.get('accessToken')
          };

          this.authenticateSocket(data, socket, emit)
            .then(this.setJWT)
            .catch(error => {
              debug('Error re-authenticating after socket upgrade', error);
              socket.authenticated = false;
              app.emit('reauthentication-error', error);
            });
        }
      });
    };

But then it says "TypeError: Cannot read property 'engine' of undefined" So I guess, the engine is not defined at socket.io.engine.on.

Any clue?

bzd2000 avatar Jun 09 '19 12:06 bzd2000

Simply put an empty eventemitter to fix it

(<any>socket).io = {
    engine: new EventEmitter()
}

socket.on('connect', function() {
    (<any>socket).io.engine.emit('upgrade')
})

20051231 avatar Jun 26 '19 05:06 20051231