From 667e8344b2e7bc43fbc81ba40634453aaef08823 Mon Sep 17 00:00:00 2001 From: Nikos M Date: Fri, 13 May 2016 14:59:36 +0300 Subject: [PATCH] v.1.0.1 * better minification --- src/RT.BOSH.js | 32 ++++++++++++++++---------------- src/RT.BOSH.min.js | 2 +- src/RT.Poll.js | 28 ++++++++++++++-------------- src/RT.Poll.min.js | 2 +- src/RT.WebSocket.js | 29 +++++++++++------------------ src/RT.WebSocket.min.js | 2 +- 6 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/RT.BOSH.js b/src/RT.BOSH.js index 2fbcf05..b5dd45d 100644 --- a/src/RT.BOSH.js +++ b/src/RT.BOSH.js @@ -19,10 +19,10 @@ else "use strict"; var PROTO = 'prototype', HAS = 'hasOwnProperty', toString = Object[PROTO].toString, - __super__ = RT.Client[PROTO], U = RT.Util, XHR = RT.XHR + RT_Client = RT.Client, __super__ = RT_Client[PROTO], U = RT.Util, RT_XHR = RT.XHR ; -RT.Client.BOSH = function Client_Bosh( cfg ) { +var Client_Bosh = RT_Client.BOSH = function Client_Bosh( cfg ) { var self = this; if ( !(self instanceof Client_Bosh) ) return new Client_Bosh(cfg); __super__.constructor.call( self, cfg ); @@ -32,16 +32,16 @@ RT.Client.BOSH = function Client_Bosh( cfg ) { self.$queue$ = []; self.$mID$ = 0; }; -RT.Client.Impl['bosh'] = RT.Client.Impl['long-poll'] = RT.Client.BOSH; +RT_Client.Impl['bosh'] = RT_Client.Impl['long-poll'] = Client_Bosh; /* extends RT.Client class */ -RT.Client.BOSH[PROTO] = Object.create( __super__ ); -RT.Client.BOSH[PROTO].constructor = RT.Client.BOSH; -RT.Client.BOSH[PROTO].$send$ = null; -RT.Client.BOSH[PROTO].$recv$ = null; -RT.Client.BOSH[PROTO].$queue$ = null; -RT.Client.BOSH[PROTO].$mID$ = null; -RT.Client.BOSH[PROTO].dispose = function( ){ +Client_Bosh[PROTO] = Object.create( __super__ ); +Client_Bosh[PROTO].constructor = Client_Bosh; +Client_Bosh[PROTO].$send$ = null; +Client_Bosh[PROTO].$recv$ = null; +Client_Bosh[PROTO].$queue$ = null; +Client_Bosh[PROTO].$mID$ = null; +Client_Bosh[PROTO].dispose = function( ){ var self = this; if ( self.$recv$ ) { self.$recv$.abort( ).dispose( ); self.$recv$ = null; } if ( self.$send$ ) { self.$send$.abort( ).dispose( ); self.$send$ = null; } @@ -49,13 +49,13 @@ RT.Client.BOSH[PROTO].dispose = function( ){ self.$mID$ = null; return __super__.dispose.call( self ); }; -RT.Client.BOSH[PROTO].abort = function( trigger ){ +Client_Bosh[PROTO].abort = function( trigger ){ var self = this; if ( self.$recv$ ) { self.$recv$.abort( ).dispose( ); self.$recv$ = null; } if ( self.$send$ ) { self.$send$.abort( ).dispose( ); self.$send$ = null; } return __super__.abort.call( self, true===trigger ); }; -RT.Client.BOSH[PROTO].send = function( payload ){ +Client_Bosh[PROTO].send = function( payload ){ var self = this; var send = function send( ) { var asUrlEncoded = 'urlencoded' === self.$cfg$.contentType, asXML = 'xml' === self.$cfg$.contentType, @@ -89,7 +89,7 @@ RT.Client.BOSH[PROTO].send = function( payload ){ headers['X-RT--Message'] = rt_msg = RT.UUID('------_rt_msg_', '_------'); rt_payload = rt_msgs.join( rt_msg ); } - self.$send$ = XHR.create({ + self.$send$ = RT_XHR.create({ url : self.$cfg$.endpoint + (-1 < self.$cfg$.endpoint.indexOf('?') ? '&' : '?') + '__nocache__='+(new Date().getTime()), timeout : self.$cfg$.timeout, method : 'POST', @@ -152,7 +152,7 @@ RT.Client.BOSH[PROTO].send = function( payload ){ if ( !self.$send$ ) setTimeout( send, 0 ); return self; }; -RT.Client.BOSH[PROTO].$receive$ = function( ){ +Client_Bosh[PROTO].$receive$ = function( ){ var self = this; if ( self.$recv$ ) return; var asUrlEncoded = 'urlencoded' === self.$cfg$.contentType, asXML = 'xml' === self.$cfg$.contentType, @@ -166,7 +166,7 @@ RT.Client.BOSH[PROTO].$receive$ = function( ){ 'X-RT--mID' : self.$mID$ } ; - self.$recv$ = XHR.create({ + self.$recv$ = RT_XHR.create({ url : self.$cfg$.endpoint + (-1 < self.$cfg$.endpoint.indexOf('?') ? '&' : '?') + '__nocache__='+(new Date().getTime()), timeout : self.$cfg$.timeout, method : 'POST', @@ -240,7 +240,7 @@ RT.Client.BOSH[PROTO].$receive$ = function( ){ } }, null); }; -RT.Client.BOSH[PROTO].listen = function( ){ +Client_Bosh[PROTO].listen = function( ){ var self = this; setTimeout( function( ){ self.$receive$( ); }, 10 ); return self.open( ); diff --git a/src/RT.BOSH.min.js b/src/RT.BOSH.min.js index 99c52dc..f3f55ae 100644 --- a/src/RT.BOSH.min.js +++ b/src/RT.BOSH.min.js @@ -7,4 +7,4 @@ * https://github.com/foo123/RT * **/ -!function(e,n){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?n(e.RT):"object"==typeof exports?n(require("./RT.js")):n(e.RT)&&"function"==typeof define&&define.amd&&define(function(){return e.RT})}(this,function(e){"use strict";var n="prototype",t=(Object[n].toString,e.Client[n]),$=e.Util,r=e.XHR;return e.Client.BOSH=function o(e){var n=this;return n instanceof o?(t.constructor.call(n,e),n.$cfg$.timeout=n.$cfg$.timeout||5e3,n.$send$=null,n.$recv$=null,n.$queue$=[],void(n.$mID$=0)):new o(e)},e.Client.Impl.bosh=e.Client.Impl["long-poll"]=e.Client.BOSH,e.Client.BOSH[n]=Object.create(t),e.Client.BOSH[n].constructor=e.Client.BOSH,e.Client.BOSH[n].$send$=null,e.Client.BOSH[n].$recv$=null,e.Client.BOSH[n].$queue$=null,e.Client.BOSH[n].$mID$=null,e.Client.BOSH[n].dispose=function(){var e=this;return e.$recv$&&(e.$recv$.abort().dispose(),e.$recv$=null),e.$send$&&(e.$send$.abort().dispose(),e.$send$=null),e.$queue$=null,e.$mID$=null,t.dispose.call(e)},e.Client.BOSH[n].abort=function(e){var n=this;return n.$recv$&&(n.$recv$.abort().dispose(),n.$recv$=null),n.$send$&&(n.$send$.abort().dispose(),n.$send$=null),t.abort.call(n,!0===e)},e.Client.BOSH[n].send=function(n){var t=this,o=function s(){var n="urlencoded"===t.$cfg$.contentType,o="xml"===t.$cfg$.contentType,i=t.$cfg$.charset?"charset="+String(t.$cfg$.charset):"charset=utf8",c=o?"text/xml":n?"application/x-www-form-urlencoded":"text/plain",l={Connection:"Keep-Alive","Content-Type":c+"; "+i,"X-RT--BOSH":"1","X-RT--Receive":"1","X-RT--mID":t.$mID$},u=t.$queue$.slice(),p=null,d=null;o?(l["X-RT--Send"]="1",d=u.join("")):n?(l["X-RT--Send"]="x-rt--payload",l["X-RT--Message"]=p=e.UUID("------_rt_msg_","_------"),d="x-rt--payload="+$.Url.encode(u.join(p))):(l["X-RT--Send"]="1",l["X-RT--Message"]=p=e.UUID("------_rt_msg_","_------"),d=u.join(p)),t.$send$=r.create({url:t.$cfg$.endpoint+(-1i;i++)t.emit("receive",l[i])}else e.responseText&&t.emit("receive",e.responseText);t.$queue$.length?setTimeout(s,100):t.$recv$||setTimeout(function(){t.$receive$()},100)}},d)};return t.$queue$.push(String(n)),t.$send$||setTimeout(o,0),t},e.Client.BOSH[n].$receive$=function(){var e=this;if(!e.$recv$){var n="urlencoded"===e.$cfg$.contentType,t="xml"===e.$cfg$.contentType,$=e.$cfg$.charset?"charset="+String(e.$cfg$.charset):"charset=utf8",o=t?"text/xml":n?"application/x-www-form-urlencoded":"text/plain",s={Connection:"Keep-Alive","Content-Type":o+"; "+$,"X-RT--BOSH":"1","X-RT--Receive":"1","X-RT--mID":e.$mID$};e.$recv$=r.create({url:e.$cfg$.endpoint+(-1s;s++)e.emit("receive",c[s])}else n.responseText&&e.emit("receive",n.responseText);e.$recv$||setTimeout(function(){e.$receive$()},100)}},null)}},e.Client.BOSH[n].listen=function(){var e=this;return setTimeout(function(){e.$receive$()},10),e.open()},e}); \ No newline at end of file +!function(e,n){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?n(e.RT):"object"==typeof exports?n(require("./RT.js")):n(e.RT)&&"function"==typeof define&&define.amd&&define(function(){return e.RT})}(this,function(e){"use strict";var n="prototype",t=(Object[n].toString,e.Client),$=t[n],r=e.Util,o=e.XHR,s=t.BOSH=function c(e){var n=this;return n instanceof c?($.constructor.call(n,e),n.$cfg$.timeout=n.$cfg$.timeout||5e3,n.$send$=null,n.$recv$=null,n.$queue$=[],void(n.$mID$=0)):new c(e)};return t.Impl.bosh=t.Impl["long-poll"]=s,s[n]=Object.create($),s[n].constructor=s,s[n].$send$=null,s[n].$recv$=null,s[n].$queue$=null,s[n].$mID$=null,s[n].dispose=function(){var e=this;return e.$recv$&&(e.$recv$.abort().dispose(),e.$recv$=null),e.$send$&&(e.$send$.abort().dispose(),e.$send$=null),e.$queue$=null,e.$mID$=null,$.dispose.call(e)},s[n].abort=function(e){var n=this;return n.$recv$&&(n.$recv$.abort().dispose(),n.$recv$=null),n.$send$&&(n.$send$.abort().dispose(),n.$send$=null),$.abort.call(n,!0===e)},s[n].send=function(n){var t=this,$=function s(){var n="urlencoded"===t.$cfg$.contentType,$="xml"===t.$cfg$.contentType,c=t.$cfg$.charset?"charset="+String(t.$cfg$.charset):"charset=utf8",i=$?"text/xml":n?"application/x-www-form-urlencoded":"text/plain",u={Connection:"Keep-Alive","Content-Type":i+"; "+c,"X-RT--BOSH":"1","X-RT--Receive":"1","X-RT--mID":t.$mID$},l=t.$queue$.slice(),p=null,d=null;$?(u["X-RT--Send"]="1",d=l.join("")):n?(u["X-RT--Send"]="x-rt--payload",u["X-RT--Message"]=p=e.UUID("------_rt_msg_","_------"),d="x-rt--payload="+r.Url.encode(l.join(p))):(u["X-RT--Send"]="1",u["X-RT--Message"]=p=e.UUID("------_rt_msg_","_------"),d=l.join(p)),t.$send$=o.create({url:t.$cfg$.endpoint+(-1c;c++)t.emit("receive",u[c])}else e.responseText&&t.emit("receive",e.responseText);t.$queue$.length?setTimeout(s,100):t.$recv$||setTimeout(function(){t.$receive$()},100)}},d)};return t.$queue$.push(String(n)),t.$send$||setTimeout($,0),t},s[n].$receive$=function(){var e=this;if(!e.$recv$){var n="urlencoded"===e.$cfg$.contentType,t="xml"===e.$cfg$.contentType,$=e.$cfg$.charset?"charset="+String(e.$cfg$.charset):"charset=utf8",r=t?"text/xml":n?"application/x-www-form-urlencoded":"text/plain",s={Connection:"Keep-Alive","Content-Type":r+"; "+$,"X-RT--BOSH":"1","X-RT--Receive":"1","X-RT--mID":e.$mID$};e.$recv$=o.create({url:e.$cfg$.endpoint+(-1s;s++)e.emit("receive",i[s])}else n.responseText&&e.emit("receive",n.responseText);e.$recv$||setTimeout(function(){e.$receive$()},100)}},null)}},s[n].listen=function(){var e=this;return setTimeout(function(){e.$receive$()},10),e.open()},e}); \ No newline at end of file diff --git a/src/RT.Poll.js b/src/RT.Poll.js index 6c539d2..28aaf65 100644 --- a/src/RT.Poll.js +++ b/src/RT.Poll.js @@ -19,10 +19,10 @@ else "use strict"; var PROTO = 'prototype', HAS = 'hasOwnProperty', toString = Object[PROTO].toString, - __super__ = RT.Client[PROTO], U = RT.Util, XHR = RT.XHR + RT_Client = RT.Client, __super__ = RT_Client[PROTO], U = RT.Util, RT_XHR = RT.XHR ; -RT.Client.Poll = function Client_Poll( cfg ) { +var Client_Poll = RT_Client.Poll = function Client_Poll( cfg ) { var self = this; if ( !(self instanceof Client_Poll) ) return new Client_Poll(cfg); __super__.constructor.call( self, cfg ); @@ -32,16 +32,16 @@ RT.Client.Poll = function Client_Poll( cfg ) { self.$mID$ = 0; self.$queue$ = []; }; -RT.Client.Impl['poll'] = RT.Client.Impl['short-poll'] = RT.Client.Poll; +RT_Client.Impl['poll'] = RT_Client.Impl['short-poll'] = Client_Poll; /* extends RT.Client class */ -RT.Client.Poll[PROTO] = Object.create( __super__ ); -RT.Client.Poll[PROTO].constructor = RT.Client.Poll; -RT.Client.Poll[PROTO].$timer$ = null; -RT.Client.Poll[PROTO].$xhr$ = null; -RT.Client.Poll[PROTO].$queue$ = null; -RT.Client.Poll[PROTO].$mID$ = null; -RT.Client.Poll[PROTO].dispose = function( ){ +Client_Poll[PROTO] = Object.create( __super__ ); +Client_Poll[PROTO].constructor = Client_Poll; +Client_Poll[PROTO].$timer$ = null; +Client_Poll[PROTO].$xhr$ = null; +Client_Poll[PROTO].$queue$ = null; +Client_Poll[PROTO].$mID$ = null; +Client_Poll[PROTO].dispose = function( ){ var self = this; if ( self.$timer$ ) { clearTimeout( self.$timer$ ); self.$timer$ = null; } if ( self.$xhr$ ) { self.$xhr$.abort( ).dispose( ); self.$xhr$ = null; } @@ -49,18 +49,18 @@ RT.Client.Poll[PROTO].dispose = function( ){ self.$queue$ = null; return __super__.dispose.call( self ); }; -RT.Client.Poll[PROTO].abort = function( trigger ){ +Client_Poll[PROTO].abort = function( trigger ){ var self = this; if ( self.$timer$ ) { clearTimeout( self.$timer$ ); self.$timer$ = null; } if ( self.$xhr$ ) { self.$xhr$.abort( ).dispose( ); self.$xhr$ = null; } return __super__.abort.call( self, true===trigger ); }; -RT.Client.Poll[PROTO].send = function( payload ){ +Client_Poll[PROTO].send = function( payload ){ var self = this; self.$queue$.push( String(payload) ); return self; }; -RT.Client.Poll[PROTO].listen = function( ){ +Client_Poll[PROTO].listen = function( ){ var self = this; var poll = function poll( ) { var asUrlEncoded = 'urlencoded' === self.$cfg$.contentType, asXML = 'xml' === self.$cfg$.contentType, @@ -96,7 +96,7 @@ RT.Client.Poll[PROTO].listen = function( ){ rt_payload = rt_msgs.join( rt_msg ); } } - self.$xhr$ = XHR.create({ + self.$xhr$ = RT_XHR.create({ url : self.$cfg$.endpoint + (-1 < self.$cfg$.endpoint.indexOf('?') ? '&' : '?') + '__nocache__='+(new Date().getTime()), method : 'POST', responseType : /*asXML ? 'xml' :*/ 'text', diff --git a/src/RT.Poll.min.js b/src/RT.Poll.min.js index 4a06ba9..4935979 100644 --- a/src/RT.Poll.min.js +++ b/src/RT.Poll.min.js @@ -7,4 +7,4 @@ * https://github.com/foo123/RT * **/ -!function(e,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?t(e.RT):"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]),l=e.Util,o=e.XHR;return e.Client.Poll=function r(e){var t=this;return t instanceof r?(n.constructor.call(t,e),t.$cfg$.pollInterval=t.$cfg$.pollInterval||1e3,t.$timer$=null,t.$xhr$=null,t.$mID$=0,void(t.$queue$=[])):new r(e)},e.Client.Impl.poll=e.Client.Impl["short-poll"]=e.Client.Poll,e.Client.Poll[t]=Object.create(n),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.$timer$&&(clearTimeout(e.$timer$),e.$timer$=null),e.$xhr$&&(e.$xhr$.abort().dispose(),e.$xhr$=null),e.$mID$=null,e.$queue$=null,n.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().dispose(),t.$xhr$=null),n.abort.call(t,!0===e)},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,n=function r(){var n="urlencoded"===t.$cfg$.contentType,i="xml"===t.$cfg$.contentType,$=t.$cfg$.charset?"charset="+String(t.$cfg$.charset):"charset=utf8",s=i?"text/xml":n?"application/x-www-form-urlencoded":"text/plain",u={"Content-Type":s+"; "+$,"X-RT--Poll":"1","X-RT--Receive":"1","X-RT--mID":t.$mID$},c=null,p=null,a=null;t.$queue$.length&&(p=t.$queue$.slice(),i?(u["X-RT--Send"]="1",a=p.join("")):n?(u["X-RT--Send"]="x-rt--payload",u["X-RT--Message"]=c=e.UUID("------_rt_msg_","_------"),a="x-rt--payload="+l.Url.encode(p.join(c))):(u["X-RT--Send"]="1",u["X-RT--Message"]=c=e.UUID("------_rt_msg_","_------"),a=p.join(c))),t.$xhr$=o.create({url:t.$cfg$.endpoint+(-1$;$++)t.emit("receive",u[$])}else e.responseText&&t.emit("receive",e.responseText);t.$timer$=setTimeout(r,t.$cfg$.pollInterval)}},a)};return t.$timer$=setTimeout(n,10),t.open()},e}); \ No newline at end of file +!function(e,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?t(e.RT):"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),r=n[t],o=e.Util,l=e.XHR,$=n.Poll=function i(e){var t=this;return t instanceof i?(r.constructor.call(t,e),t.$cfg$.pollInterval=t.$cfg$.pollInterval||1e3,t.$timer$=null,t.$xhr$=null,t.$mID$=0,void(t.$queue$=[])):new i(e)};return n.Impl.poll=n.Impl["short-poll"]=$,$[t]=Object.create(r),$[t].constructor=$,$[t].$timer$=null,$[t].$xhr$=null,$[t].$queue$=null,$[t].$mID$=null,$[t].dispose=function(){var e=this;return e.$timer$&&(clearTimeout(e.$timer$),e.$timer$=null),e.$xhr$&&(e.$xhr$.abort().dispose(),e.$xhr$=null),e.$mID$=null,e.$queue$=null,r.dispose.call(e)},$[t].abort=function(e){var t=this;return t.$timer$&&(clearTimeout(t.$timer$),t.$timer$=null),t.$xhr$&&(t.$xhr$.abort().dispose(),t.$xhr$=null),r.abort.call(t,!0===e)},$[t].send=function(e){var t=this;return t.$queue$.push(String(e)),t},$[t].listen=function(){var t=this,n=function r(){var n="urlencoded"===t.$cfg$.contentType,$="xml"===t.$cfg$.contentType,i=t.$cfg$.charset?"charset="+String(t.$cfg$.charset):"charset=utf8",s=$?"text/xml":n?"application/x-www-form-urlencoded":"text/plain",u={"Content-Type":s+"; "+i,"X-RT--Poll":"1","X-RT--Receive":"1","X-RT--mID":t.$mID$},c=null,p=null,a=null;t.$queue$.length&&(p=t.$queue$.slice(),$?(u["X-RT--Send"]="1",a=p.join("")):n?(u["X-RT--Send"]="x-rt--payload",u["X-RT--Message"]=c=e.UUID("------_rt_msg_","_------"),a="x-rt--payload="+o.Url.encode(p.join(c))):(u["X-RT--Send"]="1",u["X-RT--Message"]=c=e.UUID("------_rt_msg_","_------"),a=p.join(c))),t.$xhr$=l.create({url:t.$cfg$.endpoint+(-1i;i++)t.emit("receive",u[i])}else e.responseText&&t.emit("receive",e.responseText);t.$timer$=setTimeout(r,t.$cfg$.pollInterval)}},a)};return t.$timer$=setTimeout(n,10),t.open()},e}); \ No newline at end of file diff --git a/src/RT.WebSocket.js b/src/RT.WebSocket.js index b4ddb12..af1d8fa 100644 --- a/src/RT.WebSocket.js +++ b/src/RT.WebSocket.js @@ -19,7 +19,7 @@ else "use strict"; var PROTO = 'prototype', HAS = 'hasOwnProperty', toString = Object[PROTO].toString, - __super__ = RT.Client[PROTO], U = RT.Util, + RT_Client = RT.Client, __super__ = RT_Client[PROTO], WebSocket = RT.Platform.XPCOM || RT.Platform.Node ? null : (window.WebSocket || window.MozWebSocket || window.WebkitWebSocket) @@ -102,7 +102,6 @@ if ( RT.Platform.XPCOM ) if ( this._e[event] ) this._e[event]( {event:event, data:data, target:this} ); } - /** * nsIWebSocketListener method, handles the start of the websocket stream. * @@ -116,7 +115,6 @@ if ( RT.Platform.XPCOM ) self.dispatchEvent( 'open' ); } } - /** * nsIWebSocketListener method, called when the websocket is closed locally. * @@ -131,7 +129,6 @@ if ( RT.Platform.XPCOM ) self.dispatchEvent( Cr.NS_OK === aStatusCode || self._ws.CLOSE_NORMAL === aStatusCode ? 'close' : 'error', {status:aStatusCode} ); } } - /** * nsIWebSocketListener method, called when the websocket is closed * by the far end. @@ -148,7 +145,6 @@ if ( RT.Platform.XPCOM ) self.dispatchEvent( 'close', {status:aCode, statusTxt:aReason} ); } } - /** * nsIWebSocketListener method, called when the websocket receives * a text message (normally json encoded). @@ -163,7 +159,6 @@ if ( RT.Platform.XPCOM ) self.dispatchEvent( 'message', aMsg ); } } - /** * nsIWebSocketListener method, called when the websocket receives a binary message. * This class assumes that it is connected to a SimplePushServer and therefore treats @@ -179,7 +174,6 @@ if ( RT.Platform.XPCOM ) self.dispatchEvent( 'message', aMsg ); } } - /** * Create a JSON encoded message payload and send via websocket. * @@ -201,7 +195,6 @@ if ( RT.Platform.XPCOM ) } return false; } - /** * Close the websocket. */ @@ -234,24 +227,24 @@ else if ( !WebSocket ) load_websocket_shim(function( ){ WebSocket = window.WebSocket; }); } -RT.Client.WS = function Client_WS( config ) { +var Client_WS = RT_Client.WS = function Client_WS( config ) { var self = this; if ( !(self instanceof Client_WS) ) return new Client_WS(config); __super__.constructor.call( self, config ); self.$ws$ = null; }; -RT.Client.Impl['ws'] = RT.Client.Impl['websocket'] = RT.Client.Impl['web-socket'] = RT.Client.WS; +RT_Client.Impl['ws'] = RT_Client.Impl['websocket'] = RT_Client.Impl['web-socket'] = Client_WS; /* extends RT.Client class */ -RT.Client.WS[PROTO] = Object.create( __super__ ); -RT.Client.WS[PROTO].constructor = RT.Client.WS; -RT.Client.WS[PROTO].$ws$ = null; -RT.Client.WS[PROTO].dispose = function( ){ +Client_WS[PROTO] = Object.create( __super__ ); +Client_WS[PROTO].constructor = Client_WS; +Client_WS[PROTO].$ws$ = null; +Client_WS[PROTO].dispose = function( ){ var self = this; self.$ws$ = null; return __super__.dispose.call( self ); }; -RT.Client.WS[PROTO].abort = function( ){ +Client_WS[PROTO].abort = function( ){ var self = this, ws = self.$ws$; if ( ws && (WebSocket.OPEN === ws.readyState) ) { @@ -261,18 +254,18 @@ RT.Client.WS[PROTO].abort = function( ){ self.$ws$ = null; return self; }; -RT.Client.WS[PROTO].close = function( e ){ +Client_WS[PROTO].close = function( e ){ var self = this, ws = self.$ws$; if ( ws && (WebSocket.OPEN === ws.readyState) ) ws.close( ); __super__.close.call( self, e ); return self; }; -RT.Client.WS[PROTO].send = function( payload ){ +Client_WS[PROTO].send = function( payload ){ var self = this, ws = self.$ws$; if ( ws && (WebSocket.OPEN === ws.readyState) ) ws.send( String(payload) ); return self; }; -RT.Client.WS[PROTO].listen = function( ){ +Client_WS[PROTO].listen = function( ){ var self = this, ws; if ( !WebSocket && !RT.Platform.XPCOM && !RT.Platform.Node ) { diff --git a/src/RT.WebSocket.min.js b/src/RT.WebSocket.min.js index dcbbb64..ae45561 100644 --- a/src/RT.WebSocket.min.js +++ b/src/RT.WebSocket.min.js @@ -7,4 +7,4 @@ * https://github.com/foo123/RT * **/ -!function(t,e){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?e(t.RT):"object"==typeof exports?e(require("./RT.js")):e(t.RT)&&"function"==typeof define&&define.amd&&define(function(){return t.RT})}(this,function(t){"use strict";function e(t){var e,n,s=document.getElementsByTagName("scripts"),o=s[s.length-1].src.split("/").slice(0,-1).join("/"),i=document.getElementsByTagName("head")[0];window.swfobject||(e=document.createElement("script"),e.setAttribute("type","text/javascript"),e.setAttribute("language","javascript"),e.setAttribute("src",o+"/lib/ws/swfobject.js"),i.appendChild(e)),window.WEB_SOCKET_SWF_LOCATION=o+"/lib/ws/WebSocketMain.swf",window.WEB_SOCKET_FORCE_FLASH=!1,window.WEB_SOCKET_DEBUG=!1,n=document.createElement("script"),n.setAttribute("type","text/javascript"),n.setAttribute("language","javascript"),n.onload=n.onreadystatechange=function(){"loaded"!=n.readyState&&"complete"!=n.readyState||(n.onload=n.onreadystatechange=null,t&&t())},n.setAttribute("src",o+"/lib/ws/ws.js"),i.appendChild(n)}var n="prototype",s=(Object[n].toString,t.Client[n]),o=(t.Util,t.Platform.XPCOM||t.Platform.Node?null:window.WebSocket||window.MozWebSocket||window.WebkitWebSocket);if(t.Platform.XPCOM){var i=Components.classes,a=Components.interfaces,r=Components.utils,c=Components.results;r["import"]("resource://gre/modules/Services.jsm"),o=function(t,e){var n=this;e=n._e={},n.readyState=o.CONNECTING,n._ws=i["@mozilla.org/network/protocol;1?name=wss"].createInstance(a.nsIWebSocketChannel),n._ws.initLoadInfo(null,Services.scriptSecurityManager.getSystemPrincipal(),null,a.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,a.nsIContentPolicy.TYPE_WEBSOCKET),"string"==typeof e&&(e=[e]),e&&(n._ws.protocol=e.join("; ")),n._ws.asyncOpen(Services.io.newURI(t,null,null),null,0,n,null)},o.CONNECTING=0,o.OPEN=1,o.CLOSING=2,o.CLOSED=3,o.prototype={constructor:o,readyState:0,_ws:null,_e:null,addEventListener:function(t,e){this._e[t]=e},removeEventListener:function(t,e){!this._e[t]||null!=e&&e!==this._e[t]||delete this._e[t]},dispatchEvent:function(t,e){this._e[t]&&this._e[t]({event:t,data:e,target:this})},onStart:function(){var t=this;o.CONNECTING===t.readyState&&(t.readyState=o.OPEN,t.dispatchEvent("open"))},onStop:function(t,e){var n=this;o.CLOSING!==n.readyState&&o.OPEN!==n.readyState||(n.readyState=o.CLOSED,n.dispatchEvent(c.NS_OK===e||n._ws.CLOSE_NORMAL===e?"close":"error",{status:e}))},onServerClose:function(t,e,n){var s=this;o.OPEN===s.readyState&&(s.readyState=o.CLOSED,s.dispatchEvent("close",{status:e,statusTxt:n}))},onMessageAvailable:function(t,e){var n=this;o.OPEN===n.readyState&&n.dispatchEvent("message",e)},onBinaryMessageAvailable:function(t,e){var n=this;o.OPEN===n.readyState&&n.dispatchEvent("message",e)},send:function(t){var e=this;if(o.OPEN===e.readyState){try{e._ws.sendMsg(t)}catch(n){return!1}return!0}return!1},close:function(){var t=this;if(o.CLOSING!==t.readyState&&o.CLOSED!==t.readyState){t.readyState=o.CLOSING;try{t._ws.close(t._ws.CLOSE_NORMAL),t.readyState=o.CLOSED}catch(e){t.readyState=o.CLOSED}}}}}else t.Platform.Node?o=require("ws"):o||e(function(){o=window.WebSocket});return t.Client.WS=function l(t){var e=this;return e instanceof l?(s.constructor.call(e,t),void(e.$ws$=null)):new l(t)},t.Client.Impl.ws=t.Client.Impl.websocket=t.Client.Impl["web-socket"]=t.Client.WS,t.Client.WS[n]=Object.create(s),t.Client.WS[n].constructor=t.Client.WS,t.Client.WS[n].$ws$=null,t.Client.WS[n].dispose=function(){var t=this;return t.$ws$=null,s.dispose.call(t)},t.Client.WS[n].abort=function(){var t=this,e=t.$ws$;return e&&o.OPEN===e.readyState&&(e.close(),s.abort.call(t,!0)),t.$ws$=null,t},t.Client.WS[n].close=function(t){var e=this,n=e.$ws$;return n&&o.OPEN===n.readyState&&n.close(),s.close.call(e,t),e},t.Client.WS[n].send=function(t){var e=this,n=e.$ws$;return n&&o.OPEN===n.readyState&&n.send(String(t)),e},t.Client.WS[n].listen=function(){var e,n=this;return o||t.Platform.XPCOM||t.Platform.Node?(e=n.$ws$=new o(n.$cfg$.endpoint),e.addEventListener("open",function(t){n.open(t)}),e.addEventListener("close",function(t){n.close(t)}),e.addEventListener("error",function(t){n.emit("error",t)}),e.addEventListener("message",function(t){n.emit("receive",t.data)}),n):(setTimeout(function(){n.listen()},100),n)},t}); \ No newline at end of file +!function(t,e){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?e(t.RT):"object"==typeof exports?e(require("./RT.js")):e(t.RT)&&"function"==typeof define&&define.amd&&define(function(){return t.RT})}(this,function(t){"use strict";function e(t){var e,n,s=document.getElementsByTagName("scripts"),o=s[s.length-1].src.split("/").slice(0,-1).join("/"),a=document.getElementsByTagName("head")[0];window.swfobject||(e=document.createElement("script"),e.setAttribute("type","text/javascript"),e.setAttribute("language","javascript"),e.setAttribute("src",o+"/lib/ws/swfobject.js"),a.appendChild(e)),window.WEB_SOCKET_SWF_LOCATION=o+"/lib/ws/WebSocketMain.swf",window.WEB_SOCKET_FORCE_FLASH=!1,window.WEB_SOCKET_DEBUG=!1,n=document.createElement("script"),n.setAttribute("type","text/javascript"),n.setAttribute("language","javascript"),n.onload=n.onreadystatechange=function(){"loaded"!=n.readyState&&"complete"!=n.readyState||(n.onload=n.onreadystatechange=null,t&&t())},n.setAttribute("src",o+"/lib/ws/ws.js"),a.appendChild(n)}var n="prototype",s=(Object[n].toString,t.Client),o=s[n],a=t.Platform.XPCOM||t.Platform.Node?null:window.WebSocket||window.MozWebSocket||window.WebkitWebSocket;if(t.Platform.XPCOM){var r=Components.classes,i=Components.interfaces,c=Components.utils,l=Components.results;c["import"]("resource://gre/modules/Services.jsm"),a=function(t,e){var n=this;e=n._e={},n.readyState=a.CONNECTING,n._ws=r["@mozilla.org/network/protocol;1?name=wss"].createInstance(i.nsIWebSocketChannel),n._ws.initLoadInfo(null,Services.scriptSecurityManager.getSystemPrincipal(),null,i.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,i.nsIContentPolicy.TYPE_WEBSOCKET),"string"==typeof e&&(e=[e]),e&&(n._ws.protocol=e.join("; ")),n._ws.asyncOpen(Services.io.newURI(t,null,null),null,0,n,null)},a.CONNECTING=0,a.OPEN=1,a.CLOSING=2,a.CLOSED=3,a.prototype={constructor:a,readyState:0,_ws:null,_e:null,addEventListener:function(t,e){this._e[t]=e},removeEventListener:function(t,e){!this._e[t]||null!=e&&e!==this._e[t]||delete this._e[t]},dispatchEvent:function(t,e){this._e[t]&&this._e[t]({event:t,data:e,target:this})},onStart:function(){var t=this;a.CONNECTING===t.readyState&&(t.readyState=a.OPEN,t.dispatchEvent("open"))},onStop:function(t,e){var n=this;a.CLOSING!==n.readyState&&a.OPEN!==n.readyState||(n.readyState=a.CLOSED,n.dispatchEvent(l.NS_OK===e||n._ws.CLOSE_NORMAL===e?"close":"error",{status:e}))},onServerClose:function(t,e,n){var s=this;a.OPEN===s.readyState&&(s.readyState=a.CLOSED,s.dispatchEvent("close",{status:e,statusTxt:n}))},onMessageAvailable:function(t,e){var n=this;a.OPEN===n.readyState&&n.dispatchEvent("message",e)},onBinaryMessageAvailable:function(t,e){var n=this;a.OPEN===n.readyState&&n.dispatchEvent("message",e)},send:function(t){var e=this;if(a.OPEN===e.readyState){try{e._ws.sendMsg(t)}catch(n){return!1}return!0}return!1},close:function(){var t=this;if(a.CLOSING!==t.readyState&&a.CLOSED!==t.readyState){t.readyState=a.CLOSING;try{t._ws.close(t._ws.CLOSE_NORMAL),t.readyState=a.CLOSED}catch(e){t.readyState=a.CLOSED}}}}}else t.Platform.Node?a=require("ws"):a||e(function(){a=window.WebSocket});var u=s.WS=function d(t){var e=this;return e instanceof d?(o.constructor.call(e,t),void(e.$ws$=null)):new d(t)};return s.Impl.ws=s.Impl.websocket=s.Impl["web-socket"]=u,u[n]=Object.create(o),u[n].constructor=u,u[n].$ws$=null,u[n].dispose=function(){var t=this;return t.$ws$=null,o.dispose.call(t)},u[n].abort=function(){var t=this,e=t.$ws$;return e&&a.OPEN===e.readyState&&(e.close(),o.abort.call(t,!0)),t.$ws$=null,t},u[n].close=function(t){var e=this,n=e.$ws$;return n&&a.OPEN===n.readyState&&n.close(),o.close.call(e,t),e},u[n].send=function(t){var e=this,n=e.$ws$;return n&&a.OPEN===n.readyState&&n.send(String(t)),e},u[n].listen=function(){var e,n=this;return a||t.Platform.XPCOM||t.Platform.Node?(e=n.$ws$=new a(n.$cfg$.endpoint),e.addEventListener("open",function(t){n.open(t)}),e.addEventListener("close",function(t){n.close(t)}),e.addEventListener("error",function(t){n.emit("error",t)}),e.addEventListener("message",function(t){n.emit("receive",t.data)}),n):(setTimeout(function(){n.listen()},100),n)},t}); \ No newline at end of file