DVLP / signalr-no-jquery

120 stars 78 forks source link

signalr-no-jquery connection started but client events not called with websockets #37

Closed Nanddeep closed 7 months ago

Nanddeep commented 6 years ago

I am using signalr-no-jquery in Ionic and the API server is in C#. The connection starts with websockets but the client event doesn't get triggered when

Clients.Client(Context.ConnectionId).broadcast(new { NotificationType = "MESSAGE_RECEIVED" });

is called on the OnConnected() method on the API. Below is the code:

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);
});

}

Any suggestions?

yangjianwei1223 commented 6 years ago

Clients.Client should be writed before connection start.

kartik2014 commented 5 years ago

Hi..did anyone manage to fix this issue?

link87563 commented 3 years ago

hi anyone has same issue? I can not got event of data...