@project-sunbird/sunbird-pdf-player-web-component 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,396 @@
1
+ ### Note:
2
+ This version of the angular library is compatilbe with angular version 15 and may not work with older versions of the angular 15 Apps.
3
+
4
+ ## The PDF player for the Sunbird!
5
+
6
+ The PDF player library is 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. 
7
+
8
+ ## Getting started with integration steps
9
+
10
+ The pdf 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.
11
+
12
+ # Use as web components
13
+ Any web based application can use this library as a web component. It accepts couple of inputs and triggers player and telemetry events back to the application.
14
+
15
+ Follow below-mentioned steps to use it in plain javascript project:
16
+
17
+ - Insert [library](https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/web-component/sunbird-pdf-player.js) as below:
18
+ ```javascript
19
+ <script type="text/javascript" src="sunbird-pdf-player.js"></script>
20
+ ```
21
+
22
+ - Get sample playerConfig from here: [playerConfig](https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/src/app/data.ts)
23
+
24
+ - Create a custom html element: `sunbird-pdf-player`
25
+ ```javascript
26
+ const pdfElement = document.createElement('sunbird-pdf-player');
27
+ ```
28
+
29
+ - Pass data using `player-config`
30
+ ```javascript
31
+ pdfElement.setAttribute('player-config', JSON.stringify(playerConfig));
32
+ ```
33
+
34
+ **Note:** Attribute name should be in kebab-case regardless of the actual Attribute name used in the Angular app. The value of the attribute should be in **string** type, as web-component does not accept any objects or arrays.
35
+
36
+ - Listen for the output events: **playerEvent** and **telemetryEvent**
37
+
38
+ ```javascript
39
+ pdfElement.addEventListener('playerEvent', (event) => {
40
+ console.log("On playerEvent", event);
41
+ });
42
+ pdfElement.addEventListener('telemetryEvent', (event) => {
43
+ console.log("On telemetryEvent", event);
44
+ });
45
+ ```
46
+ - Append this element to existing element
47
+ ```javascript
48
+ const myPlayer = document.getElementById("my-player");
49
+ myPlayer.appendChild(pdfPlayerElement);
50
+ ```
51
+ - Refer demo [example](https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/web-component-demo/index.html)
52
+
53
+ - To run the demo project, use the following commands:
54
+ ```bash
55
+ cd web-component-demo
56
+ npx http-server --cors .
57
+ ```
58
+ open [http://127.0.0.1:8080/](http://127.0.0.1:8080/)
59
+ **Note:** Due to cors errors when you open the index.html from demo folder as file, it is recomanded to run a static server in it like [http-server](https://www.npmjs.com/package/http-server).
60
+
61
+ - ![demo](https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/web-component-demo/pdf-player-wc.png)
62
+
63
+ # Use as Web component in the Angular app
64
+
65
+ - Run command
66
+ ```bash
67
+ npm i @project-sunbird/sunbird-pdf-player-web-component
68
+ npm i reflect-metadata
69
+ ```
70
+
71
+ - Add these entries in angular json file inside assets, scripts and styles like below
72
+
73
+ ```bash
74
+ "assets": [
75
+ "src/favicon.ico",
76
+ "src/assets",
77
+ {
78
+ "glob": "**/*.*",
79
+ "input": "./node_modules/@project-sunbird/sunbird-pdf-player-web-component/assets",
80
+ "output": "/assets/"
81
+ }
82
+ ],
83
+ "styles": [
84
+ "src/styles.scss",
85
+ "node_modules/@project-sunbird/sunbird-pdf-player-web-component/styles.css"
86
+ ],
87
+ "scripts": [
88
+ "node_modules/reflect-metadata/Reflect.js",
89
+ "node_modules/@project-sunbird/sunbird-pdf-player-web-component/sunbird-pdf-player.js"
90
+ ]
91
+
92
+ ```
93
+
94
+ - Import CUSTOM_ELEMENTS_SCHEMA in app module and add it to the NgModule as part of schemas like below
95
+
96
+ ```javascript
97
+ ...
98
+ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
99
+ ...
100
+
101
+ @NgModule({
102
+ ...
103
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
104
+ ...
105
+ })
106
+
107
+ ```
108
+
109
+ - Integrating sunbird-pdf-player web component in angular component
110
+
111
+ Create a viewChild in html template of the angular component like
112
+
113
+ ```bash
114
+
115
+ <div #pdf></div>
116
+
117
+ ```
118
+
119
+ Refer the viewChild in ts file of the component and create the pdf player using document.createElement, then attach the player config and listen to the player and telemetry events like below and since we are rendering using viewChild these steps should be under ngAfterViewInit hook of the angular component.
120
+
121
+ ```bash
122
+
123
+ ....
124
+
125
+ @ViewChild('pdf') pdf: ElementRef;
126
+
127
+ ....
128
+ ngAfterViewInit() {
129
+ const playerConfig = <Config need be added>;
130
+ const pdfElement = document.createElement('sunbird-pdf-player');
131
+ pdfElement.setAttribute('player-config', JSON.stringify(playerConfig));
132
+
133
+ pdfElement.addEventListener('playerEvent', (event) => {
134
+ console.log("On playerEvent", event);
135
+ });
136
+
137
+ pdfElement.addEventListener('telemetryEvent', (event) => {
138
+ console.log("On telemetryEvent", event);
139
+ });
140
+ this.pdf.nativeElement.append(pdfElement);
141
+ }
142
+ ....
143
+
144
+ ```
145
+
146
+ **Note:** : Click to see the mock - [playerConfig](https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/src/app/data.ts) and send input config as string
147
+
148
+
149
+ # Use as Angular library in angular app
150
+
151
+ For help getting started with a new Angular app, check out the [Angular CLI](https://angular.io/cli).
152
+ If you have an Angular ≥ 9 CLI project, you could simply use our schematics to add sunbird-pdf-player library to it.
153
+
154
+ ## Step 1: Installation
155
+
156
+ Just run the following:
157
+ ```red
158
+ ng add @project-sunbird/sunbird-pdf-player-v9
159
+ ```
160
+
161
+ It will install sunbird-pdf-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
162
+
163
+ ```red
164
+ ng add @project-sunbird/sunbird-pdf-player-v9 --project myProject
165
+ ```
166
+ ### Manual installation
167
+ If you prefer not to use schematics or want to add `sunbird-pdf-player-v9` to an older project, you'll need to do the following:
168
+
169
+ <details>
170
+ <summary>Click here to show detailed instructions!</summary>
171
+
172
+ #### 1. Install the packages:
173
+
174
+ ```bash
175
+ npm install @project-sunbird/sunbird-pdf-player-v9 --save
176
+ npm install @project-sunbird/sb-styles --save
177
+ npm install @project-sunbird/client-services --save
178
+ ```
179
+
180
+ #### 2. Include the sb-styles and assets in angular.json configuration:
181
+
182
+ Add following under architect.build.assets and styles
183
+
184
+ ```diff
185
+ {
186
+ ...
187
+ "build": {
188
+ "builder": "@angular-devkit/build-angular:browser",
189
+ "options": {
190
+ ...
191
+ "assets": [
192
+ ...
193
+ + {
194
+ + "glob": "**/*.*",
195
+ + "input": "./node_modules/@project-sunbird/sunbird-pdf-player-v9/lib/assets/",
196
+ + "output": "/assets/"
197
+ + }
198
+ ...
199
+ ],
200
+ "styles": [
201
+ ...
202
+ + "./node_modules/@project-sunbird/sb-styles/assets/_styles.scss"
203
+ ...
204
+ ],
205
+ ...
206
+ }
207
+ ```
208
+
209
+
210
+ #### 3. Import the modules and components:
211
+
212
+ Import the NgModule where you want to use:
213
+
214
+ ```diff
215
+ + import { SunbirdPdfPlayerModule } from '@project-sunbird/sunbird-pdf-player-v9';
216
+ @NgModule({
217
+ ...
218
+ + imports: [SunbirdPdfPlayerModule],
219
+ ...
220
+ })
221
+ export class YourAppModule { }
222
+
223
+ ```
224
+
225
+ </details>
226
+
227
+ ## Step 2: Send input to render PDF player
228
+
229
+ Use the mock config in your component to send input to PDF player
230
+ Click to see the mock - [playerConfig](https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/src/app/data.ts)
231
+
232
+ ## Player config
233
+ ```js
234
+ var playerConfig = {
235
+ "context": {
236
+ "mode": "play", // To identify preview used by the user to play/edit/preview
237
+ "authToken": "", // Auth key to make api calls
238
+ "sid": "7283cf2e-d215-9944-b0c5-269489c6fa56", // User sessionid on portal or mobile
239
+ "did": "3c0a3724311fe944dec5df559cc4e006", // Unique id to identify the device or browser
240
+ "uid": "anonymous", // Current logged in user id
241
+ "channel": "505c7c48ac6dc1edc9b08f21db5a571d", // Unique id of the channel(Channel ID)
242
+ "pdata": {
243
+ "id": "sunbird.portal", // Producer ID. For ex: For sunbird it would be "portal" or "genie"
244
+ "ver": "3.2.12", // Version of the App
245
+ "pid": "sunbird-portal.contentplayer" // Optional. In case the component is distributed, then which instance of that component
246
+ },
247
+ "contextRollup": { // Defines the content roll up data
248
+ "l1": "505c7c48ac6dc1edc9b08f21db5a571d"
249
+ },
250
+ "tags": [ // Defines the tags data
251
+ ""
252
+ ],
253
+ "cdata": [], // Defines correlation data
254
+ "timeDiff": 0, // Defines the time difference
255
+ "objectRollup": {}, // Defines the object roll up data
256
+ "host": "", // Defines the from which domain content should be load
257
+ "endpoint": "", // Defines the end point
258
+ "userData": { // Defines the user data firstname & lastname
259
+ "firstName": "",
260
+ "lastName": ""
261
+ }
262
+ },
263
+ "config": {
264
+ "sideMenu": {
265
+ "showShare": true, // show/hide share button in side menu. default value is true
266
+ "showDownload": true, // show/hide download button in side menu. default value is true
267
+ "showReplay": true, // show/hide replay button in side menu. default value is true
268
+ "showExit": false, // show/hide exit button in side menu. default value is false
269
+ "showPrint": true // show/hide print button in side menu. default value is true
270
+ }
271
+ },
272
+ "metadata": {}, // Content metadata json object (from API response take -> response.result.content)
273
+ }
274
+
275
+ ```
276
+
277
+ ## Metadata Mandatory property description
278
+ Metadata gives complete information about the content.
279
+
280
+ Sample metadata object interface:
281
+
282
+ ```js
283
+ "metadata": {
284
+ identifier: string;
285
+ name: string;
286
+ artifactUrl: string;
287
+ streamingUrl?: string;
288
+ compatibilityLevel?: number;
289
+ pkgVersion?: number;
290
+ isAvailableLocally?: boolean;
291
+ basePath?: string;
292
+ baseDir?: string;
293
+ }
294
+ ```
295
+
296
+ In metadata, the following properties are mandatory to play the content.
297
+
298
+ |Property Name| Description| Mandatory/Optional| Without field | Comment
299
+ |--|----------------------|--| --| --|
300
+ | `identifier` | It is `string` of unique content id | Mandatory | Unable to load the content error | Its a unique content id so Its a required to log the telemetry and other data against content|
301
+ | `name` | It is `string` to represent the name of the content or pdf | Mandatory | Unable to load the content error | Its a required to show the name of the pdf while loading the pdf|
302
+ | `artifactUrl` | It is `string` url to load the pdf from artifact url | Mandatory | Unable to load the content error | It is required to load the pdf file|
303
+ | `streamingUrl` | It is `string` url to load the pdf from streaming url | Optional | Unable to load the content error | This is required if you want to load the streaming pdf URL|
304
+ | `isAvailableLocally` | It is a `boolean` value which indicate the content is locally available | Optional | Content will not load offline | It is required to know - the content is downloaded and can be played offline|
305
+ | `basePath` | It is `string` to represent the base path of the pdf file | Optional | Content will not load offline | It is required to load the pdf file in offline use case|
306
+ | `baseDir` | It is `string` to represent the base path of the pdf file | Optional | Content will not load offline | It is required to load the pdf file in offline use case |
307
+ | `compatibilityLevel` | It is `number` to represent the compatibility level | Optional | Default compatibilityLevel 4 will be set | It's an optional field
308
+ | `pkgVersion` | It is `number` to represent the version of the current packages | Optional | Default compatibilityLevel `1.0` will be set | it's an optional field
309
+
310
+ Sample config for mandatory fields
311
+ ```js
312
+ var playerConfig = {
313
+ "metadata": {
314
+ identifier: 'do_31291455031832576019477',
315
+ name: 'NAME_OF_THE_CONTENT',
316
+ artifactUrl: 'https://ntpproductionall.blob.core.windows.net/ntp-content-production/content/assets/do_31291458881611366418883/b331332333_std_5_mathssciencesocial_tm_term-1_opt.pdf'
317
+ }
318
+ }
319
+ ```
320
+
321
+ ## Telemetry property description
322
+ |Property Name| Description| Default Value | Mandatory/Optional|
323
+ |--|----------------------|--|--|
324
+ | `channel` | It is `string` which defines a channel identifier to know which channel is currently being used.| `in.sunbird` |Mandatory|
325
+ | `env` | It is an string containing Unique environment where the event has occurred | ```"contentplayer"```|Optional|
326
+ | `pdata` | It is an `object` which defines the producer information. it should have an identifier and version and canvas will log in the telemetry| ```{'id':'in.sunbird', 'ver':'1.0'}```|Mandatory|
327
+ | `mode` | It is a `string` to identify preview used by the user to play/edit/preview | ```play```|Optional|
328
+ | `sid` | It is a `string` containing user session id. | ```sid = uid ```|Optional|
329
+ | `did` | It is a `string` containing unique device id.| ```fingerPrintjs2```|Optional|
330
+ | `uid` |It is a `string` containing the user id.| ```actor.id = did ? did : "anonymous" ```|Optional|
331
+ | `authToken` | It is a `string` to send telemetry to given endpoint (API uses for authentication) | ```''```|Optional|
332
+ | `contextRollup` | It is an `object` which defines content roll up data | ```{}```|Optional|
333
+ | `objectRollup` | It is an `object` which defines object rollup data | ```{}```|Optional|
334
+ | `tags` | It is an `array`. It can be used to tag devices so that summaries or metrics can be derived via specific tags. Helpful during analysis | ```[]```|Optional|
335
+ | `cdata` | It is an `array` Correlation data. Can be used to correlate multiple events. Generally used to track user flow | ```[]```|Optional|
336
+ | `host` | It is a `string` which defines the from which domain content should be load|```window.location.origin``` |Optional|
337
+ | `userData` | It is an `object` which defines user data | ```Anonymous```|Optional|
338
+
339
+
340
+ ## Config property description
341
+ |Property Name| Description| Default Value | Mandatory/Optional
342
+ |--|----------------------|--| --|
343
+ | `config` | It is an `object` it contains the `sideMenu`. These will be used to configure the canvas | ```{ sideMenu: {"showShare": true, "showDownload": true, "showReplay": true, "showExit": false,"showPrint": true}}``` | Optional |
344
+ | `config.sideMenu.showShare` | It is `boolean` to show/hide share button in side menu| ```true```| Optional |
345
+ | `config.sideMenu.showDownload` | It is `boolean` to show/hide download button in side menu| ```true```| Optional |
346
+ | `config.sideMenu.showReplay` | It is `boolean` to show/hide replay button in side menu| ```true```| Optional |
347
+ | `config.sideMenu.showExit` | It is `boolean` to show/hide exit button in side menu| ```false```| Optional |
348
+ | `config.sideMenu.showPrint` | It is `boolean` to show/hide print button in side menu| ```true```| Optional |
349
+
350
+ ## Available components
351
+ |Feature| Notes| Selector|Code|Input|Output
352
+ |--|--|--|------------------------------------------------------------------------------------------|---|--|
353
+ | PDF Player | Can be used to render pdf | sunbird-pdf-player| *`<sunbird-pdf-player [playerConfig]="playerConfig"><sunbird-pdf-player>`*|playerConfig|playerEvent, telemetryEvent|
354
+
355
+ <br /><br />
356
+
357
+ # Use as Web component in Mobile app
358
+ For existing apps, follow these steps [steps](README.md#use-as-web-component--in-the-angular-app) to begin using.
359
+
360
+ # Use as Angular library in Mobile app
361
+ For existing apps, follow these steps to begin using.
362
+
363
+ ## Step 1: Install the packages
364
+ Click to see the steps - [InstallPackages](README.md#step-1-install-the-packages)
365
+
366
+ ## Step 2: Include the sb-styles and assets in angular.json
367
+
368
+ Click to see the steps - [IncludeStyles](README.md#step-2-include-the-sb-styles-and-assets-in-angularjson)
369
+
370
+ ## Step 3: Import the modules and components
371
+
372
+ Click to see the steps - [Import](README.md#step-3-import-the-modules-and-components)
373
+
374
+
375
+ ## Step 4: Import in component
376
+
377
+ <sunbird-video-player [playerConfig]="playerConfig" (playerEvent)="playerEvents($event)"
378
+ (telemetryEvent)="playerTelemetryEvents($event)"></sunbird-video-player>
379
+
380
+ ## Step 5: Send input to render PDF player
381
+
382
+ Click to see the input data - [playerConfig](README.md#step-4-send-input-to-render-pdf-player)
383
+
384
+ # Use as Web component in React app
385
+ For existing apps, follow these steps [steps](https://github.com/Sunbird-Knowlg/knowlg-portal/tree/release-5.3.0/react-app#readme) to begin using.
386
+
387
+ # Use as Web component in Flutter app
388
+ For existing apps, follow these steps [steps](https://github.com/Sunbird-Knowlg/knowlg-portal/tree/release-5.3.0/flutter_app#readme) to begin using.
389
+
390
+ # Use as Web component in React native app(Android)
391
+ For existing apps, follow these steps [steps](https://github.com/Sunbird-Knowlg/knowlg-portal/tree/release-5.3.0/reactNative#readme) to begin using.
392
+
393
+ ## Sample code
394
+ Click to see the sample code - [sampleCode](https://github.com/Sunbird-Ed/SunbirdEd-mobile-app/blob/release-4.8.0/src/app/player/player.page.html)
395
+ <br /><br />
396
+
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@project-sunbird/sunbird-pdf-player-web-component",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "The web component package for the sunbird pdf player",
5
5
  "main": "sunbird-pdf-player.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
- "homepage": "https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-5.5.0/README.md",
9
+ "homepage": "https://github.com/Sunbird-Knowlg/sunbird-pdf-player/blob/release-6.0.0/README.md",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/Sunbird-Knowlg/sunbird-pdf-player.git"