15.304.0 • Published 3 years ago
@angular-ru/websocket v15.304.0
WebSocket service for your Angular app
First step
import { WebsocketModule } from '@angular-ru/websocket';
@NgModule({
imports: [
// ...
WebsocketModule.forRoot()
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
Create your websocket client for your websocket controller
Example, if your websocket controller placed here wss://my-server.com/orders
, then your websocket client will be:
orders-webscoket.client.ts
import { AbstractWebsocketClient } from '@angular-ru/websocket';
export const enum OrderEvent {
ACCEPTED = 'ACCEPTED',
DECLIENED = 'DECLIENED'
}
@Injectable()
export class OrdersWebsocketClient extends AbstractWebsocketClient<OrderEvent> {
public get baseUrl(): string {
return `wss://my-server.com/`;
}
public connect(): void {
super.connect('orders');
}
}
orders.component.ts
@Component({
// ..,
providers: [OrdersWebsocketClient]
})
export class OrdersComponent {
constructor(private readonly ordersWsClient: OrdersWebsocketClient) {}
public ngOnInit() {
this.ordersWsClient.on<AcceptedModel>(OrderEvent.ACCEPTED).subscribe((event: AcceptedModel) => {
// business logic
});
}
}
15.304.0
3 years ago
15.303.0
3 years ago
15.302.1
3 years ago
15.301.3
3 years ago
15.301.0
3 years ago
15.276.2
3 years ago
15.276.0
3 years ago
15.236.0
3 years ago
15.237.0
3 years ago
15.231.1
3 years ago
15.239.0
3 years ago
15.224.0
3 years ago
15.227.0
3 years ago
15.222.1
3 years ago
15.138.0
3 years ago
15.138.1
3 years ago
15.129.0
3 years ago
15.6.2
3 years ago
15.3.0
3 years ago
15.0.1
3 years ago
15.0.0
3 years ago
14.64.2
4 years ago
14.64.1
4 years ago
14.64.0
4 years ago