使用angular9客户端时,SignalR连接断开

时间:2020-09-09 08:20:12

标签: angular signalr

一切正常。加入Room并将消息发送到room,但是在广播消息时,有角度的客户端不会收到该消息(Web和Android客户端可以毫无问题地接收到该消息) 我们意识到由于用户断开连接(因此将其从Room Signal-R组中删除),就像同一用户同时从网络或android连接到同一房间一样,角度广播也可以正常工作。 Angular似乎有什么问题? 预先感谢

   import { EventEmitter, Injectable } from '@angular/core';
import { Message } from 'src/interface/models/Chat/Message';
import {IRoomDetail } from 'src/interface/models/IRoomDetail';
import {ShareDataService} from 'src/services/shareData.service';
declare var $: any;

@Injectable({
  providedIn: 'root'
})
export class ChatServices {
  messageReceived = new EventEmitter<Message>();
  HubAddress='TheUrl';
 // HubAddress='TheUrl'
  HubProxy='ChatHub';
  Modals:IRoomDetail;

  private connectionIsEstablished = false;
  private connection: any;
  public proxy: any;

  constructor(private shareData:ShareDataService) {

  }



  public startConnection(): void {

    this.connection = $.hubConnection(this.HubAddress);
    this.proxy = this.connection.createHubProxy(this.HubProxy);
    this.connection.start().done((data: any) => {
      this.MapUserName();
    }).catch((error: any) => {
      console.log('Why? ' + error);
    });


  }

  public CheckConnect():void{
      this.connection.start().done((data: any) => {
      }).catch((error: any) => {
        console.log('Why? ' + error);
      });


  }
  onMessageReceived(){

   this.proxy.on('newMessage',(data: any)=>{
   console.log(data)
   });
 }
  private MapUserName(){
    this.proxy.invoke('MapUsername',this.shareData.getLoginInfo().User.Id);
}
public JoinRoom(RoomName=''){
let userId=this.shareData.getLoginInfo().User.Id.toString();
this.proxy.invoke('Join',RoomName,userId);
}
public SendMessage(RoomName:string,Message:string){
  let userId=this.shareData.getLoginInfo().User.Id.toString();
 this.proxy.invoke('Send',RoomName,Message,userId,'0');
}
  public broadcastMessage(): void {
    this.proxy.invoke('NotificationService', 'text message')
  .catch((error: any) => {
    });
  }

}

0 个答案:

没有答案
相关问题