Stomp client for Angular Typescript.


Keywords
angular, ngx, stomp, stompwebsocket, websocket
License
MIT
Install
npm install @elderbyte/ngx-stomp@6.0.0-beta4

Documentation

CI Status npm version

Angular STOMP Client

Simple Angular 7 STOMP over Websocket library. This library is a wrapper around the generic TypeScript Library @elderbyte/ts-stomp.

Features

  • Angular 7 Module and Service for easy integration
  • Supports native websocket transport
  • Supports SockJS emulated websocket transport

Consuming your library

To install this library, run:

$ npm install @elderbyte/ngx-stomp --save

and then from your Angular AppModule:

// Import your library
import { StompModule } from '@elderbyte/ngx-stomp';

@NgModule({
  imports: [
    // Configure StompModule
    StompModule.forRoot({
      endpointUrl: '/stomp',
      withSockJs: true
    }),
  ],
})
export class AppModule { }

Once the library is imported, you can use the StompService by importing it into your own services / components:

export class MyStompUsage {
  constructor(
    private stompService : StompService) {
    
    const topic = '/topic/metadata/changed';

    // Subscribe to the STOMP topic ...

    this.stompService.connectedClient
      .subscribe(client => {
        const sub = client.subscribe(topic);
       
        // Subscription successful -> now we can listen to messages sent to this subscription

        sub.messages.subscribe(m => {
         
          // We got a message m, do something with it
          
          this.onMediaChanged(m.bodyJson);
          
          
        }, err => {
          this.logger.error('Got filtered STOMP topic error!', err);
        })
      }, err => {
        this.logger.error('STOMP: Failed to subscribe!', err);
      });
  }
}

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © ElderByte AG