SDKsWASM
Receive custom business messages
Listen for custom business notifications delivered by the server through the WASM SDK.
CbEvents.OnRecvCustomBusinessMessage delivers business notifications from the server. Its payload is not a MessageItem. Ordinary custom chat messages still arrive through the new-message events.
function handleCustomBusinessMessage({ data }) {
const payload = parseAndValidateBusinessPayload(data);
applyBusinessPayload(payload);
}
openimsdk.on(
CbEvents.OnRecvCustomBusinessMessage,
handleCustomBusinessMessage,
);
function removeCustomBusinessMessageListener() {
openimsdk.off(
CbEvents.OnRecvCustomBusinessMessage,
handleCustomBusinessMessage,
);
}Keep a stable reference to the handler function. Update state by a stable ID or idempotency key in the business payload; do not deduplicate by arrival order or array position.
Was this page helpful?