nativescript-socket.io
nativescript-socket.io copied to clipboard
use with feathersjs
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?
Simply put an empty eventemitter to fix it
(<any>socket).io = {
engine: new EventEmitter()
}
socket.on('connect', function() {
(<any>socket).io.engine.emit('upgrade')
})