From 5d782dc3b45b31183737ea054bb5b4897ed23b76 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 16 Jun 2012 10:51:51 -0700 Subject: [PATCH] Made some modifications to js client for SSE and longpolling transports. - Always attempt reconnecting to server when SSE connections closes. This behavior was inconsistent across FF and Chrome. - Don't raise errors on the longpolling transport if we're reconnecting. --- SignalR/Scripts/jquery.signalR.js | 32 ++++++++----------- SignalR/Scripts/jquery.signalR.min.js | 2 +- .../Scripts/jquery.signalR.js | 32 ++++++++----------- .../Scripts/jquery.signalR.min.js | 2 +- .../Content/Scripts/jquery.signalR.js | 32 ++++++++----------- .../Content/Scripts/jquery.signalR.min.js | 2 +- 6 files changed, 42 insertions(+), 60 deletions(-) diff --git a/SignalR/Scripts/jquery.signalR.js b/SignalR/Scripts/jquery.signalR.js index 1942d4e36c..6aa8af631f 100644 --- a/SignalR/Scripts/jquery.signalR.js +++ b/SignalR/Scripts/jquery.signalR.js @@ -70,7 +70,7 @@ changeState = function (connection, state) { if (state !== connection.state) { // REVIEW: Should event fire before or after the state change actually occurs? - $(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state }]); + $(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state}]); connection.state = state; } }, @@ -798,26 +798,18 @@ connection.log("EventSource readyState: " + connection.eventSource.readyState); if (e.eventPhase === window.EventSource.CLOSED) { - // connection closed - if (connection.eventSource.readyState === window.EventSource.CONNECTING) { - // We don't use the EventSource's native reconnect function as it - // doesn't allow us to change the URL when reconnecting. We need - // to change the URL to not include the /connect suffix, and pass - // the last message id we received. - connection.log("EventSource reconnecting due to the server connection ending"); + // We don't use the EventSource's native reconnect function as it + // doesn't allow us to change the URL when reconnecting. We need + // to change the URL to not include the /connect suffix, and pass + // the last message id we received. + connection.log("EventSource reconnecting due to the server connection ending"); - changeState(connection, signalR.connectionState.reconnecting); + changeState(connection, signalR.connectionState.reconnecting); - if (isDisconnecting(connection) === false) { - that.reconnect(connection); - } - } - else { - // The EventSource has closed, either because its close() method was called, - // or the server sent down a "don't reconnect" frame. - connection.log("EventSource closed"); - that.stop(connection); + if (isDisconnecting(connection) === false) { + that.reconnect(connection); } + } else { // connection error connection.log("EventSource error"); @@ -1075,7 +1067,9 @@ clearTimeout(reconnectTimeOut); } - $(instance).trigger(events.onError, [data.responseText]); + if (reconnecting === false) { + $(instance).trigger(events.onError, [data.responseText]); + } window.setTimeout(function () { if (isDisconnecting(instance) === false) { diff --git a/SignalR/Scripts/jquery.signalR.min.js b/SignalR/Scripts/jquery.signalR.min.js index 5cd4df6c40..75b1ff54d2 100644 --- a/SignalR/Scripts/jquery.signalR.min.js +++ b/SignalR/Scripts/jquery.signalR.min.js @@ -6,4 +6,4 @@ * Licensed under the MIT. * https://github.com/SignalR/SignalR/blob/master/LICENSE.md */ -(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i){i!==t.state&&(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:i}]),t.state=i)},e=function(n){return n.state===i.connectionState.disconnecting||n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnecting:3,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,c=n.Deferred(),l=t.document.createElement("a");return o.state===i.connectionState.connecting||o.state===i.connectionState.connected?(c.resolve(o),c.promise()):(f(o,i.connectionState.connecting),n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),l.href=o.url,o.baseUrl=l.protocol===":"?t.document.location.protocol+"//"+t.document.location.host:l.protocol+"//"+l.host,s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),c.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||c.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),c.reject("SignalR: Error during negotiation request: "+t),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),c.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),c.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state!==i.connectionState.connected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnecting&&u.state!==i.connectionState.disconnected){try{f(u,i.connectionState.disconnecting),u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var c,a=!1,v=this,y=!o,l,h;if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(e.webSocketServerUrl?c=e.webSocketServerUrl:(h=document.location,h.protocol!=="http:"&&h.protocol!=="https:"&&(h=t.document.createElement("a"),h.href=e.url),l=h.protocol==="https:"?"wss://":"ws://",c=l+h.host),n(e).trigger(r.onSending),c+=u.getUrl(e,this.name,y),e.log("Connecting to websocket endpoint '"+c+"'"),e.socket=new t.WebSocket(c),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.connected)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s&&s();return}f(e,i.connectionState.reconnecting),v.stop(e),v.start(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(o,s,h){var c=this,v=!1,a=n(o),l=!s,p,y;if(o.eventSource&&(o.log("The connection already has an event source. Stopping it."),o.stop()),!t.EventSource){h&&(o.log("This browser doesn't support SSE."),h());return}a.trigger(r.onSending),p=u.getUrl(o,this.name,l);try{o.log("Attempting to connect to SSE endpoint '"+p+"'"),o.eventSource=new t.EventSource(p)}catch(w){o.log("EventSource failed trying to connect with error "+w.Message),h?h():(a.trigger(r.onError,[w]),l&&(o.log("EventSource reconnecting"),e(o)===!1&&c.reconnect(o)));return}y=t.setTimeout(function(){v===!1&&(o.log("EventSource timed out trying to connect"),h&&h(),l?(o.log("EventSource reconnecting"),c.reconnect(o)):(o.log("EventSource stopping the connection."),c.stop(o)))},c.timeOut),o.eventSource.addEventListener("open",function(){o.log("EventSource connected"),y&&t.clearTimeout(y),v===!1&&(v=!0,s&&s(),l&&(a.trigger(r.onReconnect),f(o,i.connectionState.connected)))},!1),o.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(o,t.JSON.parse(n.data))},!1),o.eventSource.addEventListener("error",function(n){if(!v){h&&h();return}o.log("EventSource readyState: "+o.eventSource.readyState),n.eventPhase===t.EventSource.CLOSED?o.eventSource.readyState===t.EventSource.CONNECTING?(o.log("EventSource reconnecting due to the server connection ending"),f(o,i.connectionState.reconnecting),e(o)===!1&&c.reconnect(o)):(o.log("EventSource closed"),c.stop(o)):(o.log("EventSource error"),a.trigger(r.onError))},!1)},reconnect:function(n){var i=this;t.setTimeout(function(){i.stop(n),i.start(n)},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(o,s,h){var l=this,a=u.foreverFrame.count+=1,v,y,c=n("");if(t.EventSource){h&&(o.log("This brower supports SSE, skipping Forever Frame."),h());return}n(o).trigger(r.onSending),v=u.getUrl(o,this.name),v+="&frameId="+a,c.prop("src",v),u.foreverFrame.connections[a]=o,o.log("Binding to iframe's readystatechange event."),c.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(o.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),f(o,i.connectionState.reconnecting),e(o)===!1&&l.reconnect(o))}),o.frame=c[0],o.frameId=a,s&&(o.onSuccess=s),n("body").append(c),y=t.setTimeout(function(){o.onSuccess&&(o.log("Failed to connect using forever frame source, it timed out after "+l.timeOut+"ms."),l.stop(o),h&&h())},l.timeOut)},reconnect:function(n){var i=this;t.setTimeout(function(){var r=n.frame,t=u.getUrl(n,i.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),r.src=t},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:u.processMessages,stop:function(t){t.frame&&(t.frame.stop?t.frame.stop():t.frame.document&&t.frame.document.execCommand&&t.frame.document.execCommand("Stop"),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):(n(t).trigger(r.onReconnect),f(t,i.connectionState.connected))}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;b===!0&&v===!0&&f(o,i.connectionState.reconnecting),o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&(f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window) \ No newline at end of file +(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i){i!==t.state&&(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:i}]),t.state=i)},e=function(n){return n.state===i.connectionState.disconnecting||n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnecting:3,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,c=n.Deferred(),l=t.document.createElement("a");return o.state===i.connectionState.connecting||o.state===i.connectionState.connected?(c.resolve(o),c.promise()):(f(o,i.connectionState.connecting),n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),l.href=o.url,o.baseUrl=l.protocol===":"?t.document.location.protocol+"//"+t.document.location.host:l.protocol+"//"+l.host,s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),c.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||c.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),c.reject("SignalR: Error during negotiation request: "+t),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),c.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),c.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state!==i.connectionState.connected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnecting&&u.state!==i.connectionState.disconnected){try{f(u,i.connectionState.disconnecting),u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var c,a=!1,v=this,y=!o,l,h;if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(e.webSocketServerUrl?c=e.webSocketServerUrl:(h=document.location,h.protocol!=="http:"&&h.protocol!=="https:"&&(h=t.document.createElement("a"),h.href=e.url),l=h.protocol==="https:"?"wss://":"ws://",c=l+h.host),n(e).trigger(r.onSending),c+=u.getUrl(e,this.name,y),e.log("Connecting to websocket endpoint '"+c+"'"),e.socket=new t.WebSocket(c),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.connected)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s&&s();return}f(e,i.connectionState.reconnecting),v.stop(e),v.start(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(o,s,h){var c=this,v=!1,a=n(o),l=!s,p,y;if(o.eventSource&&(o.log("The connection already has an event source. Stopping it."),o.stop()),!t.EventSource){h&&(o.log("This browser doesn't support SSE."),h());return}a.trigger(r.onSending),p=u.getUrl(o,this.name,l);try{o.log("Attempting to connect to SSE endpoint '"+p+"'"),o.eventSource=new t.EventSource(p)}catch(w){o.log("EventSource failed trying to connect with error "+w.Message),h?h():(a.trigger(r.onError,[w]),l&&(o.log("EventSource reconnecting"),e(o)===!1&&c.reconnect(o)));return}y=t.setTimeout(function(){v===!1&&(o.log("EventSource timed out trying to connect"),h&&h(),l?(o.log("EventSource reconnecting"),c.reconnect(o)):(o.log("EventSource stopping the connection."),c.stop(o)))},c.timeOut),o.eventSource.addEventListener("open",function(){o.log("EventSource connected"),y&&t.clearTimeout(y),v===!1&&(v=!0,s&&s(),l&&(a.trigger(r.onReconnect),f(o,i.connectionState.connected)))},!1),o.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(o,t.JSON.parse(n.data))},!1),o.eventSource.addEventListener("error",function(n){if(!v){h&&h();return}o.log("EventSource readyState: "+o.eventSource.readyState),n.eventPhase===t.EventSource.CLOSED?(o.log("EventSource reconnecting due to the server connection ending"),f(o,i.connectionState.reconnecting),e(o)===!1&&c.reconnect(o)):(o.log("EventSource error"),a.trigger(r.onError))},!1)},reconnect:function(n){var i=this;t.setTimeout(function(){i.stop(n),i.start(n)},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(o,s,h){var l=this,a=u.foreverFrame.count+=1,v,y,c=n("");if(t.EventSource){h&&(o.log("This brower supports SSE, skipping Forever Frame."),h());return}n(o).trigger(r.onSending),v=u.getUrl(o,this.name),v+="&frameId="+a,c.prop("src",v),u.foreverFrame.connections[a]=o,o.log("Binding to iframe's readystatechange event."),c.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(o.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),f(o,i.connectionState.reconnecting),e(o)===!1&&l.reconnect(o))}),o.frame=c[0],o.frameId=a,s&&(o.onSuccess=s),n("body").append(c),y=t.setTimeout(function(){o.onSuccess&&(o.log("Failed to connect using forever frame source, it timed out after "+l.timeOut+"ms."),l.stop(o),h&&h())},l.timeOut)},reconnect:function(n){var i=this;t.setTimeout(function(){var r=n.frame,t=u.getUrl(n,i.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),r.src=t},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:u.processMessages,stop:function(t){t.frame&&(t.frame.stop?t.frame.stop():t.frame.document&&t.frame.document.execCommand&&t.frame.document.execCommand("Stop"),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):(n(t).trigger(r.onReconnect),f(t,i.connectionState.connected))}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,w=!k,b=u.getUrl(a,l.name,w,v),p=null,y=!1;w===!0&&v===!0&&f(o,i.connectionState.reconnecting),o.log("Attempting to connect to '"+b+"' using longPolling."),a.pollXhr=n.ajax({url:b,global:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),w===!1&&n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&(f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window) \ No newline at end of file diff --git a/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js b/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js index 1942d4e36c..6aa8af631f 100644 --- a/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js +++ b/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js @@ -70,7 +70,7 @@ changeState = function (connection, state) { if (state !== connection.state) { // REVIEW: Should event fire before or after the state change actually occurs? - $(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state }]); + $(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state}]); connection.state = state; } }, @@ -798,26 +798,18 @@ connection.log("EventSource readyState: " + connection.eventSource.readyState); if (e.eventPhase === window.EventSource.CLOSED) { - // connection closed - if (connection.eventSource.readyState === window.EventSource.CONNECTING) { - // We don't use the EventSource's native reconnect function as it - // doesn't allow us to change the URL when reconnecting. We need - // to change the URL to not include the /connect suffix, and pass - // the last message id we received. - connection.log("EventSource reconnecting due to the server connection ending"); + // We don't use the EventSource's native reconnect function as it + // doesn't allow us to change the URL when reconnecting. We need + // to change the URL to not include the /connect suffix, and pass + // the last message id we received. + connection.log("EventSource reconnecting due to the server connection ending"); - changeState(connection, signalR.connectionState.reconnecting); + changeState(connection, signalR.connectionState.reconnecting); - if (isDisconnecting(connection) === false) { - that.reconnect(connection); - } - } - else { - // The EventSource has closed, either because its close() method was called, - // or the server sent down a "don't reconnect" frame. - connection.log("EventSource closed"); - that.stop(connection); + if (isDisconnecting(connection) === false) { + that.reconnect(connection); } + } else { // connection error connection.log("EventSource error"); @@ -1075,7 +1067,9 @@ clearTimeout(reconnectTimeOut); } - $(instance).trigger(events.onError, [data.responseText]); + if (reconnecting === false) { + $(instance).trigger(events.onError, [data.responseText]); + } window.setTimeout(function () { if (isDisconnecting(instance) === false) { diff --git a/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.min.js b/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.min.js index 5cd4df6c40..75b1ff54d2 100644 --- a/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.min.js +++ b/samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.min.js @@ -6,4 +6,4 @@ * Licensed under the MIT. * https://github.com/SignalR/SignalR/blob/master/LICENSE.md */ -(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i){i!==t.state&&(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:i}]),t.state=i)},e=function(n){return n.state===i.connectionState.disconnecting||n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnecting:3,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,c=n.Deferred(),l=t.document.createElement("a");return o.state===i.connectionState.connecting||o.state===i.connectionState.connected?(c.resolve(o),c.promise()):(f(o,i.connectionState.connecting),n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),l.href=o.url,o.baseUrl=l.protocol===":"?t.document.location.protocol+"//"+t.document.location.host:l.protocol+"//"+l.host,s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),c.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||c.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),c.reject("SignalR: Error during negotiation request: "+t),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),c.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),c.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state!==i.connectionState.connected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnecting&&u.state!==i.connectionState.disconnected){try{f(u,i.connectionState.disconnecting),u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var c,a=!1,v=this,y=!o,l,h;if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(e.webSocketServerUrl?c=e.webSocketServerUrl:(h=document.location,h.protocol!=="http:"&&h.protocol!=="https:"&&(h=t.document.createElement("a"),h.href=e.url),l=h.protocol==="https:"?"wss://":"ws://",c=l+h.host),n(e).trigger(r.onSending),c+=u.getUrl(e,this.name,y),e.log("Connecting to websocket endpoint '"+c+"'"),e.socket=new t.WebSocket(c),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.connected)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s&&s();return}f(e,i.connectionState.reconnecting),v.stop(e),v.start(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(o,s,h){var c=this,v=!1,a=n(o),l=!s,p,y;if(o.eventSource&&(o.log("The connection already has an event source. Stopping it."),o.stop()),!t.EventSource){h&&(o.log("This browser doesn't support SSE."),h());return}a.trigger(r.onSending),p=u.getUrl(o,this.name,l);try{o.log("Attempting to connect to SSE endpoint '"+p+"'"),o.eventSource=new t.EventSource(p)}catch(w){o.log("EventSource failed trying to connect with error "+w.Message),h?h():(a.trigger(r.onError,[w]),l&&(o.log("EventSource reconnecting"),e(o)===!1&&c.reconnect(o)));return}y=t.setTimeout(function(){v===!1&&(o.log("EventSource timed out trying to connect"),h&&h(),l?(o.log("EventSource reconnecting"),c.reconnect(o)):(o.log("EventSource stopping the connection."),c.stop(o)))},c.timeOut),o.eventSource.addEventListener("open",function(){o.log("EventSource connected"),y&&t.clearTimeout(y),v===!1&&(v=!0,s&&s(),l&&(a.trigger(r.onReconnect),f(o,i.connectionState.connected)))},!1),o.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(o,t.JSON.parse(n.data))},!1),o.eventSource.addEventListener("error",function(n){if(!v){h&&h();return}o.log("EventSource readyState: "+o.eventSource.readyState),n.eventPhase===t.EventSource.CLOSED?o.eventSource.readyState===t.EventSource.CONNECTING?(o.log("EventSource reconnecting due to the server connection ending"),f(o,i.connectionState.reconnecting),e(o)===!1&&c.reconnect(o)):(o.log("EventSource closed"),c.stop(o)):(o.log("EventSource error"),a.trigger(r.onError))},!1)},reconnect:function(n){var i=this;t.setTimeout(function(){i.stop(n),i.start(n)},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(o,s,h){var l=this,a=u.foreverFrame.count+=1,v,y,c=n("");if(t.EventSource){h&&(o.log("This brower supports SSE, skipping Forever Frame."),h());return}n(o).trigger(r.onSending),v=u.getUrl(o,this.name),v+="&frameId="+a,c.prop("src",v),u.foreverFrame.connections[a]=o,o.log("Binding to iframe's readystatechange event."),c.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(o.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),f(o,i.connectionState.reconnecting),e(o)===!1&&l.reconnect(o))}),o.frame=c[0],o.frameId=a,s&&(o.onSuccess=s),n("body").append(c),y=t.setTimeout(function(){o.onSuccess&&(o.log("Failed to connect using forever frame source, it timed out after "+l.timeOut+"ms."),l.stop(o),h&&h())},l.timeOut)},reconnect:function(n){var i=this;t.setTimeout(function(){var r=n.frame,t=u.getUrl(n,i.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),r.src=t},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:u.processMessages,stop:function(t){t.frame&&(t.frame.stop?t.frame.stop():t.frame.document&&t.frame.document.execCommand&&t.frame.document.execCommand("Stop"),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):(n(t).trigger(r.onReconnect),f(t,i.connectionState.connected))}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;b===!0&&v===!0&&f(o,i.connectionState.reconnecting),o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&(f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window) \ No newline at end of file +(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i){i!==t.state&&(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:i}]),t.state=i)},e=function(n){return n.state===i.connectionState.disconnecting||n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnecting:3,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,c=n.Deferred(),l=t.document.createElement("a");return o.state===i.connectionState.connecting||o.state===i.connectionState.connected?(c.resolve(o),c.promise()):(f(o,i.connectionState.connecting),n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),l.href=o.url,o.baseUrl=l.protocol===":"?t.document.location.protocol+"//"+t.document.location.host:l.protocol+"//"+l.host,s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),c.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||c.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),c.reject("SignalR: Error during negotiation request: "+t),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),c.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),c.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state!==i.connectionState.connected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnecting&&u.state!==i.connectionState.disconnected){try{f(u,i.connectionState.disconnecting),u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var c,a=!1,v=this,y=!o,l,h;if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(e.webSocketServerUrl?c=e.webSocketServerUrl:(h=document.location,h.protocol!=="http:"&&h.protocol!=="https:"&&(h=t.document.createElement("a"),h.href=e.url),l=h.protocol==="https:"?"wss://":"ws://",c=l+h.host),n(e).trigger(r.onSending),c+=u.getUrl(e,this.name,y),e.log("Connecting to websocket endpoint '"+c+"'"),e.socket=new t.WebSocket(c),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.connected)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s&&s();return}f(e,i.connectionState.reconnecting),v.stop(e),v.start(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(o,s,h){var c=this,v=!1,a=n(o),l=!s,p,y;if(o.eventSource&&(o.log("The connection already has an event source. Stopping it."),o.stop()),!t.EventSource){h&&(o.log("This browser doesn't support SSE."),h());return}a.trigger(r.onSending),p=u.getUrl(o,this.name,l);try{o.log("Attempting to connect to SSE endpoint '"+p+"'"),o.eventSource=new t.EventSource(p)}catch(w){o.log("EventSource failed trying to connect with error "+w.Message),h?h():(a.trigger(r.onError,[w]),l&&(o.log("EventSource reconnecting"),e(o)===!1&&c.reconnect(o)));return}y=t.setTimeout(function(){v===!1&&(o.log("EventSource timed out trying to connect"),h&&h(),l?(o.log("EventSource reconnecting"),c.reconnect(o)):(o.log("EventSource stopping the connection."),c.stop(o)))},c.timeOut),o.eventSource.addEventListener("open",function(){o.log("EventSource connected"),y&&t.clearTimeout(y),v===!1&&(v=!0,s&&s(),l&&(a.trigger(r.onReconnect),f(o,i.connectionState.connected)))},!1),o.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(o,t.JSON.parse(n.data))},!1),o.eventSource.addEventListener("error",function(n){if(!v){h&&h();return}o.log("EventSource readyState: "+o.eventSource.readyState),n.eventPhase===t.EventSource.CLOSED?(o.log("EventSource reconnecting due to the server connection ending"),f(o,i.connectionState.reconnecting),e(o)===!1&&c.reconnect(o)):(o.log("EventSource error"),a.trigger(r.onError))},!1)},reconnect:function(n){var i=this;t.setTimeout(function(){i.stop(n),i.start(n)},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(o,s,h){var l=this,a=u.foreverFrame.count+=1,v,y,c=n("");if(t.EventSource){h&&(o.log("This brower supports SSE, skipping Forever Frame."),h());return}n(o).trigger(r.onSending),v=u.getUrl(o,this.name),v+="&frameId="+a,c.prop("src",v),u.foreverFrame.connections[a]=o,o.log("Binding to iframe's readystatechange event."),c.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(o.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),f(o,i.connectionState.reconnecting),e(o)===!1&&l.reconnect(o))}),o.frame=c[0],o.frameId=a,s&&(o.onSuccess=s),n("body").append(c),y=t.setTimeout(function(){o.onSuccess&&(o.log("Failed to connect using forever frame source, it timed out after "+l.timeOut+"ms."),l.stop(o),h&&h())},l.timeOut)},reconnect:function(n){var i=this;t.setTimeout(function(){var r=n.frame,t=u.getUrl(n,i.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),r.src=t},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:u.processMessages,stop:function(t){t.frame&&(t.frame.stop?t.frame.stop():t.frame.document&&t.frame.document.execCommand&&t.frame.document.execCommand("Stop"),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):(n(t).trigger(r.onReconnect),f(t,i.connectionState.connected))}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,w=!k,b=u.getUrl(a,l.name,w,v),p=null,y=!1;w===!0&&v===!0&&f(o,i.connectionState.reconnecting),o.log("Attempting to connect to '"+b+"' using longPolling."),a.pollXhr=n.ajax({url:b,global:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),w===!1&&n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&(f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window) \ No newline at end of file diff --git a/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.js b/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.js index 1942d4e36c..6aa8af631f 100644 --- a/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.js +++ b/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.js @@ -70,7 +70,7 @@ changeState = function (connection, state) { if (state !== connection.state) { // REVIEW: Should event fire before or after the state change actually occurs? - $(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state }]); + $(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state}]); connection.state = state; } }, @@ -798,26 +798,18 @@ connection.log("EventSource readyState: " + connection.eventSource.readyState); if (e.eventPhase === window.EventSource.CLOSED) { - // connection closed - if (connection.eventSource.readyState === window.EventSource.CONNECTING) { - // We don't use the EventSource's native reconnect function as it - // doesn't allow us to change the URL when reconnecting. We need - // to change the URL to not include the /connect suffix, and pass - // the last message id we received. - connection.log("EventSource reconnecting due to the server connection ending"); + // We don't use the EventSource's native reconnect function as it + // doesn't allow us to change the URL when reconnecting. We need + // to change the URL to not include the /connect suffix, and pass + // the last message id we received. + connection.log("EventSource reconnecting due to the server connection ending"); - changeState(connection, signalR.connectionState.reconnecting); + changeState(connection, signalR.connectionState.reconnecting); - if (isDisconnecting(connection) === false) { - that.reconnect(connection); - } - } - else { - // The EventSource has closed, either because its close() method was called, - // or the server sent down a "don't reconnect" frame. - connection.log("EventSource closed"); - that.stop(connection); + if (isDisconnecting(connection) === false) { + that.reconnect(connection); } + } else { // connection error connection.log("EventSource error"); @@ -1075,7 +1067,9 @@ clearTimeout(reconnectTimeOut); } - $(instance).trigger(events.onError, [data.responseText]); + if (reconnecting === false) { + $(instance).trigger(events.onError, [data.responseText]); + } window.setTimeout(function () { if (isDisconnecting(instance) === false) { diff --git a/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.min.js b/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.min.js index 5cd4df6c40..75b1ff54d2 100644 --- a/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.min.js +++ b/samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.min.js @@ -6,4 +6,4 @@ * Licensed under the MIT. * https://github.com/SignalR/SignalR/blob/master/LICENSE.md */ -(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i){i!==t.state&&(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:i}]),t.state=i)},e=function(n){return n.state===i.connectionState.disconnecting||n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnecting:3,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,c=n.Deferred(),l=t.document.createElement("a");return o.state===i.connectionState.connecting||o.state===i.connectionState.connected?(c.resolve(o),c.promise()):(f(o,i.connectionState.connecting),n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),l.href=o.url,o.baseUrl=l.protocol===":"?t.document.location.protocol+"//"+t.document.location.host:l.protocol+"//"+l.host,s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),c.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||c.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),c.reject("SignalR: Error during negotiation request: "+t),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),c.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),c.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state!==i.connectionState.connected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnecting&&u.state!==i.connectionState.disconnected){try{f(u,i.connectionState.disconnecting),u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var c,a=!1,v=this,y=!o,l,h;if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(e.webSocketServerUrl?c=e.webSocketServerUrl:(h=document.location,h.protocol!=="http:"&&h.protocol!=="https:"&&(h=t.document.createElement("a"),h.href=e.url),l=h.protocol==="https:"?"wss://":"ws://",c=l+h.host),n(e).trigger(r.onSending),c+=u.getUrl(e,this.name,y),e.log("Connecting to websocket endpoint '"+c+"'"),e.socket=new t.WebSocket(c),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.connected)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s&&s();return}f(e,i.connectionState.reconnecting),v.stop(e),v.start(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(o,s,h){var c=this,v=!1,a=n(o),l=!s,p,y;if(o.eventSource&&(o.log("The connection already has an event source. Stopping it."),o.stop()),!t.EventSource){h&&(o.log("This browser doesn't support SSE."),h());return}a.trigger(r.onSending),p=u.getUrl(o,this.name,l);try{o.log("Attempting to connect to SSE endpoint '"+p+"'"),o.eventSource=new t.EventSource(p)}catch(w){o.log("EventSource failed trying to connect with error "+w.Message),h?h():(a.trigger(r.onError,[w]),l&&(o.log("EventSource reconnecting"),e(o)===!1&&c.reconnect(o)));return}y=t.setTimeout(function(){v===!1&&(o.log("EventSource timed out trying to connect"),h&&h(),l?(o.log("EventSource reconnecting"),c.reconnect(o)):(o.log("EventSource stopping the connection."),c.stop(o)))},c.timeOut),o.eventSource.addEventListener("open",function(){o.log("EventSource connected"),y&&t.clearTimeout(y),v===!1&&(v=!0,s&&s(),l&&(a.trigger(r.onReconnect),f(o,i.connectionState.connected)))},!1),o.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(o,t.JSON.parse(n.data))},!1),o.eventSource.addEventListener("error",function(n){if(!v){h&&h();return}o.log("EventSource readyState: "+o.eventSource.readyState),n.eventPhase===t.EventSource.CLOSED?o.eventSource.readyState===t.EventSource.CONNECTING?(o.log("EventSource reconnecting due to the server connection ending"),f(o,i.connectionState.reconnecting),e(o)===!1&&c.reconnect(o)):(o.log("EventSource closed"),c.stop(o)):(o.log("EventSource error"),a.trigger(r.onError))},!1)},reconnect:function(n){var i=this;t.setTimeout(function(){i.stop(n),i.start(n)},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(o,s,h){var l=this,a=u.foreverFrame.count+=1,v,y,c=n("");if(t.EventSource){h&&(o.log("This brower supports SSE, skipping Forever Frame."),h());return}n(o).trigger(r.onSending),v=u.getUrl(o,this.name),v+="&frameId="+a,c.prop("src",v),u.foreverFrame.connections[a]=o,o.log("Binding to iframe's readystatechange event."),c.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(o.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),f(o,i.connectionState.reconnecting),e(o)===!1&&l.reconnect(o))}),o.frame=c[0],o.frameId=a,s&&(o.onSuccess=s),n("body").append(c),y=t.setTimeout(function(){o.onSuccess&&(o.log("Failed to connect using forever frame source, it timed out after "+l.timeOut+"ms."),l.stop(o),h&&h())},l.timeOut)},reconnect:function(n){var i=this;t.setTimeout(function(){var r=n.frame,t=u.getUrl(n,i.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),r.src=t},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:u.processMessages,stop:function(t){t.frame&&(t.frame.stop?t.frame.stop():t.frame.document&&t.frame.document.execCommand&&t.frame.document.execCommand("Stop"),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):(n(t).trigger(r.onReconnect),f(t,i.connectionState.connected))}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;b===!0&&v===!0&&f(o,i.connectionState.reconnecting),o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&(f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window) \ No newline at end of file +(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i){i!==t.state&&(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:i}]),t.state=i)},e=function(n){return n.state===i.connectionState.disconnecting||n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnecting:3,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,c=n.Deferred(),l=t.document.createElement("a");return o.state===i.connectionState.connecting||o.state===i.connectionState.connected?(c.resolve(o),c.promise()):(f(o,i.connectionState.connecting),n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),l.href=o.url,o.baseUrl=l.protocol===":"?t.document.location.protocol+"//"+t.document.location.host:l.protocol+"//"+l.host,s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),c.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||c.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),c.reject("SignalR: Error during negotiation request: "+t),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),c.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),c.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state!==i.connectionState.connected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnecting&&u.state!==i.connectionState.disconnected){try{f(u,i.connectionState.disconnecting),u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var c,a=!1,v=this,y=!o,l,h;if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(e.webSocketServerUrl?c=e.webSocketServerUrl:(h=document.location,h.protocol!=="http:"&&h.protocol!=="https:"&&(h=t.document.createElement("a"),h.href=e.url),l=h.protocol==="https:"?"wss://":"ws://",c=l+h.host),n(e).trigger(r.onSending),c+=u.getUrl(e,this.name,y),e.log("Connecting to websocket endpoint '"+c+"'"),e.socket=new t.WebSocket(c),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.connected)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s&&s();return}f(e,i.connectionState.reconnecting),v.stop(e),v.start(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(o,s,h){var c=this,v=!1,a=n(o),l=!s,p,y;if(o.eventSource&&(o.log("The connection already has an event source. Stopping it."),o.stop()),!t.EventSource){h&&(o.log("This browser doesn't support SSE."),h());return}a.trigger(r.onSending),p=u.getUrl(o,this.name,l);try{o.log("Attempting to connect to SSE endpoint '"+p+"'"),o.eventSource=new t.EventSource(p)}catch(w){o.log("EventSource failed trying to connect with error "+w.Message),h?h():(a.trigger(r.onError,[w]),l&&(o.log("EventSource reconnecting"),e(o)===!1&&c.reconnect(o)));return}y=t.setTimeout(function(){v===!1&&(o.log("EventSource timed out trying to connect"),h&&h(),l?(o.log("EventSource reconnecting"),c.reconnect(o)):(o.log("EventSource stopping the connection."),c.stop(o)))},c.timeOut),o.eventSource.addEventListener("open",function(){o.log("EventSource connected"),y&&t.clearTimeout(y),v===!1&&(v=!0,s&&s(),l&&(a.trigger(r.onReconnect),f(o,i.connectionState.connected)))},!1),o.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(o,t.JSON.parse(n.data))},!1),o.eventSource.addEventListener("error",function(n){if(!v){h&&h();return}o.log("EventSource readyState: "+o.eventSource.readyState),n.eventPhase===t.EventSource.CLOSED?(o.log("EventSource reconnecting due to the server connection ending"),f(o,i.connectionState.reconnecting),e(o)===!1&&c.reconnect(o)):(o.log("EventSource error"),a.trigger(r.onError))},!1)},reconnect:function(n){var i=this;t.setTimeout(function(){i.stop(n),i.start(n)},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(o,s,h){var l=this,a=u.foreverFrame.count+=1,v,y,c=n("");if(t.EventSource){h&&(o.log("This brower supports SSE, skipping Forever Frame."),h());return}n(o).trigger(r.onSending),v=u.getUrl(o,this.name),v+="&frameId="+a,c.prop("src",v),u.foreverFrame.connections[a]=o,o.log("Binding to iframe's readystatechange event."),c.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(o.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),f(o,i.connectionState.reconnecting),e(o)===!1&&l.reconnect(o))}),o.frame=c[0],o.frameId=a,s&&(o.onSuccess=s),n("body").append(c),y=t.setTimeout(function(){o.onSuccess&&(o.log("Failed to connect using forever frame source, it timed out after "+l.timeOut+"ms."),l.stop(o),h&&h())},l.timeOut)},reconnect:function(n){var i=this;t.setTimeout(function(){var r=n.frame,t=u.getUrl(n,i.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),r.src=t},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:u.processMessages,stop:function(t){t.frame&&(t.frame.stop?t.frame.stop():t.frame.document&&t.frame.document.execCommand&&t.frame.document.execCommand("Stop"),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):(n(t).trigger(r.onReconnect),f(t,i.connectionState.connected))}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,w=!k,b=u.getUrl(a,l.name,w,v),p=null,y=!1;w===!0&&v===!0&&f(o,i.connectionState.reconnecting),o.log("Attempting to connect to '"+b+"' using longPolling."),a.pollXhr=n.ajax({url:b,global:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),w===!1&&n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&(f(o,i.connectionState.connected),n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window) \ No newline at end of file