install socket io and getting an example up

This commit is contained in:
Beverly Nguyen
2025-03-26 12:54:21 -07:00
parent 3af8f782ec
commit e0e8c56a61
9 changed files with 177 additions and 6 deletions

View File

@@ -0,0 +1,20 @@
const socket = io();
const jobId = document.querySelector("[data-job-id]").dataset.jobId;
socket.on('connect', () => {
console.log('Connected to server');
});
// Join a room
socket.emit("join", { room: `job-${jobId}` });
console.log("🧠 Joined room:", `job-${jobId}`);
// Listen for job updates
socket.on("job_update", function (data) {
const el = document.querySelector(`[data-key="${data.key}"]`);
if (el) {
el.textContent = "✅ Real-time update success!";
el.classList.add("text-success"); // Add a class instead
}
});