7
7
8
8
// TODO: support reconnects with same id
9
9
10
- // TODO: We keep getting:
11
- // connection to 'ws...' failed: Invalid frame header
12
-
13
- import WebSocket from 'reconnecting-websocket' ;
10
+ import { WebSocket } from 'partysocket' ;
14
11
import Logdown from 'logdown' ;
15
12
import sharedb from 'sharedb/lib/sharedb' ;
16
13
import type {
@@ -155,7 +152,7 @@ class SharedbAceBinding {
155
152
// this.radarManager.removeView();
156
153
this . initializeLocalPresence ( ) ;
157
154
for ( const [ id , update ] of Object . entries ( this . usersPresence . remotePresences ) ) {
158
- this . initializeRemotePresence ( id , update ) ;
155
+ this . updatePresence ( id , update ) ;
159
156
}
160
157
} ;
161
158
@@ -164,12 +161,13 @@ class SharedbAceBinding {
164
161
*/
165
162
listen = ( ) => {
166
163
// TODO: Also update view on window resize
164
+ // TODO: Clicking on radar indicator is not exactly accurate
167
165
this . session . on ( 'change' , this . onLocalChange ) ;
168
166
this . session . on ( 'changeScrollTop' , this . onLocalChangeScrollTop ) ;
169
167
this . doc . on ( 'op' , this . onRemoteChange ) ;
170
168
this . doc . on ( 'load' , this . onRemoteReload ) ;
171
169
172
- this . usersPresence . on ( 'receive' , this . onPresenceUpdate ) ;
170
+ this . usersPresence . on ( 'receive' , this . updatePresence ) ;
173
171
this . session . selection . on ( 'changeCursor' , this . onLocalCursorChange ) ;
174
172
this . session . selection . on ( 'changeSelection' , this . onLocalSelectionChange ) ;
175
173
} ;
@@ -183,7 +181,7 @@ class SharedbAceBinding {
183
181
this . doc . off ( 'op' , this . onRemoteChange ) ;
184
182
this . doc . off ( 'load' , this . onRemoteReload ) ;
185
183
186
- this . usersPresence . off ( 'receive' , this . onPresenceUpdate ) ;
184
+ this . usersPresence . off ( 'receive' , this . updatePresence ) ;
187
185
this . session . selection . off ( 'changeCursor' , this . onLocalCursorChange ) ;
188
186
this . session . selection . off ( 'changeSelection' , this . onLocalSelectionChange ) ;
189
187
} ;
@@ -347,7 +345,7 @@ class SharedbAceBinding {
347
345
}
348
346
} ;
349
347
350
- onPresenceUpdate = ( id : string , update : PresenceUpdate ) => {
348
+ updatePresence = ( id : string , update : PresenceUpdate ) => {
351
349
// TODO: logger and error handling
352
350
// TODO: separate into multiple handlers
353
351
if ( update === null ) {
@@ -387,19 +385,19 @@ class SharedbAceBinding {
387
385
}
388
386
389
387
if ( update . radarViewRows ) {
390
- const intialRows = AceViewportUtil . indicesToRows (
388
+ const rows = AceViewportUtil . indicesToRows (
391
389
this . editor ,
392
390
update . radarViewRows . start ,
393
391
update . radarViewRows . end
394
392
) ;
395
393
try {
396
- this . radarManager . setViewRows ( id , intialRows ) ;
394
+ this . radarManager . setViewRows ( id , rows ) ;
397
395
} catch {
398
396
this . radarManager . addView (
399
397
id ,
400
398
update . user . name ,
401
399
update . user . color ,
402
- intialRows ,
400
+ rows ,
403
401
update . radarCursorRow || 0
404
402
) ;
405
403
}
@@ -451,47 +449,6 @@ class SharedbAceBinding {
451
449
} ) ;
452
450
} ;
453
451
454
- // TODO: Actually the same as onPresenceUpdate
455
- initializeRemotePresence = ( id : string , update : PresenceUpdate ) => {
456
- if ( update . cursorPos ) {
457
- try {
458
- this . cursorManager . setCursor ( id , update . cursorPos ) ;
459
- } catch {
460
- this . cursorManager . addCursor ( id , update . user . name , update . user . color , update . cursorPos ) ;
461
- }
462
- }
463
-
464
- if ( update . selectionRange ) {
465
- const ranges = AceRangeUtil . fromJson ( update . selectionRange ) ;
466
- try {
467
- this . selectionManager . setSelection ( id , ranges ) ;
468
- } catch {
469
- this . selectionManager . addSelection ( id , update . user . name , update . user . color , ranges ) ;
470
- }
471
- }
472
-
473
- if ( update . radarViewRows ) {
474
- const rows = AceViewportUtil . indicesToRows (
475
- this . editor ,
476
- update . radarViewRows . start ,
477
- update . radarViewRows . end
478
- ) ;
479
-
480
- try {
481
- this . radarManager . setViewRows ( id , rows ) ;
482
- this . radarManager . setCursorRow ( id , update . radarCursorRow || 0 ) ;
483
- } catch {
484
- this . radarManager . addView (
485
- id ,
486
- update . user . name ,
487
- update . user . color ,
488
- rows ,
489
- update . radarCursorRow || 0
490
- ) ;
491
- }
492
- }
493
- } ;
494
-
495
452
destroyPresence = ( ) => {
496
453
// TODO: logger and error handling
497
454
this . localPresence ?. destroy ( ) ;
0 commit comments