Skip to content

tep-pl/ng-stomp

 
 

Repository files navigation

npm npm Bower Travis Code Climate Gemnasium

ngStomp

STOMP promised for AngularJS

Installation

Install via Bower:

bower install --save ng-stomp

Install via npm:

npm install --save ng-stomp

Add SockJS + STOMP + (minified) Stompie:

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

Declare the module as a dependency in your application:

angular.module('yourApp', ['ngStomp']);

Usage

Inject it in your controller:

angular
    .module('app')
    .controller('Ctrl', ['$stomp', '$scope', function ($stomp, $scope) {
        // ...
    }

Example

Use and subscribe:

// redirect debug
$stomp.setDebug(function (args) {
    document.getElementById('log').value += args + '\n';
});

$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(function () {

        });
    });

Packages

No packages published

Languages

  • JavaScript 100.0%