refactor: 视频流前后端适配
This commit is contained in:
323
src/APIClient.ts
323
src/APIClient.ts
@@ -129,8 +129,8 @@ export class VideoStreamClient {
|
||||
* 获取 HTTP 视频流服务状态
|
||||
* @return 服务状态信息
|
||||
*/
|
||||
getStatus( cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/Status";
|
||||
getServiceStatus( cancelToken?: CancelToken): Promise<VideoStreamServiceStatus> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/ServiceStatus";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
@@ -149,11 +149,11 @@ export class VideoStreamClient {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetStatus(_response);
|
||||
return this.processGetServiceStatus(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetStatus(response: AxiosResponse): Promise<any> {
|
||||
protected processGetServiceStatus(response: AxiosResponse): Promise<VideoStreamServiceStatus> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
@@ -167,9 +167,8 @@ export class VideoStreamClient {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
result200 = VideoStreamServiceStatus.fromJS(resultData200);
|
||||
return Promise.resolve<VideoStreamServiceStatus>(result200);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
@@ -182,10 +181,10 @@ export class VideoStreamClient {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
return Promise.resolve<VideoStreamServiceStatus>(null as any);
|
||||
}
|
||||
|
||||
myEndpoint( cancelToken?: CancelToken): Promise<any> {
|
||||
myEndpoint( cancelToken?: CancelToken): Promise<VideoStreamEndpoint> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/MyEndpoint";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
@@ -209,7 +208,7 @@ export class VideoStreamClient {
|
||||
});
|
||||
}
|
||||
|
||||
protected processMyEndpoint(response: AxiosResponse): Promise<any> {
|
||||
protected processMyEndpoint(response: AxiosResponse): Promise<VideoStreamEndpoint> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
@@ -223,9 +222,8 @@ export class VideoStreamClient {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
result200 = VideoStreamEndpoint.fromJS(resultData200);
|
||||
return Promise.resolve<VideoStreamEndpoint>(result200);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
@@ -238,7 +236,7 @@ export class VideoStreamClient {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
return Promise.resolve<VideoStreamEndpoint>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,8 +299,12 @@ export class VideoStreamClient {
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
disableHdmiTransmission( cancelToken?: CancelToken): Promise<FileResponse | null> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/DisableTransmission";
|
||||
setVideoStreamEnable(enable: boolean | undefined, cancelToken?: CancelToken): Promise<FileResponse | null> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/SetVideoStreamEnable?";
|
||||
if (enable === null)
|
||||
throw new Error("The parameter 'enable' cannot be null.");
|
||||
else if (enable !== undefined)
|
||||
url_ += "enable=" + encodeURIComponent("" + enable) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
@@ -322,11 +324,11 @@ export class VideoStreamClient {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processDisableHdmiTransmission(_response);
|
||||
return this.processSetVideoStreamEnable(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDisableHdmiTransmission(response: AxiosResponse): Promise<FileResponse | null> {
|
||||
protected processSetVideoStreamEnable(response: AxiosResponse): Promise<FileResponse | null> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
@@ -432,7 +434,7 @@ export class VideoStreamClient {
|
||||
* 获取支持的分辨率列表
|
||||
* @return 支持的分辨率列表
|
||||
*/
|
||||
getSupportedResolutions( cancelToken?: CancelToken): Promise<any> {
|
||||
getSupportedResolutions( cancelToken?: CancelToken): Promise<AvailableResolutionsResponse[]> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/SupportedResolutions";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
@@ -456,7 +458,7 @@ export class VideoStreamClient {
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetSupportedResolutions(response: AxiosResponse): Promise<any> {
|
||||
protected processGetSupportedResolutions(response: AxiosResponse): Promise<AvailableResolutionsResponse[]> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
@@ -470,9 +472,15 @@ export class VideoStreamClient {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
if (Array.isArray(resultData200)) {
|
||||
result200 = [] as any;
|
||||
for (let item of resultData200)
|
||||
result200!.push(AvailableResolutionsResponse.fromJS(item));
|
||||
}
|
||||
else {
|
||||
result200 = <any>null;
|
||||
}
|
||||
return Promise.resolve<AvailableResolutionsResponse[]>(result200);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
@@ -486,7 +494,7 @@ export class VideoStreamClient {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
return Promise.resolve<AvailableResolutionsResponse[]>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -626,6 +634,74 @@ export class VideoStreamClient {
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置摄像头连接参数
|
||||
* @return 配置结果
|
||||
*/
|
||||
configureCamera( cancelToken?: CancelToken): Promise<any> {
|
||||
let url_ = this.baseUrl + "/api/VideoStream/ConfigureCamera";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processConfigureCamera(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processConfigureCamera(response: AxiosResponse): Promise<any> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<any>(result200);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
let result500: any = null;
|
||||
let resultData500 = _responseText;
|
||||
result500 = Exception.fromJS(resultData500);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<any>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class BsdlParserClient {
|
||||
@@ -6927,6 +7003,157 @@ export class UDPClient {
|
||||
}
|
||||
}
|
||||
|
||||
/** 表示视频流服务的运行状态 */
|
||||
export class VideoStreamServiceStatus implements IVideoStreamServiceStatus {
|
||||
/** 服务是否正在运行 */
|
||||
isRunning!: boolean;
|
||||
/** 服务监听的端口号 */
|
||||
serverPort!: number;
|
||||
/** 当前连接的客户端端点列表 */
|
||||
clientEndpoints!: VideoStreamEndpoint[];
|
||||
/** 当前连接的客户端数量 */
|
||||
connectedClientsNum!: number;
|
||||
|
||||
constructor(data?: IVideoStreamServiceStatus) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
if (!data) {
|
||||
this.clientEndpoints = [];
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.isRunning = _data["isRunning"];
|
||||
this.serverPort = _data["serverPort"];
|
||||
if (Array.isArray(_data["clientEndpoints"])) {
|
||||
this.clientEndpoints = [] as any;
|
||||
for (let item of _data["clientEndpoints"])
|
||||
this.clientEndpoints!.push(VideoStreamEndpoint.fromJS(item));
|
||||
}
|
||||
this.connectedClientsNum = _data["connectedClientsNum"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): VideoStreamServiceStatus {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new VideoStreamServiceStatus();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["isRunning"] = this.isRunning;
|
||||
data["serverPort"] = this.serverPort;
|
||||
if (Array.isArray(this.clientEndpoints)) {
|
||||
data["clientEndpoints"] = [];
|
||||
for (let item of this.clientEndpoints)
|
||||
data["clientEndpoints"].push(item ? item.toJSON() : <any>undefined);
|
||||
}
|
||||
data["connectedClientsNum"] = this.connectedClientsNum;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** 表示视频流服务的运行状态 */
|
||||
export interface IVideoStreamServiceStatus {
|
||||
/** 服务是否正在运行 */
|
||||
isRunning: boolean;
|
||||
/** 服务监听的端口号 */
|
||||
serverPort: number;
|
||||
/** 当前连接的客户端端点列表 */
|
||||
clientEndpoints: VideoStreamEndpoint[];
|
||||
/** 当前连接的客户端数量 */
|
||||
connectedClientsNum: number;
|
||||
}
|
||||
|
||||
/** 表示摄像头连接状态信息 */
|
||||
export class VideoStreamEndpoint implements IVideoStreamEndpoint {
|
||||
boardId!: string;
|
||||
mjpegUrl!: string;
|
||||
videoUrl!: string;
|
||||
snapshotUrl!: string;
|
||||
htmlUrl!: string;
|
||||
usbCameraUrl!: string;
|
||||
isEnabled!: boolean;
|
||||
/** 视频流的帧率(FPS) */
|
||||
frameRate!: number;
|
||||
frameWidth!: number;
|
||||
frameHeight!: number;
|
||||
/** 视频分辨率(如 640x480) */
|
||||
resolution!: string;
|
||||
|
||||
constructor(data?: IVideoStreamEndpoint) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.boardId = _data["boardId"];
|
||||
this.mjpegUrl = _data["mjpegUrl"];
|
||||
this.videoUrl = _data["videoUrl"];
|
||||
this.snapshotUrl = _data["snapshotUrl"];
|
||||
this.htmlUrl = _data["htmlUrl"];
|
||||
this.usbCameraUrl = _data["usbCameraUrl"];
|
||||
this.isEnabled = _data["isEnabled"];
|
||||
this.frameRate = _data["frameRate"];
|
||||
this.frameWidth = _data["frameWidth"];
|
||||
this.frameHeight = _data["frameHeight"];
|
||||
this.resolution = _data["resolution"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): VideoStreamEndpoint {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new VideoStreamEndpoint();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["boardId"] = this.boardId;
|
||||
data["mjpegUrl"] = this.mjpegUrl;
|
||||
data["videoUrl"] = this.videoUrl;
|
||||
data["snapshotUrl"] = this.snapshotUrl;
|
||||
data["htmlUrl"] = this.htmlUrl;
|
||||
data["usbCameraUrl"] = this.usbCameraUrl;
|
||||
data["isEnabled"] = this.isEnabled;
|
||||
data["frameRate"] = this.frameRate;
|
||||
data["frameWidth"] = this.frameWidth;
|
||||
data["frameHeight"] = this.frameHeight;
|
||||
data["resolution"] = this.resolution;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** 表示摄像头连接状态信息 */
|
||||
export interface IVideoStreamEndpoint {
|
||||
boardId: string;
|
||||
mjpegUrl: string;
|
||||
videoUrl: string;
|
||||
snapshotUrl: string;
|
||||
htmlUrl: string;
|
||||
usbCameraUrl: string;
|
||||
isEnabled: boolean;
|
||||
/** 视频流的帧率(FPS) */
|
||||
frameRate: number;
|
||||
frameWidth: number;
|
||||
frameHeight: number;
|
||||
/** 视频分辨率(如 640x480) */
|
||||
resolution: string;
|
||||
}
|
||||
|
||||
export class Exception implements IException {
|
||||
declare message: string;
|
||||
innerException?: Exception | undefined;
|
||||
@@ -7021,6 +7248,54 @@ export interface IResolutionConfigRequest {
|
||||
height: number;
|
||||
}
|
||||
|
||||
export class AvailableResolutionsResponse implements IAvailableResolutionsResponse {
|
||||
width!: number;
|
||||
height!: number;
|
||||
name!: string;
|
||||
value!: string;
|
||||
|
||||
constructor(data?: IAvailableResolutionsResponse) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.width = _data["width"];
|
||||
this.height = _data["height"];
|
||||
this.name = _data["name"];
|
||||
this.value = _data["value"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): AvailableResolutionsResponse {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new AvailableResolutionsResponse();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["width"] = this.width;
|
||||
data["height"] = this.height;
|
||||
data["name"] = this.name;
|
||||
data["value"] = this.value;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IAvailableResolutionsResponse {
|
||||
width: number;
|
||||
height: number;
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class ProblemDetails implements IProblemDetails {
|
||||
type?: string | undefined;
|
||||
title?: string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user