Uncaught (in promise): Cannot send data if the connection is not in the 'Connected' State. while connecting the signalR with angular

Viewed 1069

While connecting the signalR with angular I am getting the error

Uncaught (in promise): Error: Cannot send data if the connection is not in the 'Connected' State."

and my code is

dashboard.service.ts

private hubConnection: signalR.HubConnection
initWebSocket() {
    this.hubConnection = new signalR.HubConnectionBuilder()
      //.configureLogging(signalR.LogLevel.Debug)
      .withUrl('http://localhost:5000/Notification',{
       skipNegotiation: true,
        transport: signalR.HttpTransportType.WebSockets
      })
      .build();
  this.hubConnection
      .start()
      .then(() => console.log('Connection started'))
      //.then(() => console.log(this.hubConnection.connectionId)
      .catch(err => console.log('Error while starting connection: ' + err))

      const EmailId = "abc@mail.com";
      this.hubConnection.invoke("Registerd", EmailId);
      console.log("Registered", EmailId);

Can anyone help me to overcome this error

1 Answers
Related