首页 > 解决方案 > 以角度结束http请求

问题描述

我正在开发一个 Angular 应用程序,但我的 HTTP 获取遇到了一些问题。我每 70 毫秒获取一次 HTTP,但由于某种原因,我总是有一个或多个未决。我想知道是否有一种方法可以跳过那些待处理的请求,或者我是否可以设置超时?

这是我的 HTTP 获取:

public getData(): Observable<any> {
   return this.httpClient.get('http://IP_ADRESS:3490/testStream', {responseType: 'arraybuffer'});
}

public putData(): void {
   this.canChangePicture = false;
   let comp: number;
   this.getData().subscribe((resp) => {
     console.log(resp);
     const responseArray: Uint8ClampedArray = new Uint8ClampedArray(resp);
     const newTabTemp: Uint8ClampedArray = new Uint8ClampedArray(this.maxHeight * this.maxWidth * 4);
     comp = 0;
     for (let i = 0; i < this.maxHeight * this.maxWidth * 4; i = i + 4) {
       newTabTemp[i] = responseArray[comp];
       newTabTemp[i + 1] = responseArray[comp];
       newTabTemp[i + 2] = responseArray[comp];
       newTabTemp[i + 3] = 255;
       comp = comp + 1;
     }
     let nouvData: ImageData;
     nouvData = new ImageData(newTabTemp, this.maxWidth, this.maxHeight);
     this.contextVideo.putImageData(nouvData, BORDERX / 2, BORDERY / 2);
     this.canChangePicture = true;
   });
}

标签: javascriptangulartypescripthttpget

解决方案


推荐阅读