Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Add function filterSocketsByUserInNamespace #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomasbatto
Copy link

Reason

I was trying to find sockets corresponding to certain users to join them to a room and then emit a mesagge to that room from the namespace, but this message was never received by the sockets. Creating this new function allow me to achieve this.

Problem

const nsp = io.of('/game')

nsp.on('connection', function(socket){
    let usersSockets = passportSocketIo.filterSocketsByUser(io, (user) => {
              return user._id == 'someId'
            })
    usersSockets.forEach((uSocket)=> {
         uSocket.join('room1')
    })
   nsp.to('room1').emit('joined', 'the game will start soon')
})

Solution

const nsp = io.of('/game')

nsp.on('connection', function(socket){
    let usersSockets = passportSocketIo.filterSocketsByUserInNamespace(nsp, (user) => {
              return user._id == 'someId'
            })
    usersSockets.forEach((uSocket)=> {
         uSocket.join('room1')
    })
   nsp.to('room1').emit('joined', 'the game will start soon')
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant