@beeworks/imsdk / event / on
on()
on<
T>(event,cb): () =>void
订阅事件
监听指定的事件,当事件触发时执行回调函数。
Type Parameters
T
T = any
Parameters
event
string
事件名称 EventType
cb
Listener<T>
回调函数,接收事件载荷
Returns
() => void - 取消当前订阅的函数
():
void
Returns
void
Example
typescript
import { EventType } from './events';
const off = on(EventType.CHAT_MESSAGE_NEW, (msg) => {
console.log('New message:', msg);
});
// Later, to unsubscribe:
off();