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
evt:MutexoEventName- The name of the event to emit.msg:DataOf<EvtName>- The data to pass to the event listeners.
Returns
boolean:trueif the event had listeners,falseotherwise.
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({})
);