mirror of
https://github.com/Eugeny/tabby-web.git
synced 2026-08-18 23:36:05 +01:00
wip
This commit is contained in:
@@ -1,11 +1,53 @@
|
||||
import { Buffer } from 'buffer'
|
||||
import { Subject } from 'rxjs'
|
||||
import { debounceTime } from 'rxjs/operators'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
|
||||
export class SocketProxy {
|
||||
connect$ = new Subject<void>()
|
||||
data$ = new Subject<Buffer>()
|
||||
|
||||
webSocket: WebSocket
|
||||
initialBuffer: Buffer
|
||||
|
||||
constructor (...args) {
|
||||
console.log('ws ctr', args)
|
||||
this.initialBuffer = Buffer.from('')
|
||||
}
|
||||
|
||||
connect (...args) {
|
||||
console.log('ws connect', args)
|
||||
this.webSocket = new WebSocket(`ws://${location.host}/api/1/gateway/tcp`)
|
||||
this.webSocket.onopen = event => {
|
||||
this.connect$.next()
|
||||
this.connect$.complete()
|
||||
this.webSocket.send(this.initialBuffer)
|
||||
this.initialBuffer = Buffer.from('')
|
||||
}
|
||||
this.webSocket.onmessage = async event => {
|
||||
this.data$.next(Buffer.from(await event.data.arrayBuffer()))
|
||||
}
|
||||
}
|
||||
|
||||
write (chunk: Buffer): void {
|
||||
if (!this.webSocket.readyState) {
|
||||
this.initialBuffer = Buffer.concat([this.initialBuffer, chunk])
|
||||
} else {
|
||||
this.webSocket.send(chunk)
|
||||
}
|
||||
}
|
||||
|
||||
close (error: Error): void {
|
||||
console.warn('socket destroy', error)
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AppConnectorService {
|
||||
config: any
|
||||
version: any
|
||||
Socket = SocketProxy
|
||||
private configUpdate = new Subject<string>()
|
||||
|
||||
constructor (private http: HttpClient) {
|
||||
@@ -23,4 +65,8 @@ export class AppConnectorService {
|
||||
this.configUpdate.next(content)
|
||||
this.config.content = content
|
||||
}
|
||||
|
||||
getAppVersion (): string {
|
||||
return this.version.version
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user