js BroadcastChannel 小案例(未测试)

export const ContractBroadcastChannel = class {
  channelName: string;
  channel: BroadcastChannel;
  constructor() {
    this.channelName = 'ContractChannel';
    this.channel = window.BroadcastChannel ? new BroadcastChannel(this.channelName) : null;
  }
  postMessage = (data) => {
    return this.channel?.postMessage(data);
  };
  onMessage = (data) => {
    return this.channel?.onmessage(data);
  };
};

 

posted @ 2024-02-02 11:20  最好的年纪  阅读(34)  评论(0编辑  收藏  举报