I have installed @aspnet/signalr in my Angular 6 project
I tried all the other options found in stack-over flow for the signalr issue. Below is my service code:
import { Injectable } from '@angular/core';
import * as signalR from "@aspnet/signalr";
import { UserService } from 'app/@core/data/users.service';
@Injectable()
export class SignalRService {
private url = baseurl+'&users='
public data;
private hubConnection: signalR.HubConnection;
constructor(private user: UserService) { }
public startConnection = () => {
let loggedInuser = this.user.getUserEmail();
let accessToken ="some token";
var options = {
transport: signalR.HttpTransportType.WebSockets,
logging: signalR.LogLevel.Trace,
accessTokenFactory: () => accessToken
};
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(this.url + loggedInuser , options)
.build();
this.hubConnection.serverTimeoutInMilliseconds = 9999999999999;
this.hubConnection
.start()
.then(() => console.log('Connection started'))
.catch(err => {
console.log('url: ' + this.url + loggedInuser)
console.log('Error while starting connection: ', err)
})
}
public addTransferChartDataListener = () => {
this.hubConnection.on('AppNotifications', (data) => {
this.data = data;
console.log(data);
});
}
}
When I run the ngOninit() of notification component, I get "Websocket is not in OPEN state" message in console. Where is that I'm doing wrong?
Example I followed to implement this is https://code-maze.com/netcore-signalr-angular/