diff --git a/package.json b/package.json index 47afb46..8a26600 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yaj-sse", - "version": "0.3.0", + "version": "0.2.1", "description": "Yaj Plugin for Server-Sent Events (SSE) EventSource Polyfill", "main": "yaj-sse.js", "directories": { @@ -9,7 +9,7 @@ "scripts": { "minify-yaj": "./node_modules/.bin/uglifyjs --compress 'drop_console,drop_debugger' --mangle -o yaj-sse.min.js yaj-sse.js", "minify": "npm run minify-yaj", - "publish-patch": "npm test && npm run minify-yaj && git add yaj.min.* && git commit -m 'minify' && npm version patch && git push && git push --tags && npm publish" + "publish-patch": "npm run minify-yaj && git add yaj-*.min.* && git commit -m 'minify' && npm version patch && git push && git push --tags && npm publish" }, "repository": { "type": "git", diff --git a/yaj-sse.min.js b/yaj-sse.min.js index a850f8e..dc96a2c 100644 --- a/yaj-sse.min.js +++ b/yaj-sse.min.js @@ -1 +1 @@ -var SSE=function(e,n){function t(){u="event",c=new EventSource(a),c.successCount=0,c.onmessage=o.onMessage,c.onopen=function(e){0===c.successCount++&&o.onOpen(e)},c.onerror=function(e){e.target.readyState===EventSource.CLOSED&&o.onError(e)};for(var e in o.events)c.addEventListener(e,o.events[e],!1)}function r(){u="ajax",c={successCount:0,id:null,retry:3e3,data:"",event:""},s()}function s(){if(c){var e={"Last-Event-ID":c.id};for(var n in o.headers)e[n]=o.headers[n];yo().request({url:a,method:"GET",headers:e,success:function(e,n,t){if(c){0===c.successCount++&&o.onOpen();var r=e.split("\n");c.data="";var a=0;for(var i in r){var u=r[i].indexOf(":"),v=[r[i].substr(0,u),r[i].substr(u+1)];switch(v[0]){case"":v[1]||1!==a++||(eventMessage={data:c.data,lastEventId:c.id,origin:t.responseURL,returnValue:!0},c.event&&o.events[c.event]?o.events[c.event](eventMessage):o.onMessage(eventMessage),c.data="",c.event="",a=0);break;case"retry":a=0,c.retry=parseInt(v[1].trim());break;case"id":a=0,c.id=v[1].trim();break;case"event":a=0,c.event=v[1].trim();break;case"data":a=0,c.data+=(""!==c.data?"\n":"")+v[1].trim();break;default:a=0}}setTimeout(function(){s()},c.retry)}},error:o.onError})}}var a=e,o={onOpen:function(e){},onEnd:function(e){},onError:function(e){},onMessage:function(e){},options:{},headers:{},events:{}};for(var i in n)o[i]=n[i];var u=null,c=null;return{start:function(){return c?!1:(!window.EventSource||o.options.forceAjax||Object.keys(o.headers).length>0?r(this):t(this),!0)},stop:function(){return c?(!window.EventSource||o.options.forceAjax||Object.keys(o.headers).length>0||c.close(),o.onEnd(),c=null,u=null,!0):!1}}}; \ No newline at end of file +var SSE=function(e,n){function t(){u="event",(i=new EventSource(a)).successCount=0,i.onmessage=o.onMessage,i.onopen=function(e){0==i.successCount++&&o.onOpen(e)},i.onerror=function(e){e.target.readyState===EventSource.CLOSED&&o.onError(e)};for(var e in o.events)i.addEventListener(e,o.events[e],!1)}function r(){u="ajax",i={successCount:0,id:null,retry:3e3,data:"",event:""},s()}function s(){if(i){var e={"Last-Event-ID":i.id};for(var n in o.headers)e[n]=o.headers[n];Yaj.request({url:a,method:"GET",headers:e,success:function(e,n,t){if(i){0==i.successCount++&&o.onOpen();var r=e.split("\n");i.data="";var a=0;for(var u in r){var c=r[u].indexOf(":"),v=[r[u].substr(0,c),r[u].substr(c+1)];switch(v[0]){case"":v[1]||1!=a++||(eventMessage={data:i.data,lastEventId:i.id,origin:t.responseURL,returnValue:!0},i.event&&o.events[i.event]?o.events[i.event](eventMessage):o.onMessage(eventMessage),i.data="",i.event="",a=0);break;case"retry":a=0,i.retry=parseInt(v[1].trim());break;case"id":a=0,i.id=v[1].trim();break;case"event":a=0,i.event=v[1].trim();break;case"data":a=0,i.data+=(""!==i.data?"\n":"")+v[1].trim();break;default:a=0}}setTimeout(function(){s()},i.retry)}},error:o.onError})}}var a=e,o={onOpen:function(e){},onEnd:function(e){},onError:function(e){},onMessage:function(e){},options:{},headers:{},events:{}};yoCopy(n,o);var u=null,i=null;return{start:function(){return!i&&(!window.EventSource||o.options.forceAjax||Object.keys(o.headers).length>0?r():t(),!0)},stop:function(){return!!i&&(!window.EventSource||o.options.forceAjax||Object.keys(o.headers).length>0||i.close(),o.onEnd(),i=null,u=null,!0)}}}; \ No newline at end of file