setHostConnected method

void setHostConnected(
  1. String hostId, {
  2. required bool connected,
})

Sets the connection of host hostId and publishes the ephemeral host.presence_changed to the devices of everyone who sees the host.

Implementation

void setHostConnected(String hostId, {required bool connected}) {
  final h = hosts[hostId]!..connected = connected;
  for (final viewer in hostViewers(h)) {
    publishEphemeral(
      'host.presence_changed',
      resource: {'kind': 'host', 'id': h.id},
      payload: {'host_id': h.id, 'connected': connected},
      audience: viewer,
      devices: {
        for (final d in devices.values)
          if (d.userId == viewer) d.id,
      },
    );
  }
}