Skip to content

Commit

Permalink
add option to specify protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Jul 15, 2024
1 parent 630e08e commit 2c3c71e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/y-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const readMessage = (provider, buf, emitSynced) => {
*/
const setupWS = (provider) => {
if (provider.shouldConnect && provider.ws === null) {
const websocket = new provider._WS(provider.url)
const websocket = new provider._WS(provider.url, provider.protocols)
websocket.binaryType = 'arraybuffer'
provider.ws = websocket
provider.wsconnecting = true
Expand Down Expand Up @@ -246,6 +246,7 @@ export class WebsocketProvider extends Observable {
* @param {boolean} [opts.connect]
* @param {awarenessProtocol.Awareness} [opts.awareness]
* @param {Object<string,string>} [opts.params] specify url parameters
* @param {Array<string>} [opts.protocols] specify websocket protocols
* @param {typeof WebSocket} [opts.WebSocketPolyfill] Optionall provide a WebSocket polyfill
* @param {number} [opts.resyncInterval] Request server state every `resyncInterval` milliseconds
* @param {number} [opts.maxBackoffTime] Maximum amount of time to wait before trying to reconnect (we try to reconnect using exponential backoff)
Expand All @@ -255,6 +256,7 @@ export class WebsocketProvider extends Observable {
connect = true,
awareness = new awarenessProtocol.Awareness(doc),
params = {},
protocols = [],
WebSocketPolyfill = WebSocket,
resyncInterval = -1,
maxBackoffTime = 2500,
Expand All @@ -274,6 +276,7 @@ export class WebsocketProvider extends Observable {
* @type {Object<string,string>}
*/
this.params = params
this.protocols = protocols
this.roomname = roomname
this.doc = doc
this._WS = WebSocketPolyfill
Expand Down

0 comments on commit 2c3c71e

Please sign in to comment.