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

19 lines
559 B
TypeScript
Raw Normal View History

2021-02-14 13:23:36 +01:00
// SafariがBroadcastChannel未実装なのでライブラリを使う
import { BroadcastChannel } from 'broadcast-channel';
2021-02-21 06:35:54 +01:00
export const reloadChannel = new BroadcastChannel<boolean>('reload');
2021-02-14 13:23:36 +01:00
// BroadcastChannelを用いて、クライアントが一斉にreloadするようにします。
2021-02-21 06:45:20 +01:00
export function unisonReload(redirectToRoot: boolean = false) {
2021-02-21 06:35:54 +01:00
reloadChannel.postMessage(!!redirectToRoot);
reload();
}
2021-02-21 06:45:20 +01:00
export function reload(redirectToRoot: boolean = false) {
2021-02-21 06:35:54 +01:00
if (redirectToRoot) {
location.href = '/';
} else {
location.reload();
}
2021-02-14 13:23:36 +01:00
}