SkillAgentSearch skills...

Stompie

Angular Module for STOMP over Websockets.

Install / Use

/learn @mrolafsson/Stompie
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Stompie

If you're planning to stomp all over some sockets this little angularity to deal with STOMP queues is just the thing for you. On the big iron, server side, we're using Spring.

Getting started

  1. If you're using bower just install:
bower install -save stompie
  1. OK I know it's obvious but add <script> tags to the module and the two required dependencies:
<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>
  1. Declare the module as a dependency in your application:
angular.module('yourApplication', ['stompie']);
  1. Inject it in your controller:
angular.module('yourApplication')
    .controller('YourCtrl', ['$stompie', '$scope', function ($stompie, $scope) {
        // ...
    }
  1. Use and subscribe:
$stompie.using('/your/stomp/endpoint', function () {

    // The $scope bindings are updated for you so no need to $scope.$apply.
    // The subscription object is returned by the method.
    var subscription = $stompie.subscribe('/your/topic', function (data) {
        $scope.foo = data;
    });

    // Unsubscribe using said subscription object.
    subscription.unsubscribe();

    // Send messages to a STOMP broker.
    $stompie.send('/some/queue', {message: 'some message'});

    // Disconnect from the socket.
    $stompie.disconnect(function () {
        // Called once you're out...
    });

});

Helpful information

  • You can call $stompie.using() as many times as you want, it will reuse the same socket connection.
  • The underlying libraries also mean that you can register multiple subscribers.
  • The $stompie.subscribe() callback will attempt to parse the response.
  • Objects you pass to $stompie.send() will be stringified.

Bedtime reading:

  • https://github.com/sockjs/sockjs-client
  • http://jmesnil.net/stomp-websocket/doc/
  • https://github.com/jmesnil/stomp-websocket/

For everything else, there's MasterCard.

View on GitHub
GitHub Stars4
CategoryDevelopment
Updated8y ago
Forks1

Languages

JavaScript

Security Score

55/100

Audited on Sep 14, 2017

No findings