// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebSocketHandlerCore webSocketHandlerCode) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //app.UseHttpsRedirection(); app.UseCors(builder => builder.WithOrigins(Appsettings.app(new string[] { "Startup", "Cors", "IPs" }).Split(',')) .AllowAnyHeader() .AllowAnyMethod()); //跨域 app.UseMiddlewareAll(); app.UseSwagger(); app.UseSwaggerUI(option => { option.SwaggerEndpoint("/swagger/BlogVue/swagger.json", "Framework.Core"); option.RoutePrefix = string.Empty; option.DocumentTitle = "Framework.Core API"; }); //开启静态文件处理 app.UseStaticFiles(); var filePath = Path.Combine(env.ContentRootPath, "images"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } app.UseStaticFiles(new StaticFileOptions { RequestPath = "/images", FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "images")) }); app.UseRouting(); // 先开启认证 app.UseAuthentication(); // 然后是授权中间件 app.UseAuthorization(); app.QuartzManager(); var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(20), ReceiveBufferSize = 4 * 1024 }; app.UseWebSockets(webSocketOptions); app.MapWebSocketManager("/ws", webSocketHandlerCode); app.UseEndpoints(endpoints => { //endpoints.MapGrpcService<MsgServiceImpl>(); endpoints.MapControllers(); endpoints.MapHub <ChatHub>("/api2/chatHub"); }); }
public MessageToWebSocketJob(WebSocketHandlerCore socketHandlerCore, WebSocketConnectionManager connectionManager, ILogger <MessageToWebSocketJob> logger) { this.socketHandlerCore = socketHandlerCore; this.connectionManager = connectionManager; this.logger = logger; }
public WebSocketManagerController(WebSocketConnectionManager connectionManager, WebSocketHandlerCore webSocketHandler) { this.connectionManager = connectionManager; this.webSocketHandler = webSocketHandler; }