On line (5), we have our led message handler, which is responsible for updating the HTML controls with the current brightness level of our LED:
socket.on('led', function(dataFromServer) { // (5)
console.log(dataFromServer)
if (dataFromServer.level !== undefined) {
$("input[type=range].brightnessLevel").val(dataFromServer.level);
$("#brightnessLevel").html(dataFromServer.level);
}
});
If you review the Python server's @socketio.on('connect') handler, you will notice it contains the line emit("led", state). When a new client connects to the server, it emits back to the connecting client a message containing the current state of our LED. It's the JavaScript socket.on('led', ...) part on line (5) that consumes this message.
Next, we have the jQuery document ready callback.