Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(sync): Allow to pass disableBc to createSyncServiceProvider()
This is required for Cypress tests where we want the broadcast channel
synchronization to be disabled.

If not passed, default to `true` in debug mode and `false` otherwise.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Jul 11, 2023
commit f0396923a4ed15ec104d7e9533ac3a053cea725b
1 change: 1 addition & 0 deletions cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('Sync service provider', function() {
syncService,
fileId,
initialSession: null,
disableBc: true,
})
}

Expand Down
6 changes: 4 additions & 2 deletions src/services/SyncServiceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ import { logger } from '../helpers/logger.js'
* @param {object} options.syncService - sync service to build upon
* @param {number} options.fileId - file id of the file to open
* @param {object} options.initialSession - initialSession to start from
* @param {boolean} options.disableBc - disable broadcast channel synchronization (default: disabled in debug mode, enabled otherwise)
*/
export default function createSyncServiceProvider({ ydoc, syncService, fileId, initialSession }) {
export default function createSyncServiceProvider({ ydoc, syncService, fileId, initialSession, disableBc }) {
if (!fileId) {
// We need a file id as a unique identifier for y.js as otherwise state might leak between different files
throw new Error('fileId is required')
}
const WebSocketPolyfill = initWebSocketPolyfill(syncService, fileId, initialSession)
disableBc = disableBc ?? !!window?._oc_debug
const websocketProvider = new WebsocketProvider(
'ws://localhost:1234',
'file:' + fileId,
ydoc,
{ WebSocketPolyfill, disableBc: true },
{ WebSocketPolyfill, disableBc },
)
websocketProvider.on('status', event => logger.debug('status', event))
return websocketProvider
Expand Down