9 lines
17 KiB
JavaScript
9 lines
17 KiB
JavaScript
|
/*!
|
||
|
* SignalR JavaScript Library v0.5.3
|
||
|
* http://signalr.net/
|
||
|
*
|
||
|
* Copyright David Fowler and Damian Edwards 2012
|
||
|
* Licensed under the MIT.
|
||
|
* https://github.com/SignalR/SignalR/blob/master/LICENSE.md
|
||
|
*/
|
||
|
(function(n,t){"use strict";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,e,o=!1,f=n(t),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))}},c=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)},u=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},s=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.events=r,i.changeState=u,i.isDisconnecting=s,i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.hub={start:function(){throw"SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/hubs'><\/script>.";}},f.load(function(){o=!0}),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(e,s){var h=this,l={waitForPageLoad:!0,transport:"auto",jsonp:!1},y,a=h.deferral||n.Deferred(),v=t.document.createElement("a"),p;return(n.type(e)==="function"?s=e:n.type(e)==="object"&&(n.extend(l,e),n.type(l.callback)==="function"&&(s=l.callback)),!o&&l.waitForPageLoad===!0)?(f.load(function(){h.deferral=a,h.start(e,s)}),a.promise()):u(h,i.connectionState.disconnected,i.connectionState.connecting)===!1?(a.resolve(h),a.promise()):(v.href=h.url,v.protocol&&v.protocol!==":"?(h.protocol=v.protocol,h.host=v.host,h.baseUrl=v.protocol+"//"+v.host):(h.protocol=t.document.location.protocol,h.host=t.document.location.host,h.baseUrl=h.protocol+"//"+h.host),h.wsProtocol=h.protocol==="https:"?"wss://":"ws://",c(h.url)&&(h.log("Auto detected cross domain url."),l.transport==="auto"&&(l.jsonp||(l.jsonp=!n.support.cors,l.jsonp&&h.log("Using jsonp because this browser doesn't support CORS")),l.transport=l.jsonp===!0?"longPolling":["webSockets","longPolling"])),h.ajaxDataType=l.jsonp?"jsonp":"json",n(h).bind(r.onStart,function(){n.type(s)==="function"&&s.call(h),a.resolve(h)}),y=function(t,e){if(e=e||0,e>=t.length){h.transport||(n(h).trigger(r.onError,"SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization."),a.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization."),h.stop());return}var o=t[e],s=n.type(o)==="object"?o:i.transports[o];if(o.indexOf("_")===0){y(t,e+1);return}s.start(h,function(){h.transport=s,u(h,i.connectionState.connecting,i.connectionState.connected),n(h).trigger(r.onStart),f.unload(function(){h.stop(!1)})},function(){y(t,e+1)})},p=h.url+"/negotiate",h.log("Negotiating with '"+p+"'."),n.ajax({url:p,global:!1,cache:!1,type:"GET",data:{},dataType:h.ajaxDataType,error:function(t){n(h).trigger(r.onError,[t.responseText]),a.reject("SignalR: Error during negotiation request: "+t.responseText),h.stop()},success:function(t){if(h.appRelativeUrl=t.Url,h.id=t.ConnectionId,h.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(h).trigger(r.onError,"SignalR: Incompatible protocol version."),a.reject("SignalR: Incompatible protocol version.");return}n(h).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(l.transport)?n.each(l.transport,function(){var t=th
|