File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ import { io } from 'socket.io-client'
3737 *
3838 * @prop {Record<string, unknown>= } auth
3939 * (Optional) Add the authentication data
40+ *
41+ * @prop {ClientSocket= } socket
42+ * (Optional) Supply custom socket.io client socket. If supplied, `socketIoOptions` will be ignored.
4043 */
4144
4245/**
@@ -138,7 +141,8 @@ export class SocketIOProvider extends Observable {
138141 awareness = enableAwareness ? new AwarenessProtocol . Awareness ( doc ) : undefined ,
139142 resyncInterval = - 1 ,
140143 disableBc = false ,
141- auth = { }
144+ auth = { } ,
145+ socket,
142146 } = { } ,
143147 socketIoOptions = undefined
144148 ) {
@@ -157,13 +161,17 @@ export class SocketIOProvider extends Observable {
157161 this . disableBc = disableBc
158162 this . _socketIoOptions = socketIoOptions
159163
160- this . socket = io ( `${ this . url } /yjs|${ roomName } ` , {
161- autoConnect : false ,
162- transports : [ 'websocket' ] ,
163- forceNew : true ,
164- auth,
165- ...socketIoOptions
166- } )
164+ if ( socket ) {
165+ this . socket = socket
166+ } else {
167+ this . socket = io ( `${ this . url } /yjs|${ roomName } ` , {
168+ autoConnect : false ,
169+ transports : [ 'websocket' ] ,
170+ forceNew : true ,
171+ auth,
172+ ...socketIoOptions
173+ } )
174+ }
167175 this . _socketIoOptions = socketIoOptions
168176
169177 this . doc . on ( 'update' , this . onUpdateDoc )
You can’t perform that action at this time.
0 commit comments