ng2-STOMP-Over-WebSocket
STOMP Over WebSocket service for angular2
Competible with: angular4 and ionic3
3 step of installation
- npm i --save stompjs
- npm i --save sockjs-client
- npm i --save ng2-stomp-service
Setup
In -> typings.d.ts
Add stompjs
and sockjs-client
module declaration
declare module 'stompjs';declare module 'sockjs-client';
In -> app.module.ts
; @
Fast usage example
; private subscription : any; { //configuration stomp; //start connection stomp; } //responsepublic { console}
The Queue
When your application is going to scale the 'fast usage example' is not for you.. but it's helpful for beginning.
When you have routes and different actions in your application you will need to use 'queue' of subscriptions with after()
and done()
methods.
First create queue of subscriptions. The first one 'init' is required then we can add other queue for example 'user' and assign it as false.
stomp;
When connection established we have to call done()
methdod with 'init' parameter.
stomp
Now we can use after()
method in different components and classes. Which checks continuously if specified queue have been done.
stomp
As you can see we subscribed 'user' destination when 'init' queue has been complated. As you understand you can done your queue list when you want.. If some component needs user information you have to use following code
stomp
Methods
/** * Stomp configuration. * @param * {host:string} websocket endpoint * {headers?:Object} headers (optional) * {heartbeatIn?: number} heartbeats out (optional) * {heartbeatOut?: number} heartbeat in (optional) * {debug?:boolean} debuging (optional) * {recTimeout?:number} reconnection time (ms) (optional) * {queue:Object} queue object * {queueCheckTime?:number} queue cheking Time (ms) (optional) */ stomp; /** * Start connection * @return */ stomp /** * Subscribe. * @param * @param * @param */ stomp; /** * Send message. * @param * @param * @param */ stomp; /** * Unsubscribe subscription. */ thissubscription; /** * Disconnect * @return */ stomp /** * After specified subscription queue. * @param * @return */ stomp /** * Done specified subscription queue. * @param */ stomp /** * Turn specified subscription queue on pending mode * @param */ stomp