@@ -5,6 +5,7 @@ import * as http from "http";
5
5
import * as socketio from "socket.io" ;
6
6
import { WebviewPanel } from "vscode" ;
7
7
import { SERVER_INFO } from "./constants" ;
8
+ import { DeviceSelectionService } from "./service/deviceSelectionService" ;
8
9
9
10
export const DEBUGGER_MESSAGES = {
10
11
EMITTER : {
@@ -24,14 +25,14 @@ export class DebuggerCommunicationServer {
24
25
private serverHttp : http . Server ;
25
26
private serverIo : socketio . Server ;
26
27
private simulatorWebview : WebviewPanel | undefined ;
27
- private currentActiveDevice ;
28
+ private deviceSelectionService : DeviceSelectionService ;
28
29
private isPendingResponse = false ;
29
30
private pendingCallbacks : Function [ ] = [ ] ;
30
31
31
32
constructor (
32
33
webviewPanel : WebviewPanel | undefined ,
33
34
port = SERVER_INFO . DEFAULT_SERVER_PORT ,
34
- currentActiveDevice : string
35
+ deviceSelectionService : DeviceSelectionService
35
36
) {
36
37
this . port = port ;
37
38
this . serverHttp = new http . Server ( ) ;
@@ -42,7 +43,7 @@ export class DebuggerCommunicationServer {
42
43
this . initEventsHandlers ( ) ;
43
44
console . info ( `Server running on port ${ this . port } ` ) ;
44
45
45
- this . currentActiveDevice = currentActiveDevice ;
46
+ this . deviceSelectionService = deviceSelectionService ;
46
47
}
47
48
48
49
// send the message to start closing the connection
@@ -119,12 +120,16 @@ export class DebuggerCommunicationServer {
119
120
try {
120
121
const messageToWebview = JSON . parse ( data ) ;
121
122
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
+ ) {
124
129
this . simulatorWebview . webview . postMessage ( {
125
- active_device : this . currentActiveDevice ,
130
+ active_device : this . deviceSelectionService . getCurrentActiveDevice ( ) ,
126
131
command : "set-state" ,
127
- state : JSON . parse ( messageToWebview . data ) ,
132
+ state : messageState ,
128
133
} ) ;
129
134
}
130
135
}
0 commit comments