How to use the @microsoft/signalr.HubConnectionBuilder function in @microsoft/signalr

To help you get started, we’ve selected a few @microsoft/signalr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dotnet / aspnetcore / src / Components / Web.JS / src / Boot.Server.ts View on Github external
async function initializeConnection(options: CircuitStartOptions, logger: Logger, circuit: CircuitDescriptor): Promise {
  const hubProtocol = new MessagePackHubProtocol();
  (hubProtocol as unknown as { name: string }).name = 'blazorpack';

  const connectionBuilder = new signalR.HubConnectionBuilder()
    .withUrl('_blazor')
    .withHubProtocol(hubProtocol);

  options.configureSignalR(connectionBuilder);

  const connection = connectionBuilder.build();

  setEventDispatcher((descriptor, args) => {
    connection.send('DispatchBrowserEvent', JSON.stringify(descriptor), JSON.stringify(args));
  });

  // Configure navigation via SignalR
  window['Blazor']._internal.navigationManager.listenForNavigationEvents((uri: string, intercepted: boolean): Promise => {
    return connection.send('OnLocationChanged', uri, intercepted);
  });
github damienbod / AspNetCoreAngularSignalR / src / AspNetCoreAngularSignalR / angularApp / app / news / news.service.ts View on Github external
private init() {

        this._hubConnection = new signalR.HubConnectionBuilder()
            .withUrl('https://localhost:44324/looney')
            .configureLogging(signalR.LogLevel.Information)
            .build();

        this._hubConnection.start().catch(err => console.error(err.toString()));

        this._hubConnection.on('Send', (newsItem: NewsItem) => {
            this.store.dispatch(new NewsActions.ReceivedItemAction(newsItem));
        });

        this._hubConnection.on('JoinGroup', (data: string) => {
            console.log('recieved data from the hub');
            console.log(data);
            this.store.dispatch(new NewsActions.ReceivedGroupJoinedAction(data));
        });
github asadsahi / AspNetCoreSpa / src / Presentation / Web / ClientApp / src / app / +examples / examples / signalr / chat / chat.component.ts View on Github external
ngOnInit() {
    this.config = [
      {
        name: 'message',
        type: FieldTypes.Textbox,
        label: 'Message',
        validation: [Validators.required],
      },
      {
        name: 'button',
        type: FieldTypes.Button,
        label: 'Send',
        onSubmit: this.sendMessage.bind(this),
      },
    ];
    this.hub = new HubConnectionBuilder().withUrl(`${this.baseUrl}chathub`).build();

    this.hub.on('send', (data: any) => {
      const received = `Received: ${data}`;
      this.messages.push(received);
    });

    this.hub
      .start()
      .then(() => console.log('Hub connection started'))
      .catch(err => console.log('Error while establishing connection: ' + err));
  }
}
github damienbod / AspNetCoreAngularSignalR / src / AspNetCoreAngularSignalR / angularApp / app / images / components / images.component.ts View on Github external
ngOnInit() {
        this._hubConnection = new signalR.HubConnectionBuilder()
            .withUrl('https://localhost:44324/zub')
            .configureLogging(signalR.LogLevel.Trace)
            .build();

        this._hubConnection.stop();

        this._hubConnection.start().catch(err => {
            console.error(err.toString());
        });

        this._hubConnection.on('ImageMessage', (data: any) => {
            console.log(data);
            this.images.push(data);
        });

    }
github asadsahi / AspNetCoreSpa / src / AspNetCoreSpa.Web / ClientApp / src / app / +examples / examples / signalr / move-shape / draggable.directive.ts View on Github external
ngOnInit() {
    this._hubConnection = new HubConnectionBuilder().withUrl(`${this.baseUrl}shapeHub`).build();
    this._hubConnection.on('shapeMoved', function(x, y) {
      this.element.nativeElement.css({ left: x, top: y });
    });

    const target = this.element.nativeElement;
    const mouseup = fromEvent(target, 'mouseup');
    const mousemove = fromEvent(document, 'mousemove');
    const mousedown = fromEvent(target, 'mousedown');

    const mousedrag = mousedown.pipe(
      flatMap((md: any) => {
        const startX = md.clientX + window.scrollX,
          startY = md.clientY + window.scrollY,
          startLeft = parseInt(md.target.style.left, 10) || 0,
          startTop = parseInt(md.target.style.top, 10) || 0;
github dotnet-architecture / eShopOnContainers / src / Web / WebSPA / Client / modules / shared / services / signalr.service.ts View on Github external
private register() {
        this._hubConnection = new HubConnectionBuilder()
            .withUrl(this.SignalrHubUrl + '/hub/notificationhub', {
                accessTokenFactory: () => this.securityService.GetToken()
            })
            .configureLogging(LogLevel.Information)
            .withAutomaticReconnect()
            .build();
    }
github FabianGosebrink / ASPNETCore-Angular-SignalR-Typescript / frontend / angularsignalrclient / src / app / core / services / signalR.service.ts View on Github external
private createConnection() {
    this.hubConnection = new HubConnectionBuilder()
      .withUrl(environment.baseUrls.server + 'coolmessages')
      .withAutomaticReconnect()
      .configureLogging(LogLevel.Information)
      .build();
  }
github dotnet / aspnetcore / src / SignalR / clients / ts / FunctionalTests / ts / HubConnectionTests.ts View on Github external
function getConnectionBuilder(transportType?: HttpTransportType, url?: string, options?: IHttpConnectionOptions): HubConnectionBuilder {
    let actualOptions: IHttpConnectionOptions = options || {};
    if (transportType) {
        actualOptions.transport = transportType;
    }
    actualOptions = { ...actualOptions, ...commonOptions };

    return new HubConnectionBuilder()
        .configureLogging(TestLogger.instance)
        .withUrl(url || TESTHUBENDPOINT_URL, actualOptions);
}