我正在开发Angular应用程序,而我的HTTP get遇到了一些麻烦。我使HTTP每70毫秒获取一次,但由于某种原因,我总是有一个或多个未决。我想知道是否有办法跳过那些待处理的请求,或者是否可以设置超时?
这是我的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;
});
}