SyncAccumulator
Defined in: src/sync-accumulator.ts:265
The purpose of this class is to accumulate /sync responses such that a complete “initial” JSON response can be returned which accurately represents the sum total of the /sync responses accumulated to date. It only handles room data: that is, everything under the “rooms” top-level key.
This class is used when persisting room data so a complete /sync response can be loaded from disk and incremental syncs can be performed on the server, rather than asking the server to do an initial sync on startup.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SyncAccumulator(
opts?):SyncAccumulator
Defined in: src/sync-accumulator.ts:276
Parameters
Section titled “Parameters”IOpts = {}
Returns
Section titled “Returns”SyncAccumulator
Methods
Section titled “Methods”accumulate()
Section titled “accumulate()”accumulate(
syncResponse,fromDatabase?):void
Defined in: src/sync-accumulator.ts:280
Parameters
Section titled “Parameters”syncResponse
Section titled “syncResponse”fromDatabase?
Section titled “fromDatabase?”boolean = false
Returns
Section titled “Returns”void
getJSON()
Section titled “getJSON()”getJSON(
forDatabase?):ISyncData
Defined in: src/sync-accumulator.ts:632
Return everything under the ‘rooms’ key from a /sync response which represents all room data that should be stored. This should be paired with the sync token which represents the most recent /sync response provided to accumulate().
Parameters
Section titled “Parameters”forDatabase?
Section titled “forDatabase?”boolean = false
True to generate a sync to be saved to storage
Returns
Section titled “Returns”An object with a “nextBatch”, “roomsData” and “accountData” keys. The “nextBatch” key is a string which represents at what point in the /sync stream the accumulator reached. This token should be used when restarting a /sync stream at startup. Failure to do so can lead to missing events. The “roomsData” key is an Object which represents the entire /sync response from the ‘rooms’ key onwards. The “accountData” key is a list of raw events which represent global account data.
getNextBatchToken()
Section titled “getNextBatchToken()”getNextBatchToken():
string
Defined in: src/sync-accumulator.ts:781
Returns
Section titled “Returns”string
removeEventsFromRoom()
Section titled “removeEventsFromRoom()”removeEventsFromRoom(
roomId,eventIds):void
Defined in: src/sync-accumulator.ts:785
Parameters
Section titled “Parameters”roomId
Section titled “roomId”string
eventIds
Section titled “eventIds”string[]
Returns
Section titled “Returns”void