sonic-widget 2.4.8 → 2.5.1
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/LICENSE +21 -21
- package/README.md +312 -312
- package/dist/index.js +1485 -1498
- package/dist/models/Tensorflow/coco_ssd_lite_mobilenet_v2/group1-shard1of5 +0 -0
- package/dist/models/Tensorflow/coco_ssd_lite_mobilenet_v2/group1-shard2of5 +0 -0
- package/dist/models/Tensorflow/coco_ssd_lite_mobilenet_v2/group1-shard3of5 +0 -0
- package/dist/models/Tensorflow/coco_ssd_lite_mobilenet_v2/group1-shard4of5 +0 -0
- package/dist/models/Tensorflow/coco_ssd_lite_mobilenet_v2/group1-shard5of5 +0 -0
- package/dist/models/Tensorflow/coco_ssd_lite_mobilenet_v2/model.json +21549 -0
- package/dist/service-worker.js +79 -76
- package/package.json +52 -52
- package/dist/models/TasksVision/object/float16/efficientdet_lite0.tflite +0 -0
package/README.md
CHANGED
|
@@ -1,312 +1,312 @@
|
|
|
1
|
-
<center>
|
|
2
|
-
|
|
3
|
-
<h1> SONIC WIDGET </h1>
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/sonic-widget)
|
|
6
|
-
[](https://www.npmjs.com/package/sonic-widget)
|
|
7
|
-
[](https://www.jsdelivr.com/package/npm/sonic-widget)
|
|
8
|
-
[](https://www.jsdelivr.com/package/npm/sonic-widget)
|
|
9
|
-
|
|
10
|
-
</center>
|
|
11
|
-
|
|
12
|
-
## Installation:
|
|
13
|
-
|
|
14
|
-
**Sonic Widget** - _used to show the onboard kyc at your web page itself._
|
|
15
|
-
|
|
16
|
-
Use this script tag to get access to the widget:
|
|
17
|
-
|
|
18
|
-
```html
|
|
19
|
-
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
or
|
|
23
|
-
|
|
24
|
-
in **Angular** can be used by installing package from npm
|
|
25
|
-
|
|
26
|
-
```shell
|
|
27
|
-
npm install sonic-widget
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
and adding path in `angular.json`
|
|
31
|
-
|
|
32
|
-
```json
|
|
33
|
-
"scripts": [ "node_modules/sonic-widget/dist/index.js" ]
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## Implementation Details for Angular TypeScript:
|
|
38
|
-
|
|
39
|
-
**Steps:-**
|
|
40
|
-
|
|
41
|
-
1. Create or open an angular TS project.
|
|
42
|
-
|
|
43
|
-
2. Use this script tag to get access to the widget at initial html page:
|
|
44
|
-
|
|
45
|
-
```html
|
|
46
|
-
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
or
|
|
50
|
-
|
|
51
|
-
it can be added in `angular.json` by installing the npm package
|
|
52
|
-
|
|
53
|
-
```json
|
|
54
|
-
"scripts": [ "node_modules/sonic-widget/dist/index.js" ]
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
3. At `app.component.html`, Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
|
|
58
|
-
|
|
59
|
-
```html
|
|
60
|
-
<button id="xxxx">Open</button>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
4. Add a div tag with the id **`sonic-web-widget`** at the specific place. It is used to display the sonic module with the help of this id.
|
|
64
|
-
|
|
65
|
-
```html
|
|
66
|
-
<div id="sonic-web-widget"></div>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
5. Add a declaration for var *sonic* at TS file `app.component.ts`.
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
declare var sonic: any;
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
6. Next, add the functionality to call widget in the base of onInit.
|
|
76
|
-
|
|
77
|
-
```ts
|
|
78
|
-
ngOnInit(): void {
|
|
79
|
-
|
|
80
|
-
const config = {
|
|
81
|
-
baseurl: string, // the base url of the backend server
|
|
82
|
-
docModelUrl: string, // the doc model url of the document recognition process
|
|
83
|
-
maskModelUrl: string, // the mask model url of the mask detect process
|
|
84
|
-
showPage: boolean, // used to show the page or not
|
|
85
|
-
|
|
86
|
-
videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
|
|
87
|
-
appId: string, // application policy identifier
|
|
88
|
-
accountId: string, // account can be taken from operator axiom account
|
|
89
|
-
appName: string, // representing name of the application (Optional)
|
|
90
|
-
userName: string, // user prospective data
|
|
91
|
-
userId: string, // user document number to identity
|
|
92
|
-
email: string, // user prospective data
|
|
93
|
-
phone: string, // user prospective data
|
|
94
|
-
applicationNo: string, // user prospective data
|
|
95
|
-
isMalay: boolean, //used to change the default language english to malay
|
|
96
|
-
branchId: string, //used to identify the bank branch
|
|
97
|
-
sendLogsEmail: boolean, //used to send logs through email
|
|
98
|
-
blinkThreshold: number, // used for blink threshold
|
|
99
|
-
objectPersonThreshold: number, // used for object Person score threshold
|
|
100
|
-
objectPhoneThreshold: number, // used for object Phone score threshold
|
|
101
|
-
onMessage: function (data) {}, // callback function, when api response message or error or any other actions
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// get the element used in the action button
|
|
105
|
-
var container = document.getElementById('xxxx');
|
|
106
|
-
// on click of element widget works
|
|
107
|
-
container?.addEventListener('click', function () {
|
|
108
|
-
sonic?.SonicWidget(config);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
7. Add service worker for widget to protect the multiple calls for tensorflow. So, it will have cache to reuse it. Here, I'm adding `service-worker.js` file at `src/assets` folder. So, below steps will be based on this file path.
|
|
114
|
-
|
|
115
|
-
```javascript
|
|
116
|
-
const CACHE_NAME = 'demo-app-ai-tensorflow-models-cache-v1';
|
|
117
|
-
const urlsToCache = [
|
|
118
|
-
// coco ssd - tensorflow model
|
|
119
|
-
// document model - teachable machine drive link or folder path
|
|
120
|
-
// mask model - teachable machine drive link or folder path
|
|
121
|
-
// face landmark model - mediapipe tasks-vision
|
|
122
|
-
// hand landmark model - mediapipe tasks-vision
|
|
123
|
-
// Add more model files if necessary
|
|
124
|
-
]
|
|
125
|
-
|
|
126
|
-
self.addEventListener('install', function(event) {
|
|
127
|
-
// Perform install steps
|
|
128
|
-
event.waitUntil(
|
|
129
|
-
caches.open(CACHE_NAME)
|
|
130
|
-
.then(function(cache) {
|
|
131
|
-
return cache.addAll(urlsToCache);
|
|
132
|
-
})
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
self.addEventListener('fetch', function(event) {
|
|
137
|
-
const request = event.request;
|
|
138
|
-
|
|
139
|
-
// Skip caching for requests from browser extensions
|
|
140
|
-
if (request.url.startsWith('chrome-extension://')) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
event.respondWith(
|
|
145
|
-
caches.match(request)
|
|
146
|
-
.then(function(response) {
|
|
147
|
-
// Cache hit - return response
|
|
148
|
-
if (response) {
|
|
149
|
-
return response;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Clone the request
|
|
153
|
-
const fetchRequest = request.clone();
|
|
154
|
-
|
|
155
|
-
return fetch(fetchRequest).then(
|
|
156
|
-
function(response) {
|
|
157
|
-
// Check if we received a valid response
|
|
158
|
-
if(!response || response.status !== 200 || response.type !== 'basic') {
|
|
159
|
-
return response;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Clone the response
|
|
163
|
-
const responseToCache = response.clone();
|
|
164
|
-
// Save the response for future matching
|
|
165
|
-
caches.open(CACHE_NAME)
|
|
166
|
-
.then(function(cache) {
|
|
167
|
-
cache.put(request, responseToCache);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
return response;
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
})
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
8. Use this script tag to get access to the service worker at initial html page:
|
|
178
|
-
|
|
179
|
-
```html
|
|
180
|
-
<script src="src/assets/service-worker.js"></script>
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
or
|
|
184
|
-
|
|
185
|
-
it can be added in `angular.json` by installing the npm package
|
|
186
|
-
|
|
187
|
-
```json
|
|
188
|
-
"scripts": [ ..., "src/assets/service-worker.js" ]
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
9. Register the service worker at your required place:
|
|
192
|
-
```ts
|
|
193
|
-
ngAfterViewInit(): void {
|
|
194
|
-
if ('serviceWorker' in navigator) {
|
|
195
|
-
window.addEventListener('load', () => {
|
|
196
|
-
navigator.serviceWorker.register('/demo-app/assets/service-worker.js').then(
|
|
197
|
-
(registration) => {
|
|
198
|
-
console.log(
|
|
199
|
-
'ServiceWorker registered with scope: ',
|
|
200
|
-
registration.scope
|
|
201
|
-
);
|
|
202
|
-
},
|
|
203
|
-
(err) => {
|
|
204
|
-
console.error('ServiceWorker registration failed: ', err);
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
## Implementation Details for Vanilla JavaScript:
|
|
215
|
-
|
|
216
|
-
**Steps:-**
|
|
217
|
-
|
|
218
|
-
1. Create or open an html file.
|
|
219
|
-
|
|
220
|
-
2. Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
|
|
221
|
-
|
|
222
|
-
```html
|
|
223
|
-
<button id="xxxx">Open</button>
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
3. Add a div tag with the id **`sonic-web-widget`** at the last or beginning of the body tag. It is used to display the sonic module with the help of this id.
|
|
227
|
-
|
|
228
|
-
```html
|
|
229
|
-
<div id="sonic-web-widget"></div>
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
4. Add a Script tag to the head tag or body tag. And use the latest version.
|
|
233
|
-
|
|
234
|
-
```html
|
|
235
|
-
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
5. Next, add the script tag at a necessary place. But add below the widget script.
|
|
239
|
-
|
|
240
|
-
```html
|
|
241
|
-
<script>
|
|
242
|
-
const config = {
|
|
243
|
-
baseurl: string, // the base url of the backend server
|
|
244
|
-
docModelUrl: string, // the doc model url of the document recognition process
|
|
245
|
-
maskModelUrl: string, // the mask model url of the mask detect process
|
|
246
|
-
showPage: boolean, // used to show the page or not
|
|
247
|
-
|
|
248
|
-
videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
|
|
249
|
-
appId: string, // application policy identifier
|
|
250
|
-
appName: string, // representing name of the application (Optional)
|
|
251
|
-
accountId: string, // account can be taken from operator axiom account
|
|
252
|
-
userName: string, // user prospective data
|
|
253
|
-
userId: string, // user document number to identity
|
|
254
|
-
email: string, // user prospective data
|
|
255
|
-
phone: string, // user prospective data
|
|
256
|
-
applicationNo: string, // user prospective data
|
|
257
|
-
isMalay: boolean, //used to change the default language english to malay
|
|
258
|
-
branchId: string, // branch id to identify the branch of the bank
|
|
259
|
-
sendLogsEmail: boolean, //used to send logs through email
|
|
260
|
-
blinkThreshold: number, // threshold used to calculate the user blinked or not, with range limit 0-1(default value is 0.35)
|
|
261
|
-
objectPersonThreshold: number, // used for object Person score threshold with range limit 0-1(default value is 0.35)
|
|
262
|
-
objectPhoneThreshold: number, // used for object Phone score threshold with range limit 0-1(default value is 0.35)
|
|
263
|
-
onMessage: function (data) {}, // callback function, when api response message or error or any other actions
|
|
264
|
-
};
|
|
265
|
-
// get the element used in the action button
|
|
266
|
-
var container = document.getElementById('xxxx');
|
|
267
|
-
// on click of element widget works
|
|
268
|
-
container.addEventListener('click', function () {
|
|
269
|
-
sonic.SonicWidget(config);
|
|
270
|
-
});
|
|
271
|
-
</script>
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
_Here, the config variable is used to pass the data. And the container variable is to get the dom element of the id **`xxxx`** button and add it to the event listener. It checks if the button is clicked and sends the config object data to the **`sonic`** module.
|
|
275
|
-
**`sonic.SonicWidget(config)`**_
|
|
276
|
-
|
|
277
|
-
_You can get the logs with **`onMessage`** for all actions and stages.
|
|
278
|
-
Check with **`data.code`**_
|
|
279
|
-
|
|
280
|
-
```
|
|
281
|
-
0 - info message from application
|
|
282
|
-
1 - success api call
|
|
283
|
-
-1 - failed api call
|
|
284
|
-
-2 - error message from application
|
|
285
|
-
-3 - configuration error message
|
|
286
|
-
2 - on close application
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
**Note:-**
|
|
290
|
-
|
|
291
|
-
<!-- - _**`serviceWorkerPath`** should pass as a string value. It is used as the service worker path and its default path is **`/demo-app/assets/service-worker.js`** and Cache name should be different to fix conflict._ -->
|
|
292
|
-
- _**`baseurl`** should pass as a string value. It is used as the base URL for API calls._
|
|
293
|
-
- _**`docModelUrl`** should pass as a string value. It is used as the base URL for document model._
|
|
294
|
-
- _**`maskModelUrl`** should pass as a string value. It is used as the base URL for mask model._
|
|
295
|
-
- _**`showPage`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget page open or close._
|
|
296
|
-
- _**`
|
|
297
|
-
- _**`videoURL`** should pass as a string value as url. It is used to show the video onboard sonic kyc and it is optional._
|
|
298
|
-
- _**`accountId`** should pass as a string value. It is used to get the JWT token and proceed with the operator account._
|
|
299
|
-
- _**`isMalay`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget default language english or malay._
|
|
300
|
-
- _**`branchId`** should pass as a string value. It is used to find bank branch available for operator account for onboard sonic kyc._
|
|
301
|
-
- _**`appId`** should pass as a string value. It is used to find an application policy for onboard sonic kyc._
|
|
302
|
-
- _**`appName`** should pass as a string value. It is used for onboard kyc application name. it is optional and default **`Sonic`** ._
|
|
303
|
-
- _**`userName`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
304
|
-
- _**`userId`** should pass as a string value. It is used to create an application for onboard sonic kyc and to compare your identity with the document._
|
|
305
|
-
- _**`email`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
306
|
-
- _**`phone`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
307
|
-
- _**`applicationNo`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
308
|
-
- _**`sendLogsEmail`** is used to pass a boolean value. It is used to send logs to client email address._
|
|
309
|
-
- _**`blinkThreshold`** is used to pass a numerical value. It is used to check the user blinks (range 0-1 and default 0.5)._
|
|
310
|
-
- _**`objectPersonThreshold`** is used to pass a numerical value. It is used to check the image person as object found with required score as threshold (range 0-1 and default 0.925)._
|
|
311
|
-
- _**`objectPhoneThreshold`** is used to pass a numerical value. It is used to check the image phone/laptop as object found with required score as threshold (range 0-1 and default 0.5)._
|
|
312
|
-
- _**`onMessage`** is a callback function. It is getting called when the API gives a message or at any configuration error. Return data is an object with its API endpoint and result._
|
|
1
|
+
<center>
|
|
2
|
+
|
|
3
|
+
<h1> SONIC WIDGET </h1>
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/sonic-widget)
|
|
6
|
+
[](https://www.npmjs.com/package/sonic-widget)
|
|
7
|
+
[](https://www.jsdelivr.com/package/npm/sonic-widget)
|
|
8
|
+
[](https://www.jsdelivr.com/package/npm/sonic-widget)
|
|
9
|
+
|
|
10
|
+
</center>
|
|
11
|
+
|
|
12
|
+
## Installation:
|
|
13
|
+
|
|
14
|
+
**Sonic Widget** - _used to show the onboard kyc at your web page itself._
|
|
15
|
+
|
|
16
|
+
Use this script tag to get access to the widget:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.5.1/dist/index.min.js"></script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
or
|
|
23
|
+
|
|
24
|
+
in **Angular** can be used by installing package from npm
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
npm install sonic-widget
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
and adding path in `angular.json`
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
"scripts": [ "node_modules/sonic-widget/dist/index.js" ]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Implementation Details for Angular TypeScript:
|
|
38
|
+
|
|
39
|
+
**Steps:-**
|
|
40
|
+
|
|
41
|
+
1. Create or open an angular TS project.
|
|
42
|
+
|
|
43
|
+
2. Use this script tag to get access to the widget at initial html page:
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.5.1/dist/index.min.js"></script>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
or
|
|
50
|
+
|
|
51
|
+
it can be added in `angular.json` by installing the npm package
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
"scripts": [ "node_modules/sonic-widget/dist/index.js" ]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
3. At `app.component.html`, Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<button id="xxxx">Open</button>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
4. Add a div tag with the id **`sonic-web-widget`** at the specific place. It is used to display the sonic module with the help of this id.
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<div id="sonic-web-widget"></div>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
5. Add a declaration for var *sonic* at TS file `app.component.ts`.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
declare var sonic: any;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
6. Next, add the functionality to call widget in the base of onInit.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
ngOnInit(): void {
|
|
79
|
+
|
|
80
|
+
const config = {
|
|
81
|
+
baseurl: string, // the base url of the backend server
|
|
82
|
+
docModelUrl: string, // the doc model url of the document recognition process
|
|
83
|
+
maskModelUrl: string, // the mask model url of the mask detect process
|
|
84
|
+
showPage: boolean, // used to show the page or not
|
|
85
|
+
speedCheckURL: string, // public URL of the internet speed check
|
|
86
|
+
videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
|
|
87
|
+
appId: string, // application policy identifier
|
|
88
|
+
accountId: string, // account can be taken from operator axiom account
|
|
89
|
+
appName: string, // representing name of the application (Optional)
|
|
90
|
+
userName: string, // user prospective data
|
|
91
|
+
userId: string, // user document number to identity
|
|
92
|
+
email: string, // user prospective data
|
|
93
|
+
phone: string, // user prospective data
|
|
94
|
+
applicationNo: string, // user prospective data
|
|
95
|
+
isMalay: boolean, //used to change the default language english to malay
|
|
96
|
+
branchId: string, //used to identify the bank branch
|
|
97
|
+
sendLogsEmail: boolean, //used to send logs through email
|
|
98
|
+
blinkThreshold: number, // used for blink threshold
|
|
99
|
+
objectPersonThreshold: number, // used for object Person score threshold
|
|
100
|
+
objectPhoneThreshold: number, // used for object Phone score threshold
|
|
101
|
+
onMessage: function (data) {}, // callback function, when api response message or error or any other actions
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// get the element used in the action button
|
|
105
|
+
var container = document.getElementById('xxxx');
|
|
106
|
+
// on click of element widget works
|
|
107
|
+
container?.addEventListener('click', function () {
|
|
108
|
+
sonic?.SonicWidget(config);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
7. Add service worker for widget to protect the multiple calls for tensorflow. So, it will have cache to reuse it. Here, I'm adding `service-worker.js` file at `src/assets` folder. So, below steps will be based on this file path.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
const CACHE_NAME = 'demo-app-ai-tensorflow-models-cache-v1';
|
|
117
|
+
const urlsToCache = [
|
|
118
|
+
// coco ssd - tensorflow model
|
|
119
|
+
// document model - teachable machine drive link or folder path
|
|
120
|
+
// mask model - teachable machine drive link or folder path
|
|
121
|
+
// face landmark model - mediapipe tasks-vision
|
|
122
|
+
// hand landmark model - mediapipe tasks-vision
|
|
123
|
+
// Add more model files if necessary
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
self.addEventListener('install', function(event) {
|
|
127
|
+
// Perform install steps
|
|
128
|
+
event.waitUntil(
|
|
129
|
+
caches.open(CACHE_NAME)
|
|
130
|
+
.then(function(cache) {
|
|
131
|
+
return cache.addAll(urlsToCache);
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
self.addEventListener('fetch', function(event) {
|
|
137
|
+
const request = event.request;
|
|
138
|
+
|
|
139
|
+
// Skip caching for requests from browser extensions
|
|
140
|
+
if (request.url.startsWith('chrome-extension://')) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
event.respondWith(
|
|
145
|
+
caches.match(request)
|
|
146
|
+
.then(function(response) {
|
|
147
|
+
// Cache hit - return response
|
|
148
|
+
if (response) {
|
|
149
|
+
return response;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Clone the request
|
|
153
|
+
const fetchRequest = request.clone();
|
|
154
|
+
|
|
155
|
+
return fetch(fetchRequest).then(
|
|
156
|
+
function(response) {
|
|
157
|
+
// Check if we received a valid response
|
|
158
|
+
if(!response || response.status !== 200 || response.type !== 'basic') {
|
|
159
|
+
return response;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Clone the response
|
|
163
|
+
const responseToCache = response.clone();
|
|
164
|
+
// Save the response for future matching
|
|
165
|
+
caches.open(CACHE_NAME)
|
|
166
|
+
.then(function(cache) {
|
|
167
|
+
cache.put(request, responseToCache);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return response;
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
8. Use this script tag to get access to the service worker at initial html page:
|
|
178
|
+
|
|
179
|
+
```html
|
|
180
|
+
<script src="src/assets/service-worker.js"></script>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
or
|
|
184
|
+
|
|
185
|
+
it can be added in `angular.json` by installing the npm package
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
"scripts": [ ..., "src/assets/service-worker.js" ]
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
9. Register the service worker at your required place:
|
|
192
|
+
```ts
|
|
193
|
+
ngAfterViewInit(): void {
|
|
194
|
+
if ('serviceWorker' in navigator) {
|
|
195
|
+
window.addEventListener('load', () => {
|
|
196
|
+
navigator.serviceWorker.register('/demo-app/assets/service-worker.js').then(
|
|
197
|
+
(registration) => {
|
|
198
|
+
console.log(
|
|
199
|
+
'ServiceWorker registered with scope: ',
|
|
200
|
+
registration.scope
|
|
201
|
+
);
|
|
202
|
+
},
|
|
203
|
+
(err) => {
|
|
204
|
+
console.error('ServiceWorker registration failed: ', err);
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
## Implementation Details for Vanilla JavaScript:
|
|
215
|
+
|
|
216
|
+
**Steps:-**
|
|
217
|
+
|
|
218
|
+
1. Create or open an html file.
|
|
219
|
+
|
|
220
|
+
2. Add a button with the id **`xxxx`**. It is used to call the widget by on click event.
|
|
221
|
+
|
|
222
|
+
```html
|
|
223
|
+
<button id="xxxx">Open</button>
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
3. Add a div tag with the id **`sonic-web-widget`** at the last or beginning of the body tag. It is used to display the sonic module with the help of this id.
|
|
227
|
+
|
|
228
|
+
```html
|
|
229
|
+
<div id="sonic-web-widget"></div>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
4. Add a Script tag to the head tag or body tag. And use the latest version.
|
|
233
|
+
|
|
234
|
+
```html
|
|
235
|
+
<script src="https://cdn.jsdelivr.net/npm/sonic-widget@2.5.1/dist/index.min.js"></script>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
5. Next, add the script tag at a necessary place. But add below the widget script.
|
|
239
|
+
|
|
240
|
+
```html
|
|
241
|
+
<script>
|
|
242
|
+
const config = {
|
|
243
|
+
baseurl: string, // the base url of the backend server
|
|
244
|
+
docModelUrl: string, // the doc model url of the document recognition process
|
|
245
|
+
maskModelUrl: string, // the mask model url of the mask detect process
|
|
246
|
+
showPage: boolean, // used to show the page or not
|
|
247
|
+
speedCheckURL: string, // public URL of the internet speed check
|
|
248
|
+
videoURL: string, // url of video to do (e.g: demo doing kyc) (Optional)
|
|
249
|
+
appId: string, // application policy identifier
|
|
250
|
+
appName: string, // representing name of the application (Optional)
|
|
251
|
+
accountId: string, // account can be taken from operator axiom account
|
|
252
|
+
userName: string, // user prospective data
|
|
253
|
+
userId: string, // user document number to identity
|
|
254
|
+
email: string, // user prospective data
|
|
255
|
+
phone: string, // user prospective data
|
|
256
|
+
applicationNo: string, // user prospective data
|
|
257
|
+
isMalay: boolean, //used to change the default language english to malay
|
|
258
|
+
branchId: string, // branch id to identify the branch of the bank
|
|
259
|
+
sendLogsEmail: boolean, //used to send logs through email
|
|
260
|
+
blinkThreshold: number, // threshold used to calculate the user blinked or not, with range limit 0-1(default value is 0.35)
|
|
261
|
+
objectPersonThreshold: number, // used for object Person score threshold with range limit 0-1(default value is 0.35)
|
|
262
|
+
objectPhoneThreshold: number, // used for object Phone score threshold with range limit 0-1(default value is 0.35)
|
|
263
|
+
onMessage: function (data) {}, // callback function, when api response message or error or any other actions
|
|
264
|
+
};
|
|
265
|
+
// get the element used in the action button
|
|
266
|
+
var container = document.getElementById('xxxx');
|
|
267
|
+
// on click of element widget works
|
|
268
|
+
container.addEventListener('click', function () {
|
|
269
|
+
sonic.SonicWidget(config);
|
|
270
|
+
});
|
|
271
|
+
</script>
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
_Here, the config variable is used to pass the data. And the container variable is to get the dom element of the id **`xxxx`** button and add it to the event listener. It checks if the button is clicked and sends the config object data to the **`sonic`** module.
|
|
275
|
+
**`sonic.SonicWidget(config)`**_
|
|
276
|
+
|
|
277
|
+
_You can get the logs with **`onMessage`** for all actions and stages.
|
|
278
|
+
Check with **`data.code`**_
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
0 - info message from application
|
|
282
|
+
1 - success api call
|
|
283
|
+
-1 - failed api call
|
|
284
|
+
-2 - error message from application
|
|
285
|
+
-3 - configuration error message
|
|
286
|
+
2 - on close application
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Note:-**
|
|
290
|
+
|
|
291
|
+
<!-- - _**`serviceWorkerPath`** should pass as a string value. It is used as the service worker path and its default path is **`/demo-app/assets/service-worker.js`** and Cache name should be different to fix conflict._ -->
|
|
292
|
+
- _**`baseurl`** should pass as a string value. It is used as the base URL for API calls._
|
|
293
|
+
- _**`docModelUrl`** should pass as a string value. It is used as the base URL for document model._
|
|
294
|
+
- _**`maskModelUrl`** should pass as a string value. It is used as the base URL for mask model._
|
|
295
|
+
- _**`showPage`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget page open or close._
|
|
296
|
+
- _**`speedCheckURL`** should pass as a string value. It is used to detect internet speed and intimate the user._
|
|
297
|
+
- _**`videoURL`** should pass as a string value as url. It is used to show the video onboard sonic kyc and it is optional._
|
|
298
|
+
- _**`accountId`** should pass as a string value. It is used to get the JWT token and proceed with the operator account._
|
|
299
|
+
- _**`isMalay`** is used to pass a boolean value ( **`true`** or **`false`** ). To toggle the widget default language english or malay._
|
|
300
|
+
- _**`branchId`** should pass as a string value. It is used to find bank branch available for operator account for onboard sonic kyc._
|
|
301
|
+
- _**`appId`** should pass as a string value. It is used to find an application policy for onboard sonic kyc._
|
|
302
|
+
- _**`appName`** should pass as a string value. It is used for onboard kyc application name. it is optional and default **`Sonic`** ._
|
|
303
|
+
- _**`userName`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
304
|
+
- _**`userId`** should pass as a string value. It is used to create an application for onboard sonic kyc and to compare your identity with the document._
|
|
305
|
+
- _**`email`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
306
|
+
- _**`phone`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
307
|
+
- _**`applicationNo`** should pass as a string value. It is used to create an application for onboard sonic kyc._
|
|
308
|
+
- _**`sendLogsEmail`** is used to pass a boolean value. It is used to send logs to client email address._
|
|
309
|
+
- _**`blinkThreshold`** is used to pass a numerical value. It is used to check the user blinks (range 0-1 and default 0.5)._
|
|
310
|
+
- _**`objectPersonThreshold`** is used to pass a numerical value. It is used to check the image person as object found with required score as threshold (range 0-1 and default 0.925)._
|
|
311
|
+
- _**`objectPhoneThreshold`** is used to pass a numerical value. It is used to check the image phone/laptop as object found with required score as threshold (range 0-1 and default 0.5)._
|
|
312
|
+
- _**`onMessage`** is a callback function. It is getting called when the API gives a message or at any configuration error. Return data is an object with its API endpoint and result._
|