npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-livestomp

v1.0.3

Published

This library provides easy access to events and variables with real-time updates from a server using my library LiveStomp.

Downloads

3

Readme

LiveStomp Client for Angular

This library provides easy access to events and variables with real-time updates from a server using my library LiveStomp.

Installation

This library requires 2 peer dependencies in order to work:

npm install --save @stomp/rx-stomp @stomp/ng2-stompjs

after having installed them, you can proceed with the package installation:

npm install --save ngx-livestomp

Usage

  1. Create an object of type RxStompConfig similar to the following, customizing parameters:
export const rxStompConfig: RxStompConfig = {
  // Which server?
  brokerURL: 'ws://127.0.0.1:8080/ws',

  // Headers
  // Typical keys: login, passcode, host
  connectHeaders: {
    login: 'guest',
    passcode: 'guest',
  },

  logRawCommunication: true,

  // How often to heartbeat?
  // Interval in milliseconds, set to 0 to disable
  heartbeatIncoming: 0, // Typical value 0 - disabled
  heartbeatOutgoing: 20000, // Typical value 20000 - every 20 seconds

  // Wait in milliseconds before attempting auto reconnect
  // Set to 0 to disable
  // Typical value 500 (500 milli seconds)
  reconnectDelay: 500,

  // Will log diagnostics on console
  // It can be quite verbose, not recommended in production
  // Skip this key to stop logging to console
  debug: (msg: string): void => {
    if(!environment.production)
      console.log(new Date(), msg);
  },
};
  1. In your AppModule, import RxLiveStompModule and configure it with the object previously created:
// ... other imports
import {rxStompConfig} from "./rx-stomp.config";
import {NgxLiveStompModule} from "ngx-livestomp"

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxLiveStompModule.forRoot(rxStompConfig)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
}
  1. Now, simply use the service via DI:
@Component({
  selector: 'app-root',
  template: `
    <p *ngFor="let hero of heroes | async">
      {{hero.name}}, rating: {{hero.rating}}
    </p>
    <br>
    Hero with id 1:
    <p>{{(heroWithID1 | async)?.name}}, rating: {{(heroWithID1 | async)?.rating}}</p>
    <br>
    Poster: {{poster?.text}}
    <p></p>
  `,
  styles: []
})
export class AppComponent implements OnInit {
  heroes?: Observable<Hero[]>;
  heroWithID1?: Observable<Hero>;
  poster?: {text: string};

  constructor(private restService: NgxLiveStompService) {
  }

  ngOnInit(): void {
    this.heroes = this.restService.liveList<Hero>('http://localhost:8080/heroes', '/topic/heroes/updates');
    this.heroWithID1 = this.restService.live<Hero>('http://localhost:8080/heroes/1', '/topic/heroes/1/updates');
    this.restService.live<{ text:string }>('http://localhost:8080/poster', '/topic/poster/updates').subscribe(poster => {
      console.log(poster);
      this.poster = poster
    })
  }

}

In this example, the list heroes and the variables heroWithID1 and poster are now synchronized with back-end changes, thus are updated in real-time.

For more examples of usage, see the following repo: https://github.com/KatonKalu/Stomp-Reactive-Example