Files
gamestream-webtransport-proxy/frontend/src/routes/getStreamData.ts
T

60 lines
1.3 KiB
TypeScript

type StreamData = {
Url: string,
CertHash: Array<number>,
Width: number,
Height: number,
}
export async function getStreamData(appId: number, server_name: string): Promise<StreamData> {
try {
// Create the POST request payload
const width = 1920;
const height = 1080;
const payload = {
id: appId,
server: server_name,
server_mode: {
fps: 60,
width: width,
height: height,
},
stream_config: {
bitrate_kbps: 1024 * 10 * 5,
mode: {
fps: 60,
width: width,
height: height,
}
}
};
// Make POST request to start stream
const response = await fetch('/api/stream/start', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}: ${await response.text()}`);
}
const streamDataResp = await response.json();
console.log('Stream started:', streamDataResp);
let streamData: StreamData = { Url: streamDataResp.url, CertHash: streamDataResp.cert_hash, Width: width, Height: height };
return streamData;
} catch (error) {
console.error('Error getting stream data: ', error);
throw new Error('Failed to start stream: ' + error);
}
}