ng2-stomp
Version:
wrapper for stomp client in angular 2
1 lines • 2.24 kB
JavaScript
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@angular/core"),require("rxjs/Rx")):"function"==typeof define&&define.amd?define(["exports","@angular/core","rxjs/Rx"],n):n(t["ng2-stomp"]=t["ng2-stomp"]||{},t.ng.core,t.rxjs_Rx)}(this,function(t,n,e){"use strict";var o=function(){function t(){this.stompClient=null,this.connectionAnnouncedSource=new e.Subject,this.connectionAnnounced$=this.connectionAnnouncedSource.asObservable()}return t.prototype.announceconnection=function(t){this.connectionAnnouncedSource.next(t)},t.prototype.setUsedSubscription=function(t){this.stompClient.usedSubscriptions[t.id]=t},t.prototype.getStompClient=function(t){var n=Stomp.over(new SockJS(t,null,{transports:[]}));return n.usedSubscriptions={},this.stompClient=n,e.Observable.of(n)},t.prototype.getConnection=function(t){var n=this;if(!this.stompClient||null===this.stompClient)throw new Error("stompClient cannot be null");return e.Observable.of(this.stompClient.connect(t,function(){n.announceconnection(n.stompClient)}))},t.prototype.subscribeToTopic=function(t,n,o){if(o&&this.stompClient&&this.stompClient.subscriptions[o.id])return e.Observable.of(this.stompClient.usedSubscriptions[o.id]);if(!this.stompClient||null===this.stompClient)throw new Error("stompClient cannot be null");return e.Observable.of(this.stompClient.subscribe(t,function(t){n&&n(JSON.parse(t.body))},o))},t.prototype.unSubscribe=function(t){this.stompClient.usedSubscriptions[t].unsubscribe(),delete this.stompClient.usedSubscriptions[t]},t.prototype.sendMessage=function(t,n,o){return e.Observable.of(this.stompClient.send(t,o,n))},t.prototype.disconnect=function(){e.Observable.of(this.stompClient.disconnect(function(){}))},t.decorators=[{type:n.Injectable}],t.ctorParameters=function(){return[]},t}(),i=function(){function t(t){if(t)throw new Error("Ng2StompModule is already loaded. Import it in the AppModule only")}return t.forRoot=function(){return{ngModule:t,providers:[o]}},t.decorators=[{type:n.NgModule,args:[{imports:[],providers:[]}]}],t.ctorParameters=function(){return[{type:t,decorators:[{type:n.Optional},{type:n.SkipSelf}]}]},t}();t.Ng2StompModule=i,t.Ng2StompService=o,Object.defineProperty(t,"__esModule",{value:!0})});