jormungandr-bite/packages/client/src/scripts/unison-reload.ts
ThatOneCalculator 2aab2de38d refactor: 🎨 rome
2023-01-12 20:40:33 -08:00

15 lines
504 B
TypeScript

// SafariがBroadcastChannel未実装なのでライブラリを使う
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();
}
}