I have a web api that receive response from payment bank gateway and I want to send this response to my angular app through signalR,
but angular not receive it, and redirect to my web api Uri.
await _hubContext.Clients.All.SendAsync("ReceiveMessage", result.Data);
my hup:
public class MyHub : Hub
{
public async Task SendMessage(string message)
{
try
{
await Clients.All.SendAsync("ReceiveMessage", message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
my angular code :
@Output() onSignalRMessage: EventEmitter<any> = new EventEmitter();
constructor(private router: Router) {
this.startConnection();
this.receiveMessage();
}
public startConnection = () => {
console.log('Starting connection...');
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl('https://localhost:5033/myHub'
, {
accessTokenFactory: () => localStorage.getItem('tax-cookie')
})
.build();
this.hubConnection.start()
.then(() => console.log('Connection started'))
.catch(err => console.log('Error while starting connection: ' + err));
}
receiveMessage = () => {
this.hubConnection.on('ReceiveMessage', (message: string) => {
console.log('receiveMessage: ' + message);
this.paymentStatusSubject.next(message);
this.onSignalRMessage.emit(this.paymentStatusSubject);
});
}
public addTransferChartDataListener() {
this.hubConnection.on('ReceiveMessage', (data) => {
console.log('ReceiveMessage: ' + data);
});
}
}
app.component.ts :
export class AppComponent {
private hubConnection: signalR.HubConnection;
constructor(
private signalRService: SignalRService,
private router: Router
) { }
public messages = [];
ngOnInit() {
this.signalRService.onSignalRMessage.subscribe((data) => {
this.messages.push(data);
console.log('receiveMessage: ' + this.messages[0]);
})
}
it redirect to webApi Uri and not run angular!!
can anyone help me?