Skip to content

Commit

Permalink
bug: websocket secure not used in browser (#118)
Browse files Browse the repository at this point in the history
* feat-fix: wss in browser

* lint-fix: apply linter fixes
  • Loading branch information
EagleoutIce authored Oct 2, 2024
1 parent b7fca20 commit ed81260
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/flowr/server-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class FlowrServerSession implements FlowrSession {
const port = getConfig().get<number>(Settings.ServerPort, 1042)
this.outputChannel.appendLine(`Connecting to flowR server using ${type} at ${host}:${port}`)
// if the type is auto, we still start with a (secure!) websocket connection first
this.connection = isWeb() ? new BrowserWsConnection() : type == 'tcp' ? new TcpConnection() : new WsConnection(type !== 'websocket')
this.connection = isWeb() ? new BrowserWsConnection(type !== 'websocket') : type == 'tcp' ? new TcpConnection() : new WsConnection(type !== 'websocket')
this.connection.connect(host, port, () => {
this.state = 'connected'
updateStatusBar()
Expand Down Expand Up @@ -218,9 +218,9 @@ interface Connection {
class TcpConnection implements Connection {

private socket: net.Socket | undefined

connect(host: string, port: number, connectionListener: () => void): void {
this.socket = net.createConnection(port, host, connectionListener)
this.socket = net.createConnection(port, host, connectionListener)
}

on(event: 'data' | 'close' | 'error', listener: (...args: unknown[]) => void): void {
Expand Down Expand Up @@ -265,11 +265,15 @@ class WsConnection implements Connection {
}

class BrowserWsConnection implements Connection {

private socket: WebSocket | undefined
private readonly secure: boolean
private socket: WebSocket | undefined

constructor(secure: boolean) {
this.secure = secure
}

connect(host: string, port: number, connectionListener: () => void): void {
this.socket = new WebSocket(`ws://${host}:${port}`)
this.socket = new WebSocket(`${this.secure ? 'wss' : 'ws'}://${host}:${port}`)
this.socket.addEventListener('open', connectionListener)
}

Expand Down

0 comments on commit ed81260

Please sign in to comment.