1.0.2 • Published 4 years ago

@solcre-org/ng-pusher v1.0.2

Weekly downloads
1
License
-
Repository
-
Last release
4 years ago

NgPusher

Solcre library to package all the functionalities of PusherJS.

Init

Import in module.ts the NgPusher module.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { NgPusherModule } from '@solcre-org/ng-pusher';

@NgModule({
  declarations: [AppComponent],
  imports: [
	BrowserModule,
	NgPusherModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Put this code in app_initializer or before pusherjs code

...
this.pusherService.createClient({
	apiKey: '', // Put your apiKey
	apiCluster: '' //Put your api cluster name
});
...

In the code:

const channelName: string = 'CHANNEL-NAME'; // In users case meaybe put @ID in the ends

//Pusher bind
this.pusherSubscriber = this.pusherService.bindEvent(channelName, 'CHANNEL-EVENT-NAME', (data: any) => {
	// This code is called from the server
});
//IMPORTANT: Pusher unbind (on component destroy)
if(this.pusherSubscriber){
	const channelName: string = 'CHANNEL-NAME'; 

	//Pusher unbind
	this.pusherService.unbindEvent(channelName, this.pusherSubscriber);
}