private Task ProcessNegotiationRequest(HttpContextBase context)
 {
     context.Response.ContentType = Json.MimeType;
     return(context.Response.WriteAsync(_jsonSerializer.Stringify(new
     {
         Url = VirtualPathUtility.ToAbsolute(context.Request.AppRelativeCurrentExecutionFilePath.Replace("/negotiate", "")),
         ConnectionId = _connectionIdFactory.CreateConnectionId(context),
         TryWebSockets = ClientShouldTryWebSockets
     })));
 }
示例#2
0
 private Task ProcessNegotiationRequest(HostContext context)
 {
     context.Response.ContentType = Json.MimeType;
     return(context.Response.WriteAsync(_jsonSerializer.Stringify(new
     {
         Url = context.Request.Path.Replace("/negotiate", ""),
         ConnectionId = _connectionIdFactory.CreateConnectionId(context.Request),
         TryWebSockets = context.SupportsWebSockets()
     })));
 }
示例#3
0
 private Task ProcessNegotiationRequest(HostContext context)
 {
     context.Response.ContentType = Json.MimeType;
     return(context.Response.EndAsync(_jsonSerializer.Stringify(new
     {
         Url = context.Request.Url.LocalPath.Replace("/negotiate", ""),
         ConnectionId = _connectionIdFactory.CreateConnectionId(context.Request),
         TryWebSockets = context.SupportsWebSockets(),
         WebSocketServerUrl = context.WebSocketServerUrl(),
         ProtocolVersion = "1.0"
     })));
 }
示例#4
0
        public override Task ProcessRequestAsync(HttpContext context)
        {
            Task task        = null;
            var  contextBase = new HttpContextWrapper(context);

            if (IsNegotiationRequest(context.Request))
            {
                context.Response.ContentType = Json.MimeType;
                context.Response.Write(_jsonSerializer.Stringify(new
                {
                    Url          = VirtualPathUtility.ToAbsolute(context.Request.AppRelativeCurrentExecutionFilePath.Replace("/negotiate", "")),
                    ConnectionId = _connectionIdFactory.CreateConnectionId(contextBase)
                }));
            }
            else
            {
                _transport = GetTransport(contextBase);

                string connectionId = _transport.ConnectionId;

                // If there's no connection id then this is a bad request
                if (String.IsNullOrEmpty(connectionId))
                {
                    throw new InvalidOperationException("Protocol error: Missing connection id.");
                }

                IEnumerable <string> groups = GetGroups(contextBase);

                Connection = CreateConnection(connectionId, groups, contextBase);

                // Wire up the events we need
                _transport.Connected += () =>
                {
                    task = OnConnectedAsync(contextBase, connectionId);
                };

                _transport.Received += (data) =>
                {
                    task = OnReceivedAsync(connectionId, data);
                };

                _transport.Error += (e) =>
                {
                    task = OnErrorAsync(e);
                };

                _transport.Disconnected += () =>
                {
                    task = OnDisconnectAsync(connectionId);
                };

                Func <Task> processRequestTask = _transport.ProcessRequest(Connection);

                if (processRequestTask != null)
                {
                    if (task != null)
                    {
                        return(task.Success(_ => processRequestTask()).Unwrap());
                    }
                    return(processRequestTask());
                }
            }

            return(task ?? TaskAsyncHelper.Empty);
        }