diff --git a/src/lib/components/StatusList.svelte b/src/lib/components/StatusList.svelte
index b400494..d58bdfa 100644
--- a/src/lib/components/StatusList.svelte
+++ b/src/lib/components/StatusList.svelte
@@ -3,6 +3,7 @@
SOURCE_LABEL,
sourceInTrouble,
sourceStateText,
+ transportText,
} from "#lib/format.ts";
import type { SourceStatus } from "#lib/model.ts";
@@ -10,7 +11,7 @@
* **受信の状態** (押せない並び)。画面への配信 (SSE) と、情報源ごとの受信。「出典と注意」の窓の「受信の状態」に
* いつも出し、受信に問題があるときだけ出る注意の印 (広い形はヘッダー、スマホの形は dock の右端) を押してもメニューに出す。
* ふつうの状態 (受信中) と設定で切ってあるもの (オフ) は控えた字、つながっていないものだけ注意の色の字にする
- * (状態の色は状態だけ)
+ * (状態の色は状態だけ)。名前の下に、つなぎ方 (「WebSocket」「SSE」「1 分ごとに取得」) を小さく添える
*/
let {
connected,
@@ -20,14 +21,21 @@
-
- 画面への配信
+ -
+ 画面への配信
+ SSE
+
-
{connected ? "受信中" : "再接続しています"}
{#each statuses as s (s.id)}
+ {@const via = s.state === "off" ? "" : transportText(s.transport)}
-
- {SOURCE_LABEL[s.id] ?? s.id}
+ -
+ {SOURCE_LABEL[s.id] ?? s.id}
+ {#if via}{via}{/if}
+
-
{sourceStateText(s)}
@@ -46,7 +54,21 @@
font-weight: var(--so-weight);
}
.status dt {
+ flex: 1 1 50%;
min-width: 0;
+ padding-block: var(--so-space-1);
+ }
+ /* 長い状態 (通行止めの災害の名前) は折り返す。名前の列を押しつぶさない */
+ .status dd {
+ flex: 0 1 auto;
+ min-width: 0;
+ text-align: end;
+ }
+ /* つなぎ方。名前の下に控えた小さな字で */
+ .status .via {
+ display: block;
+ color: var(--so-muted);
+ font-size: var(--so-text-xs);
}
.status .bad {
color: var(--so-warn-text);
diff --git a/src/lib/format.ts b/src/lib/format.ts
index 4610804..25d4225 100644
--- a/src/lib/format.ts
+++ b/src/lib/format.ts
@@ -6,6 +6,7 @@ import type {
Quake,
SourceId,
SourceStatus,
+ SourceTransport,
Status,
WeatherInfo,
} from "./model.ts";
@@ -17,6 +18,14 @@ const dateTime = new Intl.DateTimeFormat("ja-JP", {
hour: "2-digit",
minute: "2-digit",
});
+const dateTimeSeconds = new Intl.DateTimeFormat("ja-JP", {
+ timeZone: "Asia/Tokyo",
+ month: "numeric",
+ day: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ second: "2-digit",
+});
const fullDateTime = new Intl.DateTimeFormat("ja-JP", {
timeZone: "Asia/Tokyo",
year: "numeric",
@@ -39,6 +48,9 @@ const valid = (iso: string | undefined): iso is string =>
/** 「11/13 08:43」 */
export const jst = (iso: string | undefined) =>
valid(iso) ? dateTime.format(new Date(iso)) : "—";
+/** 「11/13 08:43:12」(受信の状態の時刻。一覧や詳しい内容の時刻は秒を出さない `jst`) */
+export const jstSeconds = (iso: string | undefined) =>
+ valid(iso) ? dateTimeSeconds.format(new Date(iso)) : "—";
/** 「2026/11/13 08:43:12」 */
export const jstFull = (iso: string | undefined) =>
valid(iso) ? fullDateTime.format(new Date(iso)) : "—";
@@ -114,19 +126,39 @@ const SOURCE_STATE: Record = {
off: "オフ",
};
-/** 情報源の受信の状態の 1 行 (「受信中・11/13 08:43」「オフ (授権碼がありません)」) */
+/** 情報源の受信の状態の 1 行 (「受信中・11/13 08:43:12」「オフ (授権碼がありません)」) */
export function sourceStateText(s: SourceStatus): string {
const state = SOURCE_STATE[s.state] ?? s.state;
if (s.state === "off") return s.reason ? `${state} (${s.reason})` : state;
const road = roadDiscoverText(s, state);
if (road) return road;
- return s.lastSeenAt ? `${state}・${jst(s.lastSeenAt)}` : state;
+ return s.lastSeenAt ? `${state}・${jstSeconds(s.lastSeenAt)}` : state;
+}
+
+/** 「1 分ごと」「30 分ごと」「1 日ごと」(割り切れるいちばん大きい単位で) */
+function everyText(ms: number): string {
+ const units: [number, string][] = [
+ [24 * 60 * 60_000, "日"],
+ [60 * 60_000, "時間"],
+ [60_000, "分"],
+ ];
+ for (const [unit, name] of units)
+ if (ms >= unit && ms % unit === 0) return `${ms / unit} ${name}ごと`;
+ return `${Math.round(ms / 1000)} 秒ごと`;
+}
+
+/** 情報源へのつなぎ方の一言 (受信の状態の名前の下)。「WebSocket」「SSE」「1 分ごとに取得」 */
+export function transportText(t: SourceTransport | undefined): string {
+ if (!t) return "";
+ if (t.kind === "websocket") return "WebSocket";
+ if (t.kind === "sse") return "SSE";
+ return `${everyText(t.everyMs)}に取得`;
}
/**
* 災害時の通行止めを自動で見つけているときの 1 行 (docs/design.md の 2.12)。
- * 「受信中・令和8年熊本地震 (1 件)・11/21 10:00 に一覧を確かめた」「災害の通行止めはありません (11/21 10:00 に確かめた)」
- * 「一覧が読めません (最後に読めたのは 11/21 07:00)」。自動の発見を使っていなければ undefined
+ * 「受信中・令和8年熊本地震 (1 件)・11/21 10:00:23 に一覧を確かめた」「災害の通行止めはありません (11/21 10:00:23 に確かめた)」
+ * 「一覧が読めません (最後に読めたのは 11/21 07:00:23)」。自動の発見を使っていなければ undefined
*/
function roadDiscoverText(s: SourceStatus, state: string): string | undefined {
const r = s.roads;
@@ -134,10 +166,10 @@ function roadDiscoverText(s: SourceStatus, state: string): string | undefined {
return undefined;
if (r.problem)
return r.checkedAt
- ? `${r.problem} (最後に読めたのは ${jst(r.checkedAt)})`
+ ? `${r.problem} (最後に読めたのは ${jstSeconds(r.checkedAt)})`
: r.problem;
if (!r.checkedAt) return "一覧を確かめています";
- const at = jst(r.checkedAt);
+ const at = jstSeconds(r.checkedAt);
const manual = r.manual > 0 ? `登録した URL ${r.manual} 件` : undefined;
const n = r.disasters.length;
if (n === 0)
diff --git a/src/lib/model.ts b/src/lib/model.ts
index 2a6c58a..49d74fb 100644
--- a/src/lib/model.ts
+++ b/src/lib/model.ts
@@ -1259,8 +1259,14 @@ export interface SourceStatus {
since: string;
/** 災害時の通行止め (`roads`) の、自動で見つけた災害 (docs/design.md の 2.12) */
roads?: RoadDiscoverStatus;
+ /** つなぎ方 (受信の状態に出す)。設定で切ってある情報源 (`off`) には無い */
+ transport?: SourceTransport;
}
+/** 情報源へのつなぎ方。WebSocket と SSE はつなぎ続け、`poll` は `everyMs` ごとに取得する */
+export type SourceTransport =
+ { kind: "websocket" } | { kind: "sse" } | { kind: "poll"; everyMs: number };
+
/** 災害時の通行止めの、国土交通省 道路局のページから自動で見つけたもの */
export interface RoadDiscoverStatus {
/** 自動の発見を使っているか (`SONAE_ROAD_DISCOVER=off` で切る) */
diff --git a/src/lib/server/sources/emsc.ts b/src/lib/server/sources/emsc.ts
index 7a321fd..d7e6d16 100644
--- a/src/lib/server/sources/emsc.ts
+++ b/src/lib/server/sources/emsc.ts
@@ -90,7 +90,9 @@ export interface EmscOptions {
}
export function emscSource(ctx: SourceContext, opts: EmscOptions = {}): Source {
- const status = new StatusTracker("emsc", ctx.onStatus);
+ const status = new StatusTracker("emsc", ctx.onStatus, {
+ kind: "websocket",
+ });
const log = opts.log ?? ((m: string) => console.log(m));
return {
id: "emsc",
diff --git a/src/lib/server/sources/jma.ts b/src/lib/server/sources/jma.ts
index 9be1685..7790c40 100644
--- a/src/lib/server/sources/jma.ts
+++ b/src/lib/server/sources/jma.ts
@@ -95,10 +95,13 @@ function feedSource(
kind: FeedKind,
opts: JmaOptions,
): Source {
- const status = new StatusTracker(kind.id, ctx.onStatus);
+ const interval = Math.max(60_000, opts.intervalMs ?? 60_000);
+ const status = new StatusTracker(kind.id, ctx.onStatus, {
+ kind: "poll",
+ everyMs: interval,
+ });
const doFetch = opts.fetch ?? fetch;
const log = opts.log ?? ((m: string) => console.log(m));
- const interval = Math.max(60_000, opts.intervalMs ?? 60_000);
const wait = opts.sleep ?? sleep;
const cache = new Map();
/**
diff --git a/src/lib/server/sources/msil.ts b/src/lib/server/sources/msil.ts
index 9c0c828..833ce8d 100644
--- a/src/lib/server/sources/msil.ts
+++ b/src/lib/server/sources/msil.ts
@@ -198,7 +198,10 @@ export function msilSource(
const k = key?.trim();
if (!k) return undefined;
const cache = new LayerCache(db);
- const status = new StatusTracker("msil", o.onStatus);
+ const status = new StatusTracker("msil", o.onStatus, {
+ kind: "poll",
+ everyMs: MSIL_INTERVAL_MS,
+ });
const doFetch = o.fetch ?? fetch;
const wait = o.sleep ?? sleep;
const now = o.now ?? Date.now;
diff --git a/src/lib/server/sources/p2p.ts b/src/lib/server/sources/p2p.ts
index e9af5db..e517871 100644
--- a/src/lib/server/sources/p2p.ts
+++ b/src/lib/server/sources/p2p.ts
@@ -22,7 +22,7 @@ export interface P2pOptions {
}
export function p2pSource(ctx: SourceContext, opts: P2pOptions = {}): Source {
- const status = new StatusTracker("p2p", ctx.onStatus);
+ const status = new StatusTracker("p2p", ctx.onStatus, { kind: "websocket" });
const doFetch = opts.fetch ?? fetch;
const log = opts.log ?? ((m: string) => console.log(m));
diff --git a/src/lib/server/sources/poll.ts b/src/lib/server/sources/poll.ts
index b7c244e..10dca3d 100644
--- a/src/lib/server/sources/poll.ts
+++ b/src/lib/server/sources/poll.ts
@@ -52,11 +52,14 @@ export const redact = (s: string) =>
);
export function pollSource(ctx: SourceContext, o: PollOptions): Source {
- const status = new StatusTracker(o.id, ctx.onStatus);
+ const interval = Math.max(o.minIntervalMs, o.intervalMs);
+ const status = new StatusTracker(o.id, ctx.onStatus, {
+ kind: "poll",
+ everyMs: interval,
+ });
const doFetch = o.fetch ?? fetch;
const wait = o.sleep ?? sleep;
const log = o.log ?? ((m: string) => console.log(m));
- const interval = Math.max(o.minIntervalMs, o.intervalMs);
const maxBackoff = Math.max(interval, o.maxBackoffMs ?? 15 * 60_000);
const gap = o.gapMs ?? 10 * 60_000;
const cache = new Map();
diff --git a/src/lib/server/sources/retry.ts b/src/lib/server/sources/retry.ts
index a8c0e76..63aa59c 100644
--- a/src/lib/server/sources/retry.ts
+++ b/src/lib/server/sources/retry.ts
@@ -7,7 +7,7 @@
*/
import { Backoff } from "#lib/backoff.ts";
-import type { SourceId, SourceStatus } from "#lib/model.ts";
+import type { SourceId, SourceStatus, SourceTransport } from "#lib/model.ts";
import { nowIso } from "#lib/server/time.ts";
// 間隔の決め方は画面の SSE の張り直しと同じ (`#lib/backoff.ts`)
@@ -33,8 +33,10 @@ export class StatusTracker {
constructor(
id: SourceId,
private readonly onChange?: (s: SourceStatus) => void,
+ transport?: SourceTransport,
) {
this.value = { id, state: "connecting", since: nowIso() };
+ if (transport) this.value.transport = transport;
}
get(): SourceStatus {
return { ...this.value };
diff --git a/src/lib/server/sources/roads.ts b/src/lib/server/sources/roads.ts
index 64334e0..789d93b 100644
--- a/src/lib/server/sources/roads.ts
+++ b/src/lib/server/sources/roads.ts
@@ -345,7 +345,10 @@ export function roadSource(
const discover = o.discover ?? false;
if (manual.length === 0 && !discover) return undefined;
const cache = new LayerCache(db);
- const status = new StatusTracker("roads", o.onStatus);
+ const status = new StatusTracker("roads", o.onStatus, {
+ kind: "poll",
+ everyMs: ROAD_INTERVAL_MS,
+ });
const doFetch = o.fetch ?? fetch;
const wait = o.sleep ?? sleep;
const now = o.now ?? Date.now;
diff --git a/src/lib/server/sources/seisjs.ts b/src/lib/server/sources/seisjs.ts
index 0c1772d..aaad554 100644
--- a/src/lib/server/sources/seisjs.ts
+++ b/src/lib/server/sources/seisjs.ts
@@ -109,7 +109,7 @@ export interface SeisOptions {
/** SeisJS の情報源。受けたものは `board` に入れるだけ */
export function seisSource(board: RtsBoard, o: SeisOptions = {}): Source {
- const status = new StatusTracker("seisjs", o.onStatus);
+ const status = new StatusTracker("seisjs", o.onStatus, { kind: "websocket" });
const doFetch = o.fetch ?? fetch;
const wait = o.sleep ?? sleep;
const now = o.now ?? Date.now;
diff --git a/src/lib/server/sources/trem.ts b/src/lib/server/sources/trem.ts
index 173f10f..5924723 100644
--- a/src/lib/server/sources/trem.ts
+++ b/src/lib/server/sources/trem.ts
@@ -142,7 +142,7 @@ export interface TremOptions {
/** TREM-RTS の情報源。受けたものは `board` に入れるだけ */
export function tremSource(board: RtsBoard, o: TremOptions = {}): Source {
- const status = new StatusTracker("trem", o.onStatus);
+ const status = new StatusTracker("trem", o.onStatus, { kind: "sse" });
const doFetch = o.fetch ?? fetch;
const wait = o.sleep ?? sleep;
const log = o.log ?? ((m: string) => console.log(m));
diff --git a/src/lib/server/sources/wolfx.ts b/src/lib/server/sources/wolfx.ts
index eeff565..8d0a46d 100644
--- a/src/lib/server/sources/wolfx.ts
+++ b/src/lib/server/sources/wolfx.ts
@@ -44,7 +44,9 @@ export function wolfxSource(
ctx: SourceContext,
opts: WolfxOptions = {},
): Source {
- const status = new StatusTracker("wolfx", ctx.onStatus);
+ const status = new StatusTracker("wolfx", ctx.onStatus, {
+ kind: "websocket",
+ });
const now = opts.now ?? nowIso;
const pollMs = opts.eqlistPollMs ?? EQLIST_POLL_MS;
const log = opts.log ?? ((m: string) => console.log(m));
diff --git a/tests/format.test.ts b/tests/format.test.ts
index 8d735d9..e0b5128 100644
--- a/tests/format.test.ts
+++ b/tests/format.test.ts
@@ -5,12 +5,15 @@ import {
EEW_DRILL_NOTE,
eewSourceLine,
floodStationsText,
+ jst,
+ jstSeconds,
jstTime,
magnitudeText,
quakeName,
sourceInTrouble,
sourceStateText,
STATUS_LABEL,
+ transportText,
waterLevelText,
} from "#lib/format.ts";
import { type Tsunami, tsunamiTop } from "#lib/model.ts";
@@ -51,10 +54,10 @@ test("受信の状態の 1 行 (受信中は最後に受けた時刻、オフは
sourceStateText({
id: "jma",
state: "connected",
- lastSeenAt: "2026-11-13T14:41:00Z",
+ lastSeenAt: "2026-11-13T14:41:07Z",
since,
}),
- ).toBe("受信中・11/13 23:41");
+ ).toBe("受信中・11/13 23:41:07");
expect(sourceStateText({ id: "p2p", state: "retrying", since })).toBe(
"再接続中",
);
@@ -68,6 +71,31 @@ test("受信の状態の 1 行 (受信中は最後に受けた時刻、オフは
).toBe("オフ (授権碼がありません)");
});
+test("受信の状態の時刻だけ秒まで出す (一覧の時刻は秒を出さない)", () => {
+ const at = "2026-11-21T01:00:23Z";
+ expect(jstSeconds(at)).toBe("11/21 10:00:23");
+ expect(jst(at)).toBe("11/21 10:00");
+ expect(jstSeconds(undefined)).toBe("—");
+});
+
+test("つなぎ方の一言", () => {
+ expect(transportText({ kind: "websocket" })).toBe("WebSocket");
+ expect(transportText({ kind: "sse" })).toBe("SSE");
+ expect(transportText({ kind: "poll", everyMs: 60_000 })).toBe(
+ "1 分ごとに取得",
+ );
+ expect(transportText({ kind: "poll", everyMs: 30 * 60_000 })).toBe(
+ "30 分ごとに取得",
+ );
+ expect(transportText({ kind: "poll", everyMs: 24 * 60 * 60_000 })).toBe(
+ "1 日ごとに取得",
+ );
+ expect(transportText({ kind: "poll", everyMs: 90_000 })).toBe(
+ "90 秒ごとに取得",
+ );
+ expect(transportText(undefined)).toBe("");
+});
+
test("設定で切ってある情報源は問題にしない (注意の印を出さない)", () => {
const since = "2026-11-13T00:00:00Z";
expect(sourceInTrouble({ id: "jma", state: "connected", since })).toBe(false);
diff --git a/tests/road-discover.test.ts b/tests/road-discover.test.ts
index d696c83..03b7f7e 100644
--- a/tests/road-discover.test.ts
+++ b/tests/road-discover.test.ts
@@ -235,7 +235,7 @@ describe("見つけた URL を取る", () => {
expect(s.state).toBe("connected");
expect(sourceInTrouble(s)).toBe(true);
expect(sourceStateText(s)).toBe(
- "一覧が読めません (最後に読めたのは 1/1 09:00)",
+ "一覧が読めません (最後に読めたのは 1/1 09:00:00)",
);
expect(waits).toEqual([5 * 60_000]);
});
@@ -338,7 +338,7 @@ describe("受信の状態の文", () => {
test("災害が無いときと、あるとき", () => {
expect(
text({ discover: true, disasters: [], manual: 0, checkedAt: at }),
- ).toBe("災害の通行止めはありません (11/21 10:00 に確かめた)");
+ ).toBe("災害の通行止めはありません (11/21 10:00:00 に確かめた)");
expect(
text({
discover: true,
@@ -346,7 +346,7 @@ describe("受信の状態の文", () => {
manual: 0,
checkedAt: at,
}),
- ).toBe("受信中・令和8年熊本地震 (1 件)・11/21 10:00 に一覧を確かめた");
+ ).toBe("受信中・令和8年熊本地震 (1 件)・11/21 10:00:00 に一覧を確かめた");
expect(
text({
discover: true,
@@ -355,12 +355,12 @@ describe("受信の状態の文", () => {
checkedAt: at,
}),
).toBe(
- "受信中・令和8年熊本地震、令和8年8月千葉豪雨 (2 件)、登録した URL 2 件・11/21 10:00 に一覧を確かめた",
+ "受信中・令和8年熊本地震、令和8年8月千葉豪雨 (2 件)、登録した URL 2 件・11/21 10:00:00 に一覧を確かめた",
);
expect(
text({ discover: true, disasters: [], manual: 1, checkedAt: at }),
).toBe(
- "受信中・登録した URL 1 件・一覧に災害はありません (11/21 10:00 に確かめた)",
+ "受信中・登録した URL 1 件・一覧に災害はありません (11/21 10:00:00 に確かめた)",
);
});
@@ -373,7 +373,7 @@ describe("受信の状態の文", () => {
checkedAt: at,
problem: "一覧が読めません",
}),
- ).toBe("一覧が読めません (最後に読めたのは 11/21 10:00)");
+ ).toBe("一覧が読めません (最後に読めたのは 11/21 10:00:00)");
expect(
text({ discover: true, disasters: [], manual: 0 }, "connecting"),
).toBe("一覧を確かめています");
diff --git a/tests/sources.test.ts b/tests/sources.test.ts
index 5f4c12c..87a99f0 100644
--- a/tests/sources.test.ts
+++ b/tests/sources.test.ts
@@ -1,5 +1,7 @@
import { describe, expect, test } from "bun:test";
+import { RtsBoard } from "#lib/server/rts-board.ts";
+import { emscSource } from "#lib/server/sources/emsc.ts";
import { jmaSource } from "#lib/server/sources/jma.ts";
import { p2pSource } from "#lib/server/sources/p2p.ts";
import {
@@ -7,6 +9,8 @@ import {
runSocket,
StatusTracker,
} from "#lib/server/sources/retry.ts";
+import { seisSource } from "#lib/server/sources/seisjs.ts";
+import { tremSource } from "#lib/server/sources/trem.ts";
import { wolfxSource } from "#lib/server/sources/wolfx.ts";
// 情報源のサーバーは立てない。WebSocket と fetch を差し替える
@@ -472,3 +476,25 @@ describe("Wolfx", () => {
await run;
});
});
+
+describe("つなぎ方 (受信の状態に出す)", () => {
+ test("WebSocket・SSE の情報源と、決まった間隔で取得する情報源", () => {
+ const { ctx } = context();
+ expect(p2pSource(ctx).status().transport).toEqual({ kind: "websocket" });
+ expect(wolfxSource(ctx).status().transport).toEqual({
+ kind: "websocket",
+ });
+ expect(emscSource(ctx).status().transport).toEqual({ kind: "websocket" });
+ expect(seisSource(new RtsBoard()).status().transport).toEqual({
+ kind: "websocket",
+ });
+ expect(tremSource(new RtsBoard()).status().transport).toEqual({
+ kind: "sse",
+ });
+ // 気象庁のフィードは 60 秒より短くしない
+ expect(jmaSource(ctx, { intervalMs: 1_000 }).status().transport).toEqual({
+ kind: "poll",
+ everyMs: 60_000,
+ });
+ });
+});