@@ -2,11 +2,11 @@ import type { LanguageName } from '@uiw/codemirror-extensions-langs';
2
2
import type { Extension , ReactCodeMirrorRef } from '@uiw/react-codemirror' ;
3
3
import { useEffect , useMemo , useRef , useState } from 'react' ;
4
4
import { yCollab } from 'y-codemirror.next' ;
5
- import { SocketIOProvider } from 'y-socket.io ' ;
5
+ import { WebsocketProvider } from 'y-websocket ' ;
6
6
import * as Y from 'yjs' ;
7
7
8
8
import { extensions as baseExtensions , getLanguage } from '@/lib/editor/extensions' ;
9
- import { COLLAB_SERVICE } from '@/services/api-clients' ;
9
+ import { COLLAB_WS } from '@/services/api-clients' ;
10
10
11
11
// credit: https://github.com/yjs/y-websocket
12
12
const usercolors = [
@@ -39,7 +39,7 @@ export const useCollab = (roomId: string) => {
39
39
const doc = new Y . Doc ( ) ;
40
40
let provider = null ;
41
41
try {
42
- provider = new SocketIOProvider ( COLLAB_SERVICE , roomId , doc , { } ) ;
42
+ provider = new WebsocketProvider ( COLLAB_WS , roomId , doc ) ;
43
43
} catch ( err ) {
44
44
const { name, message } = err as Error ;
45
45
console . error (
@@ -50,9 +50,20 @@ export const useCollab = (roomId: string) => {
50
50
const ytext = doc . getText ( 'codemirror' ) ;
51
51
const undoManager = new Y . UndoManager ( ytext ) ;
52
52
const awareness = provider . awareness ;
53
- const { color, light } = getRandomColor ( ) ;
54
53
54
+ provider . on ( 'status' , ( event : unknown ) => {
55
+ const ev = event as { status ?: string } | undefined ;
56
+ console . log ( `Connection Status: ${ ev ?. status } ` ) ;
57
+ } ) ;
58
+
59
+ // TODO: Update state store, then display avatars
60
+ awareness . on ( 'update' , ( ) => {
61
+ console . log ( awareness . getStates ( ) . values ( ) ) ; // Array of name, color, light
62
+ } ) ;
63
+
64
+ const { color, light } = getRandomColor ( ) ;
55
65
// TODO: Get user name
66
+ // TODO: Set user ID
56
67
awareness . setLocalStateField ( 'user' , {
57
68
name : `Anon` ,
58
69
color : color ,
0 commit comments