1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-17 16:18:13 +09:00
hotomoe/packages/client/src/scripts/unison-reload.ts

16 lines
504 B
TypeScript
Raw Normal View History

// 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();
}
}