SmartDeviceLink library for applications developed in JavaScript
Background details for creation of repository can be found in the SDL Evolution Proposal SDL 0235 - SDL JavaScript library. Initial implementation details can be found below.
The solution is to create a common JavaScript library that offers a public proxy object to send and receive RPCs. The library also requires implementations of all the other layers required to package and frame the data and send it over a defined transport.
Looking into the existing libraries, developed in Java and Objective-C, they contain the following superset of layers:
It is not realistic to develop a new SDL library that can provide the same set of features as the Android and iOS library all at once. Therefore it is important to focus on a "milestone 1" which includes the following fundamental elements:
1. Proxy layer
Provide a Proxy class and implementations of all RPCs according to the RPC specification v5.1. As this specification is XML structured it makes sense to develop a code generator to export all the RPCs, structs and enums to usable code.
2. SDL Session layer and Protocol layer
In the first milestone the JavaScript library should support the RPC and Bulk service types for communication. Media and projection applications may not be supported in the first release.
An open source BSON libray developed in JavaScript should be used by the SDL JavaScript library. If there is no suitable 3rd party BSON library available, a new BSON library will be created according to the specification of bsonspec.org.
3. Transport layer
The first release should come with a base/abstract definition of the transport layer. Based on this definition a WebSocket Server transport described in Cloud App Transport Adapter should be implemented with this proposal. Additionally a TCP socket client transport should be implemented for development purposes. Both transports should be implemented for Node.js runtime.
The first managers that should be introduced in future proposals should be a lifecycle manager and the file manager. Other managers (screen manager etc.) should be added in future releases.
This proposal does not include a manager layer. Managers will be introduced via new proposals.
Just as the other existing libraries, the JavaScript library requires possibilities to perform async operations. JavaScript is very well capable of serving this task especially with using the Promise pattern.
There are many sources describing the Promise pattern with JavaScript and how it is used already in the native API and other libraries and frameworks. See Mozilla: Promise and You Don't Know JS - Promises
The JavaScript library will be open source and stored in a new smartdevicelink repository on GitHub called sdl_javascript_suite. The project maintainers will be responsible for maintaining and reviewing the code and the project.
The development should be done in JavaScript (not TypeScript) following ECMA-Script 2017. All the base source code should be developed using JavaScript standard built-in objects.
The transport related source code for Node.js can use Node specific libraries needed (like socket.io). This code should be stored in a separate folder from the base source code in the repository.
NodeJS, npm, and Python3 are required:
git submodule init
git submodule update
npm install
npm run build
The output will be in the dist
folder. There is a vanilla JS and a NodeJS build, which can be placed into the corresponding example apps in the examples
folder to test out the library.