fix: stream disconnect when reload

This commit is contained in:
Fairy-Phy 2023-10-22 17:53:12 +09:00
parent e9d0e5b81e
commit 97d543415d
No known key found for this signature in database
GPG key ID: 53E58673D5961DB5
3 changed files with 9 additions and 2 deletions

View file

@ -8,7 +8,7 @@ import { common } from './common.js';
import { version, ui, lang, updateLocale } from '@/config.js';
import { i18n, updateI18n } from '@/i18n.js';
import { confirm, alert, post, popup, toast } from '@/os.js';
import { useStream } from '@/stream.js';
import { useStream, isReloading } from '@/stream.js';
import * as sound from '@/scripts/sound.js';
import { $i, refreshAccount, login, updateAccount, signout } from '@/account.js';
import { defaultStore, ColdDeviceStorage } from '@/store.js';
@ -39,6 +39,7 @@ export async function mainBoot() {
let reloadDialogShowing = false;
stream.on('_disconnected_', async () => {
if (isReloading) return;
if (defaultStore.state.serverDisconnectedBehavior === 'reload') {
location.reload();
} else if (defaultStore.state.serverDisconnectedBehavior === 'dialog') {

View file

@ -11,6 +11,8 @@ import { url } from '@/config.js';
let stream: Misskey.Stream | null = null;
let timeoutHeadBeat: number | null = null;
export let isReloading: boolean = false;
export function useStream(): Misskey.Stream {
if (stream) return stream;
@ -26,11 +28,14 @@ export function useStream(): Misskey.Stream {
export function reloadStream() {
if (!stream) return useStream();
if (timeoutHeadBeat) window.clearTimeout(timeoutHeadBeat);
isReloading = true;
stream.close();
stream.once('_connected_', () => isReloading = false);
stream.stream.reconnect();
timeoutHeadBeat = window.setTimeout(heartbeat, 1000 * 60);
return stream;
}

View file

@ -15,7 +15,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { onUnmounted } from 'vue';
import { useStream } from '@/stream.js';
import { useStream, isReloading } from '@/stream.js';
import { i18n } from '@/i18n.js';
import MkButton from '@/components/MkButton.vue';
import * as os from '@/os.js';
@ -26,6 +26,7 @@ const zIndex = os.claimZIndex('high');
let hasDisconnected = $ref(false);
function onDisconnected() {
if (isReloading) return;
hasDisconnected = true;
}