The JSON format is invalid because it contains an unexpected token "o" pointed to by the "Blob" object

I've been experimenting with a video chat code that I stumbled upon on YouTube. However, every time I try to make a call, I encounter an error. It's been a few days now and I can't seem to pinpoint where the issue lies.

Here is the snippet of the code:


  private localStream: MediaStream;

  inCall = false;
  localVideoActive = false;


  constructor(private dataService: DataService) { }

  async call(): Promise<void> {
    this.createPeerConnection();


    // Add the tracks from the local stream to the RTCPeerConnection
    this.localStream.getTracks().forEach(
      track => this.peerConnection.addTrack(track, this.localStream)
    );

    try {
      const offer: RTCSessionDescriptionInit = await this.peerConnection.createOffer(offerOptions);
      // Establish the offer as the local peer's current description.
      await this.peerConnection.setLocalDescription(offer);

      this.inCall = true;

      this.dataService.sendMessage({type: 'offer', data: offer});
    } catch (err:any) {
      this.handleGetUserMediaError(err);
    }

Answer №1

Revise your websocket send message implementation as shown below

 ws.on("message", function message(data, isBinary) {
    const parsedMessage = isBinary ? data : data.toString();
    // Proceed with the existing logic.
    console.log(parsedMessage + "\n\n");
    wss.broadcast(ws, parsedMessage);
  });

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

Combining different types and "currying" or partial application APIs in a unique way

Here is an interface that I am working with: interface IFactory<T> extends Function { (...args: any[]): (((...args: any[]) => T)|T); } After implementing the following code snippet, an error occurred: ts] Type '((...args: any[]) => ...

What could be the reason why my Angular component is experiencing input issues?

I am facing an issue with my angular class: @Component({ selector: 'main-title', styleUrls: ['main_title.scss'], template: ` <ng-template> <div class="main-title"> <h2 [ngClass]="{&apo ...

What is the reason for the lack of overlap between types in an enum?

I'm having trouble understanding why TypeScript is indicating that my condition will always be false. This is because there is no type overlap between Action.UP | Action.DOWN and Action.LEFT in this specific scenario. You can view the code snippet and ...

A guide to incorporating Material-UI ThemeProvider and WithStyles with Typescript

I've been feeling frustrated lately as I've been dedicating the past few days to migrating my React application from JavaScript to TSX. While I appreciate the type checking that TSX provides, I'm struggling with understanding how to implemen ...

Utilizing IIS Windows Authentication for Angular 4 and .Net Core 2.0: Resolving Access-Control-Allow-Origin Issue

I have tried numerous StackOverflow answers regarding this issue but none of them seem to be working effectively for me. The error message I keep encountering in the console is: Failed to load : No 'Access-Control-Allow-Origin' header is present ...

Does the Rxjs timer cease functioning when the user switches to a different window?

I have encountered an issue while setting a 60-second countdown with rxjs timer on Angular 11. The countdown works properly as long as the window is kept open. However, if I switch to another tab in the same browser, the timer stops after a few seconds. Th ...

Changing a photo into base64 format using Angular 2

How can I convert an image to base64 in Angular 2? The image is uploaded from the local filesystem. Currently, I am using fileLoadedEvent.target.result to achieve this. However, when I try to send this base64 string through REST services to Java, it fails ...

The TypeScript Generics issue arises when attempting to assign the type '{ result: true }' to type 'T'

Struggling with implementing generic types, I can't seem to make it work properly. It feels like I'm missing something simple. Here's a basic example: // some module type TMainResponse<T> = { data: T; }; interface Foo { func<T ...

The Primeng ConfirmDialog does not close when either the Yes, No, or Close(X) buttons are clicked

When using the PrimeNg ConfirmDialog (p-confirmDialog) in a P-table to delete a record, I am experiencing an issue where the confirm dialog does not close after clicking Yes/No/close(X). Below is the method that I am calling when clicking on delete: conf ...

Errors may occur when utilizing TypeScript with the Context Provider API in React

I am in the process of developing a theme changer feature and I want to save the color chosen by the user in the context. However, when I try to pass data to the value prop of the Context.Provider, I encounter an error message TS2739: Type 'Readonly&l ...

The TypeScript error message is indicating that the variable is being used as a value, even though it is only defined as a type

I'm encountering a persistent TypeScript error that I can't seem to suppress, not even with @ts-ignore. Oddly enough, the code functions perfectly at runtime when TypeScript is disabled temporarily for testing. Is TypeScript misbehaving in this s ...

personalize the text in fusioncharts' chart legend item

Is there a way to modify the legend display for the doughnut2D chart to appear as a rectangle with separate rows for the value and label, along with icons as shown in the screenshot link? If you have any code examples or implementations for this, it would ...

What measures can I take to address the TypeScript error indicating that my function is missing a return statement and the return type does not include 'undefined' in my code?

In this scenario, there is a straightforward function called make which utilizes the handle function to retry a specified number of times if it encounters an error. Once all retries have been exhausted, the make function should throw the error. const handl ...

When setting a value through the DOM, the input's value bound with ngModel in Angular does not get updated

Trying to upload a file to calculate its hash and display it in an input box. If done correctly, the value should show in the form, but when submitting the form, the value does not get sent. Only adding a blank space by clicking on the input field works: ...

Is there a way to trigger the click event in the week view of an Angular 2+ calendar?

https://i.sstatic.net/Vx2x8.png HTML Templates <mwl-calendar-week-view [viewDate]="viewDate" [refresh]="refresh" (click)="weekDayClick($event)"> </mwl-calendar-week-view> In the component file weekDayCl ...

``Using backticks to denote HTML syntax - Leveraging Google Charts to create

Has anyone found a way to incorporate HTML in ticks within a Google chart? I am attempting to insert a weather icon from This is my current attempt: const dailyData = new google.visualization.DataTable(); dailyData.addColumn('timeofday' ...

Issue with compatibility between Angular v8 application and web component polyfills in IE11 causing malfunction in rendering

Recently, I've been attempting to integrate the web component polyfills into my Angular (v8) application, but unfortunately, they don't seem to be functioning properly in IE11. To showcase this issue, I have set up a new repository containing a b ...

Guide on incorporating text input areas into specific positions within a string

Looking for a way to replace specific words in a string with input fields to enter actual values? For example... Dear Mr. [Father_name], your son/daughter [name] did not attend class today. This is what I want it to look like... Dear Mr. Shankar, your ...

When the mat-select form-field in Angular is focused, the mat-label vanishes

Recently delved into Angular and have been studying the Material documentation on mat-form-fields. Encountering a strange bug where the mat-label disappears upon focusing the form-field, only to reappear once focus is lost. The issue seems to be specific ...

What is the reason behind the lack of covariance in an interface when using a type of T[keyof T]?

I'm attempting to enable type covariance so that Type<Cat> can be treated as a Type<Animal>, for instance, treating a list of Cats as a list of Animals. However, using the type T[keyof T] in a method within the Type interface seems to hind ...