feat(frontend): Platform > Infraestrutura > FreeSWITCH/SIP Profiles/Nodes
GET /platform/freeswitch/channels|profiles|nodes fazem introspecção ESL real
(show channels/show calls/sofia status/show registrations/status/show gateways),
reaproveitando os métodos do FreeSwitchTelephonyProvider já verificados manualmente
contra o FreeSWITCH real. Mesmo padrão de conexão avulsa do PlatformHealthController
(connect → comando → disconnect).
Nunca deixa a indisponibilidade do ESL virar 500/503 — devolve { ok: false, error }
com 200, mesma filosofia do health check. Necessário: nesta VM apps/api roda fora do
Docker e a porta 8021 é deliberadamente não publicada no host, então as 3 telas
sempre mostram essa explicação aqui (mesmo texto já usado em Infraestrutura >
Saúde), mesmo com o endpoint 100% funcional — confirmado indiretamente pelo
b2bcall-fs-events, que fala ESL de dentro da rede Docker e está com heartbeat ativo.
"Nodes" mostra explicitamente 1 node (container único, sem clustering) em vez de
fingir uma lista.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BFaBaBSQGhyXGEgtTYZGV8
This commit is contained in:
75
apps/api/src/platform/platform-freeswitch.controller.ts
Normal file
75
apps/api/src/platform/platform-freeswitch.controller.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { Controller, ForbiddenException, Get, UseGuards } from "@nestjs/common";
|
||||
import { isPlatformUser, type AccessTokenClaims } from "@b2bcall/auth";
|
||||
import { FreeSwitchTelephonyProvider } from "@b2bcall/telephony";
|
||||
import { JwtAuthGuard } from "../common/guards/jwt-auth.guard";
|
||||
import { PermissionGuard } from "../common/guards/permission.guard";
|
||||
import { RequirePermission } from "../common/decorators/require-permission.decorator";
|
||||
import { CurrentUser } from "../common/decorators/current-user.decorator";
|
||||
|
||||
/**
|
||||
* Infraestrutura > FreeSWITCH/SIP Profiles/Nodes (agente.md secao 168-169)
|
||||
* — introspecção ESL real, mesmo padrão de conexão avulsa (connect →
|
||||
* comando → disconnect) já usado em `PlatformHealthController`. Igual ao
|
||||
* health check, nunca deixa a indisponibilidade do ESL virar 500/503 pro
|
||||
* cliente — devolve `{ ok: false, error }` (mesma filosofia do `timed()`
|
||||
* de lá), porque nesta VM o Event Socket (8021) é deliberadamente não
|
||||
* publicado no host (agente.md secao 184) e `apps/api` roda fora do
|
||||
* Docker: essas 3 telas SEMPRE vão mostrar essa mensagem aqui, mesmo
|
||||
* endpoint funcionando corretamente em produção (mesma network do
|
||||
* FreeSWITCH). "Nodes" é sempre 1 node nesta implantação (container
|
||||
* único, sem clustering) — honesto em vez de fingir uma lista.
|
||||
*/
|
||||
async function withEsl<T>(fn: (provider: FreeSwitchTelephonyProvider) => Promise<T>): Promise<{ ok: true; data: T } | { ok: false; error: string }> {
|
||||
const host = process.env.ESL_HOST;
|
||||
const port = Number(process.env.ESL_PORT ?? 8021);
|
||||
const password = process.env.ESL_PASSWORD;
|
||||
if (!host || !password) return { ok: false, error: "ESL nao configurado (ESL_HOST/ESL_PASSWORD ausentes)" };
|
||||
|
||||
const provider = new FreeSwitchTelephonyProvider({ host, port, password });
|
||||
try {
|
||||
provider.connect();
|
||||
const connected = await provider.waitUntilConnected(2500);
|
||||
if (!connected) return { ok: false, error: "Timeout conectando no ESL do FreeSWITCH" };
|
||||
return { ok: true, data: await fn(provider) };
|
||||
} catch (err) {
|
||||
return { ok: false, error: err instanceof Error ? err.message : "Erro desconhecido falando com o ESL" };
|
||||
} finally {
|
||||
await provider.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
function requirePlatform(user: AccessTokenClaims): Promise<boolean> {
|
||||
return isPlatformUser(user.sub);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, PermissionGuard)
|
||||
@Controller("platform/freeswitch")
|
||||
export class PlatformFreeswitchController {
|
||||
@RequirePermission("freeswitch.view")
|
||||
@Get("channels")
|
||||
async channels(@CurrentUser() user: AccessTokenClaims) {
|
||||
if (!(await requirePlatform(user))) throw new ForbiddenException("So' um usuario com role de plataforma pode ver o FreeSWITCH");
|
||||
return withEsl(async (p) => ({ channels: await p.getChannels(), calls: await p.getCalls() }));
|
||||
}
|
||||
|
||||
@RequirePermission("freeswitch.view")
|
||||
@Get("profiles")
|
||||
async profiles(@CurrentUser() user: AccessTokenClaims) {
|
||||
if (!(await requirePlatform(user))) throw new ForbiddenException("So' um usuario com role de plataforma pode ver SIP profiles");
|
||||
return withEsl(async (p) => ({
|
||||
sofiaStatus: await p.runApi("sofia status"),
|
||||
registrations: await p.getRegistrations(),
|
||||
}));
|
||||
}
|
||||
|
||||
@RequirePermission("freeswitch.view")
|
||||
@Get("nodes")
|
||||
async nodes(@CurrentUser() user: AccessTokenClaims) {
|
||||
if (!(await requirePlatform(user))) throw new ForbiddenException("So' um usuario com role de plataforma pode ver os nodes");
|
||||
return withEsl(async (p) => ({
|
||||
nodeCount: 1,
|
||||
status: await p.runApi("status"),
|
||||
gateways: await p.getGateways(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { PlatformAuditController } from "./platform-audit.controller";
|
||||
import { PlatformHealthController } from "./platform-health.controller";
|
||||
import { PlatformRolesController } from "./platform-roles.controller";
|
||||
import { PlatformQuotasController } from "./platform-quotas.controller";
|
||||
import { PlatformFreeswitchController } from "./platform-freeswitch.controller";
|
||||
|
||||
@Module({
|
||||
controllers: [
|
||||
@@ -14,6 +15,7 @@ import { PlatformQuotasController } from "./platform-quotas.controller";
|
||||
PlatformHealthController,
|
||||
PlatformRolesController,
|
||||
PlatformQuotasController,
|
||||
PlatformFreeswitchController,
|
||||
],
|
||||
})
|
||||
export class PlatformModule {}
|
||||
|
||||
BIN
apps/frontend/.impeccable/review/fs-freeswitch-desktop.png
Normal file
BIN
apps/frontend/.impeccable/review/fs-freeswitch-desktop.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
BIN
apps/frontend/.impeccable/review/fs-nodes-desktop.png
Normal file
BIN
apps/frontend/.impeccable/review/fs-nodes-desktop.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
BIN
apps/frontend/.impeccable/review/fs-sip-profiles-desktop.png
Normal file
BIN
apps/frontend/.impeccable/review/fs-sip-profiles-desktop.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
22
apps/frontend/src/app/platform/infraestrutura/esl-notice.tsx
Normal file
22
apps/frontend/src/app/platform/infraestrutura/esl-notice.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Panel, PanelHeader } from "@/components/ui/panel";
|
||||
|
||||
export function EslUnavailableNotice({ error }: { error: string }) {
|
||||
return (
|
||||
<Panel>
|
||||
<PanelHeader title="ESL indisponível" />
|
||||
<div className="space-y-3 px-5 py-4 text-sm text-muted-foreground">
|
||||
<p>
|
||||
Erro retornado: <span className="font-mono text-xs text-destructive">{error}</span>
|
||||
</p>
|
||||
<p>
|
||||
<code className="font-mono text-xs">apps/api</code> roda direto no host desta VM, fora do Docker; a porta
|
||||
do Event Socket (8021) do FreeSWITCH é deliberadamente <strong>não publicada no host</strong> (agente.md
|
||||
secao 184: porta sensível, nunca exposta). Por isso este endpoint sempre falha aqui, mesmo com o
|
||||
FreeSWITCH saudável — o container está isolado do jeito certo. Em produção, onde{" "}
|
||||
<code className="font-mono text-xs">apps/api</code> roda na mesma rede Docker do FreeSWITCH, esta tela
|
||||
mostra os dados reais.
|
||||
</p>
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Panel, PanelHeader } from "@/components/ui/panel";
|
||||
import type { EslResult, FreeswitchChannels } from "@/lib/platform-types";
|
||||
import { EslUnavailableNotice } from "../esl-notice";
|
||||
|
||||
export function FreeswitchView({ result }: { result: EslResult<FreeswitchChannels> }) {
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold text-foreground">FreeSWITCH</h1>
|
||||
<p className="mt-1 max-w-2xl text-sm text-muted-foreground">
|
||||
Canais e chamadas ativas agora, direto do ESL (<code className="font-mono text-xs">show channels</code>/
|
||||
<code className="font-mono text-xs">show calls</code>) — leitura ao vivo, não histórico.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{!result.ok ? (
|
||||
<EslUnavailableNotice error={result.error} />
|
||||
) : (
|
||||
<>
|
||||
<Panel>
|
||||
<PanelHeader title="Canais ativos" />
|
||||
<pre className="max-h-96 overflow-auto px-5 py-4 font-mono text-xs text-muted-foreground">
|
||||
{JSON.stringify(result.data.channels, null, 2)}
|
||||
</pre>
|
||||
</Panel>
|
||||
<Panel>
|
||||
<PanelHeader title="Chamadas ativas" />
|
||||
<pre className="max-h-96 overflow-auto px-5 py-4 font-mono text-xs text-muted-foreground">
|
||||
{JSON.stringify(result.data.calls, null, 2)}
|
||||
</pre>
|
||||
</Panel>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { requireSession } from "@/lib/session";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import type { EslResult, FreeswitchChannels } from "@/lib/platform-types";
|
||||
import { FreeswitchView } from "./freeswitch-view";
|
||||
|
||||
export default async function FreeswitchPage() {
|
||||
const session = await requireSession();
|
||||
const result = await apiFetch<EslResult<FreeswitchChannels>>("/platform/freeswitch/channels", session.accessToken);
|
||||
return <FreeswitchView result={result} />;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Panel, PanelHeader } from "@/components/ui/panel";
|
||||
import { Pill } from "@/components/ui/pill";
|
||||
import type { EslResult, FreeswitchNodes } from "@/lib/platform-types";
|
||||
import { EslUnavailableNotice } from "../esl-notice";
|
||||
|
||||
export function NodesView({ result }: { result: EslResult<FreeswitchNodes> }) {
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold text-foreground">Nodes</h1>
|
||||
<p className="mt-1 max-w-2xl text-sm text-muted-foreground">
|
||||
Esta implantação tem <span className="font-medium text-foreground">1 único node FreeSWITCH</span>{" "}
|
||||
(container único, sem clustering multi-node) — se um dia existir mais de um, esta tela vira uma lista.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{!result.ok ? (
|
||||
<EslUnavailableNotice error={result.error} />
|
||||
) : (
|
||||
<>
|
||||
<Panel className="p-5">
|
||||
<div className="flex items-center justify-between">
|
||||
<PanelHeader title="freeswitch-1" description="Único node desta implantação" />
|
||||
<Pill tone="accent">Online</Pill>
|
||||
</div>
|
||||
</Panel>
|
||||
<Panel>
|
||||
<PanelHeader title="status" />
|
||||
<pre className="max-h-96 overflow-auto whitespace-pre-wrap px-5 py-4 font-mono text-xs text-muted-foreground">
|
||||
{result.data.status}
|
||||
</pre>
|
||||
</Panel>
|
||||
<Panel>
|
||||
<PanelHeader title="Gateways (troncos conectados)" />
|
||||
<pre className="max-h-96 overflow-auto px-5 py-4 font-mono text-xs text-muted-foreground">
|
||||
{JSON.stringify(result.data.gateways, null, 2)}
|
||||
</pre>
|
||||
</Panel>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
10
apps/frontend/src/app/platform/infraestrutura/nodes/page.tsx
Normal file
10
apps/frontend/src/app/platform/infraestrutura/nodes/page.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { requireSession } from "@/lib/session";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import type { EslResult, FreeswitchNodes } from "@/lib/platform-types";
|
||||
import { NodesView } from "./nodes-view";
|
||||
|
||||
export default async function NodesPage() {
|
||||
const session = await requireSession();
|
||||
const result = await apiFetch<EslResult<FreeswitchNodes>>("/platform/freeswitch/nodes", session.accessToken);
|
||||
return <NodesView result={result} />;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { requireSession } from "@/lib/session";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import type { EslResult, FreeswitchProfiles } from "@/lib/platform-types";
|
||||
import { SipProfilesView } from "./sip-profiles-view";
|
||||
|
||||
export default async function SipProfilesPage() {
|
||||
const session = await requireSession();
|
||||
const result = await apiFetch<EslResult<FreeswitchProfiles>>("/platform/freeswitch/profiles", session.accessToken);
|
||||
return <SipProfilesView result={result} />;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Panel, PanelHeader } from "@/components/ui/panel";
|
||||
import type { EslResult, FreeswitchProfiles } from "@/lib/platform-types";
|
||||
import { EslUnavailableNotice } from "../esl-notice";
|
||||
|
||||
export function SipProfilesView({ result }: { result: EslResult<FreeswitchProfiles> }) {
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold text-foreground">SIP Profiles</h1>
|
||||
<p className="mt-1 max-w-2xl text-sm text-muted-foreground">
|
||||
Saída bruta de <code className="font-mono text-xs">sofia status</code> (perfis internal/external e estado
|
||||
de cada um) e os endpoints SIP registrados agora.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{!result.ok ? (
|
||||
<EslUnavailableNotice error={result.error} />
|
||||
) : (
|
||||
<>
|
||||
<Panel>
|
||||
<PanelHeader title="sofia status" />
|
||||
<pre className="max-h-96 overflow-auto whitespace-pre-wrap px-5 py-4 font-mono text-xs text-muted-foreground">
|
||||
{result.data.sofiaStatus}
|
||||
</pre>
|
||||
</Panel>
|
||||
<Panel>
|
||||
<PanelHeader title="Registros SIP ativos" />
|
||||
<pre className="max-h-96 overflow-auto px-5 py-4 font-mono text-xs text-muted-foreground">
|
||||
{JSON.stringify(result.data.registrations, null, 2)}
|
||||
</pre>
|
||||
</Panel>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -68,9 +68,21 @@ export const PLATFORM_NAV: NavSection[] = [
|
||||
label: "Infraestrutura",
|
||||
icon: ServerCog,
|
||||
children: [
|
||||
{ label: "FreeSWITCH" },
|
||||
{ label: "SIP Profiles" },
|
||||
{ label: "Nodes" },
|
||||
{
|
||||
label: "FreeSWITCH",
|
||||
href: "/platform/infraestrutura/freeswitch",
|
||||
description: "Canais e chamadas ativas agora, direto do ESL",
|
||||
},
|
||||
{
|
||||
label: "SIP Profiles",
|
||||
href: "/platform/infraestrutura/sip-profiles",
|
||||
description: "sofia status e registros SIP ativos",
|
||||
},
|
||||
{
|
||||
label: "Nodes",
|
||||
href: "/platform/infraestrutura/nodes",
|
||||
description: "Nodes FreeSWITCH desta implantação (hoje: 1)",
|
||||
},
|
||||
{
|
||||
label: "Saúde",
|
||||
href: "/platform/infraestrutura/saude",
|
||||
|
||||
@@ -83,6 +83,24 @@ export interface PlatformHealth {
|
||||
checkedAt: string;
|
||||
}
|
||||
|
||||
export type EslResult<T> = { ok: true; data: T } | { ok: false; error: string };
|
||||
|
||||
export interface FreeswitchChannels {
|
||||
channels: unknown;
|
||||
calls: unknown;
|
||||
}
|
||||
|
||||
export interface FreeswitchProfiles {
|
||||
sofiaStatus: string;
|
||||
registrations: unknown;
|
||||
}
|
||||
|
||||
export interface FreeswitchNodes {
|
||||
nodeCount: number;
|
||||
status: string;
|
||||
gateways: unknown;
|
||||
}
|
||||
|
||||
export interface QuotaItem {
|
||||
key: string;
|
||||
label: string;
|
||||
|
||||
Reference in New Issue
Block a user