feat: add per-port SCTE35 inject to useRecorder hook
This commit is contained in:
parent
fd4c364144
commit
e39241d7b1
1 changed files with 47 additions and 31 deletions
|
|
@ -13,18 +13,13 @@ export function useRecorder() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE}/ports/${portIndex}/start`, {
|
const response = await fetch(`${API_BASE}/ports/${portIndex}/start`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(config),
|
body: JSON.stringify(config),
|
||||||
});
|
});
|
||||||
|
if (!response.ok) throw new Error(`Failed to start recording: ${response.statusText}`);
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to start recording: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
const msg = err instanceof Error ? err.message : 'Unknown error';
|
||||||
setError(errorMessage);
|
setError(msg);
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
@ -37,23 +32,19 @@ export function useRecorder() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE}/ports/${portIndex}/stop`, {
|
const response = await fetch(`${API_BASE}/ports/${portIndex}/stop`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
if (!response.ok) throw new Error(`Failed to stop recording: ${response.statusText}`);
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to stop recording: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
const msg = err instanceof Error ? err.message : 'Unknown error';
|
||||||
setError(errorMessage);
|
setError(msg);
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Global SCTE35 inject (hits all SRT outputs) */
|
||||||
const injectSCTE35 = async (
|
const injectSCTE35 = async (
|
||||||
eventId: number,
|
eventId: number,
|
||||||
durationSeconds: number,
|
durationSeconds: number,
|
||||||
|
|
@ -64,30 +55,55 @@ export function useRecorder() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE}/scte35/inject`, {
|
const response = await fetch(`${API_BASE}/scte35/inject`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
event_id: eventId,
|
event_id: eventId,
|
||||||
duration_seconds: durationSeconds,
|
duration_seconds: durationSeconds,
|
||||||
webhook_url: webhookUrl || null,
|
webhook_url: webhookUrl || null,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
if (!response.ok) throw new Error(`Failed to inject SCTE35: ${response.statusText}`);
|
||||||
if (!response.ok) {
|
return await response.json() as SCTE35Marker;
|
||||||
throw new Error(`Failed to inject SCTE35 marker: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data: SCTE35Marker = await response.json();
|
|
||||||
return data;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
const msg = err instanceof Error ? err.message : 'Unknown error';
|
||||||
setError(errorMessage);
|
setError(msg);
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { startRecording, stopRecording, injectSCTE35, loading, error };
|
/** Per-port SCTE35 inject — targets a specific port's SRT output(s) */
|
||||||
|
const injectSCTE35ForPort = async (
|
||||||
|
portIndex: number,
|
||||||
|
eventId: number,
|
||||||
|
durationSeconds: number,
|
||||||
|
srtDestinationUrl?: string,
|
||||||
|
webhookUrl?: string
|
||||||
|
): Promise<SCTE35Marker | null> => {
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE}/ports/${portIndex}/scte35/inject`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
event_id: eventId,
|
||||||
|
duration_seconds: durationSeconds,
|
||||||
|
webhook_url: webhookUrl || null,
|
||||||
|
srt_destination_url: srtDestinationUrl || null,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error(`Failed to inject SCTE35 on port ${portIndex}: ${response.statusText}`);
|
||||||
|
return await response.json() as SCTE35Marker;
|
||||||
|
} catch (err) {
|
||||||
|
const msg = err instanceof Error ? err.message : 'Unknown error';
|
||||||
|
setError(msg);
|
||||||
|
throw err;
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { startRecording, stopRecording, injectSCTE35, injectSCTE35ForPort, loading, error };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue