Sharkey/packages/frontend/src/scripts/unison-reload.ts

16 lines
504 B
TypeScript
Raw Normal View History

2022-11-24 11:27:05 +02:00
// SafariがBroadcastChannel未実装なのでライブラリを使う
2022-04-27 20:57:59 +03:00
import { BroadcastChannel } from 'broadcast-channel';
export const reloadChannel = new BroadcastChannel<string | null>('reload');
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
export function unisonReload(path?: string) {
if (path !== undefined) {
reloadChannel.postMessage(path);
location.href = path;
} else {
reloadChannel.postMessage(null);
location.reload();
}
}