Installation
🏷️ System requirements
The following are prerequisites to using the QuML player
Angular
15.2.3
The QuML player is tested against the above version of angular. Updating to the latest versions needs further testing.
For more information on installing angular, see angular.io/cli. If you are unsure what version of Angular runs on your system, run “ng version” in a command prompt (terminal) window. Angular requires an active LTS or maintenance LTS version of Node.js. Refer here for more details on Angular CLI dependencies
💠 The QuML player for the Sunbird!
The QuML player library components are powered by Angular. This player is primarily designed to be used on Sunbird consumption platforms (mobile app, web portal, offline desktop app) to drive reusability and maintainability, hence reducing the redundant development effort significantly, and it can be integrated with any platform irrespective of the platforms and the frontend frameworks. It is exported not only as an angular library but also as a web component aims to make it easy to share, discover, and reuse web components. It creates a framework agnostic way of composing and repurposing code.
📑 Getting started with integration steps
The QuML player can be integrated as a web component and also as an angular library in angular application projects and it can also be integrated into any mobile framework as a web component.
Use as web components 🌏
QuML Library can also be used as a web component which means if your project does not use a JavaScript framework but prefers platform-based HTML, CSS, and JavaScript, you may wish to use QuML Library in this way. Simply follow the below-mentioned steps to use it in plain JavaScript project:
Insert library as below:
<script type="text/javascript" src="sunbird-quml-player.js"></script>Create an asset folder and copy all the files from here, the library requires these assets internally to work well.
Create a custom HTML element:
sunbird-quml-playerconst qumlPlayerElement = document.createElement('sunbird-quml-player');Get sample playerConfig from here: playerConfig and pass data using
player-configqumlPlayerElement.setAttribute('player-config', JSON.stringify(playerConfig));Note: Attribute should be in string type
Pass the Question List API baseUrl for, e.g.
window.questionListUrl = 'https://dev.inquiry.sunbird.org/api/question/v2/list';Listen for the output events:
playerEventandtelemetryEventqumlPlayerElement.addEventListener('playerEvent', (event) => { console.log("On playerEvent", event); }); qumlPlayerElement.addEventListener('telemetryEvent', (event) => { console.log("On telemetryEvent", event); });Append this element to the existing element
const myPlayer = document.getElementById("my-player"); myPlayer.appendChild(qumlPlayerElement);▶️ Refer demo example
Use as web component in the Angular app
Run command
Add these entries in an angular JSON file inside assets, scripts, and styles like below
Import CUSTOM_ELEMENTS_SCHEMA in the app module and add it to the NgModule as part of schemas like below
Integrating sunbird-quml-player web component in the angular component
Create a viewChild in HTML template of the angular component like
Refer to the
viewChildin the ts file of the component and create the QuML player using thedocument.createElement, then attach the player config and listen to the player and telemetry events like below and since we are rendering usingviewChildthese steps should be under thengAfterViewInithook of the angular component.Note:: Click to see the mock - playerConfig and send the input config as a string
Pass the Question List API baseUrl for, e.g.
You're done! Sunbird QuML Player is now ready to play in your application. Use the following CLI command to run your application locally
To see your application in the browser, Go to http://localhost:4200.
Use as Angular library in Angular app
For help in getting started with a new Angular app, check out the Angular CLI. If you have an Angular ≥ 9 CLI project, you could simply use our schematics to add sunbird-quml-player library to it.
For existing apps, follow the below-mentioned steps:
🏷️ Installation
Just run the following:
It will install sunbird-quml-player for the default application specified in your angular.json. If you have multiple projects, and you want to target a specific application, you could specify the --project option
Schematics will create question-cursor-implementation.service.ts. Please update the listUrl in it. For more information refer question-cursor-implementation.service.ts and do not forget to add your question list API URL here, for example
Manual installation
If you prefer not to use schematics or want to add sunbird-quml-player to an older project, you'll need to do the following:
Click here to show detailed instructions!
🏷️ Step 1: Install Packages
These are the peer Dependencies of the library, need to be installed in order to use this library.
Note: As QuML library is build with angular version 15, we are using bootstrap@^4.6.2 and ngx-bootstrap@^10.0.0 which are the compatible versions. For more reference Check compatibility document for ng-bootstrap here
🏷️ Step 2: Add question-cursor-implementation.service
Create a question-cursor-implementation.service.ts in a project and which will implement the QuestionCursor abstract class.
QuestionCursor is an abstract class, exported from the library, which needs to be implemented. Basically, it has some methods which should make an API request over HTTP
For more information refer question-cursor-implementation.service.ts and do not forget to add your question list API URL here, for example: listUrl = "https://dev.inquiry.sunbird.org/api/question/v2/list";
🏷️ Step 3: Include the styles, scripts and assets in angular.json
Add the following under architect.build.assets for default project
🏷️ Step 4: Import the modules and components
Import the required modules such as CarouselModule, QumlLibraryModule, HttpClientModule and question-cursor-implementation.service as below:
Note: To avoid CORS errors, add proxy configuration for API's refer - proxy.conf.json
🏷️ Send input to render QuML player
Users can get a response from the api/questionset/v1/hierarchy/:do_id or can use the provided mock config for the demo
Use the mock config in your component to send input to the QuML player as playerConfig Click to see the mock - samplePlayerConfig
🟠 Available components
QuML Player
Can be used to render QuML
quml-main-player
<quml-main-player [playerConfig]="playerConfig"><quml-main-player>
playerConfig
playerEvent, telemetryEvent
🔻 Input Parameters
playerConfig: Object - [Required]
Note: context is optional, which is used for capturing the telemetry event. If context is not passed in playerConfig telemetry event of player will not be captured.
Here is the detailed description of playerConfig: player-configuration
🔻 Output Events
playerEvent() - It provides heartbeat event for each action performed in the player.
telemetryEvent() - It provides the sequence of telemetry events such as
START, INTERACT, IMPRESSION, SUMMARY, END
🏷️ Run the application
You are done! Use the following CLI command to run your application locally
To see your application in the browser, go to http://localhost:4200.
📑 QuML Player Contribution Guide
Repo Setup
Install Node 14.20.x and Angular 15
Clone the Repo with desired release branch - https://github.com/Sunbird-inQuiry/player
Add the baseUrl in the environment.ts and proxy.conf.json files
If there are any changes in API endpoints, update the app.constant.ts file
Change the default content ID in the
app.component.tsfile if pointing to different baseUrlRun
npm iin root folderRun
npm iinprojects/quml-libraryOpen two terminal windows (on the root folder)
Run
npm run buildonce this run completes, run the next command - let it be running on 1st terminal windowRun
npm run serveon the second terminal window (This will copy assets from thequml-libraryto the library dist folder)Now it will be served on
http://localhost:4200/To run the web-component
npm run build-web-component
Last updated
Was this helpful?