PATH:
home
/
letacommog
/
crmleta
/
layouts
/
v7
/
lib
/
jquery
/
websockets
(function($){ $.extend({WebSocket:function(url,protocol,options){ var defaults={url:url,http:null,enableProtocols:false,enablePipes:false,encoding:"utf-8",method:"post",delay:0,interval:3000};options=$.extend({},defaults,options);const WS_ID="WebSocketPipe";const CONNECTING=0;const OPEN=1;const CLOSING=2;const CLOSED=3;var _functionTable={onopen:function(){},onerror:function(e){},onclose:function(){},onmessage:function(e){},send:function(d){_ws._send(d);}};function _token(){return Math.random().toString(36).substr(2);}function _urlWsToHttp(url){var protocol=(url.attr("protocol")==="wss")?"https://":"http://";var host=url.attr("host");var port=((url.attr("protocol")=="wss"&&url.attr("port")!=443)||(url.attr("protocol")=="ws"&&url.attr("port")!=80)?":"+url.attr("port"):"");var path=((url.attr("path")!="/")?url.attr("path"):"");return protocol+host+port+path;}function _dispatchProtocol(e,direction,ws){for(var protocol in ws.protocols){e=ws.protocols[protocol].callback(e,direction);}return e;}function _dispatchPipe(id,e){for(var pipe in ws.pipes){if(pipe==id){var p=ws.pipes[pipe];if(p.onmessage!=undefined&&typeof(p.onmessage)=="function"){p.onmessage(e);}}}}function _proxy(trigger,e){return _functionTable[trigger](e);}function _injectHook(event,ws){if(event=="send"){ws._send=ws.send;}ws[event]=function(e){if(event=="onmessage"){e=_dispatchProtocol(e,"i",ws);for(pipe in ws.pipes){$(ws.pipes[pipe]).trigger(e);}}(event=="send")?e=_dispatchProtocol(e,"o",ws):null;_proxy(event,e);};window.WebSocket.prototype.__defineSetter__(event,function(v){_functionTable[event]=v;});window.WebSocket.prototype.__defineGetter__(event,function(){return _functionTable[event];});}function _protocol(name,callback){return{name:name,callback:callback};}function _pipe(url){return $.extend(_getWebSocketSkeleton(url,false),{packet:function(uid){return{type:WS_ID,action:"message",data:null,uid:uid};},startup:function(){var p=this.packet(this.uid,this.url);p.action="startup";p.data=this.url;_ws.send(JSON.stringify(p));},shutdown:function(){var p=this.packet(this.uid,this.url);p.action="shutdown";_ws.send(JSON.stringify(p));},send:function(data){var p=this.packet(this.uid,this.url);p.data=data;_ws.send(JSON.stringify(p));$(this).triggerHandler("send");},start:function(){this.startup();$(this).triggerHandler("open");},close:function(){this.shutdown();$(this).triggerHandler("close");}});}function _getWebSocketSkeleton(url,isNative){return{type:"WebSocket",uid:_token(),readyState:CONNECTING,bufferedAmount:0,url:url,send:function(data){},start:function(){},close:function(){},onopen:function(){},onerror:function(e){},onclose:function(){},onmessage:function(e){},protocols:{},pipes:{},registerPipe:function(url,protocol,options){var p=new _pipe(url);for(event in _functionTable){if(event!="send"){_injectHook(event,p);}}p=$.extend(p,options);p.start();return this.pipes[p.id]=p;},unregisterPipe:function(id){this.pipes[id]=null;},registerProtocol:function(name,callback){var p=new _protocol(name,callback);return this.protocols[name]=p;},unregisterProtocol:function(name){this.protocols[name]=null;},extension:null,protocol:null,reason:null,binaryType:null};}function _ErrorEvent(error){var e=jQuery.Event("error");e.data=data;return e;}function _MessageEvent(data){var e=jQuery.Event("message");e.data=data;return e;}function _WebSocket(url){var _interval,_handler,_emulation={send:function(data){var success=true;$.ajax({async:false,type:options.method,url:url+((options.method=="GET"&&options.arguments)?"?"+$.param(options.arguments):""),data:((options.method=="POST"&&options.arguments)?$.param($.extend(options.arguments,{data:data})):null),dataType:"text",contentType:"application/x-www-form-urlencoded; charset="+options.encoding,success:function(data){$(_emulation).trigger(new _MessageEvent(_dispatchProtocol(data,"i",_emulation)));},error:function(xhr,data,errorThrown){success=false;$(_emulation).trigger(_ErrorEvent(data));}});return success;},close:function(){clearTimeout(_handler);clearInterval(_interval);this.readyState=CLOSED;$(_emulation).triggerHandler("close");}};function _poll(){$.ajax({type:options.method,url:url+((options.method=="GET"&&options.arguments)?"?"+$.param(options.arguments):""),dataType:"text",data:((options.method=="POST"&&options.arguments)?$.param(options.arguments):null),success:function(data){$(_emulation).trigger(new _MessageEvent(data));},error:function(xhr,data,errorThrown){success=false;$(_emulation).trigger(_ErrorEvent(data));}});$(_emulation).triggerHandler("send");}_handler=setTimeout(function(){_emulation.readyState=OPEN;_poll();_interval=setInterval(_poll,options.interval);$(_emulation).triggerHandler("open");},options.delay);return _emulation;}function _extend(source,destination){for(property in source){if(!destination[property]){destination[property]=source[property];}}return destination;}function _getWebSocket(url){var ws,isNative=true;if(window.WebSocket){if(typeof(MozWebSocket)=="function"){ws=new MozWebSocket(url);}else{ws=new WebSocket(url);}}else{window.WebSocket=_WebSocket;url=options.http;isNative=false;ws=new WebSocket(url);}return _extend(_getWebSocketSkeleton(url,isNative),ws);}var _ws=_getWebSocket(options.url);for(event in _functionTable){_injectHook(event,_ws);}return _ws;}}); }) (jQuery);
[+]
..
[-] jquery.WebSocket.js.min.js
[edit]
[-] jquery.WebSocket.js
[edit]
[-] reconnecting-websocket.js
[edit]