Skip to content

Commit

Permalink
Add API doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Jan 30, 2015
1 parent 3a40107 commit 9c320d1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Readme.md
Expand Up @@ -244,11 +244,33 @@ server.listen(3000);

Gets a list of client IDs connected to this namespace (across all nodes if applicable).

An example to get all clients in a namespace:

```js
var io = require('socket.io')();
io.of('/chat').clients(function(error, clients){
if (error) throw error;
console.log(clients); // => [PZDoMHjiu8PYfRiKAAAF, Anw2LatarvGVVXEIAAAD]
});
```

An example to get all clients in namespace's room:

```js
var io = require('socket.io')();
io.of('/chat').in('general').clients(function(error, clients){
if (error) throw error;
console.log(clients); // => [PZDoMHjiu8PYfRiKAAAF, d9rZTYbZfNhVf9j9AAAE]
console.log(clients); // => [Anw2LatarvGVVXEIAAAD]
});
```

As with broadcasting, the default is all clients from the default namespace ('/'):

```js
var io = require('socket.io')();
io.clients(function(error, clients){
if (error) throw error;
console.log(clients); // => [6em3d4TJP8Et9EMNAAAA, G5p55dHhGgUnLUctAAAB]
});
```

Expand Down

0 comments on commit 9c320d1

Please sign in to comment.