Skip to content

DigitalWorldEvent

Defined in: src/models/event.ts:255

Typed Event Emitter class which can act as a Base Model for all our model and communication events. This makes it much easier for us to distinguish between events, as we now need to properly type this, so that our events are not stringly-based and prone to silly typos.

Type parameters:

  • Events - List of all events emitted by this TypedEventEmitter. Normally an enum type.
  • Arguments - A ListenerMap type providing mappings from event names to listener types.
  • SuperclassArguments - TODO: not really sure. Alternative listener mappings, I think? But only honoured for .emit?

new DigitalWorldEvent(event?): DigitalWorldEvent

Defined in: src/models/event.ts:430

Construct a Digital World Event object

Partial<IEvent> = {}

The raw (possibly encrypted) event. Do not access this property directly unless you absolutely have to. Prefer the getter methods defined on this class. Using the getter methods shields your app from changes to event JSON between protocol versions.

DigitalWorldEvent

TypedEventEmitter.constructor

error: DigitalWorldError | null = null

Defined in: src/models/event.ts:398

most recent error associated with sending the event, if any


event: Partial<IEvent> = {}

Defined in: src/models/event.ts:430

The raw (possibly encrypted) event. Do not access this property directly unless you absolutely have to. Prefer the getter methods defined on this class. Using the getter methods shields your app from changes to event JSON between protocol versions.


forwardLooking: boolean = true

Defined in: src/models/event.ts:407

True if this event is ‘forward looking’, meaning that getDirectionalContent() will return event.content and not event.prev_content. Only state events may be backwards looking Default: true. This property is experimental and may change.


localTimestamp: number

Defined in: src/models/event.ts:323


sender: RoomMember | null = null

Defined in: src/models/event.ts:333

The room member who sent this event, or null e.g. this is a presence event. This is only guaranteed to be set for events that appear in a timeline, ie. do not guarantee that it will be set on state events.


status: EventStatus | null = null

Defined in: src/models/event.ts:392

The sending status of the event.


target: RoomMember | null = null

Defined in: src/models/event.ts:341

The room member who is the target of this event, e.g. the invitee, the person being banned, etc.


readonly unstableStickyExpiresAt: number | undefined

Defined in: src/models/event.ts:420

The timestamp for when this event should expire, in milliseconds. Prefers using the server-provided value, but will fall back to local calculation.

This value is safe to use, as malicious start time and duration are appropriately capped.

If the event is not a sticky event (or not supported by the server), then this returns undefined.


static captureRejections: boolean

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:425

Value: boolean

Change the default captureRejections option on all new EventEmitter objects.

v13.4.0, v12.16.0

TypedEventEmitter.captureRejections


readonly static captureRejectionSymbol: typeof captureRejectionSymbol

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:418

Value: Symbol.for('nodejs.rejection')

See how to write a custom rejection handler.

v13.4.0, v12.16.0

TypedEventEmitter.captureRejectionSymbol


static defaultMaxListeners: number

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:464

By default, a maximum of 10 listeners can be registered for any single event. This limit can be changed for individual EventEmitter instances using the emitter.setMaxListeners(n) method. To change the default for allEventEmitter instances, the events.defaultMaxListeners property can be used. If this value is not a positive number, a RangeError is thrown.

Take caution when setting the events.defaultMaxListeners because the change affects all EventEmitter instances, including those created before the change is made. However, calling emitter.setMaxListeners(n) still has precedence over events.defaultMaxListeners.

This is not a hard limit. The EventEmitter instance will allow more listeners to be added but will output a trace warning to stderr indicating that a “possible EventEmitter memory leak” has been detected. For any single EventEmitter, the emitter.getMaxListeners() and emitter.setMaxListeners() methods can be used to temporarily avoid this warning:

import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});

The --trace-warnings command-line flag can be used to display the stack trace for such warnings.

The emitted warning can be inspected with process.on('warning') and will have the additional emitter, type, and count properties, referring to the event emitter instance, the event’s name and the number of attached listeners, respectively. Its name property is set to 'MaxListenersExceededWarning'.

v0.11.2

TypedEventEmitter.defaultMaxListeners


readonly static errorMonitor: typeof errorMonitor

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:411

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted. Therefore, the process will still crash if no regular 'error' listener is installed.

v13.6.0, v12.17.0

TypedEventEmitter.errorMonitor

get decryptionFailureReason(): DecryptionFailureCode | null

Defined in: src/models/event.ts:862

If we failed to decrypt this event, the reason for the failure. Otherwise, null.

DecryptionFailureCode | null


get isThreadRoot(): boolean

Defined in: src/models/event.ts:685

A helper to check if an event is a thread’s head or not

boolean


get relationEventId(): string | undefined

Defined in: src/models/event.ts:703

string | undefined


get replyEventId(): string | undefined

Defined in: src/models/event.ts:699

string | undefined


get threadRootId(): string | undefined

Defined in: src/models/event.ts:660

Get the event ID of the thread head

string | undefined


get unstableExtensibleEvent(): ExtensibleEvent<object> | undefined

Defined in: src/models/event.ts:481

Unstable getter to try and get an extensible event. Note that this might return a falsy value if the event could not be parsed as an extensible event.

ExtensibleEvent<object> | undefined


get unstableStickyInfo(): { duration_ms: number; duration_ttl_ms?: number; } | undefined

Defined in: src/models/event.ts:1771

Unstable getter to try and get the sticky information for the event. If the event is not a sticky event (or not supported by the server), then this returns undefined.

duration_ms is safely bounded to a hour.

{ duration_ms: number; duration_ttl_ms?: number; } | undefined

optional [captureRejectionSymbol]<K>(error, event, …args): void

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:103

K

Error

string | symbol

AnyRest

void

TypedEventEmitter.[captureRejectionSymbol]


addListener<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:70

Alias for on.

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

this

TypedEventEmitter.addListener


applyVisibilityEvent(visibilityChange?): void

Defined in: src/models/event.ts:1186

Change the visibility of an event, as per https://github.com/matrix-org/matrix-doc/pull/3531 .

IVisibilityChange

event holding a hide/unhide payload, or nothing if the event is being reset to its original visibility (presumably by a visibility event being redacted).

void

Fires DigitalWorldEventEvent.VisibilityChange if visibilityEvent caused a change in the actual visibility of this event, either by making it visible (if it was hidden), by making it hidden (if it was visible) or by changing the reason (if it was hidden).


asVisibilityChange(): IVisibilityChange | null

Defined in: src/models/event.ts:1335

Return the visibility change caused by this event, as per https://github.com/matrix-org/matrix-doc/pull/3531.

IVisibilityChange | null

If the event is a well-formed visibility change event, an instance of IVisibilityChange, otherwise null.


emit<T>(event, …args): boolean

Defined in: src/models/typed-event-emitter.ts:86

Synchronously calls each of the listeners registered for the event named event, in the order they were registered, passing the supplied arguments to each.

T extends DigitalWorldEventEmittedEvents

T

The name of the event to emit

Parameters<DigitalWorldEventHandlerMap[T]>

Arguments to pass to the listener

boolean

true if the event had listeners, false otherwise.

TypedEventEmitter.emit

emit<T>(event, …args): boolean

Defined in: src/models/typed-event-emitter.ts:87

Synchronously calls each of the listeners registered for the event named event, in the order they were registered, passing the supplied arguments to each.

T extends DigitalWorldEventEmittedEvents

T

The name of the event to emit

Parameters<DigitalWorldEventHandlerMap[T]>

Arguments to pass to the listener

boolean

true if the event had listeners, false otherwise.

TypedEventEmitter.emit


emitPromised<T>(event, …args): Promise<boolean>

Defined in: src/models/typed-event-emitter.ts:98

Similar to emit but calls all listeners within a Promise.all and returns the promise chain

T extends DigitalWorldEventEmittedEvents

T

The name of the event to emit

Parameters<DigitalWorldEventHandlerMap[T]>

Arguments to pass to the listener

Promise<boolean>

true if the event had listeners, false otherwise.

TypedEventEmitter.emitPromised

emitPromised<T>(event, …args): Promise<boolean>

Defined in: src/models/typed-event-emitter.ts:102

Similar to emit but calls all listeners within a Promise.all and returns the promise chain

T extends DigitalWorldEventEmittedEvents

T

The name of the event to emit

Parameters<DigitalWorldEventHandlerMap[T]>

Arguments to pass to the listener

Promise<boolean>

true if the event had listeners, false otherwise.

TypedEventEmitter.emitPromised


eventNames(): (string | symbol)[]

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:967

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]

(string | symbol)[]

v6.0.0

TypedEventEmitter.eventNames


flagCancelled(cancelled?): void

Defined in: src/models/event.ts:1642

Flags an event as cancelled due to future conditions. For example, a verification request event in the same sync transaction may be flagged as cancelled to warn listeners that a cancellation event is coming down the same pipe shortly.

boolean = true

Whether the event is to be cancelled or not.

void


getAge(): number | undefined

Defined in: src/models/event.ts:737

Get the age of this event. This represents the age of the event when the event arrived at the device, and not the age of the event when this function was called. Can only be returned once the server has echo’ed back

number | undefined

The age of this event in milliseconds.


getAssociatedId(): string | undefined

Defined in: src/models/event.ts:1601

For relations and redactions, returns the event_id this event is referring to.

string | undefined


getAssociatedStatus(): EventStatus | null

Defined in: src/models/event.ts:1541

Returns the status of any associated edit or redaction (not for reactions/annotations as their local echo doesn’t affect the original event), or else the status of the event.

EventStatus | null


getClaimedEd25519Key(): string | null

Defined in: src/models/event.ts:1111

Get the ed25519 the sender of this event claims to own.

For Olm messages, this claim is encoded directly in the plaintext of the event itself. For megolm messages, it is implied by the m.room_key event which established the megolm session.

Until we download the device list of the sender, it’s just a claim: the device list gives a proof that the owner of the curve25519 key used for this event (and returned by #getSenderKey) also owns the ed25519 key by signing the public curve25519 key with the ed25519 key.

In general, applications should not use this method directly, but should instead use crypto-api!CryptoApi#getEncryptionInfoForEvent.

string | null


getClearContent(): IContent | null

Defined in: src/models/event.ts:1056

Gets the cleartext content for this event. If the event is not encrypted, or encryption has not been completed, this will return null.

IContent | null

The cleartext (decrypted) content for the event


getContent<T>(): T

Defined in: src/models/event.ts:637

Get the (decrypted, if necessary) event content JSON, or the content from the replacing event, if any. See makeReplaced.

T extends IContent = IContent

T

The event content JSON, or an empty object.


getDate(): Date | null

Defined in: src/models/event.ts:587

Get the timestamp of this event, as a Date object.

Date | null

The event date, e.g. new Date(1433502692297)


getDecryptionPromise(): Promise<void> | null

Defined in: src/models/event.ts:845

Promise<void> | null


getDetails(): string

Defined in: src/models/event.ts:602

Get a string containing details of this event

This is intended for logging, to help trace errors. Example output:

string

id=$HjnOHV646n0SjLDAqFrgIjim7RCpB7cdMXFrekWYAn type=m.room.encrypted
sender=@user:example.com room=!room:example.com ts=2022-10-25T17:30:28.404Z

getDirectionalContent(): IContent

Defined in: src/models/event.ts:726

Get either ‘content’ or ‘prev_content’ depending on if this event is ‘forward-looking’ or not. This can be modified via event.forwardLooking. In practice, this means we get the chronologically earlier content value for this event (this method should surely be called getEarlierContent) This method is experimental and may change.

IContent

event.content if this event is forward-looking, else event.prev_content.


getEffectiveEvent(): IEvent

Defined in: src/models/event.ts:501

Gets the event as it would appear if it had been sent unencrypted.

If the event is encrypted, we attempt to mock up an event as it would have looked had the sender not encrypted it. If the event is not encrypted, a copy of it is simply returned as-is.

IEvent

A shallow copy of the event, in wire format, as it would have been had it not been encrypted.


getForwardingCurve25519KeyChain(): string[]

Defined in: src/models/event.ts:1126

Returns an empty array.

Previously, this returned the chain of Curve25519 keys through which this session was forwarded, via m.forwarded_room_key events. However, that is not cryptographically reliable, and clients should not be using it.

string[]

https://github.com/matrix-org/matrix-spec/issues/1089


getId(): string | undefined

Defined in: src/models/event.ts:531

Get the event_id for this event.

string | undefined

The event ID, e.g. $143350589368169JsLZx:localhost


getKeyForwardingUser(): string | undefined

Defined in: src/models/event.ts:1142

If another user forwarded the key to this message (eg via MSC4268), get the ID of that user.

string | undefined


getKeyRequestRecipients(userId): IKeyRequestRecipient[]

Defined in: src/models/event.ts:922

Calculate the recipients for keyshare requests.

string

the user who received this event.

IKeyRequestRecipient[]

array of recipients


getKeysClaimed(): Partial<Record<"ed25519", string>>

Defined in: src/models/event.ts:1088

The additional keys the sender of this encrypted event claims to possess.

Just a wrapper for #getClaimedEd25519Key (q.v.)

Partial<Record<"ed25519", string>>


getLocalAge(): number

Defined in: src/models/event.ts:747

Get the age of the event when this function was called. This is the ‘age’ field adjusted according to how long this client has had the event.

number

The age of this event in milliseconds.


getMaxListeners(): number

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:819

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.

number

v1.0.0

TypedEventEmitter.getMaxListeners


getMembershipAtEvent(): string | undefined

Defined in: src/models/event.ts:789

Get the user’s room membership at the time the event was sent, as reported by the server. This uses MSC4115.

string | undefined

The user’s room membership, or undefined if the server does not report it.


getOriginalContent<T>(): T

Defined in: src/models/event.ts:620

Get the (decrypted, if necessary) event content JSON, even if the event was replaced by another event.

T = IContent

T

The event content JSON, or an empty object.


getPrevContent(): IContent

Defined in: src/models/event.ts:712

Get the previous event content JSON. This will only return something for state events which exist in the timeline.

IContent

The previous event content JSON, or an empty object.


getPushActions(): IActionsObject | null

Defined in: src/models/event.ts:1399

Get the push actions, if known, for this event

IActionsObject | null

push actions


getPushDetails(): PushDetails

Defined in: src/models/event.ts:1408

Get the push details, if known, for this event

PushDetails

push actions


getRedactionEvent(): EmptyObject | IEvent | null

Defined in: src/models/event.ts:1382

Get the (decrypted, if necessary) redaction event JSON if event was redacted

EmptyObject | IEvent | null

The redaction event JSON, or an empty object


getRelation(): IEventRelation | null

Defined in: src/models/event.ts:1502

Get relation info for the event, if any.

IEventRelation | null


getRoomId(): string | undefined

Defined in: src/models/event.ts:571

Get the room_id for this event. This will return undefined for m.presence events.

string | undefined

The room ID, e.g. !cURbafjkfsMDVwdRDQ:matrix.org


getSender(): string | undefined

Defined in: src/models/event.ts:539

Get the user_id for this event.

string | undefined

The user ID, e.g. @alice:matrix.org


getSenderKey(): string | null

Defined in: src/models/event.ts:1079

The curve25519 key for the device that we think sent this event

For an Olm-encrypted event, this is inferred directly from the DH exchange at the start of the session: the curve25519 key is involved in the DH exchange, so only a device which holds the private part of that key can establish such a session.

For a megolm-encrypted event, it is inferred from the Olm message which established the megolm session

string | null


getServerAggregatedRelation<T>(relType): T | undefined

Defined in: src/models/event.ts:1550

T

string

T | undefined


getStateKey(): string | undefined

Defined in: src/models/event.ts:757

Get the event state_key if it has one. If necessary, this will perform string-unpacking on the state key, as per MSC4362. This will return undefined for message events.

string | undefined

The event’s state_key.


getThread(): Thread | undefined

Defined in: src/models/event.ts:1756

Get the instance of the thread associated with the current event

Thread | undefined


getTs(): number

Defined in: src/models/event.ts:579

Get the timestamp of this event.

number

The event timestamp, e.g. 1433502692297


getTxnId(): string | undefined

Defined in: src/models/event.ts:1730

string | undefined


getType(): string

Defined in: src/models/event.ts:548

Get the (decrypted, if necessary) type of event.

string

The event type, e.g. m.room.message


getUnsigned(): IUnsigned

Defined in: src/models/event.ts:1146

IUnsigned


getWireContent(): IContent

Defined in: src/models/event.ts:653

Get the (possibly encrypted) event content JSON that will be sent to the hub.

IContent

The event content JSON, or an empty object.


getWireStateKey(): string | undefined

Defined in: src/models/event.ts:770

Get the raw event state_key if it has one. This may be string-packed as per MSC4362 if the state event is encrypted. This will return undefined for message events.

string | undefined

The event’s state_key.


getWireType(): string

Defined in: src/models/event.ts:561

Get the (possibly encrypted) type of the event that will be sent to the hub.

string

The event type.


handleRemoteEcho(event): void

Defined in: src/models/event.ts:1429

Replace the event property and recalculate any properties based on it.

object

the object to assign to the event property

void


hasAssociation(): boolean

Defined in: src/models/event.ts:1615

Checks if this event is associated with another event. See getAssociatedId.

boolean


isBeingDecrypted(): boolean

Defined in: src/models/event.ts:841

Check if this event is currently being decrypted.

boolean

True if this event is currently being decrypted, else false.


isCancelled(): boolean

Defined in: src/models/event.ts:1651

Gets whether or not the event is flagged as cancelled. See flagCancelled() for more information.

boolean

True if the event is cancelled, false otherwise.


isDecryptionFailure(): boolean

Defined in: src/models/event.ts:857

Check if this event is an encrypted event which we failed to decrypt

(This implies that we might retry decryption at some point in the future)

boolean

True if this event is an encrypted event which we couldn’t decrypt.


isEncrypted(): boolean

Defined in: src/models/event.ts:1064

Check if the event is encrypted.

boolean

True if this event is encrypted.


isEquivalentTo(otherEvent?): boolean

Defined in: src/models/event.ts:1688

Determines if this event is equivalent to the given event. This only checks the event object itself, not the other properties of the event. Intended for use with toSnapshot() to identify events changing.

DigitalWorldEvent

The other event to check against.

boolean

True if the events are the same, false otherwise.


isKeySourceUntrusted(): false

Defined in: src/models/event.ts:1133

false


isRedacted(): boolean

Defined in: src/models/event.ts:1315

Check if this event has been redacted

boolean

True if this event has been redacted


isRedaction(): boolean

Defined in: src/models/event.ts:1324

Check if this event is a redaction of another event

boolean

True if this event is a redaction


isRelation(relType?): boolean

Defined in: src/models/event.ts:1484

Get whether the event is a relation event, and of a given type if relType is passed in. State events cannot be relation events

string

if given, checks that the relation is of the given type

boolean


isSending(): boolean

Defined in: src/models/event.ts:1458

Whether the event is in any phase of sending, send failure, waiting for remote echo, etc.

boolean


isState(): boolean

Defined in: src/models/event.ts:778

Check if this event is a state event.

boolean

True if this is a state event.


isVisibilityEvent(): boolean

Defined in: src/models/event.ts:1372

Check if this event alters the visibility of another event, as per https://github.com/matrix-org/matrix-doc/pull/3531.

boolean

True if this event alters the visibility of another event.


listenerCount(event): number

Defined in: src/models/typed-event-emitter.ts:115

Returns the number of listeners listening to the event named event.

EventEmitterEvents | DigitalWorldEventEmittedEvents

The name of the event being listened for

number

TypedEventEmitter.listenerCount


listeners(event): Function[]

Defined in: src/models/typed-event-emitter.ts:122

Returns a copy of the array of listeners for the event named event.

EventEmitterEvents | DigitalWorldEventEmittedEvents

Function[]

TypedEventEmitter.listeners


localRedactionEvent(): DigitalWorldEvent | null

Defined in: src/models/event.ts:1594

Returns the event that wants to redact this event, but hasn’t been sent yet.

DigitalWorldEvent | null

the event


makeRedacted(redactionEvent, room): void

Defined in: src/models/event.ts:1227

Update the content of an event in the same way it would be by the server if it were redacted before it was sent to us

DigitalWorldEvent

event causing the redaction

Room

the room in which the event exists

void


makeReplaced(newEvent?): void

Defined in: src/models/event.ts:1517

Set an event that replaces the content of this event, through an m.replace relation.

DigitalWorldEvent

the event with the replacing content, if any.

void

Fires DigitalWorldEventEvent.Replaced


markLocallyRedacted(redactionEvent): void

Defined in: src/models/event.ts:1163

DigitalWorldEvent

void


messageVisibility(): MessageVisibility

Defined in: src/models/event.ts:1214

Return instructions to display or hide the message.

MessageVisibility

Instructions determining whether the message should be displayed.


off<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:129

Alias for removeListener

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

this

TypedEventEmitter.off


on<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:150

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.

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

The name of the event.

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

The callback function

this

a reference to the EventEmitter, so that calls can be chained.

TypedEventEmitter.on


once<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:169

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.

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

The name of the event.

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

The callback function

this

a reference to the EventEmitter, so that calls can be chained.

TypedEventEmitter.once


prependListener<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:186

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.

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

The name of the event.

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

The callback function

this

a reference to the EventEmitter, so that calls can be chained.

TypedEventEmitter.prependListener


prependOnceListener<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:202

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.

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

The name of the event.

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

The callback function

this

a reference to the EventEmitter, so that calls can be chained.

TypedEventEmitter.prependOnceListener


rawListeners(event): Function[]

Defined in: src/models/typed-event-emitter.ts:243

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

EventEmitterEvents | DigitalWorldEventEmittedEvents

Function[]

TypedEventEmitter.rawListeners


removeAllListeners(event?): this

Defined in: src/models/typed-event-emitter.ts:219

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).

EventEmitterEvents | DigitalWorldEventEmittedEvents

The name of the event. If undefined, all listeners everywhere are removed.

this

a reference to the EventEmitter, so that calls can be chained.

TypedEventEmitter.removeAllListeners


removeListener<T>(event, listener): this

Defined in: src/models/typed-event-emitter.ts:232

Removes the specified listener from the listener array for the event named event.

T extends EventEmitterEvents | DigitalWorldEventEmittedEvents

T

Listener<DigitalWorldEventEmittedEvents, DigitalWorldEventHandlerMap, T>

this

a reference to the EventEmitter, so that calls can be chained.

TypedEventEmitter.removeListener


replaceLocalEventId(eventId): void

Defined in: src/models/event.ts:1472

string

void


replacingEvent(): DigitalWorldEvent | null

Defined in: src/models/event.ts:1571

Returns the event replacing the content of this event, if any. Replacements are aggregated on the server, so this would only return an event in case it came down the sync, or for local echo of edits.

DigitalWorldEvent | null


replacingEventDate(): Date | undefined

Defined in: src/models/event.ts:1578

Returns the origin_server_ts of the event replacing the content of this event, if any.

Date | undefined


replacingEventId(): string | undefined

Defined in: src/models/event.ts:1557

Returns the event ID of the event replacing the content of this event, if any.

string | undefined


setMaxListeners(n): this

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:813

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Returns a reference to the EventEmitter, so that calls can be chained.

number

this

v0.3.5

TypedEventEmitter.setMaxListeners


setPushDetails(pushActions?, rule?): void

Defined in: src/models/event.ts:1418

Set the push details for this event.

IActionsObject

push actions

IAnnotatedPushRule

the executed push rule

void


setStatus(status): void

Defined in: src/models/event.ts:1467

Update the event’s sending status and emit an event as well.

EventStatus | null

The new status

void


setThread(thread?): void

Defined in: src/models/event.ts:1738

Set the instance of a thread associated with the current event

Thread

the thread

void


setThreadId(threadId?): void

Defined in: src/models/event.ts:1760

string

void


setTxnId(txnId): void

Defined in: src/models/event.ts:1726

string

void


setUnsigned(unsigned): void

Defined in: src/models/event.ts:1150

IUnsigned

void


shouldAttemptDecryption(): boolean

Defined in: src/models/event.ts:866

boolean


toJSON(): object

Defined in: src/models/event.ts:1713

Summarise the event as JSON.

If encrypted, include both the decrypted and encrypted view of the event.

This is named toJSON for use with JSON.stringify which checks objects for functions named toJSON and will call them to customise the output if they are defined.

WARNING Do not log the result of this method; otherwise, it will end up in rageshakes, leading to a privacy violation.

object


toSnapshot(): DigitalWorldEvent

Defined in: src/models/event.ts:1669

Get a copy/snapshot of this event. The returned copy will be loosely linked back to this instance, though will have “frozen” event information. Other properties of this DigitalWorldEvent instance will be copied verbatim, which can mean they are in reference to this instance despite being on the copy too. The reference the snapshot uses does not change, however members aside from the underlying event will not be deeply cloned, thus may be mutated internally. For example, the sender profile will be copied over at snapshot time, and the sender profile internally may mutate without notice to the consumer.

This is meant to be used to snapshot the event details themselves, not the features (such as sender) surrounding the event.

DigitalWorldEvent

A snapshot of this event.


unmarkLocallyRedacted(): boolean

Defined in: src/models/event.ts:1154

boolean


updateAssociatedId(eventId): void

Defined in: src/models/event.ts:1627

Update the related id with a new one.

Used to replace a local id with remote one before sending an event with a related id.

string

the new event id

void


static addAbortListener(signal, resource): Disposable

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:403

Listens once to the abort event on the provided signal.

Listening to the abort event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call e.stopImmediatePropagation(). Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners.

This API allows safely using AbortSignals in Node.js APIs by solving these two issues by listening to the event such that stopImmediatePropagation does not prevent the listener from running.

Returns a disposable so that it may be unsubscribed from more easily.

import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}

AbortSignal

(event) => void

Disposable

Disposable that removes the abort listener.

v20.5.0

TypedEventEmitter.addAbortListener


static getEventListeners(emitter, name): Function[]

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:325

Returns a copy of the array of listeners for the event named eventName.

For EventEmitters this behaves exactly the same as calling .listeners on the emitter.

For EventTargets this is the only way to get the event listeners for the event target. This is useful for debugging and diagnostic purposes.

import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}

EventEmitter<DefaultEventMap> | EventTarget

string | symbol

Function[]

v15.2.0, v14.17.0

TypedEventEmitter.getEventListeners


static getMaxListeners(emitter): number

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:354

Returns the currently set max amount of listeners.

For EventEmitters this behaves exactly the same as calling .getMaxListeners on the emitter.

For EventTargets this is the only way to get the max event listeners for the event target. If the number of event handlers on a single EventTarget exceeds the max set, the EventTarget will print a warning.

import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}

EventEmitter<DefaultEventMap> | EventTarget

number

v19.9.0

TypedEventEmitter.getMaxListeners


static listenerCount(emitter, eventName): number

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:297

A class method that returns the number of listeners for the given eventName registered on the given emitter.

import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2

EventEmitter

The emitter to query

string | symbol

The event name

number

v0.9.12

TypedEventEmitter.listenerCount


static on(emitter, eventName, options?): AsyncIterator<any[]>

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:270

import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here

Returns an AsyncIterator that iterates eventName events. It will throw if the EventEmitter emits 'error'. It removes all listeners when exiting the loop. The value returned by each iteration is an array composed of the emitted event arguments.

An AbortSignal can be used to cancel waiting on events:

import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());

Use the close option to specify an array of event names that will end the iteration:

import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'

EventEmitter

string | symbol

StaticEventEmitterIteratorOptions

AsyncIterator<any[]>

An AsyncIterator that iterates eventName events emitted by the emitter

v13.6.0, v12.16.0

TypedEventEmitter.on

static on(emitter, eventName, options?): AsyncIterator<any[]>

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:275

import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here

Returns an AsyncIterator that iterates eventName events. It will throw if the EventEmitter emits 'error'. It removes all listeners when exiting the loop. The value returned by each iteration is an array composed of the emitted event arguments.

An AbortSignal can be used to cancel waiting on events:

import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());

Use the close option to specify an array of event names that will end the iteration:

import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'

EventTarget

string

StaticEventEmitterIteratorOptions

AsyncIterator<any[]>

An AsyncIterator that iterates eventName events emitted by the emitter

v13.6.0, v12.16.0

TypedEventEmitter.on


static once(emitter, eventName, options?): Promise<any[]>

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:184

Creates a Promise that is fulfilled when the EventEmitter emits the given event or that is rejected if the EventEmitter emits 'error' while waiting. The Promise will resolve with an array of all the arguments emitted to the given event.

This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error' event semantics and does not listen to the 'error' event.

import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}

The special handling of the 'error' event is only used when events.once() is used to wait for another event. If events.once() is used to wait for the ’error' event itself, then it is treated as any other kind of event without special handling:

import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom

An AbortSignal can be used to cancel waiting for the event:

import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!

EventEmitter

string | symbol

StaticEventEmitterOptions

Promise<any[]>

v11.13.0, v10.16.0

TypedEventEmitter.once

static once(emitter, eventName, options?): Promise<any[]>

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:189

Creates a Promise that is fulfilled when the EventEmitter emits the given event or that is rejected if the EventEmitter emits 'error' while waiting. The Promise will resolve with an array of all the arguments emitted to the given event.

This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error' event semantics and does not listen to the 'error' event.

import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}

The special handling of the 'error' event is only used when events.once() is used to wait for another event. If events.once() is used to wait for the ’error' event itself, then it is treated as any other kind of event without special handling:

import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom

An AbortSignal can be used to cancel waiting for the event:

import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!

EventTarget

string

StaticEventEmitterOptions

Promise<any[]>

v11.13.0, v10.16.0

TypedEventEmitter.once


static setMaxListeners(n?, …eventTargets): void

Defined in: node_modules/.pnpm/@types+node@22.20.0/node_modules/@types/node/events.d.ts:369

import { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);

number

A non-negative number. The maximum number of listeners per EventTarget event.

…(EventEmitter<DefaultEventMap> | EventTarget)[]

Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n is set as the default max for all newly created {EventTarget} and {EventEmitter} objects.

void

v15.4.0

TypedEventEmitter.setMaxListeners