rgrueneis-signalr-gen
v2.5.1
Published
Tool to generate signalr access services fro GrueneisR.SignalRAnalyzer
Readme
General
This package generates an Angular or a WPF/C# service with the specifcation of a C# hub.
Prerequesites
The backend needs to add the middleware GrueneisR.SignalRAnalyzer.
Installation
Install with npm:
npm install -D rgrueneis-signalr-genor yarn:
yarn add -D rgrueneis-signalr-genBasic usage in Angular
Add the following line to the scripts section of your package.json:
export class HomeComponent implements OnInit, MyHubServerToClient {
private hubService = inject(MyHubService);
ngOnInit(): void {
this.hubService.attach(this);
this.hubService.startConnection(`${environment.apiRoot}/hubs/myhub`);
}
ngOnDestroy(): void {
this.hubService.detach(this);
}
}Optional you can use JWT token as second parameter to startConnection, where this.getToken() returns the JWT token:
this.hubService.startConnection(`${environment.apiRoot}/hubs/myhub`, this.getToken());Configuration
The tool requires a configuration file name signalrgen.json. If it does not exist, a default version of this file is generated in the root folder after the first call.
{
"analyzerUri": "http://localhost:5000/hubanalyzer",
"relativeTargetPath": "signalrbridge"
"type": "angular",
"hubName": "DemoHub",
"useHubSuffixInContract": true,
"includeContractDtosNamespace": true
}Properties:
| Property | Description | Default |
|:-----------------------------------|:-------------|:------------|
| analyzerUri | URL to the backend where the data for the hubs is provided | "http://localhost:5000/hubanalyzer" |
| relativeTargetPath | folder where the typescript classes are generated | |
| type | angular or wpf | angular |
| hubName | If set, only the classes for this hub are generated | |
| useHubSuffixInContract | WPF only. If set, the namespace of the contract is expected to include "Hub", e.g. DemoHubContracts | false |
| includeContractDtosNamespace | WPF only. If set, adds a using like using DemoContracts.Dtos;. Use it, if your Hub interface include a DTO | false |
Script
Add the following line to the scripts section of your package.json:
"signalrGen": "signalr-gen"