The JavaScript Suite repository on GitHub provides example apps for both the browser and for NodeJS. This includes a WebEngine app, a WebSocket client app, a WebSocket server app, and a TCP client app. The examples in the folders already come with their own SDL library build files. Check each example app's readme.md
file for more information on how to run the respective app.
If your app compiles and but does not show up on the HMI, there are a few things you should check:
HOST
and PORT
environment variables are set to match the machine running SDL Core.12345
on the machine or VM running SDL Core. Also, make sure your firewall allows that outgoing port.enabled=true
.manifest.js
has provided all necessary fields and that the information is correct.For vanilla JavaScript SDL apps, connecting as a WebSocket client requires a version of SDL Core that can accept incoming WebSocket connections (at least v6.1.0). If you are using Manticore to test your app, note that it currently does not support WebSocket connections.
A workaround to this limitation is to use a proxy program for your app to connect with which modifies the incoming WebSocket connection into a TCP connection. The proxy program then connects to SDL Core on the app's behalf and passes through your transport data. A Java program that does exactly this is available in the repository's JavaScript example folder called proxy.jar
. Check the example app's readme.md
for how to run it. Please check the Connecting to an Infotainment System guide for more detailed instructions on how to get the emulator's IP address and port number.
This workaround for older versions of Core is also necessary for WebEngine apps.
SDL Core acts as the WebSocket client in this case. The information about your app and how Core should connect to it must go into the policy table. Check the Connecting to an Infotainment System guide's Configuring the Connection section for how to set up your policy table to point to your app
The following snippet is a truncated version of what is needed to set up the WebSocket server to accept and pass connections to the SDL library. This example uses the ws
npm module for WebSocket connections. Refer to the integration basics guide for the full integration setup.
const SDL = require('./SDL.min.js'); const WS = require('ws'); const PORT = 3000; // create a WebSocket Server const appWebSocketServer = new WS.Server({ port: PORT, }); console.log(`WebSocket Server listening on port ${PORT}`); // Event listener for incoming WebSocket connections appWebSocketServer.on('connection', (connection) => { ... /* truncated snippet to show only the transport configuration setup */ /* each new connection corresponds to a new instance of your app */ lifecycleConfig.setTransportConfig( new SDL.transport.WebSocketServerConfig( connection ) ); ... });