From 96819f1c2285c00ff0e79fa8a14f50f321eff564 Mon Sep 17 00:00:00 2001 From: Nikos M Date: Wed, 11 May 2016 01:37:33 +0300 Subject: [PATCH] v.0.1.0 --- src/RT.BOSH.js | 4 ++-- src/RT.BOSH.min.js | 2 +- src/RT.Poll.js | 20 ++++++++------------ src/RT.Poll.min.js | 2 +- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/RT.BOSH.js b/src/RT.BOSH.js index 5f9aa58..1ccecea 100644 --- a/src/RT.BOSH.js +++ b/src/RT.BOSH.js @@ -85,7 +85,6 @@ RT.Client.BOSH[PROTO].send = function( payload ){ }; RT.Client.BOSH[PROTO].listen = function( ){ var self = this; - self.emit( 'open' ); var listen = function listen( ) { self.$recv$ = XHR.create({ url : self.$cfg$.url + (-1 < self.$cfg$.url.indexOf('?') ? '&' : '?') + '__nocache__='+(new Date().getTime()), @@ -135,7 +134,8 @@ RT.Client.BOSH[PROTO].listen = function( ){ }, null); }; setTimeout( listen, 0 ); - return self; + return self.emit( 'open' ); + }; // export it diff --git a/src/RT.BOSH.min.js b/src/RT.BOSH.min.js index a3d19aa..7f174e5 100644 --- a/src/RT.BOSH.min.js +++ b/src/RT.BOSH.min.js @@ -7,4 +7,4 @@ * https://github.com/foo123/RT * **/ -!function(e,t){"use strict";"object"==typeof exports?t(require("./RT.js")):t(e.RT)&&"function"==typeof define&&define.amd&&define(function(){return e.RT})}(this,function(e){"use strict";var t="prototype",n=(Object[t].toString,e.Client[t]),r=e.Util,o=e.XHR;return e.Client.BOSH=function i(e){var t=this;return t instanceof i?(n.constructor.call(t,e),t.$cfg$.timeout=t.$cfg$.timeout||1e3,t.$send$=null,t.$recv$=null,void(t.$mID$=0)):new i(e)},e.Client.Impl.bosh=e.Client.Impl["long-poll"]=e.Client.BOSH,e.Client.BOSH[t]=Object.create(n),e.Client.BOSH[t].constructor=e.Client.BOSH,e.Client.BOSH[t].$send$=null,e.Client.BOSH[t].$recv$=null,e.Client.BOSH[t].$mID$=null,e.Client.BOSH[t].dispose=function(){var e=this;return e.abort(),e.$mID$=null,n.dispose.call(e)},e.Client.BOSH[t].abort=function(e){var t=this;return t.$recv$&&(t.$recv$.abort(!0===e),t.$recv$=null),t.$send$=null,t},e.Client.BOSH[t].send=function(e){var t=this;return o.create({url:t.$cfg$.url+(-1s;s++)e.emit("receive",c[s])}l&&(e.$mID$=l),setTimeout(n,0)}},null)};return setTimeout(t,0),e},e}); \ No newline at end of file +!function(e,t){"use strict";"object"==typeof exports?t(require("./RT.js")):t(e.RT)&&"function"==typeof define&&define.amd&&define(function(){return e.RT})}(this,function(e){"use strict";var t="prototype",n=(Object[t].toString,e.Client[t]),r=e.Util,o=e.XHR;return e.Client.BOSH=function i(e){var t=this;return t instanceof i?(n.constructor.call(t,e),t.$cfg$.timeout=t.$cfg$.timeout||1e3,t.$send$=null,t.$recv$=null,void(t.$mID$=0)):new i(e)},e.Client.Impl.bosh=e.Client.Impl["long-poll"]=e.Client.BOSH,e.Client.BOSH[t]=Object.create(n),e.Client.BOSH[t].constructor=e.Client.BOSH,e.Client.BOSH[t].$send$=null,e.Client.BOSH[t].$recv$=null,e.Client.BOSH[t].$mID$=null,e.Client.BOSH[t].dispose=function(){var e=this;return e.abort(),e.$mID$=null,n.dispose.call(e)},e.Client.BOSH[t].abort=function(e){var t=this;return t.$recv$&&(t.$recv$.abort(!0===e),t.$recv$=null),t.$send$=null,t},e.Client.BOSH[t].send=function(e){var t=this;return o.create({url:t.$cfg$.url+(-1s;s++)e.emit("receive",c[s])}l&&(e.$mID$=l),setTimeout(n,0)}},null)};return setTimeout(t,0),e.emit("open")},e}); \ No newline at end of file diff --git a/src/RT.Poll.js b/src/RT.Poll.js index 7023672..139640c 100644 --- a/src/RT.Poll.js +++ b/src/RT.Poll.js @@ -52,7 +52,12 @@ RT.Client.Poll[PROTO].abort = function( trigger ){ if ( self.$xhr$ ) { self.$xhr$.abort( true===trigger ); self.$xhr$ = null; } return self; }; -RT.Client.Poll[PROTO].$poll$ = function( immediate ){ +RT.Client.Poll[PROTO].send = function( payload ){ + var self = this; + self.$queue$.push( String(payload) ); + return self; +}; +RT.Client.Poll[PROTO].listen = function( ){ var self = this; var poll = function poll( ) { var headers = { @@ -111,17 +116,8 @@ RT.Client.Poll[PROTO].$poll$ = function( immediate ){ } }, msgs ? ('rt_payload='+U.Url.encode( msgs.join( rt_msg ) )) : null); }; - self.$timer$ = setTimeout(poll, true === immediate ? 0 : self.$cfg$.pollInterval); - return self; -}; -RT.Client.Poll[PROTO].send = function( payload ){ - var self = this; - self.$queue$.push( String(payload) ); - return self; -}; -RT.Client.Poll[PROTO].listen = function( ){ - var self = this; - return self.emit( 'open' ).$poll$( true ); + self.$timer$ = setTimeout(poll, 0); + return self.emit( 'open' ); }; // export it diff --git a/src/RT.Poll.min.js b/src/RT.Poll.min.js index d2770fe..a79c0cb 100644 --- a/src/RT.Poll.min.js +++ b/src/RT.Poll.min.js @@ -7,4 +7,4 @@ * https://github.com/foo123/RT * **/ -!function(e,l){"use strict";"object"==typeof exports?l(require("./RT.js")):l(e.RT)&&"function"==typeof define&&define.amd&&define(function(){return e.RT})}(this,function(e){"use strict";var l="prototype",t=(Object[l].toString,e.Client[l]),n=e.Util,r=e.XHR;return e.Client.Poll=function o(e){var l=this;return l instanceof o?(t.constructor.call(l,e),l.$cfg$.pollInterval=l.$cfg$.pollInterval||1e3,l.$timer$=null,l.$xhr$=null,l.$mID$=0,void(l.$queue$=[])):new o(e)},e.Client.Impl.poll=e.Client.Impl["short-poll"]=e.Client.Poll,e.Client.Poll[l]=Object.create(t),e.Client.Poll[l].constructor=e.Client.Poll,e.Client.Poll[l].$timer$=null,e.Client.Poll[l].$xhr$=null,e.Client.Poll[l].$queue$=null,e.Client.Poll[l].$mID$=null,e.Client.Poll[l].dispose=function(){var e=this;return e.abort(),e.$mID$=null,e.$queue$=null,t.dispose.call(e)},e.Client.Poll[l].abort=function(e){var l=this;return l.$timer$&&(clearTimeout(l.$timer$),l.$timer$=null),l.$xhr$&&(l.$xhr$.abort(!0===e),l.$xhr$=null),l},e.Client.Poll[l].$poll$=function(l){var t=this,o=function i(){var l={"Content-Type":"application/x-www-form-urlencoded; charset=utf8","X-RT--Poll":"1","X-RT--Receive":"1","X-RT--mID":t.$mID$},o=null,$=null;t.$queue$.length&&(l["X-RT--Send"]="1",l["X-RT--Message"]=o=e.UUID("----------------------"),$=t.$queue$.slice()),t.$xhr$=r.create({url:t.$cfg$.url+(-1$;$++)t.emit("receive",s[$])}o&&(t.$mID$=o),s&&t.$queue$.splice(0,s.length),t.$timer$=setTimeout(i,t.$cfg$.pollInterval)}},$?"rt_payload="+n.Url.encode($.join(o)):null)};return t.$timer$=setTimeout(o,!0===l?0:t.$cfg$.pollInterval),t},e.Client.Poll[l].send=function(e){var l=this;return l.$queue$.push(String(e)),l},e.Client.Poll[l].listen=function(){var e=this;return e.emit("open").$poll$(!0)},e}); \ No newline at end of file +!function(e,t){"use strict";"object"==typeof exports?t(require("./RT.js")):t(e.RT)&&"function"==typeof define&&define.amd&&define(function(){return e.RT})}(this,function(e){"use strict";var t="prototype",l=(Object[t].toString,e.Client[t]),n=e.Util,r=e.XHR;return e.Client.Poll=function o(e){var t=this;return t instanceof o?(l.constructor.call(t,e),t.$cfg$.pollInterval=t.$cfg$.pollInterval||1e3,t.$timer$=null,t.$xhr$=null,t.$mID$=0,void(t.$queue$=[])):new o(e)},e.Client.Impl.poll=e.Client.Impl["short-poll"]=e.Client.Poll,e.Client.Poll[t]=Object.create(l),e.Client.Poll[t].constructor=e.Client.Poll,e.Client.Poll[t].$timer$=null,e.Client.Poll[t].$xhr$=null,e.Client.Poll[t].$queue$=null,e.Client.Poll[t].$mID$=null,e.Client.Poll[t].dispose=function(){var e=this;return e.abort(),e.$mID$=null,e.$queue$=null,l.dispose.call(e)},e.Client.Poll[t].abort=function(e){var t=this;return t.$timer$&&(clearTimeout(t.$timer$),t.$timer$=null),t.$xhr$&&(t.$xhr$.abort(!0===e),t.$xhr$=null),t},e.Client.Poll[t].send=function(e){var t=this;return t.$queue$.push(String(e)),t},e.Client.Poll[t].listen=function(){var t=this,l=function o(){var l={"Content-Type":"application/x-www-form-urlencoded; charset=utf8","X-RT--Poll":"1","X-RT--Receive":"1","X-RT--mID":t.$mID$},i=null,u=null;t.$queue$.length&&(l["X-RT--Send"]="1",l["X-RT--Message"]=i=e.UUID("----------------------"),u=t.$queue$.slice()),t.$xhr$=r.create({url:t.$cfg$.url+(-1u;u++)t.emit("receive",s[u])}i&&(t.$mID$=i),s&&t.$queue$.splice(0,s.length),t.$timer$=setTimeout(o,t.$cfg$.pollInterval)}},u?"rt_payload="+n.Url.encode(u.join(i)):null)};return t.$timer$=setTimeout(l,0),t.emit("open")},e}); \ No newline at end of file