deepstreamIO / deepstream.io

deepstream.io server
https://deepstreamio.github.io
MIT License
7.14k stars 381 forks source link

deepstream@5.0.5 onClientDisconnect event not fired #1038

Closed caracal7 closed 4 years ago

caracal7 commented 4 years ago

Server code

const { Deepstream } = require( '@deepstream/server' ); // v.5.0.5

const DeepstreamServer = new Deepstream( {
    httpServer: {
        type: 'default',
        options: {
            port: 6020,
            host: '127.0.0.1'
        }
    },
})

DeepstreamServer.set('authentication', {
    isValidUser( handshakeData, authData ) {
        return {
            isValid: true,
            id: authData.username,
        }
    },
    async whenReady () {
        console.log('whenReady')
    },
    //  This event never fired!!!
    onClientDisconnect( username ) {
        console.log( 'onClientDisconnect', username )
    },
});

DeepstreamServer.start();
console.log( 'DeepStream started...' );
yasserf commented 4 years ago

I think that might be because your not implementing the actual plugin interface.

Will look at it and get back to you

caracal7 commented 4 years ago
const DeepstreamServer = new Deepstream( {
    httpServer: {
        type: 'default',
        options: {
            port: 6020,
            host: '127.0.0.1'
        }
    },
    auth: [{
        path: './PATH/my-authentication.js',
        options: {}
    }]
})

my-authentication.js

const { DeepstreamPlugin } = require('@deepstream/types')

module.exports = class TokenAuthentication extends DeepstreamPlugin {

    constructor ( pluginOptions,  services) {
         super()
    }

    async isValidUser(connectionData, authData) {
     console.log('isValidUser')
         return null
    }

    async whenReady () {
     console.log('whenReady')
    }

    //  This event never fired!!!
    async onClientDisconnect( username ) {
    console.log( 'onClientDisconnect', username )
    }

}

also didn't work

caracal7 commented 4 years ago

@yasserf No ideas how to catch onClientDisconnect event?

caracal7 commented 4 years ago

I didn't know TypeScript. I make little hack and solve my problem

deepstream.io/src/connection-endpoint/base/connection-endpoint.ts line:385

if (this.services.authentication.onClientDisconnect) {
  this.services.authentication.onClientDisconnect(socketWrapper.user)

I changed to

// @ts-ignore
if (this.services.authentication.auths[0].onClientDisconnect) {
  // @ts-ignore
  this.services.authentication.auths[0].onClientDisconnect(socketWrapper.userId)

But this is not good solution 🤗

yasserf commented 4 years ago

Hey!

That’s almost completely correct, just needs to be a loop instead. I’ll put in the fix. Thank you finding it!

On Sat, 8 Feb 2020 at 09:44, Dmitry notifications@github.com wrote:

I didn't know TypeScript. I make little hack witch solve my problem

deepstream.io/src/connection-endpoint/base/connection-endpoint.ts line:385

if (this.services.authentication.onClientDisconnect) {

this.services.authentication.onClientDisconnect(socketWrapper.user)

I changed to

// @ts-ignore

if (this.services.authentication.auths[0].onClientDisconnect) {

// @ts-ignore

this.services.authentication.auths[0].onClientDisconnect(socketWrapper.userId)

But this is not good solution 🤗

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/deepstreamIO/deepstream.io/issues/1038?email_source=notifications&email_token=AAU3WS242L5LWL2IGORXNL3RBXB3LA5CNFSM4KIOOPKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELERB5I#issuecomment-583602421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU3WSYZWVTNUXG5AG7HXT3RBXB3LANCNFSM4KIOOPKA .

yasserf commented 4 years ago

Should be fixed in 5.0.6, let me know!

caracal7 commented 4 years ago

@yasserf Version 5.0.7

deepstream.io/src/connection-endpoint/base/connection-endpoint.ts line:386

this.services.authentication.onClientDisconnect(socketWrapper.user)

need to be replaced to

this.services.authentication.onClientDisconnect(socketWrapper.userId)

in order to onClientDisconnect return ID

yasserf commented 4 years ago

Interesting that didn’t get caught by typescript. Will look at it.

caracal7 commented 4 years ago

@yasserf did you fix with issue?

yasserf commented 4 years ago

I put in a fix but DS didnt release due an NPM issue which I didn’t look into

caracal7 commented 4 years ago

Thanks a lot )

yasserf commented 4 years ago

Released in 5.0.9