WIP new websocket setup; build setup changes; types cleanup

This commit is contained in:
2025-12-10 04:37:26 +00:00
parent f1e3557db1
commit da4e87d3cd
7 changed files with 54 additions and 55 deletions

View File

@@ -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!' }");
});
}
}

View 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();
}
}
}

File diff suppressed because one or more lines are too long

1
src/typings.d.ts vendored
View File

@@ -1 +0,0 @@
// declare var showdown: any;