Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/debuggerCommunicationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as http from "http";
import * as socketio from "socket.io";
import { WebviewPanel } from "vscode";
import { SERVER_INFO } from "./constants";
import { DeviceSelectionService } from "./service/deviceSelectionService";

export const DEBUGGER_MESSAGES = {
EMITTER: {
Expand All @@ -24,14 +25,14 @@ export class DebuggerCommunicationServer {
private serverHttp: http.Server;
private serverIo: socketio.Server;
private simulatorWebview: WebviewPanel | undefined;
private currentActiveDevice;
private deviceSelectionService: DeviceSelectionService;
private isPendingResponse = false;
private pendingCallbacks: Function[] = [];

constructor(
webviewPanel: WebviewPanel | undefined,
port = SERVER_INFO.DEFAULT_SERVER_PORT,
currentActiveDevice: string
deviceSelectionService: DeviceSelectionService
) {
this.port = port;
this.serverHttp = new http.Server();
Expand All @@ -42,7 +43,7 @@ export class DebuggerCommunicationServer {
this.initEventsHandlers();
console.info(`Server running on port ${this.port}`);

this.currentActiveDevice = currentActiveDevice;
this.deviceSelectionService = deviceSelectionService;
}

// send the message to start closing the connection
Expand Down Expand Up @@ -119,12 +120,16 @@ export class DebuggerCommunicationServer {
try {
const messageToWebview = JSON.parse(data);
if (messageToWebview.type === "state") {
console.log(`State recieved: ${messageToWebview.data}`);
if (this.simulatorWebview) {
const messageState = JSON.parse(messageToWebview.data);
if (
this.simulatorWebview &&
messageState.device_name ===
this.deviceSelectionService.getCurrentActiveDevice()
) {
this.simulatorWebview.webview.postMessage({
active_device: this.currentActiveDevice,
active_device: this.deviceSelectionService.getCurrentActiveDevice(),
command: "set-state",
state: JSON.parse(messageToWebview.data),
state: messageState,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ export async function activate(context: vscode.ExtensionContext) {
new DebuggerCommunicationServer(
currentPanel,
utils.getServerPortConfig(),
deviceSelectionService.getCurrentActiveDevice()
deviceSelectionService
)
);

Expand Down