All Projects → devsullo → ng2-STOMP-Over-WebSocket

devsullo / ng2-STOMP-Over-WebSocket

Licence: MIT license
STOMP Over WebSocket service for angular2

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to ng2-STOMP-Over-WebSocket

spring-websocket-angular6
Example for using Spring Websocket and Angular with Stomp Messaging
Stars: ✭ 18 (-48.57%)
Mutual labels:  angular2, websockets, sockjs, stomp
ng2-storage
A local and session storage wrapper for angular 2.
Stars: ✭ 14 (-60%)
Mutual labels:  angular2, ng2
ng2-fontawesome
An easy-to-use directive for font awesome icons.
Stars: ✭ 20 (-42.86%)
Mutual labels:  angular2, ng2
demo-spring-websocket
'WebSockets with Spring: HTTP and WebSocket; WebSocket with SockJS fallback; STOMP over WebSocket' articles and source code.
Stars: ✭ 30 (-14.29%)
Mutual labels:  sockjs, stomp
ic-datepicker
Angular (2+) datepicker component
Stars: ✭ 27 (-22.86%)
Mutual labels:  angular2, ng2
angular-odata-es5
OData Service for Angular.io (es5 version)
Stars: ✭ 45 (+28.57%)
Mutual labels:  service, angular2
spring-boot-vuejs-websockets
✔️ Simple spring-boot vue.js app with websockets and docker support
Stars: ✭ 30 (-14.29%)
Mutual labels:  sockjs, stomp
angular-progress-http
[DEPRECATED] Use @angular/common/http instead
Stars: ✭ 43 (+22.86%)
Mutual labels:  angular2, ng2
general-angular
Realtime Angular Admin/CRUD Front End App
Stars: ✭ 24 (-31.43%)
Mutual labels:  angular2, websockets
showdown-battle-bot
Socket Battle Bot for Pokemon Showdown (http://pokemonshowdown.com/)
Stars: ✭ 19 (-45.71%)
Mutual labels:  socket, websockets
ng-data-picker
🏄🏼 A data picker based on Angular 4+ (like native datetime picker of iOS)
Stars: ✭ 24 (-31.43%)
Mutual labels:  angular2, ng2
ng-leaflet
Angular 2 component for Leaflet 1.x (WIP - Help Wanted)
Stars: ✭ 16 (-54.29%)
Mutual labels:  angular2, ng2
angular2-signature-pad
Signature pad component for Angular 2.x and above.
Stars: ✭ 17 (-51.43%)
Mutual labels:  angular2, ng2
ng2-stompjs-demo
Angular 2 demo using stomp.js in Typescript
Stars: ✭ 42 (+20%)
Mutual labels:  angular2, stomp
ng-stomp
📑 STOMP for AngularJS
Stars: ✭ 42 (+20%)
Mutual labels:  sockjs, stomp
Web Socket
Laravel library for asynchronously serving WebSockets.
Stars: ✭ 225 (+542.86%)
Mutual labels:  socket, websockets
Kalm.js
The socket manager
Stars: ✭ 155 (+342.86%)
Mutual labels:  socket, websockets
Ngx Socket Io
Socket.IO module for Angular
Stars: ✭ 178 (+408.57%)
Mutual labels:  socket, angular2
spring-boot-chatrooms
Spring Boot chatroom with multiple rooms using STOMP over websockets.
Stars: ✭ 33 (-5.71%)
Mutual labels:  websockets, stomp
awesome-angular
💖 A list of awesome Angular (2️⃣➕) resources
Stars: ✭ 61 (+74.29%)
Mutual labels:  angular2, ng2

ng2-STOMP-Over-WebSocket

STOMP Over WebSocket service for angular2

Competible with: angular4 and ionic3

Website

3 step of installation

  1. npm i --save stompjs
  2. npm i --save sockjs-client
  3. 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

import { StompService } from 'ng2-stomp-service';

@NgModule({
  ...
  providers: [StompService]
})

Fast usage example

import { StompService } from 'ng2-stomp-service';

private subscription : any;

constructor(stomp: StompService) {

  //configuration
  stomp.configure({
    host:'test.com',
    debug:true,
    queue:{'init':false}
  });
  
  //start connection
  stomp.startConnect().then(() => {
    stomp.done('init');
    console.log('connected');
    
    //subscribe
    this.subscription = stomp.subscribe('/destination', this.response);
    
    //send data
    stomp.send('destionation',{"data":"data"});
    
    //unsubscribe
    this.subscription.unsubscribe();
    
    //disconnect
    stomp.disconnect().then(() => {
      console.log( 'Connection closed' )
    })
    
  });
 

}

//response
public response = (data) => {
  console.log(data)
}
  

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.configure({
    host:'test.com',
    debug:true,
    queue:{'init':false,'user':false}
  });

When connection established we have to call done() methdod with 'init' parameter.

 stomp.startConnect().then(() => {
    stomp.done('init');
 })

Now we can use after() method in different components and classes. Which checks continuously if specified queue have been done.

  stomp.after('init').then(()=>{
    stomp.subscribe('user',(data)=>{
    
      //here we done our queue
      stomp.done('user');
      
    })
  })

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.after('user').then(()=>{
    console.log('do something')
  })

Methods

  /**
   * Stomp configuration.
   * @param {object} config: a configuration object.
   *                 {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.configure();
  
  /**
   * Start connection
   * @return {Promise} if resolved
   */
  stomp.startConnect()
  
  /**
   * Subscribe.
   * @param {string} destination: subscibe destination.
   * @param {Function} callback(message,headers): called after server response.
   * @param {object} headers: optional headers.
   */
  stomp.subscribe();
  
  /**
   * Send message.
   * @param {string} destination: send destination.
   * @param {object} body: a object that sends.
   * @param {object} headers: optional headers.
   */
  stomp.send();
  
  /**
   * Unsubscribe subscription.
   */
  this.subscription.unsubscribe();

  /**
   * Disconnect
   * @return {Promise} if resolved
   */
  stomp.disconnect()
  
  /**
   * After specified subscription queue.
   * @param {string} name: queue name.
   * @return {Promise} if resolved
   */
  stomp.after()
  
  /**
   * Done specified subscription queue.
   * @param {string} name: queue name.
   */
  stomp.done()
  
  /**
   * Turn specified subscription queue on pending mode
   * @param {string} name: queue name.
   */
  stomp.pending()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].