As @HipsterBrown said, most of what you're looking for is already in the code base, just needs to be refactored...
const spotlight = document.getElementById("spotlight-toggle");
spotlight.addEventListener("click", function(event) {
spotlight.dataset.state = spotlight.dataset.state === "on" ? "off" : "on";
socket.emit("remote-control", { spotlight: spotlight.dataset.state });
});
Then in index.js, change this: https://github.com/bocoup/j5ik-reconbot-tessel-edition/blob/master/index.js#L60-L62 to this:
const relay = new five.Relay("A7");
connection.on("remote-control", data => {
if (data.axis) {
rover.update(data.axis);
}
if (data.spotlight) {
if (data.spotlight === "on") {
relay.close();
} else {
relay.open();
}
}
});