79714734

Date: 2025-07-25 12:45:38
Score: 3.5
Natty:
Report link
  startConnection(userId: string) {
    this.hubConnection = new signalR.HubConnectionBuilder()
      .withUrl(
        `${environment.apiUrl.replace(
          '/api',
          ''
        )}/notificationHub?userId=${userId}`,
        {
          accessTokenFactory: () => localStorage.getItem('authToken') || '',
        }
      )
      .build();

    this.hubConnection
      .start()
      .then(() => console.log('SignalR Connected'))
      .catch((err) => console.error('SignalR Connection Error: ', err));

    this.hubConnection.on(
      'ReceiveNotification',
      (message: NotificationModel) => {
        this.notifications.next(message);
        //alert(message); // You can replace this with a UI notification
      }
    );
  }

this code also show a same error..
please help me to resolve it
Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.

Reasons:
  • Blacklisted phrase (1): help me
  • RegEx Blacklisted phrase (3): please help me to resolve it
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Surya S