@@ -5,6 +5,7 @@ import * as http from "http";
55import * as socketio from "socket.io" ;
66import { WebviewPanel } from "vscode" ;
77import { SERVER_INFO } from "./constants" ;
8+ import { DeviceSelectionService } from "./service/deviceSelectionService" ;
89
910export const DEBUGGER_MESSAGES = {
1011 EMITTER : {
@@ -24,14 +25,14 @@ export class DebuggerCommunicationServer {
2425 private serverHttp : http . Server ;
2526 private serverIo : socketio . Server ;
2627 private simulatorWebview : WebviewPanel | undefined ;
27- private currentActiveDevice ;
28+ private deviceSelectionService : DeviceSelectionService ;
2829 private isPendingResponse = false ;
2930 private pendingCallbacks : Function [ ] = [ ] ;
3031
3132 constructor (
3233 webviewPanel : WebviewPanel | undefined ,
3334 port = SERVER_INFO . DEFAULT_SERVER_PORT ,
34- currentActiveDevice : string
35+ deviceSelectionService : DeviceSelectionService
3536 ) {
3637 this . port = port ;
3738 this . serverHttp = new http . Server ( ) ;
@@ -42,7 +43,7 @@ export class DebuggerCommunicationServer {
4243 this . initEventsHandlers ( ) ;
4344 console . info ( `Server running on port ${ this . port } ` ) ;
4445
45- this . currentActiveDevice = currentActiveDevice ;
46+ this . deviceSelectionService = deviceSelectionService ;
4647 }
4748
4849 // send the message to start closing the connection
@@ -119,12 +120,16 @@ export class DebuggerCommunicationServer {
119120 try {
120121 const messageToWebview = JSON . parse ( data ) ;
121122 if ( messageToWebview . type === "state" ) {
122- console . log ( `State recieved: ${ messageToWebview . data } ` ) ;
123- if ( this . simulatorWebview ) {
123+ const messageState = JSON . parse ( messageToWebview . data ) ;
124+ if (
125+ this . simulatorWebview &&
126+ messageState . device_name ===
127+ this . deviceSelectionService . getCurrentActiveDevice ( )
128+ ) {
124129 this . simulatorWebview . webview . postMessage ( {
125- active_device : this . currentActiveDevice ,
130+ active_device : this . deviceSelectionService . getCurrentActiveDevice ( ) ,
126131 command : "set-state" ,
127- state : JSON . parse ( messageToWebview . data ) ,
132+ state : messageState ,
128133 } ) ;
129134 }
130135 }
0 commit comments