Я использую signalr-no-jquery [https://www.npmjs.com/package/signalr-no-jquery] в Ionic, а сервер API находится в C #.Соединение начинается с веб-сокетов, но клиентское событие не запускается при вызове
Clients.Client(Context.ConnectionId).broadcast(new { NotificationType = "MESSAGE_RECEIVED" });
в методе OnConnected () API.Ниже приведен код:
private path: string = 'http://localhost/ABCAPI/';
private proxy: string = 'notificationHub';
private connection: any;
private hubProxy: any;
messageReceived = new EventEmitter<any>();
connectionEstablished = new EventEmitter<boolean>();
connectionExists = false;
constructor() {
this.connection = hubConnection(this.path,{
useDefaultPath: true,
transport:["serverSentEvents","longPolling"]
});
this.hubProxy = this.connection.createHubProxy('ABCServer');
this.registerOnserverEvents();
this.startConnection();
}
private startConnection(): void {
this.connection.start()
.done((data: any) => {
console.log('SignalR Connected with: ' + data.transport.name);
console.log('Now connected, connection ID=' + data.id);
this.connectionEstablished.emit(true);
this.connectionExists = true;
})
.fail((error: any) => {
console.log('SignalR Could not connect: ' + error);
this.connectionEstablished.emit(false);
}
private registerOnserverEvents(): void {
this.hubProxy.on('broadcast', (data: any) => {
console.log(data);
this.messageReceived.emit(data);
});
}
Есть предложения?