Skip to content

Commit 2ca9f19

Browse files
committed
feat: allow supply socket client to provider
1 parent ded3f1d commit 2ca9f19

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/y-socket-io/client.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)