Skip to content

Commit

Permalink
Step 4 - Get present members
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonWoolf committed Nov 18, 2016
1 parent 5a39594 commit c0376c9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@ channel.attach(function(err) {
console.log('We are now successfully present');
});
});

console.log("Press <enter> to get the presence set, or q<enter> to quit.");
process.stdin.resume();
process.stdin.on('data', function (chunk) {
switch(chunk.toString()) {
case "\n":
channel.presence.get(function(err, members) {
if(err) { return console.log("Error fetching presence data: " + err); }
console.log('There are ' + members.length + ' clients present on this channel');
});
break;
case "q\n":
/* Close the realtime connection explicitly on quitting to avoid the
* presence member sticking around for 15s; see
* https://support.ably.io/solution/articles/3000059875-why-don-t-presence-members-leave-as-soon-as-i-close-a-tab- */
realtime.close();
process.exit();
}
});

0 comments on commit c0376c9

Please sign in to comment.