Giter Site home page Giter Site logo

ng-stomp's Introduction

npm Bower Travis Code Climate Gemnasium js-standard-style Beevelop

ngStomp

STOMP promised for AngularJS

Installation

Install via Bower:

bower install --save ng-stomp

Add standalone version (dependencies included) to your HTML file

<script src="bower_components/ng-stomp/dist/ng-stomp.standalone.min.js"></script>

Or add SockJS + STOMP + (minified) ngStomp individually:

<script src="bower_components/sockjs/sockjs.min.js"></script>
<script src="bower_components/stomp-websocket/lib/stomp.min.js"></script>
<script src="bower_components/ng-stomp/dist/ng-stomp.min.js"></script>

Install via npm:

npm install --save ng-stomp

Add standalone version (dependencies included) to your HTML file

<script src="node_modules/ng-stomp/dist/ng-stomp.standalone.min.js"></script>

Or add SockJS + STOMP + (minified) Stompie individually:

<script src="node_modules/sockjs/sockjs.min.js"></script>
<script src="node_modules/stompjs/lib/stomp.min.js"></script>
<script src="node_modules/ng-stomp/dist/ng-stomp.min.js"></script>

Usage

Inject it in your controller:

angular
  // Declare ngStomp as a dependency for you module
  .module('app', ['ngStomp'])

  // use $stomp in your controllers, services, directives,...
  .controller('Ctrl', function ($stomp, $scope, $log) {
    $stomp.setDebug(function (args) {
      $log.debug(args)
    })

    $stomp
      .connect('/endpoint', connectHeaders)

      // frame = CONNECTED headers
      .then(function (frame) {
        var subscription = $stomp.subscribe('/dest', function (payload, headers, res) {
          $scope.payload = payload
        }, {
          'headers': 'are awesome'
        })

        // Unsubscribe
        subscription.unsubscribe()

        // Send message
        $stomp.send('/dest', {
          message: 'body'
        }, {
          priority: 9,
          custom: 42 // Custom Headers
        })

        // Disconnect
        $stomp.disconnect().then(function () {
          $log.info('disconnected')
        })
      })
  })

API-Docs (TBD)

  • setDebug(callback)
  • connect(endpoint, headers)
  • disconnect
  • subscribe(destination, callback, headers)
  • on(destination, callback, headers)
  • unsubscribe(subscription)
  • off(subscription)
  • send(destination, body, headers)

ng-stomp's People

Contributors

beevelop avatar conteit avatar fedy2 avatar

Watchers

James Cloos avatar Rizki Putra Ramadhan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.