open-index/open-npm huggingface dataset:
npm package: @jheubuch/ng-ws-template
Description: Angular WebSocket template for AsyncAPI generator
Author: Jonas Heubuch
Latest version: 1.0.3

# AsyncAPI Angular WebSocket Template

This template generates a typescript module for WebSocket connections based on `rxjs`.

## Usage

```
ag asyncapi.json @jheubuch/ng-ws-template -p server=serverName -o outputDir
```
This will generate your channel services and message models to your specified output
directory.

## Supported Parameters

|Name|Description|Required|Example|
|----|-----------|--------|-------|
|server|Specifies the server in the AsyncAPI document which should be used for client generation.|Yes|`server=production`|
|clientId|Specifies the client id for the client you are generating the APIs for. (For use with AsyncApiWebSocketMiddleware).|No|`clientId=FrontendApp`|

## What is being generated
- The services for communication to the server (can be found at `output/services/index.ts`)
- The models used in the Messages (can be found at `output/models/{Message}.ts`)
- The API module which provides the services and can be included in the `app.module.ts` (can be found at `output/api.module.ts`)

### How to use the services

1. Include ApiModule to your AppModule:
```
 import { ApiModule } from '{output}/api.module';

 @NgModule({
     ...
     imports: [
         ...,
         ApiModule
     ]
 })
```

2. Use the services in your components via dependency injection:
```
 import { HelloWorldService } from '{output}/services';

 export class AppComponent {
     ...
     constructor(
         private helloWorldService: HelloWorldService
     ) { ... }
 }
```

3. Send to and receive from the service:
```
 // Subscribe to receive data; will be triggered every time something is received on the channel
 this.helloWorldService.subject.subscribe((data => {
     // Do something with your data!
 }));

 // Send data to your channel
 this.helloWorldService.sendToSocket(object);
```