@@ -84,10 +84,10 @@ const decodeRedisRoomStreamName = (rediskey, expectedPrefix) => {
84
84
85
85
/**
86
86
* @param {import('./storage.js').AbstractStorage } store
87
- * @param {{ redisPrefix?: string, redisUrl?: string } } opts
87
+ * @param {{ redisPrefix?: string, redisUrl?: string, enableAwareness?: boolean } } opts
88
88
*/
89
- export const createApiClient = async ( store , { redisPrefix, redisUrl } ) => {
90
- const a = new Api ( store , redisPrefix , redisUrl )
89
+ export const createApiClient = async ( store , { redisPrefix, redisUrl, enableAwareness = true } ) => {
90
+ const a = new Api ( store , redisPrefix , redisUrl , { enableAwareness } )
91
91
await a . redis . connect ( )
92
92
try {
93
93
await a . redis . xGroupCreate ( a . redisWorkerStreamName , a . redisWorkerGroupName , '0' , { MKSTREAM : true } )
@@ -100,10 +100,13 @@ export class Api {
100
100
* @param {import('./storage.js').AbstractStorage } store
101
101
* @param {string= } prefix
102
102
* @param {string= } url
103
+ * @param {Object } opts
104
+ * @param {boolean= } opts.enableAwareness
103
105
*/
104
- constructor ( store , prefix = 'y' , url = env . ensureConf ( 'ysr-redis' ) ) {
106
+ constructor ( store , prefix = 'y' , url = env . ensureConf ( 'ysr-redis' ) , { enableAwareness = true } = { } ) {
105
107
this . store = store
106
108
this . prefix = prefix
109
+ this . enableAwareness = enableAwareness
107
110
this . consumername = random . uuidv4 ( )
108
111
/**
109
112
* After this timeout, a new worker will pick up the task
@@ -240,8 +243,11 @@ export class Api {
240
243
if ( docMessages ?. messages ) logApi ( `processing messages of length: ${ docMessages ?. messages . length } in room: ${ room } ` )
241
244
const docstate = await this . store . retrieveDoc ( room , docid )
242
245
const ydoc = new Y . Doc ( )
243
- const awareness = new awarenessProtocol . Awareness ( ydoc )
244
- awareness . setLocalState ( null ) // we don't want to propagate awareness state
246
+ let awareness = null
247
+ if ( this . enableAwareness ) {
248
+ awareness = new awarenessProtocol . Awareness ( ydoc )
249
+ awareness . setLocalState ( null ) // we don't want to propagate awareness state
250
+ }
245
251
const now = performance . now ( )
246
252
if ( docstate ) { Y . applyUpdateV2 ( ydoc , docstate . doc ) }
247
253
let changed = false
@@ -257,7 +263,9 @@ export class Api {
257
263
break
258
264
}
259
265
case 1 : { // awareness message
260
- awarenessProtocol . applyAwarenessUpdate ( awareness , decoding . readVarUint8Array ( decoder ) , null )
266
+ if ( this . enableAwareness && awareness ) {
267
+ awarenessProtocol . applyAwarenessUpdate ( awareness , decoding . readVarUint8Array ( decoder ) , null )
268
+ }
261
269
break
262
270
}
263
271
}
@@ -394,7 +402,7 @@ export class Api {
394
402
395
403
/**
396
404
* @param {import('./storage.js').AbstractStorage } store
397
- * @param {{ redisPrefix?: string, redisUrl?: string } } opts
405
+ * @param {{ redisPrefix?: string, redisUrl?: string, enableAwareness?: boolean } } opts
398
406
*/
399
407
export const createWorker = async ( store , opts ) => {
400
408
const a = await createApiClient ( store , opts )
0 commit comments