コード例 #1
0
ファイル: Session.cs プロジェクト: tmds/Tmds.SockJS
 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
ファイル: SessionManager.cs プロジェクト: tmds/Tmds.SockJS
        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),
                });
            }
        }
コード例 #3
0
 public static void UseBroadcast(this IApplicationBuilder app, PathString path, SockJSOptions options = null)
 {
     app.UseSockJS(path, options ?? new SockJSOptions());
     app.UseMiddleware<BroadcastMiddleware>(path);
 }
コード例 #4
0
 public static void UseSockJS(this IApplicationBuilder app, PathString prefix, SockJSOptions options)
 {
     app.Use(next => new SessionManager(prefix, next, options).Invoke);
 }