Troubleshooting Angular's HTTP Get Functionality

Currently, I am developing an application where the client is built using Angular and the server is in C. I am facing an issue with my HTTP Get method but unable to pinpoint the problem. The function "updateStream()" is invoked every 70 milliseconds.

public updateStream(): void {
   if (this.isVideoRunning && this.canChangePicture) {
     console.log('put is called');
     this.putData();
   }
}

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

public putData(): void {
   console.log('put function');
   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;
  });
}

The issue that I encountered was that my canvas content was rarely changing. To troubleshoot, I added some "console.log" statements and realized that my program was failing to enter the "this.getData().subscribe()..." block after a few requests.

https://i.sstatic.net/3JT0u.png

Despite consistently entering the "putData()" function, it was skipping the "this.getData().subscribe()..." block. What could be causing this behavior in my code and how can I resolve it?

EDIT:

Screenshot of the pending request https://i.sstatic.net/Kt0vj.png timing tab: https://i.sstatic.net/IvU89.png Request/response https://i.sstatic.net/qndUD.png

Answer №1

By selecting a request in the network tab, you can investigate why it is currently Pending.

In case the request is stalled, Chrome may have queued it for processing. To learn more about stalling and how to address this issue, visit this resource

If the server is not responding, it's recommended to check the backend for any issues.

Under certain conditions, consider invoking updateStream() after the previous operation has finished executing.

Alternatively, if suitable for your requirements, you might want to explore using Websockets or SSE for faster communication compared to traditional HTTP methods.

Answer №2

You have a total of 3 console.log statements in your code.

  1. There is a console.log statement inside the updateStream function that logs 'put is called'.
  2. Another console.log statement can be found in the putData function, which logs 'put function'.
  3. The third console.log statement logs the response (resp) inside the getData.Subscribe() method.

Upon inspecting your console.log outputs, I noticed an Observable <ArrayBuffer> data type being logged.

This suggests that your HttpClient request and response are functioning correctly.

Could you demonstrate this response in Chrome Dev Tools for further analysis?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with absolute import in React TypeScript application

An error occurs when trying to import a module, displaying the following message: Compiled with problems: × ERROR in ./src/App.tsx 5:0-33 Module not found: Error: Can't resolve 'routes' in 'F:\Tamrinat\Porfolio\microsite ...

Detecting unutilized space in a collection of divs with varying sizes using JavaScript and CSS

To better understand my issue, I created a StackBlitz demo: https://stackblitz.com/edit/angular-aqmahw?file=src/app/tiles-example.css Screenshot My tiles can have four different widths (25%, 50%, 75%, 100%). The tiles must fit on only two lines, so if a ...

Create a new data structure that generates a different type of generic data

I'm struggling to find the right words, so I'll provide an illustration: // For observables type UnwrappedObs<T> = T extends Observable<infer T> ? T : never; // For promises type UnwrappedPro<T> = T extends PromiseLike<infer ...

Guide to setting up a foundational observer class in Typescript/React

In my React app, I have a recurring pattern where multiple components observe the same model. Each component has code that resembles the following: export interface IAppModel { someLocation: { x: number, y: number } ; doSomething: () => void; } ...

The attribute 'fromHTML' is not recognized within the structure of 'jsPDF' object

When attempting to convert an HTML code to a PDF using jsPDF, I encountered an issue. Despite trying to use the recommended jsPDF.fromHTML() function, I received an error message stating: "Property 'fromHTML' does not exist on type 'jsPDF&ap ...

Forming a distinct array from a collection of objects

Describing demoList: demoList = [ { id: 1, validFrom: "2019-06-01T00:00:00", validTo: "2020-06-17T00:00:00", xxxM: 50, xxxN: 2.2, xxxQ45: 2, xxxQ100: 1.65, xxxQ125: null, xxxQ150: null, xxxQ2 ...

Using Selenium WebDriver with JavaScript: Handling Mouse Events (mouseover, click, keyup) in Selenium WebDriver

I am currently working on integrating Selenium testing for mouse events with dynamically generated elements. Specifically, I am attempting to trigger a "mouseover" event on an element and then interact with some icons within it. However, I have encountere ...

What is the best way to change a blob into a base64 format using Node.js with TypeScript?

When making an internal call to a MicroService in Node.js with TypeScript, I am receiving a blob image as the response. My goal is to convert this blob image into Base64 format so that I can use it to display it within an EJS image tag. I attempted to ach ...

Step-by-step guide to rapidly resolve all issues in VS Code using TypeScript

After extensive searching in VS code, I have not been able to find a quick fix all solution in the documentation or plugins. Is this feature actually non-existent, or is it possible that I am overlooking a keybinding? (I am currently utilizing typescript s ...

Issue occurred when trying to load controllers during the migration process from AngularJS1 to Angular6

Currently, I am in the process of upgrading AngularJS1 components to Angular6. My strategy involves creating wrappers for all existing AngularJS1 components by extending "UpgradeComponent" and storing them under the folder "directive-wrappers". However, wh ...

There seems to be an issue with compiling Typescript on a particular machine

My small project compiles perfectly on my home machine, but I encounter hundreds of errors when trying to compile it on another PC. The only noticeable difference in the environment is that the problematic PC is running Windows 8 (machines running Windows ...

Utilizing both POST and GET methods in AsyncTask when sending HTTP requests

I am currently in the process of developing an application that involves retrieving data from a server through various steps: Step 1: Initiate a request via Http POST to a specific URL with predefined header content. Step 2: Receive a partial link as a r ...

What is the best way to save a Map for future use in different components?

Let's say I define an enum like this: export enum SomeEnum { SomeLongName = 1, AnotherName = 2 } Within my display components, I'm utilizing an enum map to translate the enum values into strings for presentation on the web app: enumMap = new Map ...

Encountering difficulty importing TypeScript files dynamically within a Deno executable

When attempting to import a file from aws in an exe using its public link based on user input, I am facing difficulties For example, I generated my exe with the command below deno compile --allow-all main.ts Users execute this exe using commands like ./e ...

Angular 14 struggles with Bootstrap installation

I encountered an issue while trying to install Bootstrap in Angular 14 using "ng add @ng-bootstrap/ng-bootstrap" in PhpStorm IDEA. How can I resolve this error situation? Error Error ...

Error encountered during Ionic iOS build caused by google-plus plugin

Seeking solution for the error below, unsure where to begin. While attempting to compile my Ionic project for iOS, encountering the following issue: $ ionic cordova build ios .... /Plugins/cordova-plugin-googleplus/GooglePlus.h:2:9: fatal error: 'Goog ...

Assigning a default value to an HTML datepicker in Angular

I've been struggling to set a default value for the date picker using [(ngModel)]. I've tried various methods but none have worked so far. Here's my HTML: <input id="START_DATE" type="datetime-local" [(ngModel)]="startDate"/> Althou ...

Accessing Angular2 form validation: receive a reference to ngForm

I'm trying to figure out how to have a reference to "myform" in the component. Is there a way to do this without using a formbuilder? I'd like to avoid that if possible. <form #myForm="ngForm"> <label class="col-sm-12" [class.ng-i ...

Error encountered while installing node modules within an angular workspace

Currently, I am facing an issue with my workspace where the command npm install is giving me a series of errors that I cannot seem to resolve. I have tried running it as an admin, manually deleting the node_modules folder, asking for help from a senior col ...

Exploring the power of Angular 4's Observable forkJoin with Arrays

I need some help understanding how to efficiently use Angular 4 and Observables in my program. In my Component, I am creating a list of "things" that need to be sent to an API. I also have a Service that takes an element ("thing) and sends it to the API, r ...