@@ -31,15 +31,16 @@ function Canvas(props: {}): JSX.Element {
31
31
//remote cursor data
32
32
const [ remoteCursors , setRemoteCursors ] = useState ( [ ] ) ;
33
33
34
- // toggle switch
34
+ // Toggle switch for live cursor tracking
35
35
const [ toggleSwitch , setToggleSwitch ] = useState ( true ) ;
36
36
37
- // toggle text
37
+ // Toggle button text for live cursor tracking button - on/off
38
38
const [ toggleText , setToggleText ] = useState ( 'off' ) ;
39
39
const toggleButton = ( ) => {
40
40
setToggleText ( toggleText === 'on' ? 'off' : 'on' ) ;
41
41
} ;
42
42
43
+ // Prevents lagging and provides smoother user experience got live cursor tracking (milliseconds can be adjusted but 300ms is most optimal)
43
44
const debounceSetPosition = debounce ( ( newX , newY ) => {
44
45
//emit socket event every 300ms when cursor moves
45
46
if ( userList . length > 1 )
@@ -91,10 +92,11 @@ function Canvas(props: {}): JSX.Element {
91
92
} ) ;
92
93
} ;
93
94
94
- console . log ( 'userList:' , userList ) ;
95
+ // console.log('userList:', userList);
95
96
//[{x,y,remoteUserName, isVisible}, {...}, {...}]
96
- console . log ( 'remoteCursors:' , remoteCursors ) ;
97
+ // console.log('remoteCursors:', remoteCursors);
97
98
99
+ // Removes the mouse cursor of the user that leaves the collaboration room.
98
100
const handleCursorDeleteFromServer = ( ) => {
99
101
setRemoteCursors ( ( prevRemoteCursors ) =>
100
102
prevRemoteCursors . map ( ( cursor ) => ( {
@@ -104,6 +106,7 @@ function Canvas(props: {}): JSX.Element {
104
106
) ;
105
107
} ;
106
108
109
+ // Function that will turn on/off socket depending on toggle Switch.
107
110
const handleToggleSwitch = ( ) => {
108
111
setToggleSwitch ( ! toggleSwitch ) ;
109
112
//checks the state before it's updated so need to check the opposite condition
@@ -133,9 +136,7 @@ function Canvas(props: {}): JSX.Element {
133
136
}
134
137
} ;
135
138
136
- console . log ( 'Toggle Switch:' , toggleSwitch ) ;
137
-
138
- //Function to handle the click events.
139
+ //Function to handle the multiple click events of the toggle button.
139
140
const multipleClicks = ( ) => {
140
141
handleToggleSwitch ( ) ;
141
142
toggleButton ( ) ;
@@ -192,7 +193,6 @@ function Canvas(props: {}): JSX.Element {
192
193
childId : childId
193
194
} ) ;
194
195
}
195
- // console.log('emit changeFocusAction event is triggered in canvas');
196
196
} ;
197
197
198
198
// onClickHandler is responsible for changing the focused component and child component
@@ -325,6 +325,7 @@ function Canvas(props: {}): JSX.Element {
325
325
currentComponent . style
326
326
) ;
327
327
328
+ // Array of colors that color code users as they join the room (In a set order)
328
329
const userColors = [
329
330
'#FC00BD' ,
330
331
'#D0FC00' ,
@@ -365,7 +366,6 @@ function Canvas(props: {}): JSX.Element {
365
366
</ div >
366
367
)
367
368
) }
368
-
369
369
< label className = "switch" >
370
370
{ userList . length > 1 && (
371
371
< button
0 commit comments