Skip to content

Commit 74909a3

Browse files
knightburtonyichoi
authored andcommitted
Clearify the connect and the disconnect events in the debugger session (#11)
IoT.js-Debug-DCO-1.0-Signed-off-by: Imre Kiss [email protected]
1 parent 1e7ffb2 commit 74909a3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/IotjsDebugger.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import {
2020
LoggingDebugSession, DebugSession, Logger, logger, InitializedEvent, OutputEvent, Thread, Source,
21-
StoppedEvent, ContinuedEvent, StackFrame
21+
StoppedEvent, ContinuedEvent, StackFrame, TerminatedEvent
2222
} from 'vscode-debugadapter';
2323
import { DebugProtocol } from 'vscode-debugprotocol';
2424
import * as Fs from 'fs';
@@ -133,6 +133,11 @@ class IotjsDebugSession extends LoggingDebugSession {
133133
this.handleSource(data);
134134
};
135135

136+
const onClose = () => {
137+
this.log('onClose');
138+
this.sendEvent(new TerminatedEvent());
139+
};
140+
136141
const protocolDelegate = <JerryDebugProtocolDelegate>{
137142
onBacktrace,
138143
onBreakpointHit,
@@ -142,7 +147,10 @@ class IotjsDebugSession extends LoggingDebugSession {
142147

143148
this._protocolhandler = new JerryDebugProtocolHandler(protocolDelegate);
144149
this._debuggerClient = new JerryDebuggerClient(<JerryDebuggerOptions>{
145-
delegate: this._protocolhandler,
150+
delegate: {
151+
onMessage: (message: Uint8Array) => this._protocolhandler.onMessage(message),
152+
onClose
153+
},
146154
host: args.address,
147155
port: args.port
148156
});
@@ -169,6 +177,7 @@ class IotjsDebugSession extends LoggingDebugSession {
169177

170178
this._debuggerClient.disconnect();
171179

180+
this.sendEvent(new TerminatedEvent());
172181
this.sendResponse(response);
173182
}
174183

src/JerryDebuggerClient.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface JerryDebuggerOptions {
2525

2626
export interface JerryDebuggerDelegate {
2727
onMessage: (message: Uint8Array) => void;
28+
onClose?: () => void;
2829
}
2930

3031
export const DEFAULT_DEBUGGER_HOST = 'localhost';
@@ -51,6 +52,7 @@ export class JerryDebuggerClient {
5152
this.socket = new WebSocket(`ws://${this.host}:${this.port}/jerry-debugger`);
5253
this.socket.binaryType = 'arraybuffer';
5354
this.socket.on('message', this.onMessage.bind(this));
55+
this.socket.on('close', () => this.onClose());
5456

5557
this.connectPromise = new Promise((resolve, reject) => {
5658
if (!this.socket) {
@@ -72,7 +74,7 @@ export class JerryDebuggerClient {
7274

7375
disconnect() {
7476
if (this.socket) {
75-
this.socket.terminate();
77+
this.socket.close();
7678
this.socket = undefined;
7779
}
7880
}
@@ -81,6 +83,12 @@ export class JerryDebuggerClient {
8183
this.delegate.onMessage(new Uint8Array(data));
8284
}
8385

86+
onClose() {
87+
if (this.delegate.onClose) {
88+
this.delegate.onClose();
89+
}
90+
}
91+
8492
send(data: Uint8Array) {
8593
this.socket!.send(data);
8694
}

0 commit comments

Comments
 (0)