Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dissconnect another client through a different client? #3418

Closed
2 tasks
ghost opened this issue Mar 12, 2019 · 3 comments
Closed
2 tasks

How to dissconnect another client through a different client? #3418

ghost opened this issue Mar 12, 2019 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@ghost
Copy link

ghost commented Mar 12, 2019

Note: for support questions, please use one of these channels: stackoverflow or slack

For bug reports and feature requests for the Swift client, please open an issue there.

For bug reports and feature requests for the Java client, please open an issue there.

You want to:

  • report a bug
  • request a feature

Current behaviour

What is actually happening?

Steps to reproduce (if the current behaviour is a bug)

Note: the best way (and by that we mean the only way) to get a quick answer is to provide a failing test case by forking the following fiddle.

Expected behaviour

What is expected?

Setup

  • OS:
  • browser:
  • socket.io version:

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@ghost
Copy link
Author

ghost commented Mar 12, 2019

I'm making a simple multiplayer tag game: https://repl.it/@Helixable/Multiplayer-Tag-v10
I want to make admins be able to kick other players. How do I do this?

@boolee
Copy link

boolee commented Mar 15, 2019

records every palyers socket.id in local db,like redis in one room,then just emit to those players offline socket.to(player1.socket.id).to(player2.socket.id).emit('offline')

@darrachequesne darrachequesne added the enhancement New feature or request label Feb 23, 2021
darrachequesne added a commit that referenced this issue Mar 2, 2021
This commit adds the following methods:

- fetchSockets: returns the matching socket instances

Syntax:

```js
// return all Socket instances
const sockets = await io.fetchSockets();

// return all Socket instances of the "admin" namespace in the "room1" room
const sockets = await io.of("/admin").in("room1").fetchSockets();
```

- socketsJoin: makes the matching socket instances join the specified rooms

Syntax:

```js
// make all Socket instances join the "room1" room
io.socketsJoin("room1");

// make all Socket instances of the "admin" namespace in the "room1" room join the "room2" room
io.of("/admin").in("room1").socketsJoin("room2");
```

- socketsLeave: makes the matching socket instances leave the specified rooms

Syntax:

```js
// make all Socket instances leave the "room1" room
io.socketsLeave("room1");

// make all Socket instances of the "admin" namespace in the "room1" room leave the "room2" room
io.of("/admin").in("room1").socketsLeave("room2");
```

- disconnectSockets: makes the matching socket instances disconnect

Syntax:

```js
// make all Socket instances disconnect
io.disconnectSockets();

// make all Socket instances of the "admin" namespace in the "room1" room disconnect
io.of("/admin").in("room1").disconnectSockets();
```

Those methods share the same semantics as broadcasting. They will also
work with multiple Socket.IO servers when using the Redis adapter. In
that case, the fetchSockets() method will return a list of RemoteSocket
instances, which expose a subset of the methods and attributes of the
Socket class (the "request" attribute cannot be mocked, for example).

Related:

- #3042
- #3418
- #3570
- socketio/socket.io-redis-adapter#283
@darrachequesne
Copy link
Member

For future readers: this was implemented in b25495c and included in socket.io@4.0.0

Syntax:

// make all Socket instances disconnect
io.disconnectSockets();

// make all Socket instances of the "admin" namespace in the "room1" room disconnect
io.of("/admin").in("room1").disconnectSockets();

Documentation: https://socket.io/docs/v3/migrating-from-3-x-to-4-0/#Additional-utility-methods

@darrachequesne darrachequesne added this to the 4.0.0 milestone Mar 11, 2021
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
This commit adds the following methods:

- fetchSockets: returns the matching socket instances

Syntax:

```js
// return all Socket instances
const sockets = await io.fetchSockets();

// return all Socket instances of the "admin" namespace in the "room1" room
const sockets = await io.of("/admin").in("room1").fetchSockets();
```

- socketsJoin: makes the matching socket instances join the specified rooms

Syntax:

```js
// make all Socket instances join the "room1" room
io.socketsJoin("room1");

// make all Socket instances of the "admin" namespace in the "room1" room join the "room2" room
io.of("/admin").in("room1").socketsJoin("room2");
```

- socketsLeave: makes the matching socket instances leave the specified rooms

Syntax:

```js
// make all Socket instances leave the "room1" room
io.socketsLeave("room1");

// make all Socket instances of the "admin" namespace in the "room1" room leave the "room2" room
io.of("/admin").in("room1").socketsLeave("room2");
```

- disconnectSockets: makes the matching socket instances disconnect

Syntax:

```js
// make all Socket instances disconnect
io.disconnectSockets();

// make all Socket instances of the "admin" namespace in the "room1" room disconnect
io.of("/admin").in("room1").disconnectSockets();
```

Those methods share the same semantics as broadcasting. They will also
work with multiple Socket.IO servers when using the Redis adapter. In
that case, the fetchSockets() method will return a list of RemoteSocket
instances, which expose a subset of the methods and attributes of the
Socket class (the "request" attribute cannot be mocked, for example).

Related:

- socketio#3042
- socketio#3418
- socketio#3570
- socketio/socket.io-redis-adapter#283
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants