Skip to content
This repository
Browse code

Made websocket implementation for self host on .NET 4.5.

- Made a .NET 45 solution with asp.net and self host impl for 4.5
- Shared websocket logic between asp.net host and self host.
- Made AcceptWebSocket return a Task instead of void.
- Updated websocket js to wait for reconncetDelay instead of hammering the server with reconnects.
  • Loading branch information...
commit e94d091100a86396d6efa81f72fca6198cbb57f1 1 parent 712c92b
David Fowler authored July 01, 2012

Showing 35 changed files with 540 additions and 122 deletions. Show diff stats Hide diff stats

  1. 2  Build/Build.proj
  2. 6  SignalR.Hosting.AspNet/AspNetRequest.cs
  3. 43  SignalR.Hosting.AspNet45.sln
  4. 2  SignalR.Hosting.AspNet45/Infrastructure/ByteBuffer.cs
  5. 2  SignalR.Hosting.AspNet45/Infrastructure/TaskQueue.cs
  6. 2  SignalR.Hosting.AspNet45/Properties/AssemblyInfo.cs
  7. 2  SignalR.Hosting.AspNet45/SignalR.Hosting.AspNet45.csproj
  8. 5  SignalR.Hosting.AspNet45/{AspNetWebSocketHandler.cs → WebSockets/DefaultWebSocketHandler.cs}
  9. 12  SignalR.Hosting.AspNet45/WebSockets/WebSocketHandler.cs
  10. 2  SignalR.Hosting.AspNet45/WebSockets/WebSocketMessage.cs
  11. 4  SignalR.Hosting.AspNet45/WebSockets/WebSocketMessageReader.cs
  12. 4  SignalR.Hosting.Memory/Request.cs
  13. 4  SignalR.Hosting.Owin/OwinRequest.cs
  14. 36  SignalR.Hosting.Self/HttpListenerRequestWrapper.cs
  15. 13  SignalR.Hosting.Self/HttpListenerResponseWrapper.cs
  16. 4  SignalR.Hosting.Self/Infrastructure/ResponseExtensions.cs
  17. 6  SignalR.Hosting.Self/Server.cs
  18. 10  SignalR.Hosting.Self45/Properties/AssemblyInfo.cs
  19. 104  SignalR.Hosting.Self45/SignalR.Hosting.Self45.csproj
  20. 2  SignalR/Hosting/IRequest.cs
  21. 20  SignalR/Scripts/jquery.signalR.js
  22. 2  SignalR/Scripts/jquery.signalR.min.js
  23. 4  SignalR/Transports/WebSocketTransport.cs
  24. 96  SignalR45.sln
  25. 20  samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js
  26. 2  samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.min.js
  27. 20  samples/SignalR.Hosting.AspNet45.Samples/Scripts/jquery.signalR.js
  28. 2  samples/SignalR.Hosting.AspNet45.Samples/Scripts/jquery.signalR.min.js
  29. 20  samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.js
  30. 2  samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.min.js
  31. 58  samples/SignalR.Hosting.Self45.Samples/Program.cs
  32. 36  samples/SignalR.Hosting.Self45.Samples/Properties/AssemblyInfo.cs
  33. 89  samples/SignalR.Hosting.Self45.Samples/SignalR.Hosting.Self.Samples.csproj
  34. 22  samples/SignalR.Hosting.Self45.Samples/app.config
  35. 4  samples/SignalR.Hosting.Self45.Samples/packages.config
2  Build/Build.proj
@@ -115,7 +115,7 @@
115 115
              Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml')"
116 116
              Properties="Configuration=$(Configuration)" />
117 117
              
118  
-    <MSBuild Projects="$(ProjectRoot)\SignalR.Hosting.AspNet45.sln"
  118
+    <MSBuild Projects="$(ProjectRoot)\SignalR45.sln"
119 119
              Targets="Build"
120 120
              Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\Web')"
121 121
              Properties="Configuration=$(Configuration)" />
6  SignalR.Hosting.AspNet/AspNetRequest.cs
@@ -146,16 +146,18 @@ private static GetUnvalidatedCollections ResolveCollectionsMethod()
146 146
             return (GetUnvalidatedCollections)Delegate.CreateDelegate(typeof(GetUnvalidatedCollections), firstArgument: null, method: getUnvalidatedCollectionsMethod);
147 147
         }
148 148
 
149  
-        public void AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
  149
+        public Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
150 150
         {
151 151
 #if NET45
152 152
             _context.AcceptWebSocketRequest(ws =>
153 153
             {
154  
-                var handler = new AspNetWebSocketHandler();
  154
+                var handler = new SignalR.WebSockets.DefaultWebSocketHandler();
155 155
                 var task = handler.ProcessWebSocketRequestAsync(ws);
156 156
                 callback(handler).Then(h => h.CleanClose(), handler);
157 157
                 return task;
158 158
             });
  159
+
  160
+            return TaskAsyncHelper.Empty;
159 161
 #else
160 162
             throw new NotSupportedException();
161 163
 #endif
43  SignalR.Hosting.AspNet45.sln
... ...
@@ -1,43 +0,0 @@
1  
-
2  
-Microsoft Visual Studio Solution File, Format Version 12.00
3  
-# Visual Studio 11
4  
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.AspNet45", "SignalR.Hosting.AspNet45\SignalR.Hosting.AspNet45.csproj", "{6F53F576-0E35-4E89-8D4D-B6B40084A16C}"
5  
-EndProject
6  
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR", "SignalR\SignalR.csproj", "{1B9A82C4-BCA1-4834-A33E-226F17BE070B}"
7  
-EndProject
8  
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.Common", "SignalR.Hosting.Common\SignalR.Hosting.Common.csproj", "{3B71F0AE-D4B6-4F47-BF62-333D45615673}"
9  
-EndProject
10  
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{A7D75EA8-1439-4D57-9B88-EC60842B5FB3}"
11  
-EndProject
12  
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.AspNet.Samples", "samples\SignalR.Hosting.AspNet45.Samples\SignalR.Hosting.AspNet.Samples.csproj", "{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}"
13  
-EndProject
14  
-Global
15  
-	GlobalSection(SolutionConfigurationPlatforms) = preSolution
16  
-		Debug|Any CPU = Debug|Any CPU
17  
-		Release|Any CPU = Release|Any CPU
18  
-	EndGlobalSection
19  
-	GlobalSection(ProjectConfigurationPlatforms) = postSolution
20  
-		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21  
-		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|Any CPU.Build.0 = Debug|Any CPU
22  
-		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|Any CPU.ActiveCfg = Release|Any CPU
23  
-		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|Any CPU.Build.0 = Release|Any CPU
24  
-		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25  
-		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|Any CPU.Build.0 = Debug|Any CPU
26  
-		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|Any CPU.ActiveCfg = Release|Any CPU
27  
-		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|Any CPU.Build.0 = Release|Any CPU
28  
-		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29  
-		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|Any CPU.Build.0 = Debug|Any CPU
30  
-		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|Any CPU.ActiveCfg = Release|Any CPU
31  
-		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|Any CPU.Build.0 = Release|Any CPU
32  
-		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33  
-		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|Any CPU.Build.0 = Debug|Any CPU
34  
-		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|Any CPU.ActiveCfg = Release|Any CPU
35  
-		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|Any CPU.Build.0 = Release|Any CPU
36  
-	EndGlobalSection
37  
-	GlobalSection(SolutionProperties) = preSolution
38  
-		HideSolutionNode = FALSE
39  
-	EndGlobalSection
40  
-	GlobalSection(NestedProjects) = preSolution
41  
-		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82} = {A7D75EA8-1439-4D57-9B88-EC60842B5FB3}
42  
-	EndGlobalSection
43  
-EndGlobal
2  SignalR.Hosting.AspNet45/Infrastructure/ByteBuffer.cs
@@ -2,7 +2,7 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Text;
4 4
 
5  
-namespace SignalR.Hosting.AspNet.Infrastructure
  5
+namespace SignalR.Infrastructure
6 6
 {    
7 7
     // Similar to MemoryStream, but tries to allocate as few objects as possible on the LOH
8 8
 
2  SignalR.Hosting.AspNet45/Infrastructure/TaskQueue.cs
... ...
@@ -1,7 +1,7 @@
1 1
 using System;
2 2
 using System.Threading.Tasks;
3 3
 
4  
-namespace SignalR.Hosting.AspNet.Infrastructure
  4
+namespace SignalR.Infrastructure
5 5
 {
6 6
     // Allows serial queuing of Task instances
7 7
     // The tasks are not called on the current synchronization context
2  SignalR.Hosting.AspNet45/Properties/AssemblyInfo.cs
@@ -2,4 +2,4 @@
2 2
 
3 3
 [assembly: AssemblyTitle("SignalR.Hosting.AspNet45")]
4 4
 [assembly: AssemblyDescription("Asp.Net host for SignalR on .NET 4.5")]
5  
-[assembly: AssemblyVersion("0.5.1.0")]
  5
+[assembly: AssemblyVersion("0.5.2.0")]
2  SignalR.Hosting.AspNet45/SignalR.Hosting.AspNet45.csproj
@@ -89,7 +89,7 @@
89 89
     <Compile Include="..\SignalR\TaskAsyncHelper.cs">
90 90
       <Link>Infrastructure\TaskAsyncHelper.cs</Link>
91 91
     </Compile>
92  
-    <Compile Include="AspNetWebSocketHandler.cs" />
  92
+    <Compile Include="WebSockets\DefaultWebSocketHandler.cs" />
93 93
     <Compile Include="Infrastructure\ByteBuffer.cs" />
94 94
     <Compile Include="Infrastructure\TaskQueue.cs" />
95 95
     <Compile Include="Properties\AssemblyInfo.cs" />
5  SignalR.Hosting.AspNet45/AspNetWebSocketHandler.cs → ...ng.AspNet45/WebSockets/DefaultWebSocketHandler.cs
... ...
@@ -1,10 +1,9 @@
1 1
 using System;
2 2
 using System.Threading.Tasks;
3  
-using SignalR.Hosting.AspNet.WebSockets;
4 3
 
5  
-namespace SignalR.Hosting.AspNet
  4
+namespace SignalR.WebSockets
6 5
 {
7  
-    internal class AspNetWebSocketHandler : WebSocketHandler, IWebSocket
  6
+    internal class DefaultWebSocketHandler : WebSocketHandler, IWebSocket
8 7
     {
9 8
         private bool _raiseEvent = true;
10 9
 
12  SignalR.Hosting.AspNet45/WebSockets/WebSocketHandler.cs
... ...
@@ -1,14 +1,12 @@
1 1
 using System;
2  
-using System.ComponentModel;
3 2
 using System.Net.WebSockets;
4 3
 using System.Runtime.InteropServices;
5 4
 using System.Text;
6 5
 using System.Threading;
7 6
 using System.Threading.Tasks;
8  
-using System.Web.WebSockets;
9  
-using SignalR.Hosting.AspNet.Infrastructure;
  7
+using SignalR.Infrastructure;
10 8
 
11  
-namespace SignalR.Hosting.AspNet.WebSockets
  9
+namespace SignalR.WebSockets
12 10
 {
13 11
     internal class WebSocketHandler
14 12
     {
@@ -108,14 +106,14 @@ public int MaxIncomingMessageSize
108 106
          * MISC PROPERTIES
109 107
          */
110 108
 
111  
-        public AspNetWebSocketContext WebSocketContext { get; set; }
  109
+        public WebSocketContext WebSocketContext { get; set; }
112 110
         public Exception Error { get; set; }
113 111
 
114 112
         /*
115 113
          * IMPLEMENTATION
116 114
          */
117 115
 
118  
-        public Task ProcessWebSocketRequestAsync(AspNetWebSocketContext webSocketContext)
  116
+        public Task ProcessWebSocketRequestAsync(WebSocketContext webSocketContext)
119 117
         {
120 118
             if (webSocketContext == null)
121 119
             {
@@ -127,7 +125,7 @@ public Task ProcessWebSocketRequestAsync(AspNetWebSocketContext webSocketContext
127 125
             return ProcessWebSocketRequestAsync(webSocketContext, () => WebSocketMessageReader.ReadMessageAsync(webSocket, buffer, MaxIncomingMessageSize));
128 126
         }
129 127
 
130  
-        internal async Task ProcessWebSocketRequestAsync(AspNetWebSocketContext webSocketContext, Func<Task<WebSocketMessage>> messageRetriever)
  128
+        internal async Task ProcessWebSocketRequestAsync(WebSocketContext webSocketContext, Func<Task<WebSocketMessage>> messageRetriever)
131 129
         {
132 130
             try
133 131
             {
2  SignalR.Hosting.AspNet45/WebSockets/WebSocketMessage.cs
... ...
@@ -1,7 +1,7 @@
1 1
 using System;
2 2
 using System.Net.WebSockets;
3 3
 
4  
-namespace SignalR.Hosting.AspNet.WebSockets
  4
+namespace SignalR.WebSockets
5 5
 {
6 6
     internal sealed class WebSocketMessage
7 7
     {
4  SignalR.Hosting.AspNet45/WebSockets/WebSocketMessageReader.cs
@@ -3,9 +3,9 @@
3 3
 using System.Text;
4 4
 using System.Threading;
5 5
 using System.Threading.Tasks;
6  
-using SignalR.Hosting.AspNet.Infrastructure;
  6
+using SignalR.Infrastructure;
7 7
 
8  
-namespace SignalR.Hosting.AspNet.WebSockets
  8
+namespace SignalR.WebSockets
9 9
 {
10 10
     internal static class WebSocketMessageReader
11 11
     {
4  SignalR.Hosting.Memory/Request.cs
@@ -109,8 +109,10 @@ public IPrincipal User
109 109
             }
110 110
         }
111 111
 
112  
-        public void AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
  112
+        public Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
113 113
         {
  114
+            // TODO: Add support
  115
+            throw new NotSupportedException();
114 116
         }
115 117
     }
116 118
 }
4  SignalR.Hosting.Owin/OwinRequest.cs
@@ -97,9 +97,9 @@ private Uri BuildUrl(Gate.Environment env)
97 97
             return new Uri(url);
98 98
         }
99 99
 
100  
-        public void AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
  100
+        public Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
101 101
         {
102  
-
  102
+            throw new NotSupportedException();
103 103
         }
104 104
     }
105 105
 }
36  SignalR.Hosting.Self/HttpListenerRequestWrapper.cs
@@ -10,20 +10,20 @@ namespace SignalR.Hosting.Self
10 10
 {
11 11
     public class HttpListenerRequestWrapper : IRequest
12 12
     {
13  
-        private readonly HttpListenerRequest _httpListenerRequest;
  13
+        private readonly HttpListenerContext _httpListenerContext;
14 14
         private NameValueCollection _form;
15 15
 
16  
-        public HttpListenerRequestWrapper(HttpListenerRequest httpListenerRequest, IPrincipal user)
  16
+        public HttpListenerRequestWrapper(HttpListenerContext httpListenerContext)
17 17
         {
18  
-            _httpListenerRequest = httpListenerRequest;
19  
-            QueryString = new NameValueCollection(httpListenerRequest.QueryString);
20  
-            Headers = new NameValueCollection(httpListenerRequest.Headers);
21  
-            Cookies = new CookieCollectionWrapper(_httpListenerRequest.Cookies);
  18
+            _httpListenerContext = httpListenerContext;
  19
+            QueryString = new NameValueCollection(httpListenerContext.Request.QueryString);
  20
+            Headers = new NameValueCollection(httpListenerContext.Request.Headers);
  21
+            Cookies = new CookieCollectionWrapper(httpListenerContext.Request.Cookies);
22 22
             ServerVariables = new NameValueCollection();
23  
-            User = user;
  23
+            User = httpListenerContext.User;
24 24
 
25 25
             // Set the client IP
26  
-            ServerVariables["REMOTE_ADDR"] = _httpListenerRequest.RemoteEndPoint.Address.ToString();
  26
+            ServerVariables["REMOTE_ADDR"] = httpListenerContext.Request.RemoteEndPoint.Address.ToString();
27 27
         }
28 28
 
29 29
         public IRequestCookieCollection Cookies
@@ -57,7 +57,7 @@ public Uri Url
57 57
         {
58 58
             get
59 59
             {
60  
-                return _httpListenerRequest.Url;
  60
+                return _httpListenerContext.Request.Url;
61 61
             }
62 62
         }
63 63
 
@@ -78,13 +78,13 @@ private void EnsureForm()
78 78
             if (_form == null)
79 79
             {
80 80
                 // Do nothing if there's no body
81  
-                if (!_httpListenerRequest.HasEntityBody)
  81
+                if (!_httpListenerContext.Request.HasEntityBody)
82 82
                 {
83 83
                     _form = new NameValueCollection();
84 84
                     return;
85 85
                 }
86 86
 
87  
-                using (var sw = new StreamReader(_httpListenerRequest.InputStream))
  87
+                using (var sw = new StreamReader(_httpListenerContext.Request.InputStream))
88 88
                 {
89 89
                     var body = sw.ReadToEnd();
90 90
                     _form = HttpUtility.ParseDelimited(body);
@@ -92,9 +92,19 @@ private void EnsureForm()
92 92
             }
93 93
         }
94 94
 
95  
-        public void AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
  95
+        public Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback)
96 96
         {
97  
-            
  97
+#if NET45
  98
+            return _httpListenerContext.AcceptWebSocketAsync(subProtocol: null).Then(ws =>
  99
+            {
  100
+                var handler = new SignalR.WebSockets.DefaultWebSocketHandler();
  101
+                var task = handler.ProcessWebSocketRequestAsync(ws);
  102
+                callback(handler).Then(h => h.CleanClose(), handler);
  103
+                return task;
  104
+            });
  105
+#else
  106
+            throw new NotSupportedException();
  107
+#endif
98 108
         }
99 109
     }
100 110
 }
13  SignalR.Hosting.Self/HttpListenerResponseWrapper.cs
@@ -45,8 +45,17 @@ public Task WriteAsync(ArraySegment<byte> data)
45 45
         {
46 46
             Interlocked.Exchange(ref _onInitialWrite, () => { }).Invoke();
47 47
 
48  
-            return DoWrite(data).Then(response => response.OutputStream.Flush(), _httpListenerResponse)
49  
-                                .Catch(ex => _ended = true);
  48
+            return DoWrite(data).Then(response =>
  49
+            {
  50
+#if NET45
  51
+                return response.OutputStream.FlushAsync();
  52
+#else
  53
+                response.OutputStream.Flush();                
  54
+                return TaskAsyncHelper.Empty;
  55
+#endif
  56
+
  57
+            }, _httpListenerResponse)
  58
+            .Catch(ex => _ended = true);
50 59
         }
51 60
 
52 61
         public Task EndAsync(ArraySegment<byte> data)
4  SignalR.Hosting.Self/Infrastructure/ResponseExtensions.cs
@@ -27,6 +27,9 @@ public static Task WriteAsync(this HttpListenerResponse response, string value)
27 27
 
28 28
         public static Task WriteAsync(this HttpListenerResponse response, ArraySegment<byte> buffer)
29 29
         {
  30
+#if NET45
  31
+            return response.OutputStream.WriteAsync(buffer.Array, buffer.Offset, buffer.Count);
  32
+#else
30 33
             try
31 34
             {
32 35
                 return Task.Factory.FromAsync((cb, state) => response.OutputStream.BeginWrite(buffer.Array, buffer.Offset, buffer.Count, cb, state),
@@ -37,6 +40,7 @@ public static Task WriteAsync(this HttpListenerResponse response, ArraySegment<b
37 40
             {
38 41
                 return TaskAsyncHelper.FromError(ex);
39 42
             }
  43
+#endif
40 44
         }
41 45
 
42 46
         public static void CloseSafe(this HttpListenerResponse response)
6  SignalR.Hosting.Self/Server.cs
@@ -160,10 +160,14 @@ private Task ProcessRequestAsync(HttpListenerContext context)
160 160
                         context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
161 161
                     }
162 162
 
163  
-                    var request = new HttpListenerRequestWrapper(context.Request, context.User);
  163
+                    var request = new HttpListenerRequestWrapper(context);
164 164
                     var response = new HttpListenerResponseWrapper(context.Response, () => RegisterForDisconnect(context, cts.Cancel), cts.Token);
165 165
                     var hostContext = new HostContext(request, response);
166 166
 
  167
+#if NET45
  168
+                    hostContext.Items[HostConstants.SupportsWebSockets] = true;
  169
+#endif
  170
+
167 171
                     if (OnProcessRequest != null)
168 172
                     {
169 173
                         OnProcessRequest(hostContext);
10  SignalR.Hosting.Self45/Properties/AssemblyInfo.cs
... ...
@@ -0,0 +1,10 @@
  1
+using System.Reflection;
  2
+using System.Runtime.CompilerServices;
  3
+using System.Runtime.InteropServices;
  4
+
  5
+// General Information about an assembly is controlled through the following 
  6
+// set of attributes. Change these attribute values to modify the information
  7
+// associated with an assembly.
  8
+[assembly: AssemblyTitle("SignalR.Hosting.Self45")]
  9
+[assembly: AssemblyDescription("HttpListener host for SignalR on .NET 4.5")]
  10
+[assembly: AssemblyVersion("0.5.2.0")]
104  SignalR.Hosting.Self45/SignalR.Hosting.Self45.csproj
... ...
@@ -0,0 +1,104 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  4
+  <PropertyGroup>
  5
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  6
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  7
+    <ProjectGuid>{1617158B-2CFD-4354-A33F-9937E508D69A}</ProjectGuid>
  8
+    <OutputType>Library</OutputType>
  9
+    <AppDesignerFolder>Properties</AppDesignerFolder>
  10
+    <RootNamespace>SignalR.Hosting.Self45</RootNamespace>
  11
+    <AssemblyName>SignalR.Hosting.Self45</AssemblyName>
  12
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  13
+    <FileAlignment>512</FileAlignment>
  14
+  </PropertyGroup>
  15
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  16
+    <DebugSymbols>true</DebugSymbols>
  17
+    <DebugType>full</DebugType>
  18
+    <Optimize>false</Optimize>
  19
+    <OutputPath>bin\Debug\</OutputPath>
  20
+    <DefineConstants>TRACE;DEBUG;NET45</DefineConstants>
  21
+    <ErrorReport>prompt</ErrorReport>
  22
+    <WarningLevel>4</WarningLevel>
  23
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  24
+    <DocumentationFile>bin\Debug\SignalR.Hosting.Self45.XML</DocumentationFile>
  25
+  </PropertyGroup>
  26
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  27
+    <DebugType>pdbonly</DebugType>
  28
+    <Optimize>true</Optimize>
  29
+    <OutputPath>bin\Release\</OutputPath>
  30
+    <DefineConstants>TRACE;NET45</DefineConstants>
  31
+    <ErrorReport>prompt</ErrorReport>
  32
+    <WarningLevel>4</WarningLevel>
  33
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  34
+    <DocumentationFile>bin\Release\SignalR.Hosting.Self45.XML</DocumentationFile>
  35
+  </PropertyGroup>
  36
+  <ItemGroup>
  37
+    <Reference Include="System" />
  38
+    <Reference Include="System.Core" />
  39
+    <Reference Include="Microsoft.CSharp" />
  40
+  </ItemGroup>
  41
+  <ItemGroup>
  42
+    <Compile Include="..\Common\CommonAssemblyInfo.cs">
  43
+      <Link>Properties\CommonAssemblyInfo.cs</Link>
  44
+    </Compile>
  45
+    <Compile Include="..\SignalR.Hosting.AspNet45\Infrastructure\ByteBuffer.cs">
  46
+      <Link>Infrastructure\ByteBuffer.cs</Link>
  47
+    </Compile>
  48
+    <Compile Include="..\SignalR.Hosting.AspNet45\Infrastructure\TaskQueue.cs">
  49
+      <Link>Infrastructure\TaskQueue.cs</Link>
  50
+    </Compile>
  51
+    <Compile Include="..\SignalR.Hosting.AspNet45\WebSockets\DefaultWebSocketHandler.cs">
  52
+      <Link>WebSockets\DefaultWebSocketHandler.cs</Link>
  53
+    </Compile>
  54
+    <Compile Include="..\SignalR.Hosting.AspNet45\WebSockets\WebSocketHandler.cs">
  55
+      <Link>WebSockets\WebSocketHandler.cs</Link>
  56
+    </Compile>
  57
+    <Compile Include="..\SignalR.Hosting.AspNet45\WebSockets\WebSocketMessage.cs">
  58
+      <Link>WebSockets\WebSocketMessage.cs</Link>
  59
+    </Compile>
  60
+    <Compile Include="..\SignalR.Hosting.AspNet45\WebSockets\WebSocketMessageReader.cs">
  61
+      <Link>WebSockets\WebSocketMessageReader.cs</Link>
  62
+    </Compile>
  63
+    <Compile Include="..\SignalR.Hosting.Self\CookieCollectionWrapper.cs">
  64
+      <Link>CookieCollectionWrapper.cs</Link>
  65
+    </Compile>
  66
+    <Compile Include="..\SignalR.Hosting.Self\HttpListenerRequestWrapper.cs">
  67
+      <Link>HttpListenerRequestWrapper.cs</Link>
  68
+    </Compile>
  69
+    <Compile Include="..\SignalR.Hosting.Self\HttpListenerResponseWrapper.cs">
  70
+      <Link>HttpListenerResponseWrapper.cs</Link>
  71
+    </Compile>
  72
+    <Compile Include="..\SignalR.Hosting.Self\Infrastructure\NativeMethods.cs">
  73
+      <Link>Infrastructure\NativeMethods.cs</Link>
  74
+    </Compile>
  75
+    <Compile Include="..\SignalR.Hosting.Self\Infrastructure\ResponseExtensions.cs">
  76
+      <Link>Infrastructure\ResponseExtensions.cs</Link>
  77
+    </Compile>
  78
+    <Compile Include="..\SignalR.Hosting.Self\Server.cs">
  79
+      <Link>Server.cs</Link>
  80
+    </Compile>
  81
+    <Compile Include="..\SignalR\TaskAsyncHelper.cs">
  82
+      <Link>Infrastructure\TaskAsyncHelper.cs</Link>
  83
+    </Compile>
  84
+    <Compile Include="Properties\AssemblyInfo.cs" />
  85
+  </ItemGroup>
  86
+  <ItemGroup>
  87
+    <ProjectReference Include="..\SignalR.Hosting.Common\SignalR.Hosting.Common.csproj">
  88
+      <Project>{3b71f0ae-d4b6-4f47-bf62-333d45615673}</Project>
  89
+      <Name>SignalR.Hosting.Common</Name>
  90
+    </ProjectReference>
  91
+    <ProjectReference Include="..\SignalR\SignalR.csproj">
  92
+      <Project>{1b9a82c4-bca1-4834-a33e-226f17be070b}</Project>
  93
+      <Name>SignalR</Name>
  94
+    </ProjectReference>
  95
+  </ItemGroup>
  96
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  97
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
  98
+       Other similar extension points exist, see Microsoft.Common.targets.
  99
+  <Target Name="BeforeBuild">
  100
+  </Target>
  101
+  <Target Name="AfterBuild">
  102
+  </Target>
  103
+  -->
  104
+</Project>
2  SignalR/Hosting/IRequest.cs
@@ -49,6 +49,6 @@ public interface IRequest
49 49
         /// Accepts an websocket request using the specified user function.
50 50
         /// </summary>
51 51
         /// <param name="callback">The callback that fires when the websocket is ready.</param>
52  
-        void AcceptWebSocketRequest(Func<IWebSocket, Task> callback);
  52
+        Task AcceptWebSocketRequest(Func<IWebSocket, Task> callback);
53 53
     }
54 54
 }
20  SignalR/Scripts/jquery.signalR.js
@@ -677,16 +677,20 @@
677 677
             },
678 678
 
679 679
             reconnect: function (connection) {
680  
-                this.stop(connection);
  680
+                var that = this;
  681
+                window.setTimeout(function () {
  682
+                    that.stop(connection);
681 683
 
682  
-                if (connection.state === signalR.connectionState.reconnecting ||
683  
-                    changeState(connection,
684  
-                                signalR.connectionState.connected,
685  
-                                signalR.connectionState.reconnecting) === true) {
  684
+                    if (connection.state === signalR.connectionState.reconnecting ||
  685
+                        changeState(connection,
  686
+                                    signalR.connectionState.connected,
  687
+                                    signalR.connectionState.reconnecting) === true) {
686 688
 
687  
-                    connection.log("Websocket reconnecting");
688  
-                    this.start(connection);
689  
-                }
  689
+                        connection.log("Websocket reconnecting");
  690
+                        that.start(connection);
  691
+                    }
  692
+                },
  693
+                connection.reconnectDelay);
690 694
             },
691 695
 
692 696
             stop: function (connection) {
2  SignalR/Scripts/jquery.signalR.min.js
@@ -6,4 +6,4 @@
6 6
 * Licensed under the MIT.
7 7
 * https://github.com/SignalR/SignalR/blob/master/LICENSE.md
8 8
 */
9  
-(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){this.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),this.start(n))},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
  9
+(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),r.start(n))},n.reconnectDelay)},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
4  SignalR/Transports/WebSocketTransport.cs
@@ -34,7 +34,7 @@ public override bool IsAlive
34 34
 
35 35
         public override Task ProcessRequest(ITransportConnection connection)
36 36
         {
37  
-            _context.Request.AcceptWebSocketRequest(socket =>
  37
+            return _context.Request.AcceptWebSocketRequest(socket =>
38 38
             {
39 39
                 _socket = socket;
40 40
 
@@ -65,8 +65,6 @@ public override Task ProcessRequest(ITransportConnection connection)
65 65
 
66 66
                 return ProcessRequestCore(connection);
67 67
             });
68  
-
69  
-            return TaskAsyncHelper.Empty;
70 68
         }
71 69
 
72 70
         public override Task Send(object value)
96  SignalR45.sln
... ...
@@ -0,0 +1,96 @@
  1
+
  2
+Microsoft Visual Studio Solution File, Format Version 12.00
  3
+# Visual Studio 2012
  4
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.AspNet45", "SignalR.Hosting.AspNet45\SignalR.Hosting.AspNet45.csproj", "{6F53F576-0E35-4E89-8D4D-B6B40084A16C}"
  5
+EndProject
  6
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR", "SignalR\SignalR.csproj", "{1B9A82C4-BCA1-4834-A33E-226F17BE070B}"
  7
+EndProject
  8
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.Common", "SignalR.Hosting.Common\SignalR.Hosting.Common.csproj", "{3B71F0AE-D4B6-4F47-BF62-333D45615673}"
  9
+EndProject
  10
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{A7D75EA8-1439-4D57-9B88-EC60842B5FB3}"
  11
+EndProject
  12
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.AspNet.Samples", "samples\SignalR.Hosting.AspNet45.Samples\SignalR.Hosting.AspNet.Samples.csproj", "{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}"
  13
+EndProject
  14
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.Self45", "SignalR.Hosting.Self45\SignalR.Hosting.Self45.csproj", "{1617158B-2CFD-4354-A33F-9937E508D69A}"
  15
+EndProject
  16
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalR.Hosting.Self.Samples", "samples\SignalR.Hosting.Self45.Samples\SignalR.Hosting.Self.Samples.csproj", "{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}"
  17
+EndProject
  18
+Global
  19
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
  20
+		Debug|Any CPU = Debug|Any CPU
  21
+		Debug|Mixed Platforms = Debug|Mixed Platforms
  22
+		Debug|x86 = Debug|x86
  23
+		Release|Any CPU = Release|Any CPU
  24
+		Release|Mixed Platforms = Release|Mixed Platforms
  25
+		Release|x86 = Release|x86
  26
+	EndGlobalSection
  27
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
  28
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  29
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Debug|Any CPU.Build.0 = Debug|Any CPU
  30
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  31
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  32
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Debug|x86.ActiveCfg = Debug|Any CPU
  33
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Release|Any CPU.ActiveCfg = Release|Any CPU
  34
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Release|Any CPU.Build.0 = Release|Any CPU
  35
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  36
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  37
+		{1617158B-2CFD-4354-A33F-9937E508D69A}.Release|x86.ActiveCfg = Release|Any CPU
  38
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  39
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|Any CPU.Build.0 = Debug|Any CPU
  40
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  41
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  42
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Debug|x86.ActiveCfg = Debug|Any CPU
  43
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|Any CPU.ActiveCfg = Release|Any CPU
  44
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|Any CPU.Build.0 = Release|Any CPU
  45
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  46
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  47
+		{1B9A82C4-BCA1-4834-A33E-226F17BE070B}.Release|x86.ActiveCfg = Release|Any CPU
  48
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  49
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|Any CPU.Build.0 = Debug|Any CPU
  50
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  51
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  52
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Debug|x86.ActiveCfg = Debug|Any CPU
  53
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|Any CPU.ActiveCfg = Release|Any CPU
  54
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|Any CPU.Build.0 = Release|Any CPU
  55
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  56
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  57
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82}.Release|x86.ActiveCfg = Release|Any CPU
  58
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  59
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|Any CPU.Build.0 = Debug|Any CPU
  60
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  61
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  62
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Debug|x86.ActiveCfg = Debug|Any CPU
  63
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|Any CPU.ActiveCfg = Release|Any CPU
  64
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|Any CPU.Build.0 = Release|Any CPU
  65
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  66
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  67
+		{3B71F0AE-D4B6-4F47-BF62-333D45615673}.Release|x86.ActiveCfg = Release|Any CPU
  68
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  69
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|Any CPU.Build.0 = Debug|Any CPU
  70
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
  71
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
  72
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Debug|x86.ActiveCfg = Debug|Any CPU
  73
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|Any CPU.ActiveCfg = Release|Any CPU
  74
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|Any CPU.Build.0 = Release|Any CPU
  75
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
  76
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
  77
+		{6F53F576-0E35-4E89-8D4D-B6B40084A16C}.Release|x86.ActiveCfg = Release|Any CPU
  78
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Debug|Any CPU.ActiveCfg = Debug|x86
  79
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
  80
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Debug|Mixed Platforms.Build.0 = Debug|x86
  81
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Debug|x86.ActiveCfg = Debug|x86
  82
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Debug|x86.Build.0 = Debug|x86
  83
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Release|Any CPU.ActiveCfg = Release|x86
  84
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Release|Mixed Platforms.ActiveCfg = Release|x86
  85
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Release|Mixed Platforms.Build.0 = Release|x86
  86
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Release|x86.ActiveCfg = Release|x86
  87
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}.Release|x86.Build.0 = Release|x86
  88
+	EndGlobalSection
  89
+	GlobalSection(SolutionProperties) = preSolution
  90
+		HideSolutionNode = FALSE
  91
+	EndGlobalSection
  92
+	GlobalSection(NestedProjects) = preSolution
  93
+		{1EA34A62-E03E-45CF-A9C9-82D2DA0FCD82} = {A7D75EA8-1439-4D57-9B88-EC60842B5FB3}
  94
+		{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9} = {A7D75EA8-1439-4D57-9B88-EC60842B5FB3}
  95
+	EndGlobalSection
  96
+EndGlobal
20  samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js
@@ -677,16 +677,20 @@
677 677
             },
678 678
 
679 679
             reconnect: function (connection) {
680  
-                this.stop(connection);
  680
+                var that = this;
  681
+                window.setTimeout(function () {
  682
+                    that.stop(connection);
681 683
 
682  
-                if (connection.state === signalR.connectionState.reconnecting ||
683  
-                    changeState(connection,
684  
-                                signalR.connectionState.connected,
685  
-                                signalR.connectionState.reconnecting) === true) {
  684
+                    if (connection.state === signalR.connectionState.reconnecting ||
  685
+                        changeState(connection,
  686
+                                    signalR.connectionState.connected,
  687
+                                    signalR.connectionState.reconnecting) === true) {
686 688
 
687  
-                    connection.log("Websocket reconnecting");
688  
-                    this.start(connection);
689  
-                }
  689
+                        connection.log("Websocket reconnecting");
  690
+                        that.start(connection);
  691
+                    }
  692
+                },
  693
+                connection.reconnectDelay);
690 694
             },
691 695
 
692 696
             stop: function (connection) {
2  samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.min.js
@@ -6,4 +6,4 @@
6 6
 * Licensed under the MIT.
7 7
 * https://github.com/SignalR/SignalR/blob/master/LICENSE.md
8 8
 */
9  
-(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){this.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),this.start(n))},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
  9
+(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),r.start(n))},n.reconnectDelay)},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
20  samples/SignalR.Hosting.AspNet45.Samples/Scripts/jquery.signalR.js
@@ -677,16 +677,20 @@
677 677
             },
678 678
 
679 679
             reconnect: function (connection) {
680  
-                this.stop(connection);
  680
+                var that = this;
  681
+                window.setTimeout(function () {
  682
+                    that.stop(connection);
681 683
 
682  
-                if (connection.state === signalR.connectionState.reconnecting ||
683  
-                    changeState(connection,
684  
-                                signalR.connectionState.connected,
685  
-                                signalR.connectionState.reconnecting) === true) {
  684
+                    if (connection.state === signalR.connectionState.reconnecting ||
  685
+                        changeState(connection,
  686
+                                    signalR.connectionState.connected,
  687
+                                    signalR.connectionState.reconnecting) === true) {
686 688
 
687  
-                    connection.log("Websocket reconnecting");
688  
-                    this.start(connection);
689  
-                }
  689
+                        connection.log("Websocket reconnecting");
  690
+                        that.start(connection);
  691
+                    }
  692
+                },
  693
+                connection.reconnectDelay);
690 694
             },
691 695
 
692 696
             stop: function (connection) {
2  samples/SignalR.Hosting.AspNet45.Samples/Scripts/jquery.signalR.min.js
@@ -6,4 +6,4 @@
6 6
 * Licensed under the MIT.
7 7
 * https://github.com/SignalR/SignalR/blob/master/LICENSE.md
8 8
 */
9  
-(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){this.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),this.start(n))},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
  9
+(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),r.start(n))},n.reconnectDelay)},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
20  samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.js
@@ -677,16 +677,20 @@
677 677
             },
678 678
 
679 679
             reconnect: function (connection) {
680  
-                this.stop(connection);
  680
+                var that = this;
  681
+                window.setTimeout(function () {
  682
+                    that.stop(connection);
681 683
 
682  
-                if (connection.state === signalR.connectionState.reconnecting ||
683  
-                    changeState(connection,
684  
-                                signalR.connectionState.connected,
685  
-                                signalR.connectionState.reconnecting) === true) {
  684
+                    if (connection.state === signalR.connectionState.reconnecting ||
  685
+                        changeState(connection,
  686
+                                    signalR.connectionState.connected,
  687
+                                    signalR.connectionState.reconnecting) === true) {
686 688
 
687  
-                    connection.log("Websocket reconnecting");
688  
-                    this.start(connection);
689  
-                }
  689
+                        connection.log("Websocket reconnecting");
  690
+                        that.start(connection);
  691
+                    }
  692
+                },
  693
+                connection.reconnectDelay);
690 694
             },
691 695
 
692 696
             stop: function (connection) {
2  samples/SignalR.Hosting.Owin.Samples/Content/Scripts/jquery.signalR.min.js
@@ -6,4 +6,4 @@
6 6
 * Licensed under the MIT.
7 7
 * https://github.com/SignalR/SignalR/blob/master/LICENSE.md
8 8
 */
9  
-(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){this.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),this.start(n))},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
  9
+(function(n,t){"use strict";var u;if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,o,r={onStart:"onStart",onStarting:"onStarting",onSending:"onSending",onReceived:"onReceived",onError:"onError",onReconnect:"onReconnect",onStateChanged:"onStateChanged",onDisconnect:"onDisconnect"},h=function(n,i){if(i!==!1){var r;typeof t.console!="undefined"&&(r="["+(new Date).toTimeString()+"] SignalR: "+n,t.console.debug?t.console.debug(r):t.console.log&&t.console.log(r))}},s=function(i){var r;return(i=n.trim(i),i.indexOf("http")!==0)?!1:(r=t.document.createElement("a"),r.href=i,r.protocol+r.host!==t.location.protocol+t.location.host)},f=function(t,i,u){return i===t.state?(n(t).trigger(r.onStateChanged,[{oldState:t.state,newState:u}]),t.state=u,!0):!1},e=function(n){return n.state===i.connectionState.disconnected};i=function(n,t,r){return new i.fn.init(n,t,r)},i.connectionState={connecting:0,connected:1,reconnecting:2,disconnected:4},i.fn=i.prototype={init:function(n,t,i){this.url=n,this.qs=t,typeof i=="boolean"&&(this.logging=i)},ajaxDataType:"json",logging:!1,state:i.connectionState.disconnected,reconnectDelay:2e3,start:function(u,e){var o=this,h={transport:"auto",jsonp:!1},a,l=n.Deferred(),c=t.document.createElement("a");return f(o,i.connectionState.disconnected,i.connectionState.connecting)===!1?(l.resolve(o),l.promise()):(n.type(u)==="function"?e=u:n.type(u)==="object"&&(n.extend(h,u),n.type(h.callback)==="function"&&(e=h.callback)),c.href=o.url,c.protocol&&c.protocol!==":"?(o.protocol=c.protocol,o.host=c.host,o.baseUrl=c.protocol+"//"+c.host):(o.protocol=t.document.location.protocol,o.host=t.document.location.host,o.baseUrl=o.protocol+"//"+o.host),o.wsProtocol=o.protocol==="https:"?"wss://":"ws://",s(o.url)&&(o.log("Auto detected cross domain url."),h.transport==="auto"&&(h.jsonp||(h.jsonp=!n.support.cors,h.jsonp&&o.log("Using jsonp because this browser doesn't support CORS")),h.transport=h.jsonp===!0?"longPolling":["webSockets","longPolling"])),o.ajaxDataType=h.jsonp?"jsonp":"json",n(o).bind(r.onStart,function(){n.type(e)==="function"&&e.call(o),l.resolve(o)}),a=function(u,e){if(e=e||0,e>=u.length){o.transport||l.reject("SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.");return}var s=u[e],h=n.type(s)==="object"?s:i.transports[s];h.start(o,function(){o.transport=h,f(o,i.connectionState.connecting,i.connectionState.connected),n(o).trigger(r.onStart),n(t).unload(function(){o.stop(!1)})},function(){a(u,e+1)})},t.setTimeout(function(){var t=o.url+"/negotiate";o.log("Negotiating with '"+t+"'."),n.ajax({url:t,global:!1,cache:!1,type:"GET",data:{},dataType:o.ajaxDataType,error:function(t){n(o).trigger(r.onError,[t.responseText]),l.reject("SignalR: Error during negotiation request: "+t.responseText),o.stop()},success:function(t){if(o.appRelativeUrl=t.Url,o.id=t.ConnectionId,o.webSocketServerUrl=t.WebSocketServerUrl,!t.ProtocolVersion||t.ProtocolVersion!=="1.0"){n(o).trigger(r.onError,"SignalR: Incompatible protocol version."),l.reject("SignalR: Incompatible protocol version.");return}n(o).trigger(r.onStarting);var f=[],u=[];n.each(i.transports,function(n){if(n==="webSockets"&&!t.TryWebSockets)return!0;u.push(n)}),n.isArray(h.transport)?n.each(h.transport,function(){var t=this;(n.type(t)==="object"||n.type(t)==="string"&&n.inArray(""+t,u)>=0)&&f.push(n.type(t)==="string"?""+t:t)}):n.type(h.transport)==="object"||n.inArray(h.transport,u)>=0?f.push(h.transport):f=u,a(f)}})},0),l.promise())},starting:function(t){var i=this,u=n(i);return u.bind(r.onStarting,function(){t.call(i),u.unbind(r.onStarting)}),i},send:function(n){var t=this;if(t.state===i.connectionState.disconnected)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";if(t.state===i.connectionState.connecting)throw"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},sending:function(t){var i=this;return n(i).bind(r.onSending,function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind(r.onReceived,function(n,r){t.call(i,r)}),i},stateChanged:function(t){var i=this;return n(i).bind(r.onStateChanged,function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind(r.onError,function(n,r){t.call(i,r)}),i},disconnected:function(t){var i=this;return n(i).bind(r.onDisconnect,function(){t.call(i)}),i},reconnected:function(t){var i=this;return n(i).bind(r.onReconnect,function(){t.call(i)}),i},stop:function(t){var u=this;if(u.state!==i.connectionState.disconnected){try{u.transport&&(u.transport.abort(u,t),u.transport.stop(u),u.transport=null),n(u).trigger(r.onDisconnect),delete u.messageId,delete u.groups}finally{f(u,u.state,i.connectionState.disconnected)}return u}},log:function(n){h(n,this.logging)}},i.fn.init.prototype=i.fn,u={addQs:function(i,r){return r.qs?typeof r.qs=="object"?i+"&"+n.param(r.qs):typeof r.qs=="string"?i+"&"+r.qs:i+"&"+t.escape(r.qs.toString()):i},getUrl:function(n,i,r,u){var o=i==="webSockets"?"":n.baseUrl,f=o+n.appRelativeUrl,e="transport="+i+"&connectionId="+t.escape(n.id);return n.data&&(e+="&connectionData="+t.escape(n.data)),r?(u&&(f=f+"/reconnect"),n.messageId&&(e+="&messageId="+n.messageId),n.groups&&(e+="&groups="+t.escape(JSON.stringify(n.groups)))):f=f+"/connect",f+="?"+e,f=this.addQs(f,n),f+="&tid="+Math.floor(Math.random()*11)},ajaxSend:function(i,u){var f=i.url+"/send?transport="+i.transport.name+"&connectionId="+t.escape(i.id);f=this.addQs(f,i),n.ajax({url:f,global:!1,type:"POST",dataType:i.ajaxDataType,data:{data:u},success:function(t){t&&n(i).trigger(r.onReceived,[t])},error:function(t,u){u!=="abort"&&(u!=="parsererror"||i.ajaxDataType!=="jsonp")&&n(i).trigger(r.onError,[t])}})},ajaxAbort:function(i,r){if(typeof i.transport!="undefined"){r=typeof r=="undefined"?!0:r;var u=i.url+"/abort?transport="+i.transport.name+"&connectionId="+t.escape(i.id);u=this.addQs(u,i),n.ajax({url:u,async:r,timeout:1e3,global:!1,type:"POST",dataType:i.ajaxDataType,data:{}}),i.log("Fired ajax abort async = "+r)}},processMessages:function(t,i){var u=n(t);if(i){if(i.Disconnect){t.log("Disconnect command received from server"),t.stop();return}i.Messages&&n.each(i.Messages,function(){try{u.trigger(r.onReceived,[this])}catch(i){t.log("Error raising received "+i),n(t).trigger(r.onError,[i])}}),i.MessageId&&(t.messageId=i.MessageId),i.TransportData&&(t.groups=i.TransportData.Groups)}},foreverFrame:{count:0,connections:{}}},i.transports={webSockets:{name:"webSockets",send:function(n,t){n.socket.send(t)},start:function(e,o,s){var h,a=!1,l=this,c=!o,y,v=n(e);if(t.MozWebSocket&&(t.WebSocket=t.MozWebSocket),!t.WebSocket){s();return}e.socket||(h=e.webSocketServerUrl?e.webSocketServerUrl:e.wsProtocol+e.host,n(e).trigger(r.onSending),h+=u.getUrl(e,this.name,c),e.log("Connecting to websocket endpoint '"+h+"'"),e.socket=new t.WebSocket(h),e.socket.onopen=function(){a=!0,e.log("Websocket opened"),o?o():f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&v.trigger(r.onReconnect)},e.socket.onclose=function(t){if(a)typeof t.wasClean!="undefined"&&t.wasClean===!1?(n(e).trigger(r.onError,[t.reason]),e.log("Unclean disconnect from websocket."+t.reason)):e.log("Websocket closed");else{s?s():c&&l.reconnect(e);return}l.reconnect(e)},e.socket.onmessage=function(i){var f=t.JSON.parse(i.data),o;f&&(o=n(e),f.Messages?u.processMessages(e,f):o.trigger(r.onReceived,[f]))})},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("Websocket reconnecting"),r.start(n))},n.reconnectDelay)},stop:function(n){n.socket!==null&&(n.log("Closing the Websocket"),n.socket.close(),n.socket=null)},abort:function(){}},serverSentEvents:{name:"serverSentEvents",timeOut:3e3,start:function(e,o,s){var c=this,a=!1,l=n(e),h=!o,y,v;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}l.trigger(r.onSending),y=u.getUrl(e,this.name,h);try{e.log("Attempting to connect to SSE endpoint '"+y+"'"),e.eventSource=new t.EventSource(y)}catch(p){e.log("EventSource failed trying to connect with error "+p.Message),s?s():(l.trigger(r.onError,[p]),h&&c.reconnect(e));return}v=t.setTimeout(function(){a===!1&&(e.log("EventSource timed out trying to connect"),e.log("EventSource readyState: "+e.eventSource.readyState),h||c.stop(e),h?e.eventSource.readyState!==t.EventSource.CONNECTING&&e.eventSource.readyState!==t.EventSource.OPEN&&c.reconnect(e):s&&s())},c.timeOut),e.eventSource.addEventListener("open",function(){e.log("EventSource connected"),v&&t.clearTimeout(v),a===!1&&(a=!0,o&&o(),h&&f(e,i.connectionState.reconnecting,i.connectionState.connected)===!0&&l.trigger(r.onReconnect))},!1),e.eventSource.addEventListener("message",function(n){n.data!=="initialized"&&u.processMessages(e,t.JSON.parse(n.data))},!1),e.eventSource.addEventListener("error",function(n){if(!a){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"),c.reconnect(e)):(e.log("EventSource error"),l.trigger(r.onError))},!1)},reconnect:function(n){var r=this;t.setTimeout(function(){r.stop(n),(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)&&(n.log("EventSource reconnecting"),r.start(n))},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n&&n.eventSource&&(n.log("EventSource calling close()"),n.eventSource.close(),n.eventSource=null,delete n.eventSource)},abort:function(n,t){u.ajaxAbort(n,t)}},foreverFrame:{name:"foreverFrame",timeOut:3e3,start:function(i,f,e){var s=this,h=u.foreverFrame.count+=1,c,l,o=n("<iframe data-signalr-connection-id='"+i.id+"' style='position:absolute;top:0;left:0;width:0;height:0;visibility:hidden;'></iframe>");if(t.EventSource){e&&(i.log("This brower supports SSE, skipping Forever Frame."),e());return}n(i).trigger(r.onSending),c=u.getUrl(i,this.name),c+="&frameId="+h,o.prop("src",c),u.foreverFrame.connections[h]=i,i.log("Binding to iframe's readystatechange event."),o.bind("readystatechange",function(){n.inArray(this.readyState,["loaded","complete"])>=0&&(i.log("Forever frame iframe readyState changed to "+this.readyState+", reconnecting"),s.reconnect(i))}),i.frame=o[0],i.frameId=h,f&&(i.onSuccess=f),n("body").append(o),l=t.setTimeout(function(){i.onSuccess&&(i.log("Failed to connect using forever frame source, it timed out after "+s.timeOut+"ms."),s.stop(i),e&&e())},s.timeOut)},reconnect:function(n){var r=this;t.setTimeout(function(){if(n.frame&&(n.state===i.connectionState.reconnecting||f(n,i.connectionState.connected,i.connectionState.reconnecting)===!0)){var e=n.frame,t=u.getUrl(n,r.name,!0)+"&frameId="+n.frameId;n.log("Upating iframe src to '"+t+"'."),e.src=t}},n.reconnectDelay)},send:function(n,t){u.ajaxSend(n,t)},receive:function(t,i){var r;u.processMessages(t,i),t.frameMessageCount=(t.frameMessageCount||0)+1,t.frameMessageCount>50&&(t.frameMessageCount=0,r=t.frame.contentWindow||t.frame.contentDocument,r&&r.document&&n("body",r.document).empty())},stop:function(t){var i=null;t.frame&&(t.frame.stop?t.frame.stop():(i=t.frame.contentWindow||t.frame.contentDocument,i.document&&i.document.execCommand&&i.document.execCommand("Stop")),n(t.frame).remove(),delete u.foreverFrame.connections[t.frameId],t.frame=null,t.frameId=null,delete t.frame,delete t.frameId,t.log("Stopping forever frame"))},abort:function(n,t){u.ajaxAbort(n,t)},getConnection:function(n){return u.foreverFrame.connections[n]},started:function(t){t.onSuccess?(t.onSuccess(),t.onSuccess=null,delete t.onSuccess):f(t,i.connectionState.reconnecting,i.connectionState.connected)===!0&&n(t).trigger(r.onReconnect)}},longPolling:{name:"longPolling",reconnectDelay:3e3,start:function(o,s){var l=this,c=!1;o.pollXhr&&(o.log("Polling xhr requests already exists, aborting."),o.stop()),o.messageId=null,t.setTimeout(function(){(function h(a,v){n(a).trigger(r.onSending);var d=a.messageId,k=d===null,b=!k,w=u.getUrl(a,l.name,b,v),p=null,y=!1;(b!==!0||v!==!0||o.state===i.connectionState.reconnecting||f(o,i.connectionState.connected,i.connectionState.reconnecting)!==!1)&&(o.log("Attempting to connect to '"+w+"' using longPolling."),a.pollXhr=n.ajax({url:w,global:!1,cache:!1,type:"GET",dataType:o.ajaxDataType,success:function(l){var w=0,p=!1;(c==!1&&(s(),c=!0),v===!0&&y===!1&&(o.log("Raising the reconnect event"),f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)),u.processMessages(a,l),l&&l.TransportData&&n.type(l.TransportData.LongPollDelay)==="number"&&(w=l.TransportData.LongPollDelay),l&&l.TimedOut&&(p=l.TimedOut),l&&l.Disconnect)||e(a)!==!0&&(w>0?t.setTimeout(function(){h(a,p)},w):h(a,p))},error:function(i,u){if(u==="abort"){o.log("Aborted xhr requst.");return}o.log("An error occurred using longPolling. Status = "+u+". "+i.responseText),p&&clearTimeout(p),n(a).trigger(r.onError,[i.responseText]),t.setTimeout(function(){e(a)===!1&&h(a,!0)},o.reconnectDelay)}}),v===!0&&(p=t.setTimeout(function(){y===!1&&f(o,i.connectionState.reconnecting,i.connectionState.connected)===!0&&(n(a).trigger(r.onReconnect),y=!0)},l.reconnectDelay)))})(o),t.setTimeout(function(){c===!1&&(s(),c=!0)},150)},250)},send:function(n,t){u.ajaxSend(n,t)},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null,delete n.pollXhr)},abort:function(n,t){u.ajaxAbort(n,t)}}},i.noConflict=function(){return n.connection===i&&(n.connection=o),i},n.connection&&(o=n.connection),n.connection=n.signalR=i})(window.jQuery,window)
58  samples/SignalR.Hosting.Self45.Samples/Program.cs
... ...
@@ -0,0 +1,58 @@
  1
+using System;
  2
+using System.Diagnostics;
  3
+using System.Threading.Tasks;
  4
+using SignalR.Samples.Raw;
  5
+
  6
+namespace SignalR.Hosting.Self.Samples
  7
+{
  8
+    class Program
  9
+    {
  10
+        static void Main(string[] args)
  11
+        {
  12
+            Debug.Listeners.Add(new ConsoleTraceListener());
  13
+            Debug.AutoFlush = true;
  14
+
  15
+            string url = "http://localhost:8081/";
  16
+            var server = new Server(url);
  17
+            server.Configuration.DisconnectTimeout = TimeSpan.Zero;
  18
+
  19
+            // Map connections
  20
+            server.MapConnection<MyConnection>("/echo")
  21
+                  .MapConnection<Raw>("/raw")
  22
+                  .MapHubs();
  23
+
  24
+            server.Start();
  25
+
  26
+            Console.WriteLine("Server running on {0}", url);
  27
+            
  28
+            while (true)
  29
+            {
  30
+                ConsoleKeyInfo ki = Console.ReadKey(true);
  31
+                if (ki.Key == ConsoleKey.X)
  32
+                {
  33
+                    break;
  34
+                }
  35
+            }
  36
+        }
  37
+
  38
+        public class MyConnection : PersistentConnection
  39
+        {
  40
+            protected override Task OnConnectedAsync(IRequest request, string connectionId)
  41
+            {
  42
+                Console.WriteLine("{0} connected", connectionId);
  43
+                return base.OnConnectedAsync(request, connectionId);
  44
+            }
  45
+
  46
+            protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
  47
+            {
  48
+                return Connection.Broadcast(data);
  49
+            }
  50
+
  51
+            protected override Task OnDisconnectAsync(string connectionId)
  52
+            {
  53
+                Console.WriteLine("{0} left", connectionId);
  54
+                return base.OnDisconnectAsync(connectionId);
  55
+            }
  56
+        }
  57
+    }
  58
+}
36  samples/SignalR.Hosting.Self45.Samples/Properties/AssemblyInfo.cs
... ...
@@ -0,0 +1,36 @@
  1
+using System.Reflection;
  2
+using System.Runtime.CompilerServices;
  3
+using System.Runtime.InteropServices;
  4
+
  5
+// General Information about an assembly is controlled through the following 
  6
+// set of attributes. Change these attribute values to modify the information
  7
+// associated with an assembly.
  8
+[assembly: AssemblyTitle("SignalR.SelfHost.Samples")]
  9
+[assembly: AssemblyDescription("")]
  10
+[assembly: AssemblyConfiguration("")]
  11
+[assembly: AssemblyCompany("Microsoft")]
  12
+[assembly: AssemblyProduct("SignalR.SelfHost.Samples")]
  13
+[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
  14
+[assembly: AssemblyTrademark("")]
  15
+[assembly: AssemblyCulture("")]
  16
+
  17
+// Setting ComVisible to false makes the types in this assembly not visible 
  18
+// to COM components.  If you need to access a type in this assembly from 
  19
+// COM, set the ComVisible attribute to true on that type.
  20
+[assembly: ComVisible(false)]
  21
+
  22
+// The following GUID is for the ID of the typelib if this project is exposed to COM
  23
+[assembly: Guid("a915cfc2-c514-4938-9e2d-3948258505ba")]
  24
+
  25
+// Version information for an assembly consists of the following four values:
  26
+//
  27
+//      Major Version
  28
+//      Minor Version 
  29
+//      Build Number
  30
+//      Revision
  31
+//
  32
+// You can specify all the values or you can default the Build and Revision Numbers 
  33
+// by using the '*' as shown below:
  34
+// [assembly: AssemblyVersion("1.0.*")]
  35
+[assembly: AssemblyVersion("1.0.0.0")]
  36
+[assembly: AssemblyFileVersion("1.0.0.0")]
89  samples/SignalR.Hosting.Self45.Samples/SignalR.Hosting.Self.Samples.csproj
... ...
@@ -0,0 +1,89 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3
+  <PropertyGroup>
  4
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
  6
+    <ProductVersion>8.0.30703</ProductVersion>
  7
+    <SchemaVersion>2.0</SchemaVersion>
  8
+    <ProjectGuid>{8FD9E25A-2268-4F6E-85F3-B83DC018ECE9}</ProjectGuid>
  9
+    <OutputType>Exe</OutputType>
  10
+    <AppDesignerFolder>Properties</AppDesignerFolder>
  11
+    <RootNamespace>SignalR.Hosting.Self.Samples</RootNamespace>
  12
+    <AssemblyName>SignalR.Hosting.Self.Samples</AssemblyName>
  13
+    <FileAlignment>512</FileAlignment>
  14
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>