smartdevicelink / sdl_javascript_suite

SmartDeviceLink library for applications developed in JavaScript
BSD 3-Clause "New" or "Revised" License
15 stars 13 forks source link

sdl_javascript_suite

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.

Proposed solution

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.

SDL library layers

Looking into the existing libraries, developed in Java and Objective-C, they contain the following superset of layers:

  1. The High Level Interface is a work-in-progress developer friendly API with the purpose to provide a programming interface similar to mobile frameworks.
  2. The Manager layer is the current programming interface that abstracts the heavy load of dealing with application lifecycle, screen, dealing with RPCs and many more.
  3. The Proxy layer also known as RPC layer, is the lower level interface with the purpose of managing the connection to the remote endpoint and sending and receiving RPCs. The RPC specification of the mobile API is implemented in this layer.
  4. The SDL Session layer is responsible for the lifecycle of service sessions for e.g. RPC/Bulk, video and audio. It packages application data and sends it to the protocol layer.
  5. The SDL protocol layer is responsible for organizing the sending and receiving of frames as per the Protocol specification
  6. The transport layer is the root level of SmartDeviceLink and therefore the most critical layer as it is responsible for the foundation of data transmission.

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:

Included tasks in this proposal

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.

Manager layer

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.

Promise based development

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

Project management

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.

Building the Project

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.