@jheubuch/ng-ws-template

1.0.3 • Public • Published

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
     ]
 })
  1. Use the services in your components via dependency injection:
 import { HelloWorldService } from '{output}/services';

 export class AppComponent {
     ...
     constructor(
         private helloWorldService: HelloWorldService
     ) { ... }
 }
  1. 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);

Package Sidebar

Install

npm i @jheubuch/ng-ws-template

Weekly Downloads

2

Version

1.0.3

License

Apache-2.0

Unpacked Size

17.7 kB

Total Files

7

Last publish

Collaborators

  • jheubuch