   !function(e){"use strict";"object"!=typeof e.usocket&&(e.usocket=function(f,t){var a=function(){},e=navigator.userAgent,r=void 0!==t.WebSocket&&3===t.WebSocket.CLOSED;!0===/Android (4.[0123]|2.\d)/.test(e)&&!1===/ Chrome\//.test(e)&&(r=!1);var d={},s="rtw.uol.com",c=!1,i=1e3,h=1e4,p=1006,g=1e3,v=4001,m=4002,b={},o=[],C=null,n=null,l=+new Date,u=null,k=function(e){return f.map(e,function(e){return[e]})},y=function(){if(45e3<=+new Date-l&&C&&!0!==C.isFake&&(d.send(""),l=+new Date),!1===d.isConnected()&&C)return C.onerror({code:"TIMEOUT"}),!1;n=setTimeout(y,5e3)},N=function(e,n,o){var t=[];o?b[o]&&t.push(b[o]):t=t.concat(k(b));for(var r=0,i=t.length;r<i;r++)void 0!==t[r]&&"function"==typeof t[r].pub&&t[r].pub(e,n)},O=function(e){if(null!==C){var n=[];if(e){if(b[e]&&n.push(b[e]),!0===C.isFake)return C.removeChannels(e),!0}else n=n.concat(k(b));for(var o=0,t=n.length;o<t;o++)n[o].off(),delete b[n[o].channelName]}},S=function(){O(),clearTimeout(n),C&&(C.onmessage=null,C.onclose=null,C.onerror=null,C=null)},w=function(e){if("string"==typeof e)o.push(e);else for(var n;n=o.shift();)C.send(n)},L=function(e){if(b[e])return b[e];if(this instanceof L==!1)return new L(e);var i={message:[],close:[],error:[],lost:[],open:[]};this.channelName=e;var n,o={};return this.data=function(e){return void 0===e?o:o=e},this.on=function(e,n){if(i[e]){var o;for(o in i[e])if(!0===i[e].hasOwnProperty(o)&&i[e][o]===n)return this;i[e].push(n)}return this},this.off=function(e,n){var o,t;if(e){var r=i[e];if(r)for(o=0,t=r.length;o<t;o++)(n&&r[o]===n||!n)&&(r[o]=null)}else for(o in i)if(!0===i.hasOwnProperty(o))for(;i[o].pop(););return this},this.close=function(){return!0===d.isConnected()&&(this.client_solicitation=!0,C.send("unsubscribe:"+e)),this},this.pub=function(e,n){for(var o=i[e],t=0,r=o.length;t<r;t++)"function"==typeof o[t]&&o[t].call(this,n)},n=(n=e)||"",null===C||4===C.readyState?((C=!0===r&&!1===c?new WebSocket("wss://"+s+"/sub?id="+n):new D("wss://"+s+"/sub?id="+n)).reconnect||(C.reconnect=a),C.onopen=function(e){w(),y(),N("open",e)},C.onmessage=d.onmessage,C.onerror=function(e){N("error",e),e.invalidChannel||S()},C.onclose=function(e,n){var o=e&&e.code||n&&n.code||0;o===p||1001===o?N("error",e):!1!==e.triggerClose&&N("close",e),S()}):!0===d.isConnected()?C.send(n):w(n),this};function D(e){var n,o,t,r,i=1,c=0,a=0,s={url:e,channels:[],channelsUpdated:{},openDelay:100},l={URL:e,CONNECTING:0,OPEN:i,CLOSING:2,CLOSED:3,isFake:!0,removeChannels:function(n){if(n)s.channels=f.grep(s.channels,function(e){return e!==n}),delete s.channelsUpdated[n],delete b[n];else for(var e;e=s.channels.pop();)delete s.channelsUpdated[e],delete b[e]},channel:"",setLastModified:function(e){s.channelsUpdated[this.channel]=e},readyState:0,reconnect:function(e,n){!n||"function"==typeof n&&!0===n.call(s)?(clearTimeout(c),c=setTimeout(u,e)):l.close(!1);return!0},send:function(e){var n=e.match(/^unsubscribe:(.+)/);n?d.onmessage('{"unsubscribed":"'+n[1]+'"}'):s.channels.push(e)},close:function(e){this.readyState=2,clearTimeout(n),clearTimeout(c),!(this.readyState=3)!==e?f(l).triggerHandler("close",{code:g}):C=null},onopen:function(){},onmessage:function(){},onerror:function(){},onclose:function(){}};function u(e){var n;if(e?n=e:(l.channel=(a>=s.channels.length&&(a=0),s.channels[a++]),n=l.channel),0===s.channels.length)return f(l).triggerHandler("close",{code:v});f.ajax({type:"GET",url:s.url+"?id="+n+"&ifmod="+(s.channelsUpdated[n]||0)+"&ts="+ +new Date,cache:!0,dataType:"script",timeout:h,success:function(){},error:function(){f(l).triggerHandler("error",{code:p})}})}return r=(t=e).match(/id=([^&]+)$/),o=null!==r&&(s.channels.push(r[1]),s.url=t.replace("wss:","https:").replace(/\?.*/,""),!0),n=setTimeout(function(){!0===o?(l.readyState=i,f(l).triggerHandler("open"),s.channels.length&&u()):f(l).triggerHandler("close",{code:m})},s.openDelay),l}return d.version="2.8.10",d.CONFIG_CHANGES="CONFIG_CHANGES",d.connect=function(e){return b[e]=new L(e),b[e]},d.disconnect=function(e){return C&&C.close(1e3,e||"NORMAL"),d},d.isConnected=function(){return!(!C||C.readyState!==C.OPEN)},d.send=function(e){return!0===this.isConnected()&&C.send(e),this},d.lastMessageTime=function(){return new Date(l)},d.onmessage=function(e){if(!e)return C.reconnect(i);if(!1===d.isConnected())return!1;var n=C.isFake?e:e.data;if(void 0===n)return C.reconnect(i);try{"object"!=typeof n&&(n=JSON.parse(n))}catch(e){return C.reconnect(1e4),N("error",{error:"INVALID_JSON"}),console.error("mensagem precisa ser um JSON válido",n)}if(n.invalidChannel)return N("error",n,n.invalidChannel),O(n.invalidChannel),C&&!0===C.isFake&&C.reconnect(i,function(){return 0<this.channels.length}),console.log("invalidChannel: ",n.invalidChannel);if(n.unsubscribed)return N("close",n,n.unsubscribed),O(n.unsubscribed),C.reconnect(200);if(!n.channelName)return C.reconnect(1e4),N("error",{error:"NO_CHANNEL_NAME"}),console.error('json precisa do atributo "channelName"',n);if(!n.lastModified)return C.reconnect(1e4),N("error",{error:"NO_LAST_MODIFIED"}),console.error('json precisa do atributo "lastModified"',n);if(void 0===b[n.channelName])return!1;var o=b[n.channelName].data().lastModified;void 0!==o&&n.prevModified!==o&&N("lost",{error:"LOST_DATA"}),b[n.channelName].data(n),l=+new Date,N("message",n,n.channelName),!0===C.isFake&&(C.setLastModified(n.lastModified),C.reconnect(200))},d.config=function(e){var n,o={domain:s,forcePolling:c,pollingDelay:i,channels:b,connection:C};if(void 0===e)return o;if("string"==typeof e)return o[e];if(!0===e.parasite&&null!==u)return!1;if(!0===d.isConnected())return console.log("usocket.confg()\tAs configurações só são aplicadas quando não há conexão estabelecida."),!1;for(n in u=e)if(!0===e.hasOwnProperty(n)){var t=e[n];switch(n){case"domain":s=t;break;case"forcePolling":c=t;break;case"pollingDelay":i=t}}return!0},d.polling=function(t,r,i,e){if(void 0!==b[t]&&void 0===e)return console.error("Não é possível fazer polling em canal com conexão WebSocket ativa.");r=r||a;var c=function(e){if(e.channelName===t||e.invalidChannel===t){r.apply(i,[e.hasOwnProperty("invalidChannel"),e]);for(var n=0,o=UOLWebSocketCollection.length;n<o;n++)UOLWebSocketCollection[n]===c&&(UOLWebSocketCollection.splice(n,1),c=null)}};UOLWebSocketCollection.push(c),f.ajax({url:"https://"+s+"/sub?id="+t+"&ifmod=0&ts="+ +new Date,cache:!0,dataType:"script",scriptCharset:"utf-8"})},(t.UOLWebSocketCollection=t.UOLWebSocketCollection||[]).push(d.onmessage),"function"!=typeof t.UOLWebSocketCallback&&(t.UOLWebSocketCallback=function(e){for(var n=t.UOLWebSocketCollection,o=0;o<n.length;o++)n[o].call(null,e)}),d}(jQuery,e)),"function"==typeof define&&define.amd&&define("usocket",[],function(){return usocket}),"undefined"!=typeof angular&&angular.module("usocket",[]).factory("usocket",[function(){return usocket}])}(window);   