Skip to content

Commit d76c776

Browse files
authored
feat: add onError cb (cudr#15)
1 parent e26d62f commit d76c776

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Check [detailed example](https://github.com/cudr/slate-collaborative/blob/master
3030
cursorData?: any // any data passed to cursor
3131
onConnect?: () => void // connect callback
3232
onDisconnect?: () => void // disconnect callback
33+
onError?: (reason: string) => void // error callback
3334
}
3435
```
3536

packages/client/src/withSocketIO.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export interface SocketIOPluginOptions {
1111

1212
onConnect?: () => void
1313
onDisconnect?: () => void
14+
15+
onError?: (msg: string) => void
1416
}
1517

1618
export interface WithSocketIOEditor {
@@ -35,7 +37,14 @@ const withSocketIO = <T extends AutomergeEditor>(
3537
) => {
3638
const e = editor as T & WithSocketIOEditor
3739

38-
const { onConnect, onDisconnect, connectOpts, url, autoConnect } = options
40+
const {
41+
onConnect,
42+
onDisconnect,
43+
onError,
44+
connectOpts,
45+
url,
46+
autoConnect
47+
} = options
3948

4049
/**
4150
* Connect to Socket.
@@ -54,6 +63,10 @@ const withSocketIO = <T extends AutomergeEditor>(
5463
})
5564
}
5665

66+
e.socket.on('error', (msg: string) => {
67+
onError && onError(msg)
68+
})
69+
5770
e.socket.on('msg', (data: CollabAction) => {
5871
e.receive(data)
5972
})

0 commit comments

Comments
 (0)