Skip to content

Event Emitter memory leak! messages added twice! #4200

Answered by darrachequesne
artstylee asked this question in Q&A
Discussion options

You must be logged in to vote

I think that's because a new listener gets added each time you receive a "msg" event on the server side. How about:

io.on("connect", (socket) => {
    socket.on("msg", (activechat, token, userlogin, message) => {
        socket.emit(userlogin, "refresh")
    })
    
    socket.on(userlogin, (msg) => {
        if (msg === "refresh ok") {
            socket.emit(activechat, message)
        }
    })
})

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@artstylee
Comment options

@artstylee
Comment options

@artstylee
Comment options

@artstylee
Comment options

Answer selected by artstylee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants