I have an MXChip which sends data to an Azure IoT Hub, from there I am using an Azure Function with Azure SignalR binding to post the device data to Azure Signal R. And I have an Angular client which will get the connection information by calling the Azure Negotiate function I had created, using the package @aspnet/signalr
.
But the problem is my Angular client is throwing an error every few seconds, and when I check, I could understand that the hubConnection.onclose
event is getting fired in every few seconds.
Below is my Angular service code.
export class SignalRService {
mxChipData: Subject < string > = new Subject();
private hubConnection: SignalR.HubConnection;
constructor(private http: HttpClient) {}
private getSignalRConnection(): Observable < SignalRConnection > {
return this.http.get < SignalRConnection > (`${environment.baseUrl}negotiate`);
}
init() {
this.getSignalRConnection().subscribe(con => {
const options = {
accessTokenFactory: () => con.accessToken
};
this.hubConnection = new SignalR.HubConnectionBuilder()
.withUrl(con.url, options)
.configureLogging(SignalR.LogLevel.Information)
.build();
this.hubConnection.on('notify', data => {
this.mxChipData.next(data);
});
this.hubConnection.start()
.catch(error => console.error(error));
this.hubConnection.onclose((error) => {
console.error(`Something went wrong: ${error}`);
});
});
}
}
Is there any way I can get rid of this behavior?