fix: try reducing number of connections

This commit is contained in:
Eric Maciel 2020-10-30 15:58:50 -04:00
parent f231ab4f01
commit 34db64edaf
2 changed files with 7 additions and 21 deletions

View File

@ -45,8 +45,6 @@ const withAutomerge = <T extends Editor>(
e.connection.open() e.connection.open()
} }
createConnection()
/** /**
* Open Automerge Connection * Open Automerge Connection
*/ */

View File

@ -7,7 +7,6 @@ import { CollabAction } from '@hiveteams/collab-bridge'
export interface SocketIOPluginOptions { export interface SocketIOPluginOptions {
url: string url: string
connectOpts: SocketIOClient.ConnectOpts connectOpts: SocketIOClient.ConnectOpts
autoConnect?: boolean
onConnect?: () => void onConnect?: () => void
onDisconnect?: () => void onDisconnect?: () => void
@ -38,21 +37,13 @@ const withSocketIO = <T extends AutomergeEditor>(
const e = editor as T & WithSocketIOEditor const e = editor as T & WithSocketIOEditor
let socket: SocketIOClient.Socket let socket: SocketIOClient.Socket
const { const { onConnect, onDisconnect, onError, connectOpts, url } = options
onConnect,
onDisconnect,
onError,
connectOpts,
url,
autoConnect
} = options
/** /**
* Connect to Socket. * Connect to Socket.
*/ */
e.connect = () => { e.connect = () => {
if (!socket) {
socket = io(url, { ...connectOpts }) socket = io(url, { ...connectOpts })
socket.on('connect', () => { socket.on('connect', () => {
@ -62,7 +53,6 @@ const withSocketIO = <T extends AutomergeEditor>(
onConnect && onConnect() onConnect && onConnect()
}) })
}
socket.on('error', (msg: string) => { socket.on('error', (msg: string) => {
onError && onError(msg) onError && onError(msg)
@ -127,8 +117,6 @@ const withSocketIO = <T extends AutomergeEditor>(
e.closeConnection() e.closeConnection()
} }
autoConnect && e.connect()
return e return e
} }