jormungandr-bite/packages/client/src/scripts/unison-reload.ts

16 lines
504 B
TypeScript
Raw Normal View History

// SafariがBroadcastChannel未実装なのでライブラリを使う
2023-01-12 21:40:33 -07:00
import { BroadcastChannel } from "broadcast-channel";
2023-01-12 21:40:33 -07:00
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();
}
}