text: !function(a,b){"use strict";"function"==typeof define&&define.amd?define(["mqttws"],b):a.EVT.WS=a.Evrythng.WS=b(a.Paho)}(this,function(a){"use strict";function b(a){return a+"_"+Math.random().toString(16).substr(2,8)}function c(b){return b.wsClient instanceof a.MQTT.Client&&b.wsClient.isConnected()}function d(d){var e=h.settings;return new Promise(function(f,g){if(c(d))f(d.wsClient);else{var h=null,i=e.apiUrl,j=b(e.clientIdPrefix);h=new a.MQTT.Client(i,j),h.connect({userName:"authorization",password:d.apiKey,keepAliveInterval:e.keepAliveInterval,onSuccess:function(){d.wsClient=h,f(d.wsClient)},onFailure:function(a){console.error("Unable to connect to WS server: "+i+", please check and try again"),g(a)}})}})}function e(b,e,f){var g=this;return d(this.scope).then(function(d){return new Promise(function(f,h){c(g.scope)||h("WS Client is not connected."),b=JSON.stringify(g.jsonify(b)),b=new a.MQTT.Message(b),b.destinationName=g.path,d.onMessageDelivered=function(){e&&e(),f()},d.send(b)})})}var f="1.0.0",g={apiUrl:"wss://ws.evrythng.com:443/mqtt",keepAliveInterval:60,clientIdPrefix:"evtjs"},h={version:f,settings:g,setup:function(a){if("[object Object]"!==Object.prototype.toString.call(a))throw new TypeError("Setup should be called with an options object.");for(var b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b]);return this.settings},install:function(a,b){function f(a,b,c){if("[object Function]"!=Object.prototype.toString.call(a))throw new TypeError("Message callback missing.");var e=this;return d(this.scope).then(function(d){return new Promise(function(f,g){d.subscribe(e.path,{onSuccess:function(){d.onMessageArrived=function(b){var c=b.payloadString;try{c=e.parse(JSON.parse(c))}catch(d){}a(c)},b&&b(d),f(d)},onFailure:function(a){console.error("Unable to subscribe to the topic: "+e.path+", please check and try again."),c&&c(a),g(a)}})})})}function g(a,b){var d=this;return new Promise(function(e,f){c(d.scope)?d.scope.wsClient.unsubscribe(d.path,{onSuccess:function(){a&&a(),e(d.scope.wsClient)},onFailure:function(a){console.error("Unable to unsubscribe to "+d.path),b&&b(a),f(a)}}):f("WS Client is not connected.")})}function h(a,c,d){var f=this;"undefined"==typeof a&&(a={});var g=this["class"]===b["class"]?"create":"update";return new Promise(function(b,h){var i={request:function(a,g){g(),e.call(f,a.data,c,d).then(b,h)}};f[g](a,{interceptors:[i]})})}a.prototype.subscribe=f,a.prototype.unsubscribe=g,a.prototype.publish=h}};return h.$inject=["resource","entity/action"],h});
  //# sourceMappingURL=evrythng-ws.min.js.map