It looks like you're assigned to the *app* variable declared at the top of *onMessage*, which makes sense, since it's there. But it doesn't look like *app* is actually being used by any other code in *onMessage*, although there's another variable named *app* defined in a callback, which is confusing.

So it seems like it would be better to remove the *app* declaration at the top of the function and just pass this.apps[message.id] here. Or pass *message.id* to *connectToApp* and let that function get the app from the ID, like many other *case*s do.

Also note that *onMessage* is a method of *simulator*, so the code can call *this.connectToApp*.