Skip to content

Commit

Permalink
fix: improve logging of cloud connection
Browse files Browse the repository at this point in the history
  • Loading branch information
zobo committed Mar 7, 2023
1 parent 75c3e1d commit 3a72ffa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class XdebugCloudConnection extends EventEmitter {

private _dbgpConnection: DbgpConnection

private _logging = true

constructor(token: string, testSocket?: net.Socket) {
super()
if (testSocket != null) {
Expand All @@ -38,8 +40,11 @@ export class XdebugCloudConnection extends EventEmitter {
this._rejectFn = null
this._dbgpConnection = new DbgpConnection(this._tlsSocket)

this._dbgpConnection.on('log', (text: string) => {
if (this._logging) { this.emit('log', text) }
});

this._dbgpConnection.on('message', (response: XMLDocument) => {
this.emit('log', response)
if (response.documentElement.nodeName === 'cloudinit') {
if (response.documentElement.firstChild && response.documentElement.firstChild.nodeName === 'error') {
this._rejectFn?.(
Expand All @@ -57,8 +62,10 @@ export class XdebugCloudConnection extends EventEmitter {
this._resolveFn?.()
}
} else if (response.documentElement.nodeName === 'init') {
this._logging = false
// spawn a new xdebug.Connection
const cx = new xdebug.Connection(new InnerCloudTransport(this._tlsSocket))
cx.on('close', () => this._logging = true)
cx.emit('message', response)
this.emit('connection', cx)
}
Expand Down

0 comments on commit 3a72ffa

Please sign in to comment.