Narnia's Psychedelic Mushrooms
Wondering what’s next for npm?Check out our public roadmap! »

ng-stomp
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/ng-stomp package

0.5.0 • Public • Published

npm Bower Travis Maintainability 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)

Install

npm i ng-stomp

DownloadsWeekly Downloads

556

Version

0.5.0

License

MIT

Unpacked Size

77.7 kB

Total Files

10

Last publish

Collaborators

  • avatar