WIP new websocket setup; build setup changes; types cleanup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, inject } from '@angular/core';
|
||||
|
||||
import { WebsocketService } from './common/services/websocket.service';
|
||||
|
||||
import { InfoBarComponent } from './editor/info-bar/info-bar.component';
|
||||
import { TabsComponent } from './editor/tabs/tabs.component';
|
||||
@@ -28,6 +30,17 @@ import { LspManagerComponent } from "./editor/lsp-manager/lsp-manager.component"
|
||||
export class AppComponent {
|
||||
title = 'Newton';
|
||||
|
||||
protected ws: WebsocketService = inject(WebsocketService);
|
||||
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit() {
|
||||
// TODO: Set with dynamic address and port
|
||||
this.ws.connect('ws://localhost:7272').subscribe(msg => {
|
||||
console.log(msg);
|
||||
// this.ws.send("{ 'text': 'Hello server!' }");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
35
src/app/common/services/websocket.service.ts
Normal file
35
src/app/common/services/websocket.service.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WebsocketService {
|
||||
|
||||
private socket$!: WebSocketSubject<any>;
|
||||
|
||||
connect(url: string): Observable<any> {
|
||||
if (!this.socket$ || this.socket$.closed) {
|
||||
this.socket$ = webSocket(
|
||||
{
|
||||
url,
|
||||
deserializer: msg => msg.data
|
||||
}
|
||||
);
|
||||
}
|
||||
return this.socket$.asObservable();
|
||||
}
|
||||
|
||||
send(message: any) {
|
||||
if (this.socket$) {
|
||||
this.socket$.next(message);
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
if (this.socket$) {
|
||||
this.socket$.complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user