Skip to content

Commit edd2151

Browse files
deps: use modern websocket implementation
1 parent b929d3c commit edd2151

File tree

5 files changed

+24
-60
lines changed

5 files changed

+24
-60
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@convergencelabs/ace-collab-ext": "^0.6.0",
4747
"event-emitter-es6": "^1.1.5",
4848
"logdown": "^3.3.1",
49-
"reconnecting-websocket": "^4.4.0",
49+
"partysocket": "^1.0.3",
5050
"sharedb": "^5.1.1"
5151
}
5252
}

source/sharedb-ace-binding.ts

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
// TODO: support reconnects with same id
99

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';
1411
import Logdown from 'logdown';
1512
import sharedb from 'sharedb/lib/sharedb';
1613
import type {
@@ -155,7 +152,7 @@ class SharedbAceBinding {
155152
// this.radarManager.removeView();
156153
this.initializeLocalPresence();
157154
for (const [id, update] of Object.entries(this.usersPresence.remotePresences)) {
158-
this.initializeRemotePresence(id, update);
155+
this.updatePresence(id, update);
159156
}
160157
};
161158

@@ -164,12 +161,13 @@ class SharedbAceBinding {
164161
*/
165162
listen = () => {
166163
// TODO: Also update view on window resize
164+
// TODO: Clicking on radar indicator is not exactly accurate
167165
this.session.on('change', this.onLocalChange);
168166
this.session.on('changeScrollTop', this.onLocalChangeScrollTop);
169167
this.doc.on('op', this.onRemoteChange);
170168
this.doc.on('load', this.onRemoteReload);
171169

172-
this.usersPresence.on('receive', this.onPresenceUpdate);
170+
this.usersPresence.on('receive', this.updatePresence);
173171
this.session.selection.on('changeCursor', this.onLocalCursorChange);
174172
this.session.selection.on('changeSelection', this.onLocalSelectionChange);
175173
};
@@ -183,7 +181,7 @@ class SharedbAceBinding {
183181
this.doc.off('op', this.onRemoteChange);
184182
this.doc.off('load', this.onRemoteReload);
185183

186-
this.usersPresence.off('receive', this.onPresenceUpdate);
184+
this.usersPresence.off('receive', this.updatePresence);
187185
this.session.selection.off('changeCursor', this.onLocalCursorChange);
188186
this.session.selection.off('changeSelection', this.onLocalSelectionChange);
189187
};
@@ -347,7 +345,7 @@ class SharedbAceBinding {
347345
}
348346
};
349347

350-
onPresenceUpdate = (id: string, update: PresenceUpdate) => {
348+
updatePresence = (id: string, update: PresenceUpdate) => {
351349
// TODO: logger and error handling
352350
// TODO: separate into multiple handlers
353351
if (update === null) {
@@ -387,19 +385,19 @@ class SharedbAceBinding {
387385
}
388386

389387
if (update.radarViewRows) {
390-
const intialRows = AceViewportUtil.indicesToRows(
388+
const rows = AceViewportUtil.indicesToRows(
391389
this.editor,
392390
update.radarViewRows.start,
393391
update.radarViewRows.end
394392
);
395393
try {
396-
this.radarManager.setViewRows(id, intialRows);
394+
this.radarManager.setViewRows(id, rows);
397395
} catch {
398396
this.radarManager.addView(
399397
id,
400398
update.user.name,
401399
update.user.color,
402-
intialRows,
400+
rows,
403401
update.radarCursorRow || 0
404402
);
405403
}
@@ -451,47 +449,6 @@ class SharedbAceBinding {
451449
});
452450
};
453451

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-
495452
destroyPresence = () => {
496453
// TODO: logger and error handling
497454
this.localPresence?.destroy();

source/sharedb-ace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @license MIT
66
*/
77

8-
import WebSocket from 'reconnecting-websocket';
8+
import { WebSocket } from 'partysocket';
99
import EventEmitter from 'event-emitter-es6';
1010
import type sharedb from 'sharedb/lib/sharedb';
1111
import { Connection as sharedbConnection } from 'sharedb/lib/client';

source/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type WebSocket from 'reconnecting-websocket';
1+
import type { WebSocket } from 'partysocket';
22

33
export interface SharedbAceUser {
44
id: string;

yarn.lock

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,11 @@ event-emitter-es6@^1.1.5:
21612161
resolved "https://registry.yarnpkg.com/event-emitter-es6/-/event-emitter-es6-1.1.5.tgz#ef95311b2e17aa39be763b031ce4af7ee9cb7849"
21622162
integrity sha1-75UxGy4Xqjm+djsDHOSvfunLeEk=
21632163

2164+
event-target-shim@^6.0.2:
2165+
version "6.0.2"
2166+
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-6.0.2.tgz#ea5348c3618ee8b62ff1d344f01908ee2b8a2b71"
2167+
integrity sha512-8q3LsZjRezbFZ2PN+uP+Q7pnHUMmAOziU2vA2OwoFaKIXxlxl38IylhSSgUorWu/rf4er67w0ikBqjBFk/pomA==
2168+
21642169
events@^3.2.0:
21652170
version "3.3.0"
21662171
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
@@ -3398,6 +3403,13 @@ parse5@6.0.1:
33983403
resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"
33993404
integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==
34003405

3406+
partysocket@^1.0.3:
3407+
version "1.0.3"
3408+
resolved "https://registry.yarnpkg.com/partysocket/-/partysocket-1.0.3.tgz#58cf1494d44900a7377592683d171fddd3d9c543"
3409+
integrity sha512-7sSojS4oCRK1Fe1h+Sa0Za5dwOf+M9VksQlynD8yqwGpLvnO4oxx9ppmOSeh6CJTMbF5gbnvUQKMK525QSBdBw==
3410+
dependencies:
3411+
event-target-shim "^6.0.2"
3412+
34013413
path-exists@^3.0.0:
34023414
version "3.0.0"
34033415
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
@@ -3576,11 +3588,6 @@ rechoir@^0.8.0:
35763588
dependencies:
35773589
resolve "^1.20.0"
35783590

3579-
reconnecting-websocket@^4.4.0:
3580-
version "4.4.0"
3581-
resolved "https://registry.yarnpkg.com/reconnecting-websocket/-/reconnecting-websocket-4.4.0.tgz#3b0e5b96ef119e78a03135865b8bb0af1b948783"
3582-
integrity sha512-D2E33ceRPga0NvTDhJmphEgJ7FUYF0v4lr1ki0csq06OdlxKfugGzN0dSkxM/NfqCxYELK4KcaTOUOjTV6Dcng==
3583-
35843591
reflect.getprototypeof@^1.0.6, reflect.getprototypeof@^1.0.9:
35853592
version "1.0.10"
35863593
resolved "https://registry.yarnpkg.com/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz#c629219e78a3316d8b604c765ef68996964e7bf9"

0 commit comments

Comments
 (0)