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.