mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
feat: add onError cb (#15)
This commit is contained in:
parent
e26d62f78d
commit
d76c7766cc
@ -30,6 +30,7 @@ Check [detailed example](https://github.com/cudr/slate-collaborative/blob/master
|
||||
cursorData?: any // any data passed to cursor
|
||||
onConnect?: () => void // connect callback
|
||||
onDisconnect?: () => void // disconnect callback
|
||||
onError?: (reason: string) => void // error callback
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -11,6 +11,8 @@ export interface SocketIOPluginOptions {
|
||||
|
||||
onConnect?: () => void
|
||||
onDisconnect?: () => void
|
||||
|
||||
onError?: (msg: string) => void
|
||||
}
|
||||
|
||||
export interface WithSocketIOEditor {
|
||||
@ -35,7 +37,14 @@ const withSocketIO = <T extends AutomergeEditor>(
|
||||
) => {
|
||||
const e = editor as T & WithSocketIOEditor
|
||||
|
||||
const { onConnect, onDisconnect, connectOpts, url, autoConnect } = options
|
||||
const {
|
||||
onConnect,
|
||||
onDisconnect,
|
||||
onError,
|
||||
connectOpts,
|
||||
url,
|
||||
autoConnect
|
||||
} = options
|
||||
|
||||
/**
|
||||
* Connect to Socket.
|
||||
@ -54,6 +63,10 @@ const withSocketIO = <T extends AutomergeEditor>(
|
||||
})
|
||||
}
|
||||
|
||||
e.socket.on('error', (msg: string) => {
|
||||
onError && onError(msg)
|
||||
})
|
||||
|
||||
e.socket.on('msg', (data: CollabAction) => {
|
||||
e.receive(data)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user