@Configuration public class WebSocketConfig implements WebSocketConfigurer {
@Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(myHandler(), "/myHandler").setAllowedOrigins("*"); } }
import { NgModule } from '@angular/core'; import { HttpClientModule } from '@angular/common/http';
@NgModule({ imports: [ HttpClientModule, ], }) export class AppModule { }
export const WS_ENDPOINT = 'ws://localhost:8080/myHandler'; export const WS_OPTIONS = { withCredentials: true };
constructor(url: string, private http: HttpClient) { this.wsSubject = webSocket({ url, ...WS_OPTIONS, }); }