Create a new sliding sync instance
The base URL of the sliding sync proxy
The lists to use for sliding sync.
The params to use for room subscriptions.
The client to use for /sync calls.
The number of milliseconds to wait for a response.
Add a custom room subscription, referred to by an arbitrary name. If a subscription with this name already exists, it is replaced. No requests are sent by calling this method.
The name of the subscription. Only used to reference this subscription in useCustomSubscription.
The subscription information.
Alias for on.
Synchronously calls each of the listeners registered for the event named
event
, in the order they were registered, passing the supplied arguments
to each.
The name of the event to emit
Rest
...args: Parameters<SlidingSyncEventHandlerMap[T]>Arguments to pass to the listener
true
if the event had listeners, false
otherwise.
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
import EventEmitter from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Rest
...args: Parameters<SlidingSyncEventHandlerMap[T]>Similar to emit
but calls all listeners within a Promise.all
and returns the promise chain
The name of the event to emit
Rest
...args: Parameters<SlidingSyncEventHandlerMap[T]>Arguments to pass to the listener
true
if the event had listeners, false
otherwise.
Rest
...args: Parameters<SlidingSyncEventHandlerMap[T]>Get the full request list parameters for a list index. This function is provided for callers to use in conjunction with setList to update fields on an existing list.
The list key to get the params for.
A copy of the list params or undefined.
Returns the number of listeners listening to the event named event
.
The name of the event being listened for
Returns a copy of the array of listeners for the event named event
.
Modify which events to retrieve for room subscriptions. Invalidates all room subscriptions such that they will be sent up afresh.
The new room subscription fields to fetch.
A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)
Modify the room subscriptions for the sync API. Calling this function will interrupt the /sync request to resend new subscriptions. If the /sync stream has not started, this will prepare the room subscriptions for when start() is called.
The new desired room subscriptions.
A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)
Alias for removeListener
Adds the listener
function to the end of the listeners array for the
event named event
.
No checks are made to see if the listener
has already been added. Multiple calls
passing the same combination of event
and listener
will result in the listener
being added, and called, multiple times.
By default, event listeners are invoked in the order they are added. The prependListener method can be used as an alternative to add the event listener to the beginning of the listeners array.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Adds a one-time listener
function for the event named event
. The
next time event
is triggered, this listener is removed and then invoked.
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The prependOnceListener method can be used as an alternative to add the event listener to the beginning of the listeners array.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Adds the listener
function to the beginning of the listeners array for the
event named event
.
No checks are made to see if the listener
has already been added. Multiple calls
passing the same combination of event
and listener
will result in the listener
being added, and called, multiple times.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Adds a one-timelistener
function for the event named event
to the beginning of the listeners array.
The next time event
is triggered, this listener is removed, and then invoked.
The name of the event.
The callback function
a reference to the EventEmitter
, so that calls can be chained.
Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
Register an extension to send with the /sync request.
The extension to register.
Removes all listeners, or those of the specified event
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Optional
event: EventEmitterEvents | SlidingSyncEventThe name of the event. If undefined, all listeners everywhere are removed.
a reference to the EventEmitter
, so that calls can be chained.
Removes the specified listener
from the listener array for the event named event
.
a reference to the EventEmitter
, so that calls can be chained.
Add or replace a list. Calling this function will interrupt the /sync request to resend new lists.
The key to modify
The new list parameters.
A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)
Set new ranges for an existing list. Calling this function when only the ranges have changed is more efficient than calling setList(index,list) as this function won't resend sticky params, whereas setList always will.
The list key to modify
The new ranges to apply.
A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)
Use a custom subscription previously added via addCustomSubscription. No requests are sent by calling this method. Use modifyRoomSubscriptions to resend subscription information.
The room to use the subscription in.
The name of the subscription. If this name is unknown, the default subscription will be used.
SlidingSync is a high-level data structure which controls the majority of sliding sync. It has no hooks into JS SDK except for needing a MatrixClient to perform the HTTP request. This means this class (and everything it uses) can be used in isolation from JS SDK if needed. To hook this up with the JS SDK, you need to use SlidingSyncSdk.