feat: add http vedio test

This commit is contained in:
alivender
2025-06-18 18:39:58 +08:00
parent 81f91b2b71
commit 4c14ada97b
8 changed files with 1365 additions and 13 deletions

View File

@@ -2189,3 +2189,144 @@ function throwException(message: string, status: number, response: string, heade
else
throw new ApiException(message, status, response, headers, null);
}
// VideoStreamClient - 手动添加用于HTTP视频流控制
export class VideoStreamClient {
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
private baseUrl: string;
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
this.http = http ? http : window as any;
this.baseUrl = baseUrl ?? "http://localhost:5000";
} /**
* 获取HTTP视频流服务状态
* @return HTTP视频流服务状态信息
*/
status(): Promise<any> {
let url_ = this.baseUrl + "/api/VideoStream/Status";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processStatus(_response);
});
}
protected processStatus(response: Response): Promise<any> {
const status = response.status;
let _headers: any = {};
if (response.headers && response.headers.forEach) {
response.headers.forEach((v: any, k: any) => _headers[k] = v);
}
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
return result200;
});
} else if (status === 500) {
return response.text().then((_responseText) => {
throw new Error(_responseText);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
throw new Error("未知的响应状态码: " + status + ", 响应文本: " + _responseText);
});
}
return Promise.resolve<any>(null as any);
} /**
* 获取HTTP视频流信息
* @return HTTP视频流信息
*/
streamInfo(): Promise<any> {
let url_ = this.baseUrl + "/api/VideoStream/StreamInfo";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processStreamInfo(_response);
});
}
protected processStreamInfo(response: Response): Promise<any> {
const status = response.status;
let _headers: any = {};
if (response.headers && response.headers.forEach) {
response.headers.forEach((v: any, k: any) => _headers[k] = v);
}
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
return result200;
});
} else if (status === 500) {
return response.text().then((_responseText) => {
throw new Error(_responseText);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
throw new Error("未知的响应状态码: " + status + ", 响应文本: " + _responseText);
});
}
return Promise.resolve<any>(null as any);
} /**
* 测试HTTP视频流连接
* @return 测试结果
*/
testConnection(): Promise<boolean> {
let url_ = this.baseUrl + "/api/VideoStream/TestConnection";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processTestConnection(_response);
});
}
protected processTestConnection(response: Response): Promise<boolean> {
const status = response.status;
let _headers: any = {};
if (response.headers && response.headers.forEach) {
response.headers.forEach((v: any, k: any) => _headers[k] = v);
}
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
return result200;
});
} else if (status === 500) {
return response.text().then((_responseText) => {
throw new Error(_responseText);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
throw new Error("未知的响应状态码: " + status + ", 响应文本: " + _responseText);
});
}
return Promise.resolve<boolean>(false);
}
}