Skip to main content

dispatchEvent

The dispatchEvent method emits a specific event, calling all registered listeners for that event.

This method is also available as emit.

events emitted are only local

dispatchEvent (or emit) only emit the event to the same client that called it.

It DOES NOT emit an event to all other clients

Signature

async dispatchEvent<EvtName extends MutexoEventName>(
evt: EvtName,
msg: DataOf<EvtName>
): boolean

Parameters

Returns

  • boolean: true if the event had listeners, false otherwise.

Examples

Emit an "input" event

const client = new MutexoClient(webSocket);

const utxoSpentHandler = _evt => {
console.log("someone spent something")
};

client.addEventListener("input", utxoSpentHandler);

// Emit an "input" event

client.dispatchEvent(
"input",
new MutexoInput({})
);