MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Real-Time Collaborative Dashboard Engine0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
18.1Architecture & State Store Design (Store Pattern)18.2Real-Time Collaborative Dashboard Engine18.3Offline-First Sync with IndexedDB & Service Worker18.4Production Bundling, Testing & Deployment
HomeTutorialsJavaScript for AdvancedReal-Time Collaborative Dashboard Engine
Offline-First Sync with IndexedDB & Service Worker

Real-Time Collaborative Dashboard Engine

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

Real-time collaboration (seen in Figma, Google Docs, and Miro) requires syncing state across multiple remote clients simultaneously over WebSockets. In this capstone lesson, you will build a Real-Time Collaborative Dashboard Engine featuring presence tracking, remote cursor coordinates, and conflict-free action synchronization.


1. System Architecture

1 Client A (Browser) WebSocket Server Client B (Browser)
2 [ Local State Store ] (Message Broker) [ Local State Store ]
3 │ │ │
4 │ 1. Dispatches local action │ │
5 ├────────────────────────────────►│ │
6 │ { type: 'CURSOR_MOVE' } │ │
7 │ │ 2. Broadcasts to all peers │
8 │ ├───────────────────────────────────►│
9 │ │ { type: 'REMOTE_CURSOR' } │
10 │ │ ▼
11 │ │ Updates Client B UI!

2. Building the Collaborative Engine Client

1class CollaborativeEngine {
2 constructor(wsUrl, store) {
3 this.wsUrl = wsUrl;
4 this.store = store;
5 this.socket = null;
6 this.clientId = 'client_' + crypto.randomUUID().slice(0, 8);
7 this.remotePresences = new Map();
8 
9 this.connect();
10 this.initMouseTracking();
11 }
12 
13 connect() {
14 this.socket = new WebSocket(this.wsUrl);
15 
16 this.socket.onopen = () => {
17 console.log(`[Collab] Connected as ${this.clientId}`);
18 // Broadcast join presence
19 this.broadcast({
20 type: 'PEER_JOIN',
21 clientId: this.clientId,
22 color: this.getRandomColor()
23 });
24 };
25 
26 this.socket.onmessage = (event) => {
27 const message = JSON.parse(event.data);
28 // Ignore self-broadcasts
29 if (message.clientId === this.clientId) return;
30 
31 this.handleRemoteMessage(message);
32 };
33 }
34 
35 initMouseTracking() {
36 // Throttle cursor broadcasts to 50ms (20fps) to conserve network
37 let lastSent = 0;
38 
39 window.addEventListener('pointermove', (e) => {
40 const now = Date.now();
41 if (now - lastSent > 50) {
42 lastSent = now;
43 this.broadcast({
44 type: 'CURSOR_UPDATE',
45 clientId: this.clientId,
46 x: e.clientX,
47 y: e.clientY
48 });
49 }
50 });
51 }
52 
53 broadcast(action) {
54 if (this.socket && this.socket.readyState === WebSocket.OPEN) {
55 this.socket.send(JSON.stringify(action));
56 }
57 }
58 
59 handleRemoteMessage(msg) {
60 switch (msg.type) {
61 case 'CURSOR_UPDATE':
62 this.updateRemoteCursor(msg.clientId, msg.x, msg.y);
63 break;
64 
65 case 'DASHBOARD_MUTATION':
66 // Dispatch remote mutation directly to local store!
67 this.store.dispatch(msg.action);
68 break;
69 
70 case 'PEER_LEAVE':
71 this.removeRemoteCursor(msg.clientId);
72 break;
73 }
74 }
75 
76 updateRemoteCursor(peerId, x, y) {
77 let cursorEl = document.querySelector(`#cursor-${peerId}`);
78 if (!cursorEl) {
79 cursorEl = document.createElement('div');
80 cursorEl.id = `cursor-${peerId}`;
81 cursorEl.className = 'remote-cursor';
82 cursorEl.innerHTML = `
83 <svg class="cursor-pointer" width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
84 <polygon points="0,0 0,20 6,15 11,24 14,22 9,13 18,13" />
85 </svg>
86 <span class="peer-label">${peerId}</span>
87 `;
88 document.body.appendChild(cursorEl);
89 }
90 
91 // High performance GPU translate
92 cursorEl.style.transform = `translate3d(${x}px, ${y}px, 0)`;
93 }
94 
95 removeRemoteCursor(peerId) {
96 const el = document.querySelector(`#cursor-${peerId}`);
97 if (el) el.remove();
98 }
99 
100 getRandomColor() {
101 return ['#ef4444', '#3b82f6', '#10b981', '#f59e0b', '#8b5cf6'][Math.floor(Math.random() * 5)];
102 }
103}

3. Remote Cursor CSS Styling

1.remote-cursor {
2 position: fixed;
3 top: 0;
4 left: 0;
5 pointer-events: none; /* Crucial: Cursor does not block clicks underneath! */
6 z-index: 99999;
7 transition: transform 0.05s linear;
8}
9 
10.remote-cursor svg {
11 color: #3b82f6;
12 filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
13}
14 
15.peer-label {
16 background: #1e293b;
17 color: white;
18 padding: 2px 6px;
19 border-radius: 4px;
20 font-size: 10px;
21 margin-left: 10px;
22 font-family: sans-serif;
23}

4. Conflict Resolution Concepts (CRDTs & OT)

When two users modify the same dashboard card at the same millisecond, simple overwriting causes data loss. Production collaborative engines use:

  • Operational Transformation (OT): Used in Google Docs; transforms operations based on concurrent revision histories.
  • Conflict-Free Replicated Data Types (CRDTs): Used in Figma and Yjs; mathematical data structures that converge deterministically on all clients without a central coordinator.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why should pointer movement events be throttled (e.g. to 50ms) before broadcasting over WebSockets?
Question 2
Why is pointer-events: none essential on remote cursor DOM elements?
Question 3
What mathematical data structure family converges deterministically across all peers without central locking?
Question 4
How are remote cursor position coordinates updated with maximum 60 FPS performance?
Question 5
Why is checking (message.clientId === this.clientId) necessary when processing incoming WebSocket broadcasts?
Next Lesson

Offline-First Sync with IndexedDB & Service Worker

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Architecture & State Store Design (Store Pattern)Offline-First Sync with IndexedDB & Service Worker

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext