Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
Nodejs Websockets User Active State with MongoDB

I have a NodeJS backend with Express and WS, and is a simple messenger-like chat app. You login, then you chat. But I want to add a feature on top of it. If a user is already logged and ACTIVE (socket connection exists, not broken) I want it's activeStatus : active in database. So that if he tries to login from a different browser, if his activeStatus is active, he won't be able to connect.

How is this achievable? I cannot understand how am I supposed to link a websocket connection to a specific ID in database, and when connection is on, update db, and when connection drops, update it to that ID again.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just set a unique parameter for WebSocket instance in wss.on('connection',...) and use it later to identify the user. Also, if you aren't able to link websocket connection to a specified user, how does your authentication work? It seems like anyone can connect to your server, if it can't differentiate between users.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda