").append( jQuery.parseHTML( responseText ) ).find( selector ) :
+
+ // Otherwise use the full result
+ responseText );
+
+ }).complete( callback && function( jqXHR, status ) {
+ self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
+ });
+ }
+
+ return this;
+};
+
+// Attach a bunch of functions for handling common AJAX events
+jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ){
+ jQuery.fn[ type ] = function( fn ){
+ return this.on( type, fn );
+ };
+});
+
+jQuery.extend({
+
+ // Counter for holding the number of active queries
+ active: 0,
+
+ // Last-Modified header cache for next request
+ lastModified: {},
+ etag: {},
+
+ ajaxSettings: {
+ url: ajaxLocation,
+ type: "GET",
+ isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
+ global: true,
+ processData: true,
+ async: true,
+ contentType: "application/x-www-form-urlencoded; charset=UTF-8",
+ /*
+ timeout: 0,
+ data: null,
+ dataType: null,
+ username: null,
+ password: null,
+ cache: null,
+ throws: false,
+ traditional: false,
+ headers: {},
+ */
+
+ accepts: {
+ "*": allTypes,
+ text: "text/plain",
+ html: "text/html",
+ xml: "application/xml, text/xml",
+ json: "application/json, text/javascript"
+ },
+
+ contents: {
+ xml: /xml/,
+ html: /html/,
+ json: /json/
+ },
+
+ responseFields: {
+ xml: "responseXML",
+ text: "responseText",
+ json: "responseJSON"
+ },
+
+ // Data converters
+ // Keys separate source (or catchall "*") and destination types with a single space
+ converters: {
+
+ // Convert anything to text
+ "* text": String,
+
+ // Text to html (true = no transformation)
+ "text html": true,
+
+ // Evaluate text as a json expression
+ "text json": jQuery.parseJSON,
+
+ // Parse text as xml
+ "text xml": jQuery.parseXML
+ },
+
+ // For options that shouldn't be deep extended:
+ // you can add your own custom options here if
+ // and when you create one that shouldn't be
+ // deep extended (see ajaxExtend)
+ flatOptions: {
+ url: true,
+ context: true
+ }
+ },
+
+ // Creates a full fledged settings object into target
+ // with both ajaxSettings and settings fields.
+ // If target is omitted, writes into ajaxSettings.
+ ajaxSetup: function( target, settings ) {
+ return settings ?
+
+ // Building a settings object
+ ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
+
+ // Extending ajaxSettings
+ ajaxExtend( jQuery.ajaxSettings, target );
+ },
+
+ ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
+ ajaxTransport: addToPrefiltersOrTransports( transports ),
+
+ // Main method
+ ajax: function( url, options ) {
+
+ // If url is an object, simulate pre-1.5 signature
+ if ( typeof url === "object" ) {
+ options = url;
+ url = undefined;
+ }
+
+ // Force options to be an object
+ options = options || {};
+
+ var transport,
+ // URL without anti-cache param
+ cacheURL,
+ // Response headers
+ responseHeadersString,
+ responseHeaders,
+ // timeout handle
+ timeoutTimer,
+ // Cross-domain detection vars
+ parts,
+ // To know if global events are to be dispatched
+ fireGlobals,
+ // Loop variable
+ i,
+ // Create the final options object
+ s = jQuery.ajaxSetup( {}, options ),
+ // Callbacks context
+ callbackContext = s.context || s,
+ // Context for global events is callbackContext if it is a DOM node or jQuery collection
+ globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
+ jQuery( callbackContext ) :
+ jQuery.event,
+ // Deferreds
+ deferred = jQuery.Deferred(),
+ completeDeferred = jQuery.Callbacks("once memory"),
+ // Status-dependent callbacks
+ statusCode = s.statusCode || {},
+ // Headers (they are sent all at once)
+ requestHeaders = {},
+ requestHeadersNames = {},
+ // The jqXHR state
+ state = 0,
+ // Default abort message
+ strAbort = "canceled",
+ // Fake xhr
+ jqXHR = {
+ readyState: 0,
+
+ // Builds headers hashtable if needed
+ getResponseHeader: function( key ) {
+ var match;
+ if ( state === 2 ) {
+ if ( !responseHeaders ) {
+ responseHeaders = {};
+ while ( (match = rheaders.exec( responseHeadersString )) ) {
+ responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
+ }
+ }
+ match = responseHeaders[ key.toLowerCase() ];
+ }
+ return match == null ? null : match;
+ },
+
+ // Raw string
+ getAllResponseHeaders: function() {
+ return state === 2 ? responseHeadersString : null;
+ },
+
+ // Caches the header
+ setRequestHeader: function( name, value ) {
+ var lname = name.toLowerCase();
+ if ( !state ) {
+ name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
+ requestHeaders[ name ] = value;
+ }
+ return this;
+ },
+
+ // Overrides response content-type header
+ overrideMimeType: function( type ) {
+ if ( !state ) {
+ s.mimeType = type;
+ }
+ return this;
+ },
+
+ // Status-dependent callbacks
+ statusCode: function( map ) {
+ var code;
+ if ( map ) {
+ if ( state < 2 ) {
+ for ( code in map ) {
+ // Lazy-add the new callback in a way that preserves old ones
+ statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
+ }
+ } else {
+ // Execute the appropriate callbacks
+ jqXHR.always( map[ jqXHR.status ] );
+ }
+ }
+ return this;
+ },
+
+ // Cancel the request
+ abort: function( statusText ) {
+ var finalText = statusText || strAbort;
+ if ( transport ) {
+ transport.abort( finalText );
+ }
+ done( 0, finalText );
+ return this;
+ }
+ };
+
+ // Attach deferreds
+ deferred.promise( jqXHR ).complete = completeDeferred.add;
+ jqXHR.success = jqXHR.done;
+ jqXHR.error = jqXHR.fail;
+
+ // Remove hash character (#7531: and string promotion)
+ // Add protocol if not provided (prefilters might expect it)
+ // Handle falsy url in the settings object (#10093: consistency with old signature)
+ // We also use the url parameter if available
+ s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
+ .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
+
+ // Alias method option to type as per ticket #12004
+ s.type = options.method || options.type || s.method || s.type;
+
+ // Extract dataTypes list
+ s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( core_rnotwhite ) || [""];
+
+ // A cross-domain request is in order when we have a protocol:host:port mismatch
+ if ( s.crossDomain == null ) {
+ parts = rurl.exec( s.url.toLowerCase() );
+ s.crossDomain = !!( parts &&
+ ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
+ ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
+ ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
+ );
+ }
+
+ // Convert data if not already a string
+ if ( s.data && s.processData && typeof s.data !== "string" ) {
+ s.data = jQuery.param( s.data, s.traditional );
+ }
+
+ // Apply prefilters
+ inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
+
+ // If request was aborted inside a prefilter, stop there
+ if ( state === 2 ) {
+ return jqXHR;
+ }
+
+ // We can fire global events as of now if asked to
+ fireGlobals = s.global;
+
+ // Watch for a new set of requests
+ if ( fireGlobals && jQuery.active++ === 0 ) {
+ jQuery.event.trigger("ajaxStart");
+ }
+
+ // Uppercase the type
+ s.type = s.type.toUpperCase();
+
+ // Determine if request has content
+ s.hasContent = !rnoContent.test( s.type );
+
+ // Save the URL in case we're toying with the If-Modified-Since
+ // and/or If-None-Match header later on
+ cacheURL = s.url;
+
+ // More options handling for requests with no content
+ if ( !s.hasContent ) {
+
+ // If data is available, append data to url
+ if ( s.data ) {
+ cacheURL = ( s.url += ( ajax_rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
+ // #9682: remove data so that it's not used in an eventual retry
+ delete s.data;
+ }
+
+ // Add anti-cache in url if needed
+ if ( s.cache === false ) {
+ s.url = rts.test( cacheURL ) ?
+
+ // If there is already a '_' parameter, set its value
+ cacheURL.replace( rts, "$1_=" + ajax_nonce++ ) :
+
+ // Otherwise add one to the end
+ cacheURL + ( ajax_rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ajax_nonce++;
+ }
+ }
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( s.ifModified ) {
+ if ( jQuery.lastModified[ cacheURL ] ) {
+ jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
+ }
+ if ( jQuery.etag[ cacheURL ] ) {
+ jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
+ }
+ }
+
+ // Set the correct header, if data is being sent
+ if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
+ jqXHR.setRequestHeader( "Content-Type", s.contentType );
+ }
+
+ // Set the Accepts header for the server, depending on the dataType
+ jqXHR.setRequestHeader(
+ "Accept",
+ s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
+ s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
+ s.accepts[ "*" ]
+ );
+
+ // Check for headers option
+ for ( i in s.headers ) {
+ jqXHR.setRequestHeader( i, s.headers[ i ] );
+ }
+
+ // Allow custom headers/mimetypes and early abort
+ if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
+ // Abort if not done already and return
+ return jqXHR.abort();
+ }
+
+ // aborting is no longer a cancellation
+ strAbort = "abort";
+
+ // Install callbacks on deferreds
+ for ( i in { success: 1, error: 1, complete: 1 } ) {
+ jqXHR[ i ]( s[ i ] );
+ }
+
+ // Get transport
+ transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
+
+ // If no transport, we auto-abort
+ if ( !transport ) {
+ done( -1, "No Transport" );
+ } else {
+ jqXHR.readyState = 1;
+
+ // Send global event
+ if ( fireGlobals ) {
+ globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
+ }
+ // Timeout
+ if ( s.async && s.timeout > 0 ) {
+ timeoutTimer = setTimeout(function() {
+ jqXHR.abort("timeout");
+ }, s.timeout );
+ }
+
+ try {
+ state = 1;
+ transport.send( requestHeaders, done );
+ } catch ( e ) {
+ // Propagate exception as error if not done
+ if ( state < 2 ) {
+ done( -1, e );
+ // Simply rethrow otherwise
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ // Callback for when everything is done
+ function done( status, nativeStatusText, responses, headers ) {
+ var isSuccess, success, error, response, modified,
+ statusText = nativeStatusText;
+
+ // Called once
+ if ( state === 2 ) {
+ return;
+ }
+
+ // State is "done" now
+ state = 2;
+
+ // Clear timeout if it exists
+ if ( timeoutTimer ) {
+ clearTimeout( timeoutTimer );
+ }
+
+ // Dereference transport for early garbage collection
+ // (no matter how long the jqXHR object will be used)
+ transport = undefined;
+
+ // Cache response headers
+ responseHeadersString = headers || "";
+
+ // Set readyState
+ jqXHR.readyState = status > 0 ? 4 : 0;
+
+ // Determine if successful
+ isSuccess = status >= 200 && status < 300 || status === 304;
+
+ // Get response data
+ if ( responses ) {
+ response = ajaxHandleResponses( s, jqXHR, responses );
+ }
+
+ // Convert no matter what (that way responseXXX fields are always set)
+ response = ajaxConvert( s, response, jqXHR, isSuccess );
+
+ // If successful, handle type chaining
+ if ( isSuccess ) {
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( s.ifModified ) {
+ modified = jqXHR.getResponseHeader("Last-Modified");
+ if ( modified ) {
+ jQuery.lastModified[ cacheURL ] = modified;
+ }
+ modified = jqXHR.getResponseHeader("etag");
+ if ( modified ) {
+ jQuery.etag[ cacheURL ] = modified;
+ }
+ }
+
+ // if no content
+ if ( status === 204 || s.type === "HEAD" ) {
+ statusText = "nocontent";
+
+ // if not modified
+ } else if ( status === 304 ) {
+ statusText = "notmodified";
+
+ // If we have data, let's convert it
+ } else {
+ statusText = response.state;
+ success = response.data;
+ error = response.error;
+ isSuccess = !error;
+ }
+ } else {
+ // We extract error from statusText
+ // then normalize statusText and status for non-aborts
+ error = statusText;
+ if ( status || !statusText ) {
+ statusText = "error";
+ if ( status < 0 ) {
+ status = 0;
+ }
+ }
+ }
+
+ // Set data for the fake xhr object
+ jqXHR.status = status;
+ jqXHR.statusText = ( nativeStatusText || statusText ) + "";
+
+ // Success/Error
+ if ( isSuccess ) {
+ deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
+ } else {
+ deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
+ }
+
+ // Status-dependent callbacks
+ jqXHR.statusCode( statusCode );
+ statusCode = undefined;
+
+ if ( fireGlobals ) {
+ globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
+ [ jqXHR, s, isSuccess ? success : error ] );
+ }
+
+ // Complete
+ completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
+
+ if ( fireGlobals ) {
+ globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
+ // Handle the global AJAX counter
+ if ( !( --jQuery.active ) ) {
+ jQuery.event.trigger("ajaxStop");
+ }
+ }
+ }
+
+ return jqXHR;
+ },
+
+ getJSON: function( url, data, callback ) {
+ return jQuery.get( url, data, callback, "json" );
+ },
+
+ getScript: function( url, callback ) {
+ return jQuery.get( url, undefined, callback, "script" );
+ }
+});
+
+jQuery.each( [ "get", "post" ], function( i, method ) {
+ jQuery[ method ] = function( url, data, callback, type ) {
+ // shift arguments if data argument was omitted
+ if ( jQuery.isFunction( data ) ) {
+ type = type || callback;
+ callback = data;
+ data = undefined;
+ }
+
+ return jQuery.ajax({
+ url: url,
+ type: method,
+ dataType: type,
+ data: data,
+ success: callback
+ });
+ };
+});
+
+/* Handles responses to an ajax request:
+ * - finds the right dataType (mediates between content-type and expected dataType)
+ * - returns the corresponding response
+ */
+function ajaxHandleResponses( s, jqXHR, responses ) {
+
+ var ct, type, finalDataType, firstDataType,
+ contents = s.contents,
+ dataTypes = s.dataTypes;
+
+ // Remove auto dataType and get content-type in the process
+ while( dataTypes[ 0 ] === "*" ) {
+ dataTypes.shift();
+ if ( ct === undefined ) {
+ ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
+ }
+ }
+
+ // Check if we're dealing with a known content-type
+ if ( ct ) {
+ for ( type in contents ) {
+ if ( contents[ type ] && contents[ type ].test( ct ) ) {
+ dataTypes.unshift( type );
+ break;
+ }
+ }
+ }
+
+ // Check to see if we have a response for the expected dataType
+ if ( dataTypes[ 0 ] in responses ) {
+ finalDataType = dataTypes[ 0 ];
+ } else {
+ // Try convertible dataTypes
+ for ( type in responses ) {
+ if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
+ finalDataType = type;
+ break;
+ }
+ if ( !firstDataType ) {
+ firstDataType = type;
+ }
+ }
+ // Or just use first one
+ finalDataType = finalDataType || firstDataType;
+ }
+
+ // If we found a dataType
+ // We add the dataType to the list if needed
+ // and return the corresponding response
+ if ( finalDataType ) {
+ if ( finalDataType !== dataTypes[ 0 ] ) {
+ dataTypes.unshift( finalDataType );
+ }
+ return responses[ finalDataType ];
+ }
+}
+
+/* Chain conversions given the request and the original response
+ * Also sets the responseXXX fields on the jqXHR instance
+ */
+function ajaxConvert( s, response, jqXHR, isSuccess ) {
+ var conv2, current, conv, tmp, prev,
+ converters = {},
+ // Work with a copy of dataTypes in case we need to modify it for conversion
+ dataTypes = s.dataTypes.slice();
+
+ // Create converters map with lowercased keys
+ if ( dataTypes[ 1 ] ) {
+ for ( conv in s.converters ) {
+ converters[ conv.toLowerCase() ] = s.converters[ conv ];
+ }
+ }
+
+ current = dataTypes.shift();
+
+ // Convert to each sequential dataType
+ while ( current ) {
+
+ if ( s.responseFields[ current ] ) {
+ jqXHR[ s.responseFields[ current ] ] = response;
+ }
+
+ // Apply the dataFilter if provided
+ if ( !prev && isSuccess && s.dataFilter ) {
+ response = s.dataFilter( response, s.dataType );
+ }
+
+ prev = current;
+ current = dataTypes.shift();
+
+ if ( current ) {
+
+ // There's only work to do if current dataType is non-auto
+ if ( current === "*" ) {
+
+ current = prev;
+
+ // Convert response if prev dataType is non-auto and differs from current
+ } else if ( prev !== "*" && prev !== current ) {
+
+ // Seek a direct converter
+ conv = converters[ prev + " " + current ] || converters[ "* " + current ];
+
+ // If none found, seek a pair
+ if ( !conv ) {
+ for ( conv2 in converters ) {
+
+ // If conv2 outputs current
+ tmp = conv2.split( " " );
+ if ( tmp[ 1 ] === current ) {
+
+ // If prev can be converted to accepted input
+ conv = converters[ prev + " " + tmp[ 0 ] ] ||
+ converters[ "* " + tmp[ 0 ] ];
+ if ( conv ) {
+ // Condense equivalence converters
+ if ( conv === true ) {
+ conv = converters[ conv2 ];
+
+ // Otherwise, insert the intermediate dataType
+ } else if ( converters[ conv2 ] !== true ) {
+ current = tmp[ 0 ];
+ dataTypes.unshift( tmp[ 1 ] );
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ // Apply converter (if not an equivalence)
+ if ( conv !== true ) {
+
+ // Unless errors are allowed to bubble, catch and return them
+ if ( conv && s[ "throws" ] ) {
+ response = conv( response );
+ } else {
+ try {
+ response = conv( response );
+ } catch ( e ) {
+ return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return { state: "success", data: response };
+}
+// Install script dataType
+jQuery.ajaxSetup({
+ accepts: {
+ script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
+ },
+ contents: {
+ script: /(?:java|ecma)script/
+ },
+ converters: {
+ "text script": function( text ) {
+ jQuery.globalEval( text );
+ return text;
+ }
+ }
+});
+
+// Handle cache's special case and crossDomain
+jQuery.ajaxPrefilter( "script", function( s ) {
+ if ( s.cache === undefined ) {
+ s.cache = false;
+ }
+ if ( s.crossDomain ) {
+ s.type = "GET";
+ }
+});
+
+// Bind script tag hack transport
+jQuery.ajaxTransport( "script", function( s ) {
+ // This transport only deals with cross domain requests
+ if ( s.crossDomain ) {
+ var script, callback;
+ return {
+ send: function( _, complete ) {
+ script = jQuery(".");
+ }
+ };
+
+ _pageWindow.load(function () { _pageLoaded = true; });
+
+ function validateTransport(requestedTransport, connection) {
+ ///
Validates the requested transport by cross checking it with the pre-defined signalR.transports
+ ///
The designated transports that the user has specified.
+ ///
The connection that will be using the requested transports. Used for logging purposes.
+ ///
+
+ if ($.isArray(requestedTransport)) {
+ // Go through transport array and remove an "invalid" tranports
+ for (var i = requestedTransport.length - 1; i >= 0; i--) {
+ var transport = requestedTransport[i];
+ if ($.type(requestedTransport) !== "object" && ($.type(transport) !== "string" || !signalR.transports[transport])) {
+ connection.log("Invalid transport: " + transport + ", removing it from the transports list.");
+ requestedTransport.splice(i, 1);
+ }
+ }
+
+ // Verify we still have transports left, if we dont then we have invalid transports
+ if (requestedTransport.length === 0) {
+ connection.log("No transports remain within the specified transport array.");
+ requestedTransport = null;
+ }
+ } else if ($.type(requestedTransport) !== "object" && !signalR.transports[requestedTransport] && requestedTransport !== "auto") {
+ connection.log("Invalid transport: " + requestedTransport.toString() + ".");
+ requestedTransport = null;
+ } else if (requestedTransport === "auto" && signalR._.ieVersion <= 8) {
+ // If we're doing an auto transport and we're IE8 then force longPolling, #1764
+ return ["longPolling"];
+
+ }
+
+ return requestedTransport;
+ }
+
+ function getDefaultPort(protocol) {
+ if (protocol === "http:") {
+ return 80;
+ } else if (protocol === "https:") {
+ return 443;
+ }
+ }
+
+ function addDefaultPort(protocol, url) {
+ // Remove ports from url. We have to check if there's a / or end of line
+ // following the port in order to avoid removing ports such as 8080.
+ if (url.match(/:\d+$/)) {
+ return url;
+ } else {
+ return url + ":" + getDefaultPort(protocol);
+ }
+ }
+
+ function ConnectingMessageBuffer(connection, drainCallback) {
+ var that = this,
+ buffer = [];
+
+ that.tryBuffer = function (message) {
+ if (connection.state === $.signalR.connectionState.connecting) {
+ buffer.push(message);
+
+ return true;
+ }
+
+ return false;
+ };
+
+ that.drain = function () {
+ // Ensure that the connection is connected when we drain (do not want to drain while a connection is not active)
+ if (connection.state === $.signalR.connectionState.connected) {
+ while (buffer.length > 0) {
+ drainCallback(buffer.shift());
+ }
+ }
+ };
+
+ that.clear = function () {
+ buffer = [];
+ };
+ }
+
+ signalR.fn = signalR.prototype = {
+ init: function (url, qs, logging) {
+ var $connection = $(this);
+
+ this.url = url;
+ this.qs = qs;
+ this._ = {
+ connectingMessageBuffer: new ConnectingMessageBuffer(this, function (message) {
+ $connection.triggerHandler(events.onReceived, [message]);
+ }),
+ onFailedTimeoutHandle: null
+ };
+ if (typeof (logging) === "boolean") {
+ this.logging = logging;
+ }
+ },
+
+ _parseResponse: function (response) {
+ var that = this;
+
+ if (!response) {
+ return response;
+ } else if (that.ajaxDataType === "text") {
+ return that.json.parse(response);
+ } else {
+ return response;
+ }
+ },
+
+ json: window.JSON,
+
+ isCrossDomain: function (url, against) {
+ ///
Checks if url is cross domain
+ ///
The base URL
+ ///
+ /// An optional argument to compare the URL against, if not specified it will be set to window.location.
+ /// If specified it must contain a protocol and a host property.
+ ///
+ var link;
+
+ url = $.trim(url);
+ if (url.indexOf("http") !== 0) {
+ return false;
+ }
+
+ against = against || window.location;
+
+ // Create an anchor tag.
+ link = window.document.createElement("a");
+ link.href = url;
+
+ // When checking for cross domain we have to special case port 80 because the window.location will remove the
+ return link.protocol + addDefaultPort(link.protocol, link.host) !== against.protocol + addDefaultPort(against.protocol, against.host);
+ },
+
+ ajaxDataType: "text",
+
+ contentType: "application/json; charset=UTF-8",
+
+ logging: false,
+
+ state: signalR.connectionState.disconnected,
+
+ keepAliveData: {},
+
+ clientProtocol: "1.3",
+
+ reconnectDelay: 2000,
+
+ transportConnectTimeout: 0, // This will be modified by the server in respone to the negotiate request. It will add any value sent down from the server to the client value.
+
+ disconnectTimeout: 30000, // This should be set by the server in response to the negotiate request (30s default)
+
+ keepAliveWarnAt: 2 / 3, // Warn user of slow connection if we breach the X% mark of the keep alive timeout
+
+ start: function (options, callback) {
+ ///
Starts the connection
+ ///
Options map
+ ///
A callback function to execute when the connection has started
+ var connection = this,
+ config = {
+ pingInterval: 300000,
+ waitForPageLoad: true,
+ transport: "auto",
+ jsonp: false
+ },
+ initialize,
+ deferred = connection._deferral || $.Deferred(), // Check to see if there is a pre-existing deferral that's being built on, if so we want to keep using it
+ parser = window.document.createElement("a");
+
+ // Persist the deferral so that if start is called multiple times the same deferral is used.
+ connection._deferral = deferred;
+
+ if (!connection.json) {
+ // no JSON!
+ throw new Error("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.");
+ }
+
+ if ($.type(options) === "function") {
+ // Support calling with single callback parameter
+ callback = options;
+ } else if ($.type(options) === "object") {
+ $.extend(config, options);
+ if ($.type(config.callback) === "function") {
+ callback = config.callback;
+ }
+ }
+
+ config.transport = validateTransport(config.transport, connection);
+
+ // If the transport is invalid throw an error and abort start
+ if (!config.transport) {
+ throw new Error("SignalR: Invalid transport(s) specified, aborting start.");
+ }
+
+ connection._.config = config;
+
+ // Check to see if start is being called prior to page load
+ // If waitForPageLoad is true we then want to re-direct function call to the window load event
+ if (!_pageLoaded && config.waitForPageLoad === true) {
+ connection._.deferredStartHandler = function () {
+ connection.start(options, callback);
+ };
+ _pageWindow.bind("load", connection._.deferredStartHandler);
+
+ return deferred.promise();
+ }
+
+ // If we're already connecting just return the same deferral as the original connection start
+ if (connection.state === signalR.connectionState.connecting) {
+ return deferred.promise();
+ } else if (changeState(connection,
+ signalR.connectionState.disconnected,
+ signalR.connectionState.connecting) === false) {
+ // We're not connecting so try and transition into connecting.
+ // If we fail to transition then we're either in connected or reconnecting.
+
+ deferred.resolve(connection);
+ return deferred.promise();
+ }
+
+ configureStopReconnectingTimeout(connection);
+
+ // Resolve the full url
+ parser.href = connection.url;
+ if (!parser.protocol || parser.protocol === ":") {
+ connection.protocol = window.document.location.protocol;
+ connection.host = window.document.location.host;
+ connection.baseUrl = connection.protocol + "//" + connection.host;
+ } else {
+ connection.protocol = parser.protocol;
+ connection.host = parser.host;
+ connection.baseUrl = parser.protocol + "//" + parser.host;
+ }
+
+ // Set the websocket protocol
+ connection.wsProtocol = connection.protocol === "https:" ? "wss://" : "ws://";
+
+ // If jsonp with no/auto transport is specified, then set the transport to long polling
+ // since that is the only transport for which jsonp really makes sense.
+ // Some developers might actually choose to specify jsonp for same origin requests
+ // as demonstrated by Issue #623.
+ if (config.transport === "auto" && config.jsonp === true) {
+ config.transport = "longPolling";
+ }
+
+ if (this.isCrossDomain(connection.url)) {
+ connection.log("Auto detected cross domain url.");
+
+ if (config.transport === "auto") {
+ // Try webSockets and longPolling since SSE doesn't support CORS
+ // TODO: Support XDM with foreverFrame
+ config.transport = ["webSockets", "longPolling"];
+ }
+
+ if (typeof (config.withCredentials) === "undefined") {
+ config.withCredentials = true;
+ }
+
+ // Determine if jsonp is the only choice for negotiation, ajaxSend and ajaxAbort.
+ // i.e. if the browser doesn't supports CORS
+ // If it is, ignore any preference to the contrary, and switch to jsonp.
+ if (!config.jsonp) {
+ config.jsonp = !$.support.cors;
+
+ if (config.jsonp) {
+ connection.log("Using jsonp because this browser doesn't support CORS.");
+ }
+ }
+
+ connection.contentType = signalR._.defaultContentType;
+ }
+
+ connection.withCredentials = config.withCredentials;
+
+ connection.ajaxDataType = config.jsonp ? "jsonp" : "text";
+
+ $(connection).bind(events.onStart, function (e, data) {
+ if ($.type(callback) === "function") {
+ callback.call(connection);
+ }
+ deferred.resolve(connection);
+ });
+
+ initialize = function (transports, index) {
+ var noTransportError = signalR._.error(resources.noTransportOnInit);
+
+ index = index || 0;
+ if (index >= transports.length) {
+ // No transport initialized successfully
+ $(connection).triggerHandler(events.onError, [noTransportError]);
+ deferred.reject(noTransportError);
+ // Stop the connection if it has connected and move it into the disconnected state
+ connection.stop();
+ return;
+ }
+
+ // The connection was aborted
+ if (connection.state === signalR.connectionState.disconnected) {
+ return;
+ }
+
+ var transportName = transports[index],
+ transport = $.type(transportName) === "object" ? transportName : signalR.transports[transportName],
+ initializationComplete = false,
+ onFailed = function () {
+ // Check if we've already triggered onFailed, onStart
+ if (!initializationComplete) {
+ initializationComplete = true;
+ window.clearTimeout(connection._.onFailedTimeoutHandle);
+ transport.stop(connection);
+ initialize(transports, index + 1);
+ }
+ };
+
+ connection.transport = transport;
+
+ if (transportName.indexOf("_") === 0) {
+ // Private member
+ initialize(transports, index + 1);
+ return;
+ }
+
+ try {
+ connection._.onFailedTimeoutHandle = window.setTimeout(function () {
+ connection.log(transport.name + " timed out when trying to connect.");
+ onFailed();
+ }, connection.transportConnectTimeout);
+
+ transport.start(connection, function () { // success
+ // Firefox 11+ doesn't allow sync XHR withCredentials: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#withCredentials
+ var isFirefox11OrGreater = signalR._.firefoxMajorVersion(window.navigator.userAgent) >= 11,
+ asyncAbort = !!connection.withCredentials && isFirefox11OrGreater;
+
+ // The connection was aborted while initializing transports
+ if (connection.state === signalR.connectionState.disconnected) {
+ return;
+ }
+
+ if (!initializationComplete) {
+ initializationComplete = true;
+
+ window.clearTimeout(connection._.onFailedTimeoutHandle);
+
+ if (transport.supportsKeepAlive && connection.keepAliveData.activated) {
+ signalR.transports._logic.monitorKeepAlive(connection);
+ }
+
+ // Used to ensure low activity clients maintain their authentication.
+ // Must be configured once a transport has been decided to perform valid ping requests.
+ configurePingInterval(connection);
+
+ changeState(connection,
+ signalR.connectionState.connecting,
+ signalR.connectionState.connected);
+
+ // Drain any incoming buffered messages (messages that came in prior to connect)
+ connection._.connectingMessageBuffer.drain();
+
+ $(connection).triggerHandler(events.onStart);
+
+ // wire the stop handler for when the user leaves the page
+ _pageWindow.bind("unload", function () {
+ connection.log("Window unloading, stopping the connection.");
+
+ connection.stop(asyncAbort);
+ });
+
+ if (isFirefox11OrGreater) {
+ // Firefox does not fire cross-domain XHRs in the normal unload handler on tab close.
+ // #2400
+ _pageWindow.bind("beforeunload", function () {
+ // If connection.stop() runs runs in beforeunload and fails, it will also fail
+ // in unload unless connection.stop() runs after a timeout.
+ window.setTimeout(function () {
+ connection.stop(asyncAbort);
+ }, 0);
+ });
+ }
+ }
+ }, onFailed);
+ }
+ catch (error) {
+ connection.log(transport.name + " transport threw '" + error.message + "' when attempting to start.");
+ onFailed();
+ }
+ };
+
+ var url = connection.url + "/negotiate",
+ onFailed = function (error, connection) {
+ var err = signalR._.error(resources.errorOnNegotiate, error);
+ $(connection).triggerHandler(events.onError, err);
+ deferred.reject(err);
+ // Stop the connection if negotiate failed
+ connection.stop();
+ };
+
+ $(connection).triggerHandler(events.onStarting);
+
+ url = signalR.transports._logic.prepareQueryString(connection, url);
+
+ // Add the client version to the negotiate request. We utilize the same addQs method here
+ // so that it can append the clientVersion appropriately to the URL
+ url = signalR.transports._logic.addQs(url, {
+ clientProtocol: connection.clientProtocol
+ });
+
+ connection.log("Negotiating with '" + url + "'.");
+
+ // Save the ajax negotiate request object so we can abort it if stop is called while the request is in flight.
+ connection._.negotiateRequest = $.ajax(
+ $.extend({}, $.signalR.ajaxDefaults, {
+ xhrFields: { withCredentials: connection.withCredentials },
+ url: url,
+ type: "GET",
+ contentType: connection.contentType,
+ data: {},
+ dataType: connection.ajaxDataType,
+ error: function (error, statusText) {
+ // We don't want to cause any errors if we're aborting our own negotiate request.
+ if (statusText !== _negotiateAbortText) {
+ onFailed(error, connection);
+ } else {
+ // This rejection will noop if the deferred has already been resolved or rejected.
+ deferred.reject(signalR._.error(resources.stoppedWhileNegotiating));
+ }
+ },
+ success: function (result) {
+ var res,
+ keepAliveData,
+ protocolError,
+ transports = [],
+ supportedTransports = [];
+
+ try {
+ res = connection._parseResponse(result);
+ } catch (error) {
+ onFailed(signalR._.error(resources.errorParsingNegotiateResponse, error), connection);
+ return;
+ }
+
+ keepAliveData = connection.keepAliveData;
+ connection.appRelativeUrl = res.Url;
+ connection.id = res.ConnectionId;
+ connection.token = res.ConnectionToken;
+ connection.webSocketServerUrl = res.WebSocketServerUrl;
+
+ // Once the server has labeled the PersistentConnection as Disconnected, we should stop attempting to reconnect
+ // after res.DisconnectTimeout seconds.
+ connection.disconnectTimeout = res.DisconnectTimeout * 1000; // in ms
+
+ // If the connection already has a transportConnectTimeout set then keep it, otherwise use the servers value.
+ connection.transportConnectTimeout = connection.transportConnectTimeout + res.TransportConnectTimeout * 1000;
+
+ // If we have a keep alive
+ if (res.KeepAliveTimeout) {
+ // Register the keep alive data as activated
+ keepAliveData.activated = true;
+
+ // Timeout to designate when to force the connection into reconnecting converted to milliseconds
+ keepAliveData.timeout = res.KeepAliveTimeout * 1000;
+
+ // Timeout to designate when to warn the developer that the connection may be dead or is not responding.
+ keepAliveData.timeoutWarning = keepAliveData.timeout * connection.keepAliveWarnAt;
+
+ // Instantiate the frequency in which we check the keep alive. It must be short in order to not miss/pick up any changes
+ keepAliveData.checkInterval = (keepAliveData.timeout - keepAliveData.timeoutWarning) / 3;
+ } else {
+ keepAliveData.activated = false;
+ }
+
+ if (!res.ProtocolVersion || res.ProtocolVersion !== connection.clientProtocol) {
+ protocolError = signalR._.error(signalR._.format(resources.protocolIncompatible, connection.clientProtocol, res.ProtocolVersion));
+ $(connection).triggerHandler(events.onError, [protocolError]);
+ deferred.reject(protocolError);
+
+ return;
+ }
+
+ $.each(signalR.transports, function (key) {
+ if (key === "webSockets" && !res.TryWebSockets) {
+ // Server said don't even try WebSockets, but keep processing the loop
+ // BUG: We should check to see if the user passed in only the webSockets transport
+ // in which case we should exit right now.
+ return true;
+ }
+ supportedTransports.push(key);
+ });
+
+ if ($.isArray(config.transport)) {
+ // ordered list provided
+ $.each(config.transport, function () {
+ var transport = this;
+ if ($.type(transport) === "object" || ($.type(transport) === "string" && $.inArray("" + transport, supportedTransports) >= 0)) {
+ transports.push($.type(transport) === "string" ? "" + transport : transport);
+ }
+ });
+ } else if ($.type(config.transport) === "object" ||
+ $.inArray(config.transport, supportedTransports) >= 0) {
+ // specific transport provided, as object or a named transport, e.g. "longPolling"
+ transports.push(config.transport);
+ } else { // default "auto"
+ transports = supportedTransports;
+ }
+ initialize(transports);
+ }
+ }
+ ));
+
+ return deferred.promise();
+ },
+
+ starting: function (callback) {
+ ///
Adds a callback that will be invoked before anything is sent over the connection
+ ///
A callback function to execute before the connection is fully instantiated.
+ ///
+ var connection = this;
+ $(connection).bind(events.onStarting, function (e, data) {
+ callback.call(connection);
+ });
+ return connection;
+ },
+
+ send: function (data) {
+ ///
Sends data over the connection
+ ///
The data to send over the connection
+ ///
+ var connection = this;
+
+ if (connection.state === signalR.connectionState.disconnected) {
+ // Connection hasn't been started yet
+ throw new Error("SignalR: Connection must be started before data can be sent. Call .start() before .send()");
+ }
+
+ if (connection.state === signalR.connectionState.connecting) {
+ // Connection hasn't been started yet
+ throw new Error("SignalR: Connection has not been fully initialized. Use .start().done() or .start().fail() to run logic after the connection has started.");
+ }
+
+ connection.transport.send(connection, data);
+ // REVIEW: Should we return deferred here?
+ return connection;
+ },
+
+ received: function (callback) {
+ ///
Adds a callback that will be invoked after anything is received over the connection
+ ///
A callback function to execute when any data is received on the connection
+ ///
+ var connection = this;
+ $(connection).bind(events.onReceived, function (e, data) {
+ if (!connection._.connectingMessageBuffer.tryBuffer(data)) {
+ callback.call(connection, data);
+ }
+ });
+ return connection;
+ },
+
+ stateChanged: function (callback) {
+ ///
Adds a callback that will be invoked when the connection state changes
+ ///
A callback function to execute when the connection state changes
+ ///
+ var connection = this;
+ $(connection).bind(events.onStateChanged, function (e, data) {
+ callback.call(connection, data);
+ });
+ return connection;
+ },
+
+ error: function (callback) {
+ ///
Adds a callback that will be invoked after an error occurs with the connection
+ ///
A callback function to execute when an error occurs on the connection
+ ///
+ var connection = this;
+ $(connection).bind(events.onError, function (e, data) {
+ callback.call(connection, data);
+ });
+ return connection;
+ },
+
+ disconnected: function (callback) {
+ ///
Adds a callback that will be invoked when the client disconnects
+ ///
A callback function to execute when the connection is broken
+ ///
+ var connection = this;
+ $(connection).bind(events.onDisconnect, function (e, data) {
+ callback.call(connection);
+ });
+ return connection;
+ },
+
+ connectionSlow: function (callback) {
+ ///
Adds a callback that will be invoked when the client detects a slow connection
+ ///
A callback function to execute when the connection is slow
+ ///
+ var connection = this;
+ $(connection).bind(events.onConnectionSlow, function (e, data) {
+ callback.call(connection);
+ });
+
+ return connection;
+ },
+
+ reconnecting: function (callback) {
+ ///
Adds a callback that will be invoked when the underlying transport begins reconnecting
+ ///
A callback function to execute when the connection enters a reconnecting state
+ ///
+ var connection = this;
+ $(connection).bind(events.onReconnecting, function (e, data) {
+ callback.call(connection);
+ });
+ return connection;
+ },
+
+ reconnected: function (callback) {
+ ///
Adds a callback that will be invoked when the underlying transport reconnects
+ ///
A callback function to execute when the connection is restored
+ ///
+ var connection = this;
+ $(connection).bind(events.onReconnect, function (e, data) {
+ callback.call(connection);
+ });
+ return connection;
+ },
+
+ stop: function (async, notifyServer) {
+ ///
Stops listening
+ ///
Whether or not to asynchronously abort the connection
+ ///
Whether we want to notify the server that we are aborting the connection
+ ///
+ var connection = this,
+ // Save deferral because this is always cleaned up
+ deferral = connection._deferral;
+
+ // Verify that we've bound a load event.
+ if (connection._.deferredStartHandler) {
+ // Unbind the event.
+ _pageWindow.unbind("load", connection._.deferredStartHandler);
+ }
+
+ // Always clean up private non-timeout based state.
+ delete connection._deferral;
+ delete connection._.config;
+ delete connection._.deferredStartHandler;
+
+ // This needs to be checked despite the connection state because a connection start can be deferred until page load.
+ // If we've deferred the start due to a page load we need to unbind the "onLoad" -> start event.
+ if (!_pageLoaded && (!connection._.config || connection._.config.waitForPageLoad === true)) {
+ connection.log("Stopping connection prior to negotiate.");
+
+ // If we have a deferral we should reject it
+ if (deferral) {
+ deferral.reject(signalR._.error(resources.stoppedWhileLoading));
+ }
+
+ // Short-circuit because the start has not been fully started.
+ return;
+ }
+
+ if (connection.state === signalR.connectionState.disconnected) {
+ return;
+ }
+
+ try {
+ connection.log("Stopping connection.");
+
+ // Clear this no matter what
+ window.clearTimeout(connection._.onFailedTimeoutHandle);
+ window.clearInterval(connection._.pingIntervalId);
+
+ if (connection.transport) {
+ if (notifyServer !== false) {
+ connection.transport.abort(connection, async);
+ }
+
+ if (connection.transport.supportsKeepAlive && connection.keepAliveData.activated) {
+ signalR.transports._logic.stopMonitoringKeepAlive(connection);
+ }
+
+ connection.transport.stop(connection);
+ connection.transport = null;
+ }
+
+ if (connection._.negotiateRequest) {
+ // If the negotiation request has already completed this will noop.
+ connection._.negotiateRequest.abort(_negotiateAbortText);
+ delete connection._.negotiateRequest;
+ }
+
+ // Trigger the disconnect event
+ $(connection).triggerHandler(events.onDisconnect);
+
+ delete connection.messageId;
+ delete connection.groupsToken;
+ delete connection.id;
+ delete connection._.pingIntervalId;
+
+ // Clear out our message buffer
+ connection._.connectingMessageBuffer.clear();
+ }
+ finally {
+ changeState(connection, connection.state, signalR.connectionState.disconnected);
+ }
+
+ return connection;
+ },
+
+ log: function (msg) {
+ log(msg, this.logging);
+ }
+ };
+
+ signalR.fn.init.prototype = signalR.fn;
+
+ signalR.noConflict = function () {
+ ///
Reinstates the original value of $.connection and returns the signalR object for manual assignment
+ ///
+ if ($.connection === signalR) {
+ $.connection = _connection;
+ }
+ return signalR;
+ };
+
+ if ($.connection) {
+ _connection = $.connection;
+ }
+
+ $.connection = $.signalR = signalR;
+
+}(window.jQuery, window));
+/* jquery.signalR.transports.common.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+
+(function ($, window, undefined) {
+ "use strict";
+
+ var signalR = $.signalR,
+ events = $.signalR.events,
+ changeState = $.signalR.changeState,
+ transportLogic;
+
+ signalR.transports = {};
+
+ function checkIfAlive(connection) {
+ var keepAliveData = connection.keepAliveData,
+ diff,
+ timeElapsed;
+
+ // Only check if we're connected
+ if (connection.state === signalR.connectionState.connected) {
+ diff = new Date();
+
+ diff.setTime(diff - keepAliveData.lastKeepAlive);
+ timeElapsed = diff.getTime();
+
+ // Check if the keep alive has completely timed out
+ if (timeElapsed >= keepAliveData.timeout) {
+ connection.log("Keep alive timed out. Notifying transport that connection has been lost.");
+
+ // Notify transport that the connection has been lost
+ connection.transport.lostConnection(connection);
+ } else if (timeElapsed >= keepAliveData.timeoutWarning) {
+ // This is to assure that the user only gets a single warning
+ if (!keepAliveData.userNotified) {
+ connection.log("Keep alive has been missed, connection may be dead/slow.");
+ $(connection).triggerHandler(events.onConnectionSlow);
+ keepAliveData.userNotified = true;
+ }
+ } else {
+ keepAliveData.userNotified = false;
+ }
+ }
+
+ // Verify we're monitoring the keep alive
+ // We don't want this as a part of the inner if statement above because we want keep alives to continue to be checked
+ // in the event that the server comes back online (if it goes offline).
+ if (keepAliveData.monitoring) {
+ window.setTimeout(function () {
+ checkIfAlive(connection);
+ }, keepAliveData.checkInterval);
+ }
+ }
+
+ function isConnectedOrReconnecting(connection) {
+ return connection.state === signalR.connectionState.connected ||
+ connection.state === signalR.connectionState.reconnecting;
+ }
+
+ function addConnectionData(url, connectionData) {
+ var appender = url.indexOf("?") !== -1 ? "&" : "?";
+
+ if (connectionData) {
+ url += appender + "connectionData=" + window.encodeURIComponent(connectionData);
+ }
+
+ return url;
+ }
+
+ transportLogic = signalR.transports._logic = {
+ pingServer: function (connection) {
+ ///
Pings the server
+ ///
Connection associated with the server ping
+ ///
+ var baseUrl, url, deferral = $.Deferred();
+
+ if (connection.transport) {
+ baseUrl = connection.transport.name === "webSockets" ? "" : connection.baseUrl;
+ url = baseUrl + connection.appRelativeUrl + "/ping";
+
+ url = transportLogic.prepareQueryString(connection, url);
+
+ $.ajax(
+ $.extend({}, $.signalR.ajaxDefaults, {
+ xhrFields: { withCredentials: connection.withCredentials },
+ url: url,
+ type: "GET",
+ contentType: connection.contentType,
+ data: {},
+ dataType: connection.ajaxDataType,
+ success: function (result) {
+ var data;
+
+ try {
+ data = connection._parseResponse(result);
+ }
+ catch (error) {
+ deferral.reject(
+ signalR._.transportError(
+ signalR.resources.pingServerFailedParse,
+ connection.transport,
+ error
+ )
+ );
+ connection.stop();
+ return;
+ }
+
+ if (data.Response === "pong") {
+ deferral.resolve();
+ }
+ else {
+ deferral.reject(
+ signalR._.transportError(
+ signalR._.format(signalR.resources.pingServerFailedInvalidResponse, result.responseText),
+ connection.transport
+ )
+ );
+ }
+ },
+ error: function (error) {
+ if (error.status === 401 || error.status === 403) {
+ deferral.reject(
+ signalR._.transportError(
+ signalR._.format(signalR.resources.pingServerFailedStatusCode, error.status),
+ connection.transport,
+ error
+ )
+ );
+ connection.stop();
+ }
+ else {
+ deferral.reject(
+ signalR._.transportError(
+ signalR.resources.pingServerFailed,
+ connection.transport,
+ error
+ )
+ );
+ }
+ }
+ }
+ ));
+
+ }
+ else {
+ deferral.reject(
+ signalR._.transportError(
+ signalR.resources.noConnectionTransport,
+ connection.transport
+ )
+ );
+ }
+
+ return deferral.promise();
+ },
+
+ prepareQueryString: function (connection, url) {
+ url = transportLogic.addQs(url, connection.qs);
+
+ return addConnectionData(url, connection.data);
+ },
+
+ addQs: function (url, qs) {
+ var appender = url.indexOf("?") !== -1 ? "&" : "?",
+ firstChar;
+
+ if (!qs) {
+ return url;
+ }
+
+ if (typeof (qs) === "object") {
+ return url + appender + $.param(qs);
+ }
+
+ if (typeof (qs) === "string") {
+ firstChar = qs.charAt(0);
+
+ if (firstChar === "?" || firstChar === "&") {
+ appender = "";
+ }
+
+ return url + appender + qs;
+ }
+
+ throw new Error("Query string property must be either a string or object.");
+ },
+
+ getUrl: function (connection, transport, reconnecting, poll) {
+ ///
Gets the url for making a GET based connect request
+ var baseUrl = transport === "webSockets" ? "" : connection.baseUrl,
+ url = baseUrl + connection.appRelativeUrl,
+ qs = "transport=" + transport + "&connectionToken=" + window.encodeURIComponent(connection.token);
+
+ if (connection.groupsToken) {
+ qs += "&groupsToken=" + window.encodeURIComponent(connection.groupsToken);
+ }
+
+ if (!reconnecting) {
+ url += "/connect";
+ } else {
+ if (poll) {
+ // longPolling transport specific
+ url += "/poll";
+ } else {
+ url += "/reconnect";
+ }
+
+ if (connection.messageId) {
+ qs += "&messageId=" + window.encodeURIComponent(connection.messageId);
+ }
+ }
+ url += "?" + qs;
+ url = transportLogic.prepareQueryString(connection, url);
+ url += "&tid=" + Math.floor(Math.random() * 11);
+ return url;
+ },
+
+ maximizePersistentResponse: function (minPersistentResponse) {
+ return {
+ MessageId: minPersistentResponse.C,
+ Messages: minPersistentResponse.M,
+ Initialized: typeof (minPersistentResponse.S) !== "undefined" ? true : false,
+ Disconnect: typeof (minPersistentResponse.D) !== "undefined" ? true : false,
+ ShouldReconnect: typeof (minPersistentResponse.T) !== "undefined" ? true : false,
+ LongPollDelay: minPersistentResponse.L,
+ GroupsToken: minPersistentResponse.G
+ };
+ },
+
+ updateGroups: function (connection, groupsToken) {
+ if (groupsToken) {
+ connection.groupsToken = groupsToken;
+ }
+ },
+
+ stringifySend: function (connection, message) {
+ if (typeof (message) === "string" || typeof (message) === "undefined" || message === null) {
+ return message;
+ }
+ return connection.json.stringify(message);
+ },
+
+ ajaxSend: function (connection, data) {
+ var payload = transportLogic.stringifySend(connection, data),
+ url = connection.url + "/send" + "?transport=" + connection.transport.name + "&connectionToken=" + window.encodeURIComponent(connection.token),
+ onFail = function (error, connection) {
+ $(connection).triggerHandler(events.onError, [signalR._.transportError(signalR.resources.sendFailed, connection.transport, error), data]);
+ };
+
+ url = transportLogic.prepareQueryString(connection, url);
+
+ return $.ajax(
+ $.extend({}, $.signalR.ajaxDefaults, {
+ xhrFields: { withCredentials: connection.withCredentials },
+ url: url,
+ type: connection.ajaxDataType === "jsonp" ? "GET" : "POST",
+ contentType: signalR._.defaultContentType,
+ dataType: connection.ajaxDataType,
+ data: {
+ data: payload
+ },
+ success: function (result) {
+ var res;
+
+ if (result) {
+ try {
+ res = connection._parseResponse(result);
+ }
+ catch (error) {
+ onFail(error, connection);
+ connection.stop();
+ return;
+ }
+
+ $(connection).triggerHandler(events.onReceived, [res]);
+ }
+ },
+ error: function (error, textStatus) {
+ if (textStatus === "abort" || textStatus === "parsererror") {
+ // The parsererror happens for sends that don't return any data, and hence
+ // don't write the jsonp callback to the response. This is harder to fix on the server
+ // so just hack around it on the client for now.
+ return;
+ }
+
+ onFail(error, connection);
+ }
+ }
+ ));
+ },
+
+ ajaxAbort: function (connection, async) {
+ if (typeof (connection.transport) === "undefined") {
+ return;
+ }
+
+ // Async by default unless explicitly overidden
+ async = typeof async === "undefined" ? true : async;
+
+ var url = connection.url + "/abort" + "?transport=" + connection.transport.name + "&connectionToken=" + window.encodeURIComponent(connection.token);
+ url = transportLogic.prepareQueryString(connection, url);
+
+ $.ajax(
+ $.extend({}, $.signalR.ajaxDefaults, {
+ xhrFields: { withCredentials: connection.withCredentials },
+ url: url,
+ async: async,
+ timeout: 1000,
+ type: "POST",
+ contentType: connection.contentType,
+ dataType: connection.ajaxDataType,
+ data: {}
+ }
+ ));
+
+ connection.log("Fired ajax abort async = " + async + ".");
+ },
+
+ tryInitialize: function (persistentResponse, onInitialized) {
+ if (persistentResponse.Initialized) {
+ onInitialized();
+ }
+ },
+
+ processMessages: function (connection, minData, onInitialized) {
+ var data,
+ $connection = $(connection);
+
+ // If our transport supports keep alive then we need to update the last keep alive time stamp.
+ // Very rarely the transport can be null.
+ if (connection.transport && connection.transport.supportsKeepAlive && connection.keepAliveData.activated) {
+ this.updateKeepAlive(connection);
+ }
+
+ if (minData) {
+ data = this.maximizePersistentResponse(minData);
+
+ if (data.Disconnect) {
+ connection.log("Disconnect command received from server.");
+
+ // Disconnected by the server
+ connection.stop(false, false);
+ return;
+ }
+
+ this.updateGroups(connection, data.GroupsToken);
+
+ if (data.MessageId) {
+ connection.messageId = data.MessageId;
+ }
+
+ if (data.Messages) {
+ $.each(data.Messages, function (index, message) {
+ $connection.triggerHandler(events.onReceived, [message]);
+ });
+
+ transportLogic.tryInitialize(data, onInitialized);
+ }
+ }
+ },
+
+ monitorKeepAlive: function (connection) {
+ var keepAliveData = connection.keepAliveData,
+ that = this;
+
+ // If we haven't initiated the keep alive timeouts then we need to
+ if (!keepAliveData.monitoring) {
+ keepAliveData.monitoring = true;
+
+ // Initialize the keep alive time stamp ping
+ that.updateKeepAlive(connection);
+
+ // Save the function so we can unbind it on stop
+ connection.keepAliveData.reconnectKeepAliveUpdate = function () {
+ that.updateKeepAlive(connection);
+ };
+
+ // Update Keep alive on reconnect
+ $(connection).bind(events.onReconnect, connection.keepAliveData.reconnectKeepAliveUpdate);
+
+ connection.log("Now monitoring keep alive with a warning timeout of " + keepAliveData.timeoutWarning + " and a connection lost timeout of " + keepAliveData.timeout + ".");
+ // Start the monitoring of the keep alive
+ checkIfAlive(connection);
+ } else {
+ connection.log("Tried to monitor keep alive but it's already being monitored.");
+ }
+ },
+
+ stopMonitoringKeepAlive: function (connection) {
+ var keepAliveData = connection.keepAliveData;
+
+ // Only attempt to stop the keep alive monitoring if its being monitored
+ if (keepAliveData.monitoring) {
+ // Stop monitoring
+ keepAliveData.monitoring = false;
+
+ // Remove the updateKeepAlive function from the reconnect event
+ $(connection).unbind(events.onReconnect, connection.keepAliveData.reconnectKeepAliveUpdate);
+
+ // Clear all the keep alive data
+ connection.keepAliveData = {};
+ connection.log("Stopping the monitoring of the keep alive.");
+ }
+ },
+
+ updateKeepAlive: function (connection) {
+ connection.keepAliveData.lastKeepAlive = new Date();
+ },
+
+ ensureReconnectingState: function (connection) {
+ if (changeState(connection,
+ signalR.connectionState.connected,
+ signalR.connectionState.reconnecting) === true) {
+ $(connection).triggerHandler(events.onReconnecting);
+ }
+ return connection.state === signalR.connectionState.reconnecting;
+ },
+
+ clearReconnectTimeout: function (connection) {
+ if (connection && connection._.reconnectTimeout) {
+ window.clearTimeout(connection._.reconnectTimeout);
+ delete connection._.reconnectTimeout;
+ }
+ },
+
+ reconnect: function (connection, transportName) {
+ var transport = signalR.transports[transportName],
+ that = this;
+
+ // We should only set a reconnectTimeout if we are currently connected
+ // and a reconnectTimeout isn't already set.
+ if (isConnectedOrReconnecting(connection) && !connection._.reconnectTimeout) {
+ connection._.reconnectTimeout = window.setTimeout(function () {
+ transport.stop(connection);
+
+ if (that.ensureReconnectingState(connection)) {
+ connection.log(transportName + " reconnecting.");
+ transport.start(connection);
+ }
+ }, connection.reconnectDelay);
+ }
+ },
+
+ handleParseFailure: function (connection, result, error, onFailed) {
+ // If we're in the initialization phase trigger onFailed, otherwise stop the connection.
+ if (connection.state === signalR.connectionState.connecting) {
+ connection.log("Failed to parse server response while attempting to connect.");
+ onFailed();
+ } else {
+ $(connection).triggerHandler(events.onError, [signalR._.transportError(
+ signalR._.format(signalR.resources.parseFailed, result),
+ connection.transport,
+ error)]);
+ connection.stop();
+ }
+ },
+
+ foreverFrame: {
+ count: 0,
+ connections: {}
+ }
+ };
+
+}(window.jQuery, window));
+/* jquery.signalR.transports.webSockets.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+
+(function ($, window, undefined) {
+ "use strict";
+
+ var signalR = $.signalR,
+ events = $.signalR.events,
+ changeState = $.signalR.changeState,
+ transportLogic = signalR.transports._logic;
+
+ signalR.transports.webSockets = {
+ name: "webSockets",
+
+ supportsKeepAlive: true,
+
+ send: function (connection, data) {
+ var payload = transportLogic.stringifySend(connection, data);
+ connection.socket.send(payload);
+ },
+
+ start: function (connection, onSuccess, onFailed) {
+ var url,
+ opened = false,
+ that = this,
+ reconnecting = !onSuccess,
+ $connection = $(connection);
+
+ if (!window.WebSocket) {
+ onFailed();
+ return;
+ }
+
+ if (!connection.socket) {
+ if (connection.webSocketServerUrl) {
+ url = connection.webSocketServerUrl;
+ } else {
+ url = connection.wsProtocol + connection.host;
+ }
+
+ url += transportLogic.getUrl(connection, this.name, reconnecting);
+
+ connection.log("Connecting to websocket endpoint '" + url + "'.");
+ connection.socket = new window.WebSocket(url);
+
+ connection.socket.onopen = function () {
+ opened = true;
+ connection.log("Websocket opened.");
+
+ transportLogic.clearReconnectTimeout(connection);
+
+ if (changeState(connection,
+ signalR.connectionState.reconnecting,
+ signalR.connectionState.connected) === true) {
+ $connection.triggerHandler(events.onReconnect);
+ }
+ };
+
+ connection.socket.onclose = function (event) {
+ // Only handle a socket close if the close is from the current socket.
+ // Sometimes on disconnect the server will push down an onclose event
+ // to an expired socket.
+
+ if (this === connection.socket) {
+ if (!opened) {
+ if (onFailed) {
+ onFailed();
+ } else if (reconnecting) {
+ that.reconnect(connection);
+ }
+ return;
+ } else if (typeof event.wasClean !== "undefined" && event.wasClean === false) {
+ // Ideally this would use the websocket.onerror handler (rather than checking wasClean in onclose) but
+ // I found in some circumstances Chrome won't call onerror. This implementation seems to work on all browsers.
+ $(connection).triggerHandler(events.onError, [signalR._.transportError(
+ signalR.resources.webSocketClosed,
+ connection.transport,
+ event)]);
+ connection.log("Unclean disconnect from websocket: " + event.reason || "[no reason given].");
+ } else {
+ connection.log("Websocket closed.");
+ }
+
+ that.reconnect(connection);
+ }
+ };
+
+ connection.socket.onmessage = function (event) {
+ var data,
+ $connection = $(connection);
+
+ try {
+ data = connection._parseResponse(event.data);
+ }
+ catch (error) {
+ transportLogic.handleParseFailure(connection, event.data, error, onFailed);
+ return;
+ }
+
+ if (data) {
+ // data.M is PersistentResponse.Messages
+ if ($.isEmptyObject(data) || data.M) {
+ transportLogic.processMessages(connection, data, onSuccess);
+ } else {
+ // For websockets we need to trigger onReceived
+ // for callbacks to outgoing hub calls.
+ $connection.triggerHandler(events.onReceived, [data]);
+ }
+ }
+ };
+ }
+ },
+
+ reconnect: function (connection) {
+ transportLogic.reconnect(connection, this.name);
+ },
+
+ lostConnection: function (connection) {
+ this.reconnect(connection);
+ },
+
+ stop: function (connection) {
+ // Don't trigger a reconnect after stopping
+ transportLogic.clearReconnectTimeout(connection);
+
+ if (connection.socket) {
+ connection.log("Closing the Websocket.");
+ connection.socket.close();
+ connection.socket = null;
+ }
+ },
+
+ abort: function (connection, async) {
+ transportLogic.ajaxAbort(connection, async);
+ }
+ };
+
+}(window.jQuery, window));
+/* jquery.signalR.transports.serverSentEvents.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+
+(function ($, window, undefined) {
+ "use strict";
+
+ var signalR = $.signalR,
+ events = $.signalR.events,
+ changeState = $.signalR.changeState,
+ transportLogic = signalR.transports._logic;
+
+ signalR.transports.serverSentEvents = {
+ name: "serverSentEvents",
+
+ supportsKeepAlive: true,
+
+ timeOut: 3000,
+
+ start: function (connection, onSuccess, onFailed) {
+ var that = this,
+ opened = false,
+ $connection = $(connection),
+ reconnecting = !onSuccess,
+ url,
+ reconnectTimeout;
+
+ if (connection.eventSource) {
+ connection.log("The connection already has an event source. Stopping it.");
+ connection.stop();
+ }
+
+ if (!window.EventSource) {
+ if (onFailed) {
+ connection.log("This browser doesn't support SSE.");
+ onFailed();
+ }
+ return;
+ }
+
+ url = transportLogic.getUrl(connection, this.name, reconnecting);
+
+ try {
+ connection.log("Attempting to connect to SSE endpoint '" + url + "'.");
+ connection.eventSource = new window.EventSource(url);
+ }
+ catch (e) {
+ connection.log("EventSource failed trying to connect with error " + e.Message + ".");
+ if (onFailed) {
+ // The connection failed, call the failed callback
+ onFailed();
+ } else {
+ $connection.triggerHandler(events.onError, [signalR._.transportError(signalR.resources.eventSourceFailedToConnect, connection.transport, e)]);
+ if (reconnecting) {
+ // If we were reconnecting, rather than doing initial connect, then try reconnect again
+ that.reconnect(connection);
+ }
+ }
+ return;
+ }
+
+ if (reconnecting) {
+ reconnectTimeout = window.setTimeout(function () {
+ if (opened === false) {
+ // If we're reconnecting and the event source is attempting to connect,
+ // don't keep retrying. This causes duplicate connections to spawn.
+ if (connection.eventSource.readyState !== window.EventSource.OPEN) {
+ // If we were reconnecting, rather than doing initial connect, then try reconnect again
+ that.reconnect(connection);
+ }
+ }
+ },
+ that.timeOut);
+ }
+
+ connection.eventSource.addEventListener("open", function (e) {
+ connection.log("EventSource connected.");
+
+ if (reconnectTimeout) {
+ window.clearTimeout(reconnectTimeout);
+ }
+
+ transportLogic.clearReconnectTimeout(connection);
+
+ if (opened === false) {
+ opened = true;
+
+ if (changeState(connection,
+ signalR.connectionState.reconnecting,
+ signalR.connectionState.connected) === true) {
+ $connection.triggerHandler(events.onReconnect);
+ }
+ }
+ }, false);
+
+ connection.eventSource.addEventListener("message", function (e) {
+ var res;
+
+ // process messages
+ if (e.data === "initialized") {
+ return;
+ }
+
+ try {
+ res = connection._parseResponse(e.data);
+ }
+ catch (error) {
+ transportLogic.handleParseFailure(connection, e.data, error, onFailed);
+ return;
+ }
+
+ transportLogic.processMessages(connection, res, onSuccess);
+ }, false);
+
+ connection.eventSource.addEventListener("error", function (e) {
+ // Only handle an error if the error is from the current Event Source.
+ // Sometimes on disconnect the server will push down an error event
+ // to an expired Event Source.
+ if (this !== connection.eventSource) {
+ return;
+ }
+
+ if (!opened) {
+ if (onFailed) {
+ onFailed();
+ }
+
+ return;
+ }
+
+ connection.log("EventSource readyState: " + connection.eventSource.readyState + ".");
+
+ if (e.eventPhase === window.EventSource.CLOSED) {
+ // 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.");
+ that.reconnect(connection);
+ } else {
+ // connection error
+ connection.log("EventSource error.");
+ $connection.triggerHandler(events.onError, [signalR._.transportError(signalR.resources.eventSourceError, connection.transport, e)]);
+ }
+ }, false);
+ },
+
+ reconnect: function (connection) {
+ transportLogic.reconnect(connection, this.name);
+ },
+
+ lostConnection: function (connection) {
+ this.reconnect(connection);
+ },
+
+ send: function (connection, data) {
+ transportLogic.ajaxSend(connection, data);
+ },
+
+ stop: function (connection) {
+ // Don't trigger a reconnect after stopping
+ transportLogic.clearReconnectTimeout(connection);
+
+ if (connection && connection.eventSource) {
+ connection.log("EventSource calling close().");
+ connection.eventSource.close();
+ connection.eventSource = null;
+ delete connection.eventSource;
+ }
+ },
+
+ abort: function (connection, async) {
+ transportLogic.ajaxAbort(connection, async);
+ }
+ };
+
+}(window.jQuery, window));
+/* jquery.signalR.transports.foreverFrame.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+
+(function ($, window, undefined) {
+ "use strict";
+
+ var signalR = $.signalR,
+ events = $.signalR.events,
+ changeState = $.signalR.changeState,
+ transportLogic = signalR.transports._logic,
+ // Used to prevent infinite loading icon spins in older versions of ie
+ // We build this object inside a closure so we don't pollute the rest of
+ // the foreverFrame transport with unnecessary functions/utilities.
+ loadPreventer = (function () {
+ var loadingFixIntervalId = null,
+ loadingFixInterval = 1000,
+ attachedTo = 0;
+
+ return {
+ prevent: function () {
+ // Prevent additional iframe removal procedures from newer browsers
+ if (signalR._.ieVersion <= 8) {
+ // We only ever want to set the interval one time, so on the first attachedTo
+ if (attachedTo === 0) {
+ // Create and destroy iframe every 3 seconds to prevent loading icon, super hacky
+ loadingFixIntervalId = window.setInterval(function () {
+ var tempFrame = $("
");
+
+ $("body").append(tempFrame);
+ tempFrame.remove();
+ tempFrame = null;
+ }, loadingFixInterval);
+ }
+
+ attachedTo++;
+ }
+ },
+ cancel: function () {
+ // Only clear the interval if there's only one more object that the loadPreventer is attachedTo
+ if (attachedTo === 1) {
+ window.clearInterval(loadingFixIntervalId);
+ }
+
+ if (attachedTo > 0) {
+ attachedTo--;
+ }
+ }
+ };
+ })();
+
+ signalR.transports.foreverFrame = {
+ name: "foreverFrame",
+
+ supportsKeepAlive: true,
+
+ // Added as a value here so we can create tests to verify functionality
+ iframeClearThreshold: 50,
+
+ start: function (connection, onSuccess, onFailed) {
+ var that = this,
+ frameId = (transportLogic.foreverFrame.count += 1),
+ url,
+ frame = $("
");
+
+ if (window.EventSource) {
+ // If the browser supports SSE, don't use Forever Frame
+ if (onFailed) {
+ connection.log("This browser supports SSE, skipping Forever Frame.");
+ onFailed();
+ }
+ return;
+ }
+
+ // Start preventing loading icon
+ // This will only perform work if the loadPreventer is not attached to another connection.
+ loadPreventer.prevent();
+
+ // Build the url
+ url = transportLogic.getUrl(connection, this.name);
+ url += "&frameId=" + frameId;
+
+ // Set body prior to setting URL to avoid caching issues.
+ $("body").append(frame);
+
+ frame.prop("src", url);
+ transportLogic.foreverFrame.connections[frameId] = connection;
+
+ connection.log("Binding to iframe's readystatechange event.");
+ frame.bind("readystatechange", function () {
+ if ($.inArray(this.readyState, ["loaded", "complete"]) >= 0) {
+ connection.log("Forever frame iframe readyState changed to " + this.readyState + ", reconnecting.");
+
+ that.reconnect(connection);
+ }
+ });
+
+ connection.frame = frame[0];
+ connection.frameId = frameId;
+
+ if (onSuccess) {
+ connection.onSuccess = function () {
+ connection.log("Iframe transport started.");
+ onSuccess();
+ delete connection.onSuccess;
+ };
+ }
+ },
+
+ reconnect: function (connection) {
+ var that = this;
+ window.setTimeout(function () {
+ if (connection.frame && transportLogic.ensureReconnectingState(connection)) {
+ var frame = connection.frame,
+ src = transportLogic.getUrl(connection, that.name, true) + "&frameId=" + connection.frameId;
+ connection.log("Updating iframe src to '" + src + "'.");
+ frame.src = src;
+ }
+ }, connection.reconnectDelay);
+ },
+
+ lostConnection: function (connection) {
+ this.reconnect(connection);
+ },
+
+ send: function (connection, data) {
+ transportLogic.ajaxSend(connection, data);
+ },
+
+ receive: function (connection, data) {
+ var cw;
+
+ transportLogic.processMessages(connection, data, connection.onSuccess);
+
+ // Protect against connection stopping from a callback trigger within the processMessages above.
+ if (connection.state === $.signalR.connectionState.connected) {
+ // Delete the script & div elements
+ connection.frameMessageCount = (connection.frameMessageCount || 0) + 1;
+ if (connection.frameMessageCount > signalR.transports.foreverFrame.iframeClearThreshold) {
+ connection.frameMessageCount = 0;
+ cw = connection.frame.contentWindow || connection.frame.contentDocument;
+ if (cw && cw.document) {
+ $("body", cw.document).empty();
+ }
+ }
+ }
+ },
+
+ stop: function (connection) {
+ var cw = null;
+
+ // Stop attempting to prevent loading icon
+ loadPreventer.cancel();
+
+ if (connection.frame) {
+ if (connection.frame.stop) {
+ connection.frame.stop();
+ } else {
+ try {
+ cw = connection.frame.contentWindow || connection.frame.contentDocument;
+ if (cw.document && cw.document.execCommand) {
+ cw.document.execCommand("Stop");
+ }
+ }
+ catch (e) {
+ connection.log("Error occurred when stopping foreverFrame transport. Message = " + e.message + ".");
+ }
+ }
+ $(connection.frame).remove();
+ delete transportLogic.foreverFrame.connections[connection.frameId];
+ connection.frame = null;
+ connection.frameId = null;
+ delete connection.frame;
+ delete connection.frameId;
+ delete connection.onSuccess;
+ delete connection.frameMessageCount;
+ connection.log("Stopping forever frame.");
+ }
+ },
+
+ abort: function (connection, async) {
+ transportLogic.ajaxAbort(connection, async);
+ },
+
+ getConnection: function (id) {
+ return transportLogic.foreverFrame.connections[id];
+ },
+
+ started: function (connection) {
+ if (changeState(connection,
+ signalR.connectionState.reconnecting,
+ signalR.connectionState.connected) === true) {
+ // If there's no onSuccess handler we assume this is a reconnect
+ $(connection).triggerHandler(events.onReconnect);
+ }
+ }
+ };
+
+}(window.jQuery, window));
+/* jquery.signalR.transports.longPolling.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+
+(function ($, window, undefined) {
+ "use strict";
+
+ var signalR = $.signalR,
+ events = $.signalR.events,
+ changeState = $.signalR.changeState,
+ isDisconnecting = $.signalR.isDisconnecting,
+ transportLogic = signalR.transports._logic;
+
+ signalR.transports.longPolling = {
+ name: "longPolling",
+
+ supportsKeepAlive: false,
+
+ reconnectDelay: 3000,
+
+ start: function (connection, onSuccess, onFailed) {
+ ///
Starts the long polling connection
+ ///
The SignalR connection to start
+ var that = this,
+ fireConnect = function () {
+ fireConnect = $.noop;
+
+ connection.log("LongPolling connected.");
+ onSuccess();
+ // Reset onFailed to null because it shouldn't be called again
+ onFailed = null;
+ },
+ tryFailConnect = function () {
+ if (onFailed) {
+ onFailed();
+ onFailed = null;
+ connection.log("LongPolling failed to connect.");
+ return true;
+ }
+
+ return false;
+ },
+ privateData = connection._,
+ reconnectErrors = 0,
+ fireReconnected = function (instance) {
+ window.clearTimeout(privateData.reconnectTimeoutId);
+ privateData.reconnectTimeoutId = null;
+
+ if (changeState(instance,
+ signalR.connectionState.reconnecting,
+ signalR.connectionState.connected) === true) {
+ // Successfully reconnected!
+ instance.log("Raising the reconnect event");
+ $(instance).triggerHandler(events.onReconnect);
+ }
+ },
+ // 1 hour
+ maxFireReconnectedTimeout = 3600000;
+
+ if (connection.pollXhr) {
+ connection.log("Polling xhr requests already exists, aborting.");
+ connection.stop();
+ }
+
+ connection.messageId = null;
+
+ privateData.reconnectTimeoutId = null;
+
+ privateData.pollTimeoutId = window.setTimeout(function () {
+ (function poll(instance, raiseReconnect) {
+ var messageId = instance.messageId,
+ connect = (messageId === null),
+ reconnecting = !connect,
+ polling = !raiseReconnect,
+ url = transportLogic.getUrl(instance, that.name, reconnecting, polling);
+
+ // If we've disconnected during the time we've tried to re-instantiate the poll then stop.
+ if (isDisconnecting(instance) === true) {
+ return;
+ }
+
+ connection.log("Opening long polling request to '" + url + "'.");
+ instance.pollXhr = $.ajax(
+ $.extend({}, $.signalR.ajaxDefaults, {
+ xhrFields: { withCredentials: connection.withCredentials },
+ url: url,
+ type: "GET",
+ dataType: connection.ajaxDataType,
+ contentType: connection.contentType,
+ success: function (result) {
+ var minData,
+ delay = 0,
+ data,
+ shouldReconnect;
+
+ connection.log("Long poll complete.");
+
+ // Reset our reconnect errors so if we transition into a reconnecting state again we trigger
+ // reconnected quickly
+ reconnectErrors = 0;
+
+ try {
+ minData = connection._parseResponse(result);
+ }
+ catch (error) {
+ transportLogic.handleParseFailure(instance, result, error, tryFailConnect);
+ return;
+ }
+
+ // If there's currently a timeout to trigger reconnect, fire it now before processing messages
+ if (privateData.reconnectTimeoutId !== null) {
+ fireReconnected(instance);
+ }
+
+ if (minData) {
+ data = transportLogic.maximizePersistentResponse(minData);
+ }
+
+ transportLogic.processMessages(instance, minData, fireConnect);
+
+ if (data &&
+ $.type(data.LongPollDelay) === "number") {
+ delay = data.LongPollDelay;
+ }
+
+ if (data && data.Disconnect) {
+ return;
+ }
+
+ if (isDisconnecting(instance) === true) {
+ return;
+ }
+
+ shouldReconnect = data && data.ShouldReconnect;
+ if (shouldReconnect) {
+ // Transition into the reconnecting state
+ // If this fails then that means that the user transitioned the connection into a invalid state in processMessages.
+ if (!transportLogic.ensureReconnectingState(instance))
+ {
+ return;
+ }
+ }
+
+ // We never want to pass a raiseReconnect flag after a successful poll. This is handled via the error function
+ if (delay > 0) {
+ privateData.pollTimeoutId = window.setTimeout(function () {
+ poll(instance, shouldReconnect);
+ }, delay);
+ } else {
+ poll(instance, shouldReconnect);
+ }
+ },
+
+ error: function (data, textStatus) {
+ // Stop trying to trigger reconnect, connection is in an error state
+ // If we're not in the reconnect state this will noop
+ window.clearTimeout(privateData.reconnectTimeoutId);
+ privateData.reconnectTimeoutId = null;
+
+ if (textStatus === "abort") {
+ connection.log("Aborted xhr request.");
+ return;
+ }
+
+ if (!tryFailConnect()) {
+
+ // Increment our reconnect errors, we assume all errors to be reconnect errors
+ // In the case that it's our first error this will cause Reconnect to be fired
+ // after 1 second due to reconnectErrors being = 1.
+ reconnectErrors++;
+
+ if (connection.state !== signalR.connectionState.reconnecting) {
+ connection.log("An error occurred using longPolling. Status = " + textStatus + ". Response = " + data.responseText + ".");
+ $(instance).triggerHandler(events.onError, [signalR._.transportError(signalR.resources.longPollFailed, connection.transport, data)]);
+ }
+
+ // Transition into the reconnecting state
+ // If this fails then that means that the user transitioned the connection into the disconnected or connecting state within the above error handler trigger.
+ if (!transportLogic.ensureReconnectingState(instance)) {
+ return;
+ }
+
+ // Call poll with the raiseReconnect flag as true after the reconnect delay
+ privateData.pollTimeoutId = window.setTimeout(function () {
+ poll(instance, true);
+ }, that.reconnectDelay);
+ }
+ }
+ }
+ ));
+
+
+ // This will only ever pass after an error has occurred via the poll ajax procedure.
+ if (reconnecting && raiseReconnect === true) {
+ // We wait to reconnect depending on how many times we've failed to reconnect.
+ // This is essentially a heuristic that will exponentially increase in wait time before
+ // triggering reconnected. This depends on the "error" handler of Poll to cancel this
+ // timeout if it triggers before the Reconnected event fires.
+ // The Math.min at the end is to ensure that the reconnect timeout does not overflow.
+ privateData.reconnectTimeoutId = window.setTimeout(function () { fireReconnected(instance); }, Math.min(1000 * (Math.pow(2, reconnectErrors) - 1), maxFireReconnectedTimeout));
+ }
+ }(connection));
+ }, 250); // Have to delay initial poll so Chrome doesn't show loader spinner in tab
+ },
+
+ lostConnection: function (connection) {
+ throw new Error("Lost Connection not handled for LongPolling");
+ },
+
+ send: function (connection, data) {
+ transportLogic.ajaxSend(connection, data);
+ },
+
+ stop: function (connection) {
+ ///
Stops the long polling connection
+ ///
The SignalR connection to stop
+
+ window.clearTimeout(connection._.pollTimeoutId);
+ window.clearTimeout(connection._.reconnectTimeoutId);
+
+ delete connection._.pollTimeoutId;
+ delete connection._.reconnectTimeoutId;
+
+ if (connection.pollXhr) {
+ connection.pollXhr.abort();
+ connection.pollXhr = null;
+ delete connection.pollXhr;
+ }
+ },
+
+ abort: function (connection, async) {
+ transportLogic.ajaxAbort(connection, async);
+ }
+ };
+
+}(window.jQuery, window));
+/* jquery.signalR.hubs.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+
+(function ($, window, undefined) {
+ "use strict";
+
+ var eventNamespace = ".hubProxy",
+ signalR = $.signalR;
+
+ function makeEventName(event) {
+ return event + eventNamespace;
+ }
+
+ // Equivalent to Array.prototype.map
+ function map(arr, fun, thisp) {
+ var i,
+ length = arr.length,
+ result = [];
+ for (i = 0; i < length; i += 1) {
+ if (arr.hasOwnProperty(i)) {
+ result[i] = fun.call(thisp, arr[i], i, arr);
+ }
+ }
+ return result;
+ }
+
+ function getArgValue(a) {
+ return $.isFunction(a) ? null : ($.type(a) === "undefined" ? null : a);
+ }
+
+ function hasMembers(obj) {
+ for (var key in obj) {
+ // If we have any properties in our callback map then we have callbacks and can exit the loop via return
+ if (obj.hasOwnProperty(key)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ function clearInvocationCallbacks(connection, error) {
+ ///
+ var callbacks = connection._.invocationCallbacks,
+ callback;
+
+ if (hasMembers(callbacks)) {
+ connection.log("Clearing hub invocation callbacks with error: " + error + ".");
+ }
+
+ // Reset the callback cache now as we have a local var referencing it
+ connection._.invocationCallbackId = 0;
+ delete connection._.invocationCallbacks;
+ connection._.invocationCallbacks = {};
+
+ // Loop over the callbacks and invoke them.
+ // We do this using a local var reference and *after* we've cleared the cache
+ // so that if a fail callback itself tries to invoke another method we don't
+ // end up with its callback in the list we're looping over.
+ for (var callbackId in callbacks) {
+ callback = callbacks[callbackId];
+ callback.method.call(callback.scope, { E: error });
+ }
+ }
+
+ // hubProxy
+ function hubProxy(hubConnection, hubName) {
+ ///
+ /// Creates a new proxy object for the given hub connection that can be used to invoke
+ /// methods on server hubs and handle client method invocation requests from the server.
+ ///
+ return new hubProxy.fn.init(hubConnection, hubName);
+ }
+
+ hubProxy.fn = hubProxy.prototype = {
+ init: function (connection, hubName) {
+ this.state = {};
+ this.connection = connection;
+ this.hubName = hubName;
+ this._ = {
+ callbackMap: {}
+ };
+ },
+
+ hasSubscriptions: function () {
+ return hasMembers(this._.callbackMap);
+ },
+
+ on: function (eventName, callback) {
+ ///
Wires up a callback to be invoked when a invocation request is received from the server hub.
+ ///
The name of the hub event to register the callback for.
+ ///
The callback to be invoked.
+ var that = this,
+ callbackMap = that._.callbackMap;
+
+ // Normalize the event name to lowercase
+ eventName = eventName.toLowerCase();
+
+ // If there is not an event registered for this callback yet we want to create its event space in the callback map.
+ if (!callbackMap[eventName]) {
+ callbackMap[eventName] = {};
+ }
+
+ // Map the callback to our encompassed function
+ callbackMap[eventName][callback] = function (e, data) {
+ callback.apply(that, data);
+ };
+
+ $(that).bind(makeEventName(eventName), callbackMap[eventName][callback]);
+
+ return that;
+ },
+
+ off: function (eventName, callback) {
+ ///
Removes the callback invocation request from the server hub for the given event name.
+ ///
The name of the hub event to unregister the callback for.
+ ///
The callback to be invoked.
+ var that = this,
+ callbackMap = that._.callbackMap,
+ callbackSpace;
+
+ // Normalize the event name to lowercase
+ eventName = eventName.toLowerCase();
+
+ callbackSpace = callbackMap[eventName];
+
+ // Verify that there is an event space to unbind
+ if (callbackSpace) {
+ // Only unbind if there's an event bound with eventName and a callback with the specified callback
+ if (callbackSpace[callback]) {
+ $(that).unbind(makeEventName(eventName), callbackSpace[callback]);
+
+ // Remove the callback from the callback map
+ delete callbackSpace[callback];
+
+ // Check if there are any members left on the event, if not we need to destroy it.
+ if (!hasMembers(callbackSpace)) {
+ delete callbackMap[eventName];
+ }
+ } else if (!callback) { // Check if we're removing the whole event and we didn't error because of an invalid callback
+ $(that).unbind(makeEventName(eventName));
+
+ delete callbackMap[eventName];
+ }
+ }
+
+ return that;
+ },
+
+ invoke: function (methodName) {
+ ///
Invokes a server hub method with the given arguments.
+ ///
The name of the server hub method.
+
+ var that = this,
+ connection = that.connection,
+ args = $.makeArray(arguments).slice(1),
+ argValues = map(args, getArgValue),
+ data = { H: that.hubName, M: methodName, A: argValues, I: connection._.invocationCallbackId },
+ d = $.Deferred(),
+ callback = function (minResult) {
+ var result = that._maximizeHubResponse(minResult),
+ source,
+ error;
+
+ // Update the hub state
+ $.extend(that.state, result.State);
+
+ if (result.Error) {
+ // Server hub method threw an exception, log it & reject the deferred
+ if (result.StackTrace) {
+ connection.log(result.Error + "\n" + result.StackTrace + ".");
+ }
+
+ // result.ErrorData is only set if a HubException was thrown
+ source = result.IsHubException ? "HubException" : "Exception";
+ error = signalR._.error(result.Error, source);
+ error.data = result.ErrorData;
+
+ d.rejectWith(that, [error]);
+ } else {
+ // Server invocation succeeded, resolve the deferred
+ d.resolveWith(that, [result.Result]);
+ }
+ };
+
+ connection._.invocationCallbacks[connection._.invocationCallbackId.toString()] = { scope: that, method: callback };
+ connection._.invocationCallbackId += 1;
+
+ if (!$.isEmptyObject(that.state)) {
+ data.S = that.state;
+ }
+
+ connection.send(data);
+
+ return d.promise();
+ },
+
+ _maximizeHubResponse: function (minHubResponse) {
+ return {
+ State: minHubResponse.S,
+ Result: minHubResponse.R,
+ Id: minHubResponse.I,
+ IsHubException: minHubResponse.H,
+ Error: minHubResponse.E,
+ StackTrace: minHubResponse.T,
+ ErrorData: minHubResponse.D
+ };
+ }
+ };
+
+ hubProxy.fn.init.prototype = hubProxy.fn;
+
+ // hubConnection
+ function hubConnection(url, options) {
+ ///
Creates a new hub connection.
+ ///
[Optional] The hub route url, defaults to "/signalr".
+ ///
[Optional] Settings to use when creating the hubConnection.
+ var settings = {
+ qs: null,
+ logging: false,
+ useDefaultPath: true
+ };
+
+ $.extend(settings, options);
+
+ if (!url || settings.useDefaultPath) {
+ url = (url || "") + "/signalr";
+ }
+ return new hubConnection.fn.init(url, settings);
+ }
+
+ hubConnection.fn = hubConnection.prototype = $.connection();
+
+ hubConnection.fn.init = function (url, options) {
+ var settings = {
+ qs: null,
+ logging: false,
+ useDefaultPath: true
+ },
+ connection = this;
+
+ $.extend(settings, options);
+
+ // Call the base constructor
+ $.signalR.fn.init.call(connection, url, settings.qs, settings.logging);
+
+ // Object to store hub proxies for this connection
+ connection.proxies = {};
+
+ connection._.invocationCallbackId = 0;
+ connection._.invocationCallbacks = {};
+
+ // Wire up the received handler
+ connection.received(function (minData) {
+ var data, proxy, dataCallbackId, callback, hubName, eventName;
+ if (!minData) {
+ return;
+ }
+
+ if (typeof (minData.I) !== "undefined") {
+ // We received the return value from a server method invocation, look up callback by id and call it
+ dataCallbackId = minData.I.toString();
+ callback = connection._.invocationCallbacks[dataCallbackId];
+ if (callback) {
+ // Delete the callback from the proxy
+ connection._.invocationCallbacks[dataCallbackId] = null;
+ delete connection._.invocationCallbacks[dataCallbackId];
+
+ // Invoke the callback
+ callback.method.call(callback.scope, minData);
+ }
+ } else {
+ data = this._maximizeClientHubInvocation(minData);
+
+ // We received a client invocation request, i.e. broadcast from server hub
+ connection.log("Triggering client hub event '" + data.Method + "' on hub '" + data.Hub + "'.");
+
+ // Normalize the names to lowercase
+ hubName = data.Hub.toLowerCase();
+ eventName = data.Method.toLowerCase();
+
+ // Trigger the local invocation event
+ proxy = this.proxies[hubName];
+
+ // Update the hub state
+ $.extend(proxy.state, data.State);
+ $(proxy).triggerHandler(makeEventName(eventName), [data.Args]);
+ }
+ });
+
+ connection.error(function (errData, origData) {
+ var data, callbackId, callback;
+
+ if (connection.transport && connection.transport.name === "webSockets") {
+ // WebSockets connections have all callbacks removed on reconnect instead
+ // as WebSockets sends are fire & forget
+ return;
+ }
+
+ if (!origData) {
+ // No original data passed so this is not a send error
+ return;
+ }
+
+ try {
+ data = window.JSON.parse(origData);
+ if (!data.I) {
+ // The original data doesn't have a callback ID so not a send error
+ return;
+ }
+ } catch (e) {
+ // The original data is not a JSON payload so this is not a send error
+ return;
+ }
+
+ callbackId = data.I;
+ callback = connection._.invocationCallbacks[callbackId];
+
+ // Invoke the callback with an error to reject the promise
+ callback.method.call(callback.scope, { E: errData });
+
+ // Delete the callback
+ connection._.invocationCallbacks[callbackId] = null;
+ delete connection._.invocationCallbacks[callbackId];
+ });
+
+ connection.reconnecting(function () {
+ if (connection.transport && connection.transport.name === "webSockets") {
+ clearInvocationCallbacks(connection, "Connection started reconnecting before invocation result was received.");
+ }
+ });
+
+ connection.disconnected(function () {
+ clearInvocationCallbacks(connection, "Connection was disconnected before invocation result was received.");
+ });
+ };
+
+ hubConnection.fn._maximizeClientHubInvocation = function (minClientHubInvocation) {
+ return {
+ Hub: minClientHubInvocation.H,
+ Method: minClientHubInvocation.M,
+ Args: minClientHubInvocation.A,
+ State: minClientHubInvocation.S
+ };
+ };
+
+ hubConnection.fn._registerSubscribedHubs = function () {
+ ///
+ /// Sets the starting event to loop through the known hubs and register any new hubs
+ /// that have been added to the proxy.
+ ///
+ var connection = this;
+
+ if (!connection._subscribedToHubs) {
+ connection._subscribedToHubs = true;
+ connection.starting(function () {
+ // Set the connection's data object with all the hub proxies with active subscriptions.
+ // These proxies will receive notifications from the server.
+ var subscribedHubs = [];
+
+ $.each(connection.proxies, function (key) {
+ if (this.hasSubscriptions()) {
+ subscribedHubs.push({ name: key });
+ connection.log("Client subscribed to hub '" + key + "'.");
+ }
+ });
+
+ if (subscribedHubs.length === 0) {
+ connection.log("No hubs have been subscribed to. The client will not receive data from hubs. To fix, declare at least one client side function prior to connection start for each hub you wish to subscribe to.");
+ }
+
+ connection.data = connection.json.stringify(subscribedHubs);
+ });
+ }
+ };
+
+ hubConnection.fn.createHubProxy = function (hubName) {
+ ///
+ /// Creates a new proxy object for the given hub connection that can be used to invoke
+ /// methods on server hubs and handle client method invocation requests from the server.
+ ///
+ ///
+ /// The name of the hub on the server to create the proxy for.
+ ///
+
+ // Normalize the name to lowercase
+ hubName = hubName.toLowerCase();
+
+ var proxy = this.proxies[hubName];
+ if (!proxy) {
+ proxy = hubProxy(this, hubName);
+ this.proxies[hubName] = proxy;
+ }
+
+ this._registerSubscribedHubs();
+
+ return proxy;
+ };
+
+ hubConnection.fn.init.prototype = hubConnection.fn;
+
+ $.hubConnection = hubConnection;
+
+}(window.jQuery, window));
+/* jquery.signalR.version.js */
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
+
+/*global window:false */
+///
+(function ($, undefined) {
+ $.signalR.version = "2.0.1";
+}(window.jQuery));
diff --git a/samples/MusicStore/wwwroot/Scripts/jquery.signalR-2.0.1.min.js b/samples/MusicStore/wwwroot/Scripts/jquery.signalR-2.0.1.min.js
new file mode 100644
index 0000000..f9eaa72
--- /dev/null
+++ b/samples/MusicStore/wwwroot/Scripts/jquery.signalR-2.0.1.min.js
@@ -0,0 +1,8 @@
+/*!
+ * ASP.NET SignalR JavaScript Library v2.0.1
+ * http://signalr.net/
+ *
+ * Copyright (C) Microsoft Corporation. All rights reserved.
+ *
+ */
+(function(n,t,i){"use strict";function w(t,i){var u,f;if(n.isArray(t)){for(u=t.length-1;u>=0;u--)f=t[u],n.type(t)==="object"||n.type(f)==="string"&&r.transports[f]||(i.log("Invalid transport: "+f+", removing it from the transports list."),t.splice(u,1));t.length===0&&(i.log("No transports remain within the specified transport array."),t=null)}else if(n.type(t)==="object"||r.transports[t]||t==="auto"){if(t==="auto"&&r._.ieVersion<=8)return["longPolling"]}else i.log("Invalid transport: "+t.toString()+"."),t=null;return t}function b(n){return n==="http:"?80:n==="https:"?443:void 0}function l(n,t){return t.match(/:\d+$/)?t:t+":"+b(n)}function k(t,i){var u=this,r=[];u.tryBuffer=function(i){return t.state===n.signalR.connectionState.connecting?(r.push(i),!0):!1};u.drain=function(){if(t.state===n.signalR.connectionState.connected)while(r.length>0)i(r.shift())};u.clear=function(){r=[]}}var f={nojQuery:"jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.",noTransportOnInit:"No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.",errorOnNegotiate:"Error during negotiation request.",stoppedWhileLoading:"The connection was stopped during page load.",stoppedWhileNegotiating:"The connection was stopped during the negotiate request.",errorParsingNegotiateResponse:"Error parsing negotiate response.",protocolIncompatible:"You are using a version of the client that isn't compatible with the server. Client version {0}, server version {1}.",sendFailed:"Send failed.",parseFailed:"Failed at parsing response: {0}",longPollFailed:"Long polling request failed.",eventSourceFailedToConnect:"EventSource failed to connect.",eventSourceError:"Error raised by EventSource",webSocketClosed:"WebSocket closed.",pingServerFailedInvalidResponse:"Invalid ping response when pinging server: '{0}'.",pingServerFailed:"Failed to ping server.",pingServerFailedStatusCode:"Failed to ping server. Server responded with status code {0}, stopping the connection.",pingServerFailedParse:"Failed to parse ping server response, stopping the connection.",noConnectionTransport:"Connection is in an invalid state, there is no transport active."};if(typeof n!="function")throw new Error(f.nojQuery);var r,h,s=t.document.readyState==="complete",e=n(t),c="__Negotiate Aborted__",u={onStart:"onStart",onStarting:"onStarting",onReceived:"onReceived",onError:"onError",onConnectionSlow:"onConnectionSlow",onReconnecting:"onReconnecting",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},a=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))}},o=function(t,i,r){return i===t.state?(t.state=r,n(t).triggerHandler(u.onStateChanged,[{oldState:i,newState:r}]),!0):!1},v=function(n){return n.state===r.connectionState.disconnected},y=function(i){var f=i._.config,e=function(t){n(i).triggerHandler(u.onError,[t])};!f.pingIntervalId&&f.pingInterval&&(i._.pingIntervalId=t.setInterval(function(){r.transports._logic.pingServer(i).fail(e)},f.pingInterval))},p=function(n){var i,u;n._.configuredStopReconnectingTimeout||(u=function(n){n.log("Couldn't reconnect within the configured timeout ("+n.disconnectTimeout+"ms), disconnecting.");n.stop(!1,!1)},n.reconnecting(function(){var n=this;n.state===r.connectionState.reconnecting&&(i=t.setTimeout(function(){u(n)},n.disconnectTimeout))}),n.stateChanged(function(n){n.oldState===r.connectionState.reconnecting&&t.clearTimeout(i)}),n._.configuredStopReconnectingTimeout=!0)};r=function(n,t,i){return new r.fn.init(n,t,i)};r._={defaultContentType:"application/x-www-form-urlencoded; charset=UTF-8",ieVersion:function(){var i,n;return t.navigator.appName==="Microsoft Internet Explorer"&&(n=/MSIE ([0-9]+\.[0-9]+)/.exec(t.navigator.userAgent),n&&(i=t.parseFloat(n[1]))),i}(),error:function(n,t){var i=new Error(n);return i.source=t,i},transportError:function(n,t,r){var u=this.error(n,r);return u.transport=t?t.name:i,u},format:function(){for(var t=arguments[0],n=0;n
<\/script>.");}};e.load(function(){s=!0});r.fn=r.prototype={init:function(t,i,r){var f=n(this);this.url=t;this.qs=i;this._={connectingMessageBuffer:new k(this,function(n){f.triggerHandler(u.onReceived,[n])}),onFailedTimeoutHandle:null};typeof r=="boolean"&&(this.logging=r)},_parseResponse:function(n){var t=this;return n?t.ajaxDataType==="text"?t.json.parse(n):n:n},json:t.JSON,isCrossDomain:function(i,r){var u;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=r||t.location,u=t.document.createElement("a"),u.href=i,u.protocol+l(u.protocol,u.host)!==r.protocol+l(r.protocol,r.host))},ajaxDataType:"text",contentType:"application/json; charset=UTF-8",logging:!1,state:r.connectionState.disconnected,keepAliveData:{},clientProtocol:"1.3",reconnectDelay:2e3,transportConnectTimeout:0,disconnectTimeout:3e4,keepAliveWarnAt:2/3,start:function(i,h){var l=this,a={pingInterval:3e5,waitForPageLoad:!0,transport:"auto",jsonp:!1},d,v=l._deferral||n.Deferred(),b=t.document.createElement("a"),k,g;if(l._deferral=v,!l.json)throw new Error("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.");if(n.type(i)==="function"?h=i:n.type(i)==="object"&&(n.extend(a,i),n.type(a.callback)==="function"&&(h=a.callback)),a.transport=w(a.transport,l),!a.transport)throw new Error("SignalR: Invalid transport(s) specified, aborting start.");return(l._.config=a,!s&&a.waitForPageLoad===!0)?(l._.deferredStartHandler=function(){l.start(i,h)},e.bind("load",l._.deferredStartHandler),v.promise()):l.state===r.connectionState.connecting?v.promise():o(l,r.connectionState.disconnected,r.connectionState.connecting)===!1?(v.resolve(l),v.promise()):(p(l),b.href=l.url,b.protocol&&b.protocol!==":"?(l.protocol=b.protocol,l.host=b.host,l.baseUrl=b.protocol+"//"+b.host):(l.protocol=t.document.location.protocol,l.host=t.document.location.host,l.baseUrl=l.protocol+"//"+l.host),l.wsProtocol=l.protocol==="https:"?"wss://":"ws://",a.transport==="auto"&&a.jsonp===!0&&(a.transport="longPolling"),this.isCrossDomain(l.url)&&(l.log("Auto detected cross domain url."),a.transport==="auto"&&(a.transport=["webSockets","longPolling"]),typeof a.withCredentials=="undefined"&&(a.withCredentials=!0),a.jsonp||(a.jsonp=!n.support.cors,a.jsonp&&l.log("Using jsonp because this browser doesn't support CORS.")),l.contentType=r._.defaultContentType),l.withCredentials=a.withCredentials,l.ajaxDataType=a.jsonp?"jsonp":"text",n(l).bind(u.onStart,function(){n.type(h)==="function"&&h.call(l);v.resolve(l)}),d=function(i,s){var w=r._.error(f.noTransportOnInit);if(s=s||0,s>=i.length){n(l).triggerHandler(u.onError,[w]);v.reject(w);l.stop();return}if(l.state!==r.connectionState.disconnected){var c=i[s],h=n.type(c)==="object"?c:r.transports[c],a=!1,p=function(){a||(a=!0,t.clearTimeout(l._.onFailedTimeoutHandle),h.stop(l),d(i,s+1))};if(l.transport=h,c.indexOf("_")===0){d(i,s+1);return}try{l._.onFailedTimeoutHandle=t.setTimeout(function(){l.log(h.name+" timed out when trying to connect.");p()},l.transportConnectTimeout);h.start(l,function(){var i=r._.firefoxMajorVersion(t.navigator.userAgent)>=11,f=!!l.withCredentials&&i;l.state!==r.connectionState.disconnected&&(a||(a=!0,t.clearTimeout(l._.onFailedTimeoutHandle),h.supportsKeepAlive&&l.keepAliveData.activated&&r.transports._logic.monitorKeepAlive(l),y(l),o(l,r.connectionState.connecting,r.connectionState.connected),l._.connectingMessageBuffer.drain(),n(l).triggerHandler(u.onStart),e.bind("unload",function(){l.log("Window unloading, stopping the connection.");l.stop(f)}),i&&e.bind("beforeunload",function(){t.setTimeout(function(){l.stop(f)},0)})))},p)}catch(b){l.log(h.name+" transport threw '"+b.message+"' when attempting to start.");p()}}},k=l.url+"/negotiate",g=function(t,i){var e=r._.error(f.errorOnNegotiate,t);n(i).triggerHandler(u.onError,e);v.reject(e);i.stop()},n(l).triggerHandler(u.onStarting),k=r.transports._logic.prepareQueryString(l,k),k=r.transports._logic.addQs(k,{clientProtocol:l.clientProtocol}),l.log("Negotiating with '"+k+"'."),l._.negotiateRequest=n.ajax(n.extend({},n.signalR.ajaxDefaults,{xhrFields:{withCredentials:l.withCredentials},url:k,type:"GET",contentType:l.contentType,data:{},dataType:l.ajaxDataType,error:function(n,t){t!==c?g(n,l):v.reject(r._.error(f.stoppedWhileNegotiating))},success:function(t){var i,e,h,o=[],s=[];try{i=l._parseResponse(t)}catch(c){g(r._.error(f.errorParsingNegotiateResponse,c),l);return}if(e=l.keepAliveData,l.appRelativeUrl=i.Url,l.id=i.ConnectionId,l.token=i.ConnectionToken,l.webSocketServerUrl=i.WebSocketServerUrl,l.disconnectTimeout=i.DisconnectTimeout*1e3,l.transportConnectTimeout=l.transportConnectTimeout+i.TransportConnectTimeout*1e3,i.KeepAliveTimeout?(e.activated=!0,e.timeout=i.KeepAliveTimeout*1e3,e.timeoutWarning=e.timeout*l.keepAliveWarnAt,e.checkInterval=(e.timeout-e.timeoutWarning)/3):e.activated=!1,!i.ProtocolVersion||i.ProtocolVersion!==l.clientProtocol){h=r._.error(r._.format(f.protocolIncompatible,l.clientProtocol,i.ProtocolVersion));n(l).triggerHandler(u.onError,[h]);v.reject(h);return}n.each(r.transports,function(n){if(n==="webSockets"&&!i.TryWebSockets)return!0;s.push(n)});n.isArray(a.transport)?n.each(a.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,s)>=0)&&o.push(n.type(t)==="string"?""+t:t)}):n.type(a.transport)==="object"||n.inArray(a.transport,s)>=0?o.push(a.transport):o=s;d(o)}})),v.promise())},starting:function(t){var i=this;return n(i).bind(u.onStarting,function(){t.call(i)}),i},send:function(n){var t=this;if(t.state===r.connectionState.disconnected)throw new Error("SignalR: Connection must be started before data can be sent. Call .start() before .send()");if(t.state===r.connectionState.connecting)throw new Error("SignalR: Connection has not been fully initialized. Use .start().done() or .start().fail() to run logic after the connection has started.");return t.transport.send(t,n),t},received:function(t){var i=this;return n(i).bind(u.onReceived,function(n,r){i._.connectingMessageBuffer.tryBuffer(r)||t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(u.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(u.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(u.onDisconnect,function(){t.call(i)}),i},connectionSlow:function(t){var i=this;return n(i).bind(u.onConnectionSlow,function(){t.call(i)}),i},reconnecting:function(t){var i=this;return n(i).bind(u.onReconnecting,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(u.onReconnect,function(){t.call(i)}),i},stop:function(i,h){var l=this,a=l._deferral;if(l._.deferredStartHandler&&e.unbind("load",l._.deferredStartHandler),delete l._deferral,delete l._.config,delete l._.deferredStartHandler,!s&&(!l._.config||l._.config.waitForPageLoad===!0)){l.log("Stopping connection prior to negotiate.");a&&a.reject(r._.error(f.stoppedWhileLoading));return}if(l.state!==r.connectionState.disconnected){try{l.log("Stopping connection.");t.clearTimeout(l._.onFailedTimeoutHandle);t.clearInterval(l._.pingIntervalId);l.transport&&(h!==!1&&l.transport.abort(l,i),l.transport.supportsKeepAlive&&l.keepAliveData.activated&&r.transports._logic.stopMonitoringKeepAlive(l),l.transport.stop(l),l.transport=null);l._.negotiateRequest&&(l._.negotiateRequest.abort(c),delete l._.negotiateRequest);n(l).triggerHandler(u.onDisconnect);delete l.messageId;delete l.groupsToken;delete l.id;delete l._.pingIntervalId;l._.connectingMessageBuffer.clear()}finally{o(l,l.state,r.connectionState.disconnected)}return l}},log:function(n){a(n,this.logging)}};r.fn.init.prototype=r.fn;r.noConflict=function(){return n.connection===r&&(n.connection=h),r};n.connection&&(h=n.connection);n.connection=n.signalR=r})(window.jQuery,window),function(n,t){"use strict";function f(u){var e=u.keepAliveData,o,s;u.state===i.connectionState.connected&&(o=new Date,o.setTime(o-e.lastKeepAlive),s=o.getTime(),s>=e.timeout?(u.log("Keep alive timed out. Notifying transport that connection has been lost."),u.transport.lostConnection(u)):s>=e.timeoutWarning?e.userNotified||(u.log("Keep alive has been missed, connection may be dead/slow."),n(u).triggerHandler(r.onConnectionSlow),e.userNotified=!0):e.userNotified=!1);e.monitoring&&t.setTimeout(function(){f(u)},e.checkInterval)}function o(n){return n.state===i.connectionState.connected||n.state===i.connectionState.reconnecting}function s(n,i){var r=n.indexOf("?")!==-1?"&":"?";return i&&(n+=r+"connectionData="+t.encodeURIComponent(i)),n}var i=n.signalR,r=n.signalR.events,e=n.signalR.changeState,u;i.transports={};u=i.transports._logic={pingServer:function(t){var e,f,r=n.Deferred();return t.transport?(e=t.transport.name==="webSockets"?"":t.baseUrl,f=e+t.appRelativeUrl+"/ping",f=u.prepareQueryString(t,f),n.ajax(n.extend({},n.signalR.ajaxDefaults,{xhrFields:{withCredentials:t.withCredentials},url:f,type:"GET",contentType:t.contentType,data:{},dataType:t.ajaxDataType,success:function(n){var u;try{u=t._parseResponse(n)}catch(f){r.reject(i._.transportError(i.resources.pingServerFailedParse,t.transport,f));t.stop();return}u.Response==="pong"?r.resolve():r.reject(i._.transportError(i._.format(i.resources.pingServerFailedInvalidResponse,n.responseText),t.transport))},error:function(n){n.status===401||n.status===403?(r.reject(i._.transportError(i._.format(i.resources.pingServerFailedStatusCode,n.status),t.transport,n)),t.stop()):r.reject(i._.transportError(i.resources.pingServerFailed,t.transport,n))}}))):r.reject(i._.transportError(i.resources.noConnectionTransport,t.transport)),r.promise()},prepareQueryString:function(n,t){return t=u.addQs(t,n.qs),s(t,n.data)},addQs:function(t,i){var r=t.indexOf("?")!==-1?"&":"?",u;if(!i)return t;if(typeof i=="object")return t+r+n.param(i);if(typeof i=="string")return u=i.charAt(0),(u==="?"||u==="&")&&(r=""),t+r+i;throw new Error("Query string property must be either a string or object.");},getUrl:function(n,i,r,f){var s=i==="webSockets"?"":n.baseUrl,e=s+n.appRelativeUrl,o="transport="+i+"&connectionToken="+t.encodeURIComponent(n.token);return n.groupsToken&&(o+="&groupsToken="+t.encodeURIComponent(n.groupsToken)),r?(e+=f?"/poll":"/reconnect",n.messageId&&(o+="&messageId="+t.encodeURIComponent(n.messageId))):e+="/connect",e+="?"+o,e=u.prepareQueryString(n,e),e+("&tid="+Math.floor(Math.random()*11))},maximizePersistentResponse:function(n){return{MessageId:n.C,Messages:n.M,Initialized:typeof n.S!="undefined"?!0:!1,Disconnect:typeof n.D!="undefined"?!0:!1,ShouldReconnect:typeof n.T!="undefined"?!0:!1,LongPollDelay:n.L,GroupsToken:n.G}},updateGroups:function(n,t){t&&(n.groupsToken=t)},stringifySend:function(n,t){return typeof t=="string"||typeof t=="undefined"||t===null?t:n.json.stringify(t)},ajaxSend:function(f,e){var h=u.stringifySend(f,e),o=f.url+"/send?transport="+f.transport.name+"&connectionToken="+t.encodeURIComponent(f.token),s=function(t,u){n(u).triggerHandler(r.onError,[i._.transportError(i.resources.sendFailed,u.transport,t),e])};return o=u.prepareQueryString(f,o),n.ajax(n.extend({},n.signalR.ajaxDefaults,{xhrFields:{withCredentials:f.withCredentials},url:o,type:f.ajaxDataType==="jsonp"?"GET":"POST",contentType:i._.defaultContentType,dataType:f.ajaxDataType,data:{data:h},success:function(t){var i;if(t){try{i=f._parseResponse(t)}catch(u){s(u,f);f.stop();return}n(f).triggerHandler(r.onReceived,[i])}},error:function(n,t){t!=="abort"&&t!=="parsererror"&&s(n,f)}}))},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var f=i.url+"/abort?transport="+i.transport.name+"&connectionToken="+t.encodeURIComponent(i.token);f=u.prepareQueryString(i,f);n.ajax(n.extend({},n.signalR.ajaxDefaults,{xhrFields:{withCredentials:i.withCredentials},url:f,async:r,timeout:1e3,type:"POST",contentType:i.contentType,dataType:i.ajaxDataType,data:{}}));i.log("Fired ajax abort async = "+r+".")}},tryInitialize:function(n,t){n.Initialized&&t()},processMessages:function(t,i,f){var e,o=n(t);if(t.transport&&t.transport.supportsKeepAlive&&t.keepAliveData.activated&&this.updateKeepAlive(t),i){if(e=this.maximizePersistentResponse(i),e.Disconnect){t.log("Disconnect command received from server.");t.stop(!1,!1);return}this.updateGroups(t,e.GroupsToken);e.MessageId&&(t.messageId=e.MessageId);e.Messages&&(n.each(e.Messages,function(n,t){o.triggerHandler(r.onReceived,[t])}),u.tryInitialize(e,f))}},monitorKeepAlive:function(t){var i=t.keepAliveData,u=this;i.monitoring?t.log("Tried to monitor keep alive but it's already being monitored."):(i.monitoring=!0,u.updateKeepAlive(t),t.keepAliveData.reconnectKeepAliveUpdate=function(){u.updateKeepAlive(t)},n(t).bind(r.onReconnect,t.keepAliveData.reconnectKeepAliveUpdate),t.log("Now monitoring keep alive with a warning timeout of "+i.timeoutWarning+" and a connection lost timeout of "+i.timeout+"."),f(t))},stopMonitoringKeepAlive:function(t){var i=t.keepAliveData;i.monitoring&&(i.monitoring=!1,n(t).unbind(r.onReconnect,t.keepAliveData.reconnectKeepAliveUpdate),t.keepAliveData={},t.log("Stopping the monitoring of the keep alive."))},updateKeepAlive:function(n){n.keepAliveData.lastKeepAlive=new Date},ensureReconnectingState:function(t){return e(t,i.connectionState.connected,i.connectionState.reconnecting)===!0&&n(t).triggerHandler(r.onReconnecting),t.state===i.connectionState.reconnecting},clearReconnectTimeout:function(n){n&&n._.reconnectTimeout&&(t.clearTimeout(n._.reconnectTimeout),delete n._.reconnectTimeout)},reconnect:function(n,r){var u=i.transports[r],f=this;o(n)&&!n._.reconnectTimeout&&(n._.reconnectTimeout=t.setTimeout(function(){u.stop(n);f.ensureReconnectingState(n)&&(n.log(r+" reconnecting."),u.start(n))},n.reconnectDelay))},handleParseFailure:function(t,u,f,e){t.state===i.connectionState.connecting?(t.log("Failed to parse server response while attempting to connect."),e()):(n(t).triggerHandler(r.onError,[i._.transportError(i._.format(i.resources.parseFailed,u),t.transport,f)]),t.stop())},foreverFrame:{count:0,connections:{}}}}(window.jQuery,window),function(n,t){"use strict";var r=n.signalR,u=n.signalR.events,f=n.signalR.changeState,i=r.transports._logic;r.transports.webSockets={name:"webSockets",supportsKeepAlive:!0,send:function(n,t){var r=i.stringifySend(n,t);n.socket.send(r)},start:function(e,o,s){var h,c=!1,l=this,a=!o,v=n(e);if(!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,h+=i.getUrl(e,this.name,a),e.log("Connecting to websocket endpoint '"+h+"'."),e.socket=new t.WebSocket(h),e.socket.onopen=function(){c=!0;e.log("Websocket opened.");i.clearReconnectTimeout(e);f(e,r.connectionState.reconnecting,r.connectionState.connected)===!0&&v.triggerHandler(u.onReconnect)},e.socket.onclose=function(t){if(this===e.socket){if(c)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).triggerHandler(u.onError,[r._.transportError(r.resources.webSocketClosed,e.transport,t)]),e.log("Unclean disconnect from websocket: "+t.reason||"[no reason given].")):e.log("Websocket closed.");else{s?s():a&&l.reconnect(e);return}l.reconnect(e)}},e.socket.onmessage=function(t){var r,f=n(e);try{r=e._parseResponse(t.data)}catch(h){i.handleParseFailure(e,t.data,h,s);return}r&&(n.isEmptyObject(r)||r.M?i.processMessages(e,r,o):f.triggerHandler(u.onReceived,[r]))})},reconnect:function(n){i.reconnect(n,this.name)},lostConnection:function(n){this.reconnect(n)},stop:function(n){i.clearReconnectTimeout(n);n.socket&&(n.log("Closing the Websocket."),n.socket.close(),n.socket=null)},abort:function(n,t){i.ajaxAbort(n,t)}}}(window.jQuery,window),function(n,t){"use strict";var i=n.signalR,u=n.signalR.events,f=n.signalR.changeState,r=i.transports._logic;i.transports.serverSentEvents={name:"serverSentEvents",supportsKeepAlive:!0,timeOut:3e3,start:function(e,o,s){var h=this,c=!1,l=n(e),a=!o,v,y;if(e.eventSource&&(e.log("The connection already has an event source. Stopping it."),e.stop()),!t.EventSource){s&&(e.log("This browser doesn't support SSE."),s());return}v=r.getUrl(e,this.name,a);try{e.log("Attempting to connect to SSE endpoint '"+v+"'.");e.eventSource=new t.EventSource(v)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message+".");s?s():(l.triggerHandler(u.onError,[i._.transportError(i.resources.eventSourceFailedToConnect,e.transport,p)]),a&&h.reconnect(e));return}a&&(y=t.setTimeout(function(){c===!1&&e.eventSource.readyState!==t.EventSource.OPEN&&h.reconnect(e)},h.timeOut));e.eventSource.addEventListener("open",function(){e.log("EventSource connected.");y&&t.clearTimeout(y);r.clearReconnectTimeout(e);c===!1&&(c=!0,f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.triggerHandler(u.onReconnect))},!1);e.eventSource.addEventListener("message",function(n){var t;if(n.data!=="initialized"){try{t=e._parseResponse(n.data)}catch(i){r.handleParseFailure(e,n.data,i,s);return}r.processMessages(e,t,o)}},!1);e.eventSource.addEventListener("error",function(n){if(this===e.eventSource){if(!c){s&&s();return}e.log("EventSource readyState: "+e.eventSource.readyState+".");n.eventPhase===t.EventSource.CLOSED?(e.log("EventSource reconnecting due to the server connection ending."),h.reconnect(e)):(e.log("EventSource error."),l.triggerHandler(u.onError,[i._.transportError(i.resources.eventSourceError,e.transport,n)]))}},!1)},reconnect:function(n){r.reconnect(n,this.name)},lostConnection:function(n){this.reconnect(n)},send:function(n,t){r.ajaxSend(n,t)},stop:function(n){r.clearReconnectTimeout(n);n&&n.eventSource&&(n.log("EventSource calling close()."),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){r.ajaxAbort(n,t)}}}(window.jQuery,window),function(n,t){"use strict";var r=n.signalR,f=n.signalR.events,e=n.signalR.changeState,i=r.transports._logic,u=function(){var u=null,f=1e3,i=0;return{prevent:function(){r._.ieVersion<=8&&(i===0&&(u=t.setInterval(function(){var t=n("