firefish/packages/client/src/stream.ts

25 lines
471 B
TypeScript
Raw Normal View History

2023-10-10 23:28:06 +09:00
import * as firefish from "firefish-js";
2023-07-20 04:17:05 +09:00
import { markRaw } from "vue";
import { url } from "@/config";
2023-11-06 21:11:39 +09:00
import { $i } from "@/reactiveAccount";
2023-07-20 04:17:05 +09:00
export const stream = markRaw(
2023-10-10 23:28:06 +09:00
new firefish.Stream(
2023-07-20 04:17:05 +09:00
url,
$i
? {
token: $i.token,
}
: null,
),
);
window.setTimeout(heartbeat, 1000 * 60);
function heartbeat(): void {
if (stream != null && document.visibilityState === "visible") {
stream.send("ping");
}
window.setTimeout(heartbeat, 1000 * 60);
}