mizzkey/src/client/scripts/unison-reload.ts

13 lines
517 B
TypeScript
Raw Normal View History

2021-02-14 13:23:36 +01:00
// SafariがBroadcastChannel未実装なのでライブラリを使う
import { BroadcastChannel } from 'broadcast-channel';
const ch = new BroadcastChannel<boolean | undefined>('reload');
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
export function unisonReload(forcedReload?: boolean) {
ch.postMessage(forcedReload);
location.reload(forcedReload as boolean);
}
ch.addEventListener('message', forcedReload => location.reload(forcedReload as boolean));