@@ -83,10 +83,10 @@ const decodeRedisRoomStreamName = (rediskey, expectedPrefix) => {
83
83
84
84
/**
85
85
* @param {import('./storage.js').AbstractStorage } store
86
- * @param {{ redisPrefix?: string, redisUrl?: string } } opts
86
+ * @param {{ redisPrefix?: string, redisUrl?: string, enableAwareness?: boolean } } opts
87
87
*/
88
- export const createApiClient = async ( store , { redisPrefix, redisUrl } ) => {
89
- const a = new Api ( store , redisPrefix , redisUrl )
88
+ export const createApiClient = async ( store , { redisPrefix, redisUrl, enableAwareness = true } ) => {
89
+ const a = new Api ( store , redisPrefix , redisUrl , { enableAwareness } )
90
90
await a . redis . connect ( )
91
91
try {
92
92
await a . redis . xGroupCreate ( a . redisWorkerStreamName , a . redisWorkerGroupName , '0' , { MKSTREAM : true } )
@@ -99,10 +99,13 @@ export class Api {
99
99
* @param {import('./storage.js').AbstractStorage } store
100
100
* @param {string= } prefix
101
101
* @param {string= } url
102
+ * @param {Object } opts
103
+ * @param {boolean= } opts.enableAwareness
102
104
*/
103
- constructor ( store , prefix = 'y' , url = env . ensureConf ( 'ysr-redis' ) ) {
105
+ constructor ( store , prefix = 'y' , url = env . ensureConf ( 'ysr-redis' ) , { enableAwareness = true } = { } ) {
104
106
this . store = store
105
107
this . prefix = prefix
108
+ this . enableAwareness = enableAwareness
106
109
this . consumername = random . uuidv4 ( )
107
110
/**
108
111
* After this timeout, a new worker will pick up the task
@@ -232,8 +235,11 @@ export class Api {
232
235
if ( docMessages ?. messages ) logApi ( `processing messages of length: ${ docMessages ?. messages . length } in room: ${ room } ` )
233
236
const docstate = await this . store . retrieveDoc ( room , docid )
234
237
const ydoc = new Y . Doc ( )
235
- const awareness = new awarenessProtocol . Awareness ( ydoc )
236
- awareness . setLocalState ( null ) // we don't want to propagate awareness state
238
+ let awareness = null
239
+ if ( this . enableAwareness ) {
240
+ awareness = new awarenessProtocol . Awareness ( ydoc )
241
+ awareness . setLocalState ( null ) // we don't want to propagate awareness state
242
+ }
237
243
const now = performance . now ( )
238
244
if ( docstate ) { Y . applyUpdateV2 ( ydoc , docstate . doc ) }
239
245
let changed = false
@@ -249,7 +255,9 @@ export class Api {
249
255
break
250
256
}
251
257
case 1 : { // awareness message
252
- awarenessProtocol . applyAwarenessUpdate ( awareness , decoding . readVarUint8Array ( decoder ) , null )
258
+ if ( this . enableAwareness && awareness ) {
259
+ awarenessProtocol . applyAwarenessUpdate ( awareness , decoding . readVarUint8Array ( decoder ) , null )
260
+ }
253
261
break
254
262
}
255
263
}
@@ -355,7 +363,7 @@ export class Api {
355
363
356
364
/**
357
365
* @param {import('./storage.js').AbstractStorage } store
358
- * @param {{ redisPrefix?: string, redisUrl?: string } } opts
366
+ * @param {{ redisPrefix?: string, redisUrl?: string, enableAwareness?: boolean } } opts
359
367
*/
360
368
export const createWorker = async ( store , opts ) => {
361
369
const a = await createApiClient ( store , opts )
0 commit comments