diff --git a/README.md b/README.md index 367f03e..cedb201 100644 --- a/README.md +++ b/README.md @@ -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 } ``` diff --git a/packages/client/src/withSocketIO.ts b/packages/client/src/withSocketIO.ts index e06dc80..03c861a 100644 --- a/packages/client/src/withSocketIO.ts +++ b/packages/client/src/withSocketIO.ts @@ -11,6 +11,8 @@ export interface SocketIOPluginOptions { onConnect?: () => void onDisconnect?: () => void + + onError?: (msg: string) => void } export interface WithSocketIOEditor { @@ -35,7 +37,14 @@ const withSocketIO = ( ) => { 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 = ( }) } + e.socket.on('error', (msg: string) => { + onError && onError(msg) + }) + e.socket.on('msg', (data: CollabAction) => { e.receive(data) })