Пример #1
0
 public Session(SessionManager sessionContainer, string sessionId, Receiver receiver, SockJsOptions options)
 {
     _clientLock     = new ReaderWriterLockSlim();
     _sessionManager = sessionContainer;
     _sessionId      = sessionId;
     _options        = options;
     _receiver       = receiver;
     _sendState      = SendOpen;
     _receiveState   = ReceiveNone;
     _receives       = new ConcurrentQueue <PendingReceive>();
     _receivesSem    = new SemaphoreSlim(0);
     _sendDequeueSem = new SemaphoreSlim(1);
     _sendsSem       = new SemaphoreSlim(0);
     _sendEnqueueSem = new SemaphoreSlim(1);
     _sends          = new ConcurrentQueue <PendingSend>();
 }
Пример #2
0
        public SessionManager(PathString prefix, RequestDelegate next, SockJsOptions options)
        {
            _prefix      = prefix;
            _next        = next;
            _options     = options;
            _rewritePath = options.RewritePath.HasValue ? options.RewritePath : _prefix;

            _iframeContent = string.Format(s_iFrameTemplate, options.JSClientLibraryUrl);
            _iframeETag    = CalculateETag(_iframeContent);

            _routes = new List <Route>(new[]
            {
                new Route("GET", TypeEmpty, false, "", HandleGreetingAsync),
                new Route("GET", TypeTop, true, "iframe[0-9-.a-z_]*.html", HandleIFrameAsync),
                new Route("GET", TypeTop, false, "info", HandleInfoAsync),
                new Route("OPTIONS", TypeTop, false, "info", HandleOptionsGetResourceAsync),
                new Route("GET", TypeSession, false, "jsonp", HandleJsonpAsync),
                new Route("POST", TypeSession, false, "jsonp_send", HandleJsonpSendAsync),
                new Route("POST", TypeSession, false, "xhr", HandleXhrAsync),
                new Route("OPTIONS", TypeSession, false, "xhr", HandleOptionsPostResourceAsync),
                new Route("POST", TypeSession, false, "xhr_send", HandleXhrSendAsync),
                new Route("OPTIONS", TypeSession, false, "xhr_send", HandleOptionsPostResourceAsync),
                new Route("POST", TypeSession, false, "xhr_streaming", HandleXhrStreamingAsync),
                new Route("OPTIONS", TypeSession, false, "xhr_streaming", HandleOptionsPostResourceAsync),
                new Route("GET", TypeSession, false, "eventsource", HandleEventSourceAsync),
                new Route("GET", TypeSession, false, "htmlfile", HandleHtmlFileAsync),
            });
            if (_options.UseWebSocket)
            {
                _routes.AddRange(new[] {
                    new Route("GET", TypeSession, false, "websocket", HandleSockJSWebSocketAsync),
                    new Route("GET", TypeTop, false, "websocket", HandleWebSocketAsync),
                });
            }
            else
            {
                _routes.AddRange(new[] {
                    new Route("GET", TypeSession, false, "websocket", HandleNoWebSocketAsync),
                    new Route("GET", TypeTop, false, "websocket", HandleNoWebSocketAsync),
                });
            }
        }
 public static void UseSockJS(this IApplicationBuilder app, PathString prefix, SockJsOptions options)
 {
     app.Use(next => new SessionManager(prefix, next, options).Invoke);
 }