JOIN MY SPONSORS

Connected Users

By connecting with { list: true, announce: true }, you receive a full list of announced users on join — then maintain it with join/leave events.

For this example, you are .... Open this page in another tab to see the activity.

Current Viewers
+ 1 other
viewers.ts
import { connect } from 'itty-sockets'

let users = []

connect('examples:viewers', {
  announce: true,
  list: true,
  as: '...',
})
.on('join', ({ uid, alias, users: list }) => {
  if (list) users = list          // initial user list on your own join
  else if (uid) users.push({ uid, alias })
})
.on('leave', ({ uid }) => {
  users = users.filter(u => u.uid !== uid)
})