Ejemplo n.º 1
0
        private Task ProcessNegotiationRequest(HostContext context)
        {
            // Total amount of time without a keep alive before the client should attempt to reconnect in seconds.
            var    keepAliveTimeout = _configurationManager.KeepAliveTimeout();
            string connectionId     = Guid.NewGuid().ToString("d");
            string connectionToken  = connectionId + ':' + GetUserIdentity(context);

            var payload = new
            {
                Url                = context.Request.Url.LocalPath.Replace("/negotiate", ""),
                ConnectionToken    = ProtectedData.Protect(connectionToken, Purposes.ConnectionToken),
                ConnectionId       = connectionId,
                KeepAliveTimeout   = keepAliveTimeout != null ? keepAliveTimeout.Value.TotalSeconds : (double?)null,
                DisconnectTimeout  = _configurationManager.DisconnectTimeout.TotalSeconds,
                TryWebSockets      = _transportManager.SupportsTransport(WebSocketsTransportName) && context.SupportsWebSockets(),
                WebSocketServerUrl = context.WebSocketServerUrl(),
                ProtocolVersion    = "1.2"
            };

            if (!String.IsNullOrEmpty(context.Request.QueryString["callback"]))
            {
                return(ProcessJsonpRequest(context, payload));
            }

            context.Response.ContentType = JsonUtility.JsonMimeType;
            return(context.Response.End(JsonSerializer.Stringify(payload)));
        }
Ejemplo n.º 2
0
        private Task ProcessNegotiationRequest(HostContext context)
        {
            var payload = new
            {
                Url                = context.Request.Url.LocalPath.Replace("/negotiate", ""),
                ConnectionId       = _connectionIdPrefixGenerator.GenerateConnectionIdPrefix(context.Request) + Guid.NewGuid().ToString("d"),
                TryWebSockets      = _transportManager.SupportsTransport(WebSocketsTransportName) && context.SupportsWebSockets(),
                WebSocketServerUrl = context.WebSocketServerUrl(),
                ProtocolVersion    = "1.0"
            };

            if (!String.IsNullOrEmpty(context.Request.QueryString["callback"]))
            {
                return(ProcessJsonpNegotiationRequest(context, payload));
            }

            context.Response.ContentType = Json.MimeType;
            return(context.Response.EndAsync(_jsonSerializer.Stringify(payload)));
        }
        private Task <NegotiateResponse> ProcessNegotiationRequest(HostContext context)
        {
            // Total amount of time without a keep alive before the client should attempt to reconnect in seconds.
            var    keepAliveTimeout = _configurationManager.KeepAliveTimeout();
            string connectionId     = Guid.NewGuid().ToString("d");
            string connectionToken  = connectionId + ':' + GetUserIdentity(context);

            var response = new NegotiateResponse(context.Request.LocalPath.Replace("/negotiate", ""),
                                                 ProtectedData.Protect(connectionToken, Purposes.ConnectionToken), connectionId,
                                                 keepAliveTimeout?.TotalSeconds,
                                                 _configurationManager.DisconnectTimeout.TotalSeconds,
                                                 _configurationManager.ConnectionTimeout.TotalSeconds,
                                                 _transportManager.SupportsTransport(WebSocketsTransportName) && context.Environment.SupportsWebSockets(),
                                                 _protocolResolver.Resolve(context.Request).ToString(),
                                                 _configurationManager.TransportConnectTimeout.TotalSeconds,
                                                 _configurationManager.LongPollDelay.TotalSeconds);

            return(SendJsonResponse(context, JsonSerializer.Stringify(response)).ContinueWith(t => response));
        }
Ejemplo n.º 4
0
        private Task ProcessNegotiationRequest(HostContext context)
        {
            // Total amount of time without a keep alive before the client should attempt to reconnect in seconds.
            var    keepAliveTimeout = _configurationManager.KeepAliveTimeout();
            string connectionId     = Guid.NewGuid().ToString("d");
            string connectionToken  = connectionId + ':' + GetUserIdentity(context);

            var payload = new
            {
                Url                     = context.Request.LocalPath.Replace("/negotiate", ""),
                ConnectionToken         = ProtectedData.Protect(connectionToken, Purposes.ConnectionToken),
                ConnectionId            = connectionId,
                KeepAliveTimeout        = keepAliveTimeout != null ? keepAliveTimeout.Value.TotalSeconds : (double?)null,
                DisconnectTimeout       = _configurationManager.DisconnectTimeout.TotalSeconds,
                TryWebSockets           = _transportManager.SupportsTransport(WebSocketsTransportName) && context.Environment.SupportsWebSockets(),
                ProtocolVersion         = _protocolResolver.Resolve(context.Request).ToString(),
                TransportConnectTimeout = _configurationManager.TransportConnectTimeout.TotalSeconds,
                LongPollDelay           = _configurationManager.LongPollDelay.TotalSeconds
            };

            return(SendJsonResponse(context, JsonSerializer.Stringify(payload)));
        }
Ejemplo n.º 5
0
        private Task ProcessNegotiationRequest(HostContext context)
        {
            var keepAlive = _configurationManager.KeepAlive;
            var payload   = new
            {
                Url                = context.Request.Url.LocalPath.Replace("/negotiate", ""),
                ConnectionId       = ConnectionIdPrefixGenerator.GenerateConnectionIdPrefix(context.Request) + Guid.NewGuid().ToString("d"),
                KeepAlive          = (keepAlive != null) ? keepAlive.Value.TotalSeconds : (double?)null,
                DisconnectTimeout  = _configurationManager.DisconnectTimeout.TotalSeconds,
                TryWebSockets      = _transportManager.SupportsTransport(WebSocketsTransportName) && context.SupportsWebSockets(),
                WebSocketServerUrl = context.WebSocketServerUrl(),
                ProtocolVersion    = "1.1"
            };

            if (!String.IsNullOrEmpty(context.Request.QueryString["callback"]))
            {
                return(ProcessJsonpNegotiationRequest(context, payload));
            }

            context.Response.ContentType = Json.MimeType;
            return(context.Response.EndAsync(JsonSerializer.Stringify(payload)));
        }