@denevads/dnv-smo 1.0.27 → 1.0.28

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/dist/smo.js CHANGED
@@ -1,796 +1,805 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AlarmaLevel = exports.LogLevel = exports.SMO_EVENT_TYPE = exports.SMO = void 0;
4
- var rxjs_1 = require("rxjs");
5
- // @ts-ignore
6
- var SMO = /** @class */ (function () {
7
- function SMO() {
8
- this.vars = {};
9
- this.id = "";
10
- this.intervalDataSource$ = (0, rxjs_1.interval)(5 * 60 * 1000);
11
- this.initOnMessage();
12
- this.smoCallBacks = new smoCallBacks(this);
13
- this.utils = new Utils(this, this.smoCallBacks);
14
- this.events = new SmoEvents(this);
15
- this.init();
16
- }
17
- SMO.prototype.init = function () {
18
- var _this = this;
19
- var match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function (s) {
20
- return decodeURIComponent(s.replace(pl, " "));
21
- }, query = window.location.search.substring(1);
22
- while (match = search.exec(query)) {
23
- this.vars[decode(match[1])] = decode(match[2]);
24
- }
25
- // @ts-ignore
26
- if (window.objJS) {
27
- // @ts-ignore
28
- window.sendToIframefromNet = function (target, iframeID, objData) {
29
- console.log("sendToIframefromNet->", JSON.stringify(target));
30
- switch (target) {
31
- case "SMO.setDatasource":
32
- _this.events.setDatasource.next(objData);
33
- break;
34
- case "SMO.checkHealthPrinter":
35
- _this.events.checkHealthPrinter.next(objData);
36
- break;
37
- }
38
- };
39
- window.external = {
40
- // @ts-ignore
41
- URLNext: window.objJS.urlNext,
42
- // @ts-ignore
43
- LimpiaCapa: window.objJS.limpiaCapa,
44
- // @ts-ignore
45
- LogFlash: window.objJS.logFlash,
46
- // @ts-ignore
47
- PageInit: window.objJS.pageInit,
48
- // @ts-ignore
49
- FinAviso: window.objJS.finAviso,
50
- // @ts-ignore
51
- ExitInteractivity: window.objJS.exitInteractivity,
52
- // @ts-ignore
53
- LogWeb: window.objJS.logWeb,
54
- // @ts-ignore
55
- RefreshPage: window.objJS.refreshPage,
56
- // @ts-ignore
57
- RefreshPageByError: window.objJS.refreshPageByError,
58
- // @ts-ignore
59
- RefreshPageByVideoEvent: window.objJS.refreshPageByVideoEvent,
60
- // @ts-ignore
61
- AuditarRecurso: window.objJS.auditarRecurso,
62
- // @ts-ignore
63
- InitSMO: window.objJS.initSMO,
64
- // @ts-ignore
65
- GetFile: window.objJS.getFile,
66
- // @ts-ignore
67
- ShowBrowser: window.objJS.showBrowser,
68
- // @ts-ignore
69
- closeBrowser: window.objJS.closeBrowser,
70
- // @ts-ignore
71
- RefreshDataSource: window.objJS.refreshDataSource,
72
- // @ts-ignore
73
- SetVariable: window.objJS.setVariable,
74
- // @ts-ignore
75
- GetVariable: window.objJS.getVariable,
76
- // @ts-ignore
77
- GetLocation: window.objJS.getLocation,
78
- // @ts-ignore
79
- SalirApp: window.objJS.salirApp,
80
- // @ts-ignore
81
- SetLocalData: window.objJS.setLocalData,
82
- // @ts-ignore
83
- GetLocalData: window.objJS.getLocalData,
84
- // @ts-ignore
85
- GetSalidaData: window.objJS.getSalidaData,
86
- // @ts-ignore
87
- EjecutaFuncion: window.objJS.ejecutaFuncion,
88
- // @ts-ignore
89
- AddObserver: window.objJS.addObserver,
90
- // @ts-ignore
91
- NotifyToObservers: window.objJS.notifyToObservers,
92
- // @ts-ignore
93
- PrintTextLine: window.objJS.printTextLine,
94
- // @ts-ignore
95
- PrintBarcode: window.objJS.printBarcode,
96
- // @ts-ignore
97
- CutPaper: window.objJS.cutPaper,
98
- // @ts-ignore
99
- PrintImage: window.objJS.printImage,
100
- // @ts-ignore
101
- CheckHealthPrinter: window.objJS.checkHealthPrinter,
102
- // @ts-ignore
103
- CheckHealth: window.objJS.checkHealth
104
- };
105
- }
106
- else {
107
- if (this.vars.idSmo) {
108
- this.id = this.vars.idSmo;
109
- if (this.vars["LowPower"] == "true" && (this.vars["url"] != undefined || this.vars["LocalData"] != undefined)) {
110
- this.smoCallBacks.onSmoLoad();
111
- return;
112
- }
113
- if (this.vars["url"] != undefined) {
114
- this.smoCallBacks.getFile(this.vars["url"]);
115
- this.intervalsubscriptionDataSource = this.intervalDataSource$.subscribe(function () {
116
- _this.smoCallBacks.getFile(_this.vars["url"]);
117
- });
118
- return;
119
- }
120
- if (this.vars["LocalData"] != undefined) {
121
- this.smoCallBacks.getLocalData(this.vars["LocalData"]);
122
- this.intervalsubscriptionDataSource = this.intervalDataSource$.subscribe(function () {
123
- _this.smoCallBacks.getLocalData(_this.vars["LocalData"]);
124
- });
125
- return;
126
- }
127
- return;
128
- }
129
- console.warn("No idSmo found in URL");
130
- }
131
- if (this.vars.idSmo) {
132
- this.id = this.vars.idSmo;
133
- return;
134
- }
135
- console.warn("No idSmo found in URL");
136
- };
137
- SMO.prototype.initOnMessage = function () {
138
- var selft = this;
139
- window.onmessage = function (e) {
140
- if (e.data.target) {
141
- var targets = e.data.target.split('.');
142
- var func = targets[targets.length - 1];
143
- if (func == SMO_EVENT_TYPE.start) {
144
- selft.start();
145
- return;
146
- }
147
- if (func == SMO_EVENT_TYPE.setDatasource) {
148
- selft.setDatasource(e.data.objData);
149
- return;
150
- }
151
- if (func == SMO_EVENT_TYPE.getVariable) {
152
- selft.getVariable(e.data.objData);
153
- return;
154
- }
155
- if (func == SMO_EVENT_TYPE.setCurrentStream) {
156
- selft.setCurrentStream(e.data.objData);
157
- return;
158
- }
159
- if (func == SMO_EVENT_TYPE.infoCurrentLocation) {
160
- selft.infoCurrentLocation(e.data.objData);
161
- return;
162
- }
163
- if (func == SMO_EVENT_TYPE.setSalidaData) {
164
- selft.setSalidaData(e.data.objData);
165
- return;
166
- }
167
- if (func == SMO_EVENT_TYPE.updatefromsalida) {
168
- selft.updatefromsalida(e.data.objData);
169
- return;
170
- }
171
- if (func == SMO_EVENT_TYPE.getRecursosByCodigo) {
172
- selft.getRecursosByCodigo(e.data.objData);
173
- return;
174
- }
175
- if (func == SMO_EVENT_TYPE.getRecursos) {
176
- selft.getRecursos(e.data.objData);
177
- }
178
- if (func == SMO_EVENT_TYPE.getRecursosDefault) {
179
- selft.getRecursosDefault(e.data.objData);
180
- }
181
- if (func == SMO_EVENT_TYPE.getRecursosRelleno) {
182
- selft.getRecursosRelleno(e.data.objData);
183
- return;
184
- }
185
- if (func == SMO_EVENT_TYPE.getVariableStorage) {
186
- selft.getVariableStorage(e.data.objData);
187
- return;
188
- }
189
- if (func == SMO_EVENT_TYPE.checkHealth) {
190
- selft.checkHealth(e.data.objData);
191
- return;
192
- }
193
- if (func == SMO_EVENT_TYPE.checkHealthPrinter) {
194
- selft.checkHealthPrinter(e.data.objData);
195
- return;
196
- }
197
- console.warn("message not implemented!!" + func);
198
- }
199
- };
200
- };
201
- SMO.prototype.start = function () {
202
- this.events.start.next({});
203
- };
204
- SMO.prototype.setDatasource = function (datasource) {
205
- this.events.setDatasource.next(datasource);
206
- this.events.setDatasourceJson.next(this.utils.xmlToJSON(datasource.xml));
207
- };
208
- SMO.prototype.getVariable = function (variable) {
209
- this.events.getVariable.next(variable);
210
- };
211
- SMO.prototype.setCurrentStream = function (stream) {
212
- this.events.setCurrentStream.next(stream);
213
- };
214
- SMO.prototype.infoCurrentLocation = function (location) {
215
- this.events.infoCurrentLocation.next(location);
216
- };
217
- SMO.prototype.setSalidaData = function (data) {
218
- this.events.setSalidaData.next(data);
219
- };
220
- SMO.prototype.updatefromsalida = function (data) {
221
- this.events.updatefromsalida.next(data);
222
- };
223
- SMO.prototype.getRecursosByCodigo = function (data) {
224
- this.events.getRecursosByCodigo.next(data);
225
- };
226
- SMO.prototype.getRecursos = function (data) {
227
- this.events.getRecursos.next(data);
228
- };
229
- SMO.prototype.getRecursosDefault = function (data) {
230
- this.events.getRecursosDefault.next(data);
231
- };
232
- SMO.prototype.getRecursosRelleno = function (data) {
233
- this.events.getRecursosRelleno.next(data);
234
- };
235
- SMO.prototype.getVariableStorage = function (variable) {
236
- this.events.getVariableStorage.next(variable);
237
- };
238
- SMO.prototype.checkHealth = function (json) {
239
- this.events.checkHealth.next(json);
240
- };
241
- SMO.prototype.checkHealthPrinter = function (json) {
242
- this.events.checkHealthPrinter.next(json);
243
- };
244
- return SMO;
245
- }());
246
- exports.SMO = SMO;
247
- var SmoEvents = /** @class */ (function () {
248
- function SmoEvents(smo) {
249
- this.start = new rxjs_1.Subject();
250
- this.setDatasource = new rxjs_1.Subject();
251
- this.setDatasourceJson = new rxjs_1.Subject();
252
- this.getVariable = new rxjs_1.Subject();
253
- this.setCurrentStream = new rxjs_1.Subject();
254
- this.infoCurrentLocation = new rxjs_1.Subject();
255
- this.setSalidaData = new rxjs_1.Subject();
256
- this.updatefromsalida = new rxjs_1.Subject();
257
- this.getRecursosByCodigo = new rxjs_1.Subject();
258
- this.getRecursos = new rxjs_1.Subject();
259
- this.getRecursosDefault = new rxjs_1.Subject();
260
- this.getRecursosRelleno = new rxjs_1.Subject();
261
- this.getVariableStorage = new rxjs_1.Subject();
262
- this.checkHealth = new rxjs_1.Subject();
263
- this.checkHealthPrinter = new rxjs_1.Subject();
264
- }
265
- return SmoEvents;
266
- }());
267
- var smoCallBacks = /** @class */ (function () {
268
- function smoCallBacks(_smo) {
269
- this.smo = _smo;
270
- }
271
- smoCallBacks.prototype.onSmoLoad = function () {
272
- this.smo.utils.sendToParent({
273
- target: "Dnv.smoCallbacks.onSmoLoad",
274
- objData: undefined,
275
- idSmo: this.smo.id
276
- }, "*");
277
- };
278
- smoCallBacks.prototype.onSmoReady = function () {
279
- this.smo.utils.sendToParent({
280
- target: "Dnv.smoCallbacks.onSmoReady",
281
- objData: undefined,
282
- idSmo: this.smo.id
283
- }, "*");
284
- };
285
- smoCallBacks.prototype.smoLog = function (msn, level) {
286
- if (level == undefined) {
287
- level = LogLevel.Info;
288
- }
289
- //level = Dnv.LogLevel.Debug...
290
- if (level == LogLevel.Debug) {
291
- console.debug(msn);
292
- }
293
- if (level == LogLevel.Info) {
294
- console.log(msn);
295
- }
296
- if (level == LogLevel.Warning) {
297
- console.warn(msn);
298
- }
299
- if (level == LogLevel.Error) {
300
- console.error(msn);
301
- }
302
- if (window.parent != window) {
303
- this.smo.utils.sendToParent({
304
- target: "Dnv.smoCallbacks.smoLog",
305
- objData: {
306
- level: level,
307
- txt: msn
308
- },
309
- idSmo: this.smo.id
310
- }, "*");
311
- }
312
- };
313
- smoCallBacks.prototype.smoAlarma = function (msn, level) {
314
- this.smo.utils.sendToParent({
315
- target: "Dnv.smoCallbacks.smoAlarma",
316
- objData: {
317
- level: level,
318
- txt: msn
319
- },
320
- idSmo: this.smo.id
321
- }, "*");
322
- };
323
- smoCallBacks.prototype.smoLogStash = function (msn) {
324
- this.smo.utils.sendToParent({
325
- target: "Dnv.smoCallbacks.smoLogStash",
326
- objData: {
327
- txt: msn
328
- },
329
- idSmo: this.smo.id
330
- }, "*");
331
- };
332
- smoCallBacks.prototype.smoLogNowShowing = function (msn) {
333
- this.smo.utils.sendToParent({
334
- target: "Dnv.smoCallbacks.smoNowShowing",
335
- objData: msn,
336
- idSmo: this.smo.id
337
- }, "*");
338
- };
339
- smoCallBacks.prototype.reiniciarDispositivo = function (msn) {
340
- //Permite reiniciar el player, proporcionando una razón para el reinicio. Solo Player HTML5
341
- this.smo.utils.sendToParent({
342
- target: "Dnv.smoCallbacks.reiniciarDispositivo",
343
- objData: {
344
- txt: msn // Razón del reinicio
345
- },
346
- idSmo: this.smo.id
347
- }, "*");
348
- };
349
- smoCallBacks.prototype.urlNext = function () {
350
- //Permite avanzar plantilla. Solo si Reloj Maestro activado.
351
- this.smo.utils.sendToParent({
352
- target: "Dnv.smoCallbacks.urlNext",
353
- objData: undefined,
354
- idSmo: this.smo.id
355
- }, "*");
356
- };
357
- smoCallBacks.prototype.exitInteractivity = function () {
358
- //Para canales interactivos, vuelve al canal de reposo. Solo Android y Player PC.
359
- this.smo.utils.sendToParent({
360
- target: "Dnv.smoCallbacks.exitInteractivity",
361
- objData: undefined,
362
- idSmo: this.smo.id
363
- }, "*");
364
- };
365
- smoCallBacks.prototype.showBrowser = function () {
366
- /* DEPRECATED NOT IMPLEMENTED */
367
- };
368
- smoCallBacks.prototype.closeBrowser = function () {
369
- /* DEPRECATED NOT IMPLEMENTED */
370
- };
371
- smoCallBacks.prototype.urlNextDirectamente = function () {
372
- /* NOT IMPLEMENTED */
373
- };
374
- smoCallBacks.prototype.setVariable = function (variable, valor) {
375
- this.smo.utils.sendToParent({
376
- target: "Dnv.smoCallbacks.setVariable",
377
- objData: {
378
- variable: variable,
379
- valor: valor
380
- },
381
- idSmo: this.smo.id
382
- }, "*");
383
- };
384
- smoCallBacks.prototype.getVariable = function (variable) {
385
- this.smo.utils.sendToParent({
386
- target: "Dnv.smoCallbacks.getVariable",
387
- objData: {
388
- variable: variable
389
- },
390
- idSmo: this.smo.id
391
- }, "*");
392
- /* MIRAR SMO.getVariable */
393
- };
394
- smoCallBacks.prototype.getFile = function (file) {
395
- this.smo.utils.sendToParent({
396
- target: "Dnv.smoCallbacks.getFile",
397
- objData: file,
398
- idSmo: this.smo.id
399
- }, "*");
400
- };
401
- smoCallBacks.prototype.setLocalData = function (variable, valor) {
402
- this.smo.utils.sendToParent({
403
- target: "Dnv.smoCallbacks.setLocalData",
404
- objData: {
405
- nameData: variable,
406
- data: valor
407
- },
408
- idSmo: this.smo.id
409
- }, "*");
410
- };
411
- smoCallBacks.prototype.getLocalData = function (variable) {
412
- this.smo.utils.sendToParent({
413
- target: "Dnv.smoCallbacks.getLocalData",
414
- objData: variable,
415
- idSmo: this.smo.id
416
- }, "*");
417
- /* MIRAR SMO.setDatasource */
418
- };
419
- smoCallBacks.prototype.getCurrentStream = function () {
420
- this.smo.utils.sendToParent({
421
- target: "Dnv.smoCallbacks.getCurrentStream",
422
- objData: undefined,
423
- idSmo: this.smo.id
424
- }, "*");
425
- /* MIRAR SMO.setCurrentStream' */
426
- };
427
- smoCallBacks.prototype.finAviso = function (id) {
428
- this.smo.utils.sendToParent({
429
- target: "Dnv.smoCallbacks.finAviso",
430
- objData: id,
431
- idSmo: this.smo.id
432
- }, "*");
433
- };
434
- smoCallBacks.prototype.refreshDatasource = function (codigo) {
435
- this.smo.utils.sendToParent({
436
- target: "Dnv.smoCallbacks.refreshDatasource",
437
- objData: codigo,
438
- idSmo: this.smo.id
439
- }, "*");
440
- };
441
- smoCallBacks.prototype.getLocation = function () {
442
- this.smo.utils.sendToParent({
443
- target: "Dnv.smoCallbacks.getLocation",
444
- objData: undefined,
445
- idSmo: this.smo.id
446
- }, "*");
447
- /* MIRAR SMO.infoCurrentLocation */
448
- };
449
- smoCallBacks.prototype.getSalidaData = function (data) {
450
- this.smo.utils.sendToParent({
451
- target: "Dnv.smoCallbacks.getSalidaData",
452
- objData: data,
453
- idSmo: this.smo.id
454
- }, "*");
455
- /* MIRAR SMO.setSalidaData */
456
- };
457
- smoCallBacks.prototype.ejecutaFuncion = function (data) {
458
- /*data ={
459
- funcion: "", // Nombre de la función que se debe ejecutar
460
- params: "" // Parámetros que debemos enviarle a la funcion. sin separadores ni nada, un string y se usa como tal. Solo esta implementada en un caso y se usa como tal sin parsear ni nada
461
- } */
462
- this.smo.utils.sendToParent({
463
- target: "Dnv.smoCallbacks.ejecutaFuncion",
464
- objData: data,
465
- idSmo: this.smo.id
466
- }, "*");
467
- };
468
- smoCallBacks.prototype.addObserver = function (data) {
469
- /*data ="fruta"
470
- */
471
- this.smo.utils.sendToParent({
472
- target: "Dnv.smoCallbacks.addObserver",
473
- objData: data,
474
- idSmo: this.smo.id
475
- }, "*");
476
- };
477
- smoCallBacks.prototype.notify = function (data) {
478
- /*data ={
479
- destino: "fruta",
480
- value: "{'fruta':'manzana', 'color':'roja'}"
481
- } */
482
- this.smo.utils.sendToParent({
483
- target: "Dnv.smoCallbacks.notify",
484
- objData: data,
485
- idSmo: this.smo.id
486
- }, "*");
487
- };
488
- smoCallBacks.prototype.playOnceChannelByTrigger = function (trigger) {
489
- this.smo.utils.sendToParent({
490
- target: "Dnv.smoCallbacks.playOnceChannelByTrigger",
491
- objData: { triggerCanal: trigger },
492
- idSmo: this.smo.id
493
- }, "*");
494
- };
495
- smoCallBacks.prototype.stopPlayOnceChannelByTrigger = function () {
496
- this.smo.utils.sendToParent({ target: "Dnv.smoCallbacks.stopPlayOnceChannelByTrigger", objData: {}, idSmo: this.smo.id }, "*");
497
- };
498
- smoCallBacks.prototype.playOnceChannel = function (codigoCanal) {
499
- this.smo.utils.sendToParent({ target: "Dnv.smoCallbacks.playOnceChannel", objData: { codigoCanal: codigoCanal, params: "PLAYONCE_CHANNEL|" + codigoCanal }, idSmo: this.smo.id }, "*");
500
- };
501
- smoCallBacks.prototype.stopPlayChannel = function () {
502
- this.smo.utils.sendToParent({ target: "Dnv.smoCallbacks.stopPlayOnceChannel", objData: {}, idSmo: this.smo.id }, "*");
503
- };
504
- smoCallBacks.prototype.editWrapperStyle = function (obj) {
505
- /*{"posX": "0px","posY": "0px","alto": "0px","ancho": "0px","overflow": "hidden","scale": 0.1,"zindex": 0.1,"opacidad": 0.1,"isMaestro": true,duracionTransition: "1s", transitionTiming: "lineal", css: string} */
506
- this.smo.utils.sendToParent({
507
- target: "Dnv.smoCallbacks.editWrapperStyle",
508
- objData: obj,
509
- idSmo: this.smo.id
510
- }, "*");
511
- };
512
- smoCallBacks.prototype.getRecursosByCodigo = function (codigos) {
513
- /** ["123456","654321"] */
514
- this.smo.utils.sendToParent({
515
- target: "Dnv.smoCallbacks.getRecursosByCodigo",
516
- objData: {
517
- recursos: codigos
518
- },
519
- idSmo: this.smo.id
520
- }, "*");
521
- };
522
- smoCallBacks.prototype.getRecursos = function () {
523
- this.smo.utils.sendToParent({
524
- target: "Dnv.smoCallbacks.getRecursos",
525
- idSmo: this.smo.id
526
- }, "*");
527
- };
528
- smoCallBacks.prototype.getRecursosDefault = function () {
529
- this.smo.utils.sendToParent({
530
- target: "Dnv.smoCallbacks.getRecursosDefault",
531
- idSmo: this.smo.id
532
- }, "*");
533
- };
534
- smoCallBacks.prototype.getRecursosRelleno = function () {
535
- this.smo.utils.sendToParent({
536
- target: "Dnv.smoCallbacks.getRecursosRelleno",
537
- idSmo: this.smo.id
538
- }, "*");
539
- };
540
- smoCallBacks.prototype.setVariableStorage = function (variable, valor) {
541
- this.smo.utils.sendToParent({
542
- target: "Dnv.smoCallbacks.setVariableStorage",
543
- objData: {
544
- variable: variable,
545
- valor: valor
546
- },
547
- idSmo: this.smo.id
548
- }, "*");
549
- };
550
- smoCallBacks.prototype.getVariableStorage = function (variable) {
551
- this.smo.utils.sendToParent({
552
- target: "Dnv.smoCallbacks.getVariableStorage",
553
- objData: {
554
- variable: variable
555
- },
556
- idSmo: this.smo.id
557
- }, "*");
558
- /* MIRAR SMO.getVariable */
559
- };
560
- smoCallBacks.prototype.printTextLine = function (txt) {
561
- this.smo.utils.sendToParent({
562
- target: "Dnv.smoCallbacks.printTextLine",
563
- objData: {
564
- txt: txt
565
- },
566
- idSmo: this.smo.id
567
- }, "*");
568
- };
569
- smoCallBacks.prototype.printBarcode = function (code, width, height) {
570
- this.smo.utils.sendToParent({
571
- target: "Dnv.smoCallbacks.printBarcode",
572
- objData: {
573
- code: code,
574
- width: width,
575
- height: height
576
- },
577
- idSmo: this.smo.id
578
- }, "*");
579
- };
580
- smoCallBacks.prototype.cutPaper = function (percent) {
581
- this.smo.utils.sendToParent({
582
- target: "Dnv.smoCallbacks.cutPaper",
583
- objData: {
584
- percent: percent
585
- },
586
- idSmo: this.smo.id
587
- }, "*");
588
- };
589
- smoCallBacks.prototype.checkHealth = function () {
590
- this.smo.utils.sendToParent({
591
- target: "Dnv.smoCallbacks.checkHealth",
592
- idSmo: this.smo.id
593
- }, "*");
594
- };
595
- smoCallBacks.prototype.checkHealthPrinter = function () {
596
- this.smo.utils.sendToParent({
597
- target: "Dnv.smoCallbacks.checkHealthPrinter",
598
- idSmo: this.smo.id
599
- }, "*");
600
- };
601
- smoCallBacks.prototype.printImage = function (image) {
602
- this.smo.utils.sendToParent({
603
- target: "Dnv.smoCallbacks.printImage",
604
- objData: {
605
- image: image
606
- },
607
- idSmo: this.smo.id
608
- }, "*");
609
- };
610
- return smoCallBacks;
611
- }());
612
- var Utils = /** @class */ (function () {
613
- function Utils(_smo, _smoCallBacks) {
614
- this.smo = _smo;
615
- this.smoCallBacks = _smoCallBacks;
616
- }
617
- // Funciones para XML to JSON
618
- Utils.prototype.xmlToJSON = function (xml) {
619
- var getxml = new DOMParser();
620
- var sinSaltosYTabulaciones = xml.replace(/[\n\r\t]/g, '');
621
- var sinEspaciosEntreTags = sinSaltosYTabulaciones.replace(/>\s*</g, '><');
622
- var xmlDoc = getxml.parseFromString(sinEspaciosEntreTags, "text/xml");
623
- // gets the JSON string
624
- var json_str = this.jsonToStr(this.setJsonObj(xmlDoc));
625
- // sets and returns the JSON object, if "rstr" undefined (not passed), else, returns JSON string
626
- return json_str;
627
- };
628
- Utils.prototype.jsonToStr = function (js_obj) {
629
- var rejsn = JSON.stringify(js_obj, undefined, 2).replace(/(\\t|\\r|\\n)/g, '').replace(/"",[\n\t\r\s]+""[,]*/g, '').replace(/(\n[\t\s\r]*\n)/g, '').replace(/[\s\t]{2,}""[,]{0,1}/g, '').replace(/"[\s\t]{1,}"[,]{0,1}/g, '').replace(/\[[\t\s]*\]/g, '""');
630
- return (rejsn.indexOf('"parsererror": {') == -1) ? rejsn : 'Invalid XML format';
631
- };
632
- Utils.prototype.sendToParent = function (obj, dest) {
633
- console.log('sendToParent->', JSON.stringify(obj));
634
- //@ts-ignore
635
- if (window.objJS) {
636
- switch (obj.target) {
637
- case "Dnv.smoCallbacks.onSmoLoad":
638
- // @ts-ignore
639
- window.objJS.onSmoLoad();
640
- break;
641
- case "Dnv.smoCallbacks.printTextLine":
642
- // @ts-ignore
643
- window.objJS.printTextLine(obj.objData.txt);
644
- break;
645
- case "Dnv.smoCallbacks.printBarcode":
646
- // @ts-ignore
647
- window.objJS.printBarcode(obj.objData.code, obj.objData.width, obj.objData.height);
648
- break;
649
- case "Dnv.smoCallbacks.cutPaper":
650
- // @ts-ignore
651
- window.objJS.cutPaper(obj.objData.percent);
652
- break;
653
- case "Dnv.smoCallbacks.printImage":
654
- // @ts-ignore
655
- window.objJS.printImage(obj.idSmo, obj.objData.image);
656
- break;
657
- case "Dnv.smoCallbacks.checkHealthPrinter":
658
- console.log('llamo a checkhealthprinter');
659
- // @ts-ignore
660
- window.objJS.checkHealthPrinter(obj.idSmo);
661
- break;
662
- case "Dnv.smoCallbacks.checkHealth":
663
- // @ts-ignore
664
- window.objJS.checkHealth();
665
- break;
666
- case "Dnv.smoCallbacks.getFile":
667
- // @ts-ignore
668
- window.objJS.getFile(dest, obj.objData);
669
- break;
670
- }
671
- return;
672
- }
673
- /* // @ts-ignore
674
- window.parent.postMessage = (target,objData,idSmo)=> {
675
- switch (target.target) {
676
- case "Dnv.smoCallbacks.onSmoLoad":
677
- // @ts-ignore
678
- window.objJS.onSmoLoad();
679
- break;
680
-
681
- case "Dnv.smoCallbacks.printTextLine":
682
- // @ts-ignore
683
- window.objJS.printTextLine(objData.txt);
684
- break;
685
- case "Dnv.smoCallbacks.printBarcode":
686
- // @ts-ignore
687
- window.objJS.printBarcode(objData.code, objData.width, objData.height);
688
- break;
689
- case "Dnv.smoCallbacks.cutPaper":
690
- // @ts-ignore
691
- window.objJS.cutPaper(objData.percent);
692
- break;
693
- case "Dnv.smoCallbacks.printImage":
694
- // @ts-ignore
695
- window.objJS.printImage(idSmo, objData.image);
696
- break;
697
- case "Dnv.smoCallbacks.checkHealthPrinter":
698
- console.log('llamo a checkhealthprinter');
699
- // @ts-ignore
700
-
701
- window.objJS.checkHealthPrinter(idSmo);
702
- break;
703
- case "Dnv.smoCallbacks.checkHealth":
704
- // @ts-ignore
705
- window.objJS.checkHealth();
706
- break;
707
-
708
-
709
- }
710
- }*/
711
- window.parent.postMessage(obj, dest);
712
- };
713
- Utils.prototype.setJsonObj = function (xml) {
714
- var js_obj = {};
715
- if (xml.nodeType == 1) { // Element
716
- if (xml.attributes.length > 0) {
717
- js_obj["@attributes"] = {};
718
- for (var j = 0; j < xml.attributes.length; j++) {
719
- var attribute = xml.attributes.item(j);
720
- js_obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
721
- }
722
- }
723
- }
724
- else if (xml.nodeType == 3) { // Text
725
- js_obj = xml.nodeValue;
726
- }
727
- else if (xml.nodeType == 4) { // CDATA
728
- js_obj = xml.nodeValue;
729
- }
730
- if (xml.hasChildNodes()) {
731
- for (var i = 0; i < xml.childNodes.length; i++) {
732
- var item = xml.childNodes.item(i);
733
- var nodeName = item.nodeName;
734
- if (typeof (js_obj[nodeName]) == "undefined") {
735
- js_obj[nodeName] = this.setJsonObj(item);
736
- }
737
- else {
738
- if (typeof (js_obj[nodeName].push) == "undefined") {
739
- var old = js_obj[nodeName];
740
- js_obj[nodeName] = [];
741
- js_obj[nodeName].push(old);
742
- }
743
- js_obj[nodeName].push(this.setJsonObj(item));
744
- }
745
- }
746
- }
747
- return js_obj;
748
- };
749
- Utils.prototype.dataToJSON = function (data) {
750
- try {
751
- var parser = new DOMParser();
752
- var xmlDoc = parser.parseFromString(data.xml, "text/xml");
753
- var dataForJSON = xmlDoc.getElementsByTagName("item")[0].innerHTML;
754
- dataForJSON = dataForJSON.replace(/{'/g, '{"').replace(/'}/g, '"}').replace(/:'/g, ':"').replace(/':/g, '":').replace(/,'/g, ',"').replace(/',/g, '",').replace(/\['/g, '["').replace(/'\]/g, '"]').replace(/(\r\n|\n|\r)/gm, "");
755
- return JSON.parse(dataForJSON);
756
- }
757
- catch (error) {
758
- return {};
759
- }
760
- };
761
- return Utils;
762
- }());
763
- var SMO_EVENT_TYPE;
764
- (function (SMO_EVENT_TYPE) {
765
- SMO_EVENT_TYPE["start"] = "start";
766
- SMO_EVENT_TYPE["setDatasource"] = "setDatasource";
767
- SMO_EVENT_TYPE["getVariable"] = "getVariable";
768
- SMO_EVENT_TYPE["setCurrentStream"] = "setCurrentStream";
769
- SMO_EVENT_TYPE["infoCurrentLocation"] = "infoCurrentLocation";
770
- SMO_EVENT_TYPE["setSalidaData"] = "setSalidaData";
771
- SMO_EVENT_TYPE["updatefromsalida"] = "updatefromsalida";
772
- SMO_EVENT_TYPE["setDatasourceJson"] = "setDatasourceJson";
773
- SMO_EVENT_TYPE["getRecursosByCodigo"] = "getRecursosByCodigo";
774
- SMO_EVENT_TYPE["getRecursos"] = "getRecursos";
775
- SMO_EVENT_TYPE["getRecursosDefault"] = "getRecursosDefault";
776
- SMO_EVENT_TYPE["getRecursosRelleno"] = "getRecursosRelleno";
777
- SMO_EVENT_TYPE["getVariableStorage"] = "getVariableStorage";
778
- SMO_EVENT_TYPE["checkHealth"] = "checkHealth";
779
- SMO_EVENT_TYPE["checkHealthPrinter"] = "checkHealthPrinter";
780
- })(SMO_EVENT_TYPE = exports.SMO_EVENT_TYPE || (exports.SMO_EVENT_TYPE = {}));
781
- var LogLevel;
782
- (function (LogLevel) {
783
- LogLevel[LogLevel["Debug"] = 0] = "Debug";
784
- LogLevel[LogLevel["Info"] = 1] = "Info";
785
- LogLevel[LogLevel["Warning"] = 2] = "Warning";
786
- LogLevel[LogLevel["Error"] = 3] = "Error";
787
- })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
788
- var AlarmaLevel;
789
- (function (AlarmaLevel) {
790
- AlarmaLevel[AlarmaLevel["Ok_off"] = 0] = "Ok_off";
791
- AlarmaLevel[AlarmaLevel["Ok"] = 1] = "Ok";
792
- AlarmaLevel[AlarmaLevel["Scanning"] = 2] = "Scanning";
793
- AlarmaLevel[AlarmaLevel["Timeout"] = 3] = "Timeout";
794
- AlarmaLevel[AlarmaLevel["Warning"] = 4] = "Warning";
795
- AlarmaLevel[AlarmaLevel["Error"] = 5] = "Error";
796
- })(AlarmaLevel = exports.AlarmaLevel || (exports.AlarmaLevel = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlarmaLevel = exports.LogLevel = exports.SMO_EVENT_TYPE = exports.SMO = void 0;
4
+ var rxjs_1 = require("rxjs");
5
+ // @ts-ignore
6
+ var SMO = /** @class */ (function () {
7
+ function SMO() {
8
+ this.vars = {};
9
+ this.id = "";
10
+ this.intervalDataSource$ = (0, rxjs_1.interval)(5 * 60 * 1000);
11
+ this.initOnMessage();
12
+ this.smoCallBacks = new smoCallBacks(this);
13
+ this.utils = new Utils(this, this.smoCallBacks);
14
+ this.events = new SmoEvents(this);
15
+ this.init();
16
+ }
17
+ SMO.prototype.init = function () {
18
+ var _this = this;
19
+ var match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function (s) {
20
+ return decodeURIComponent(s.replace(pl, " "));
21
+ }, query = window.location.search.substring(1);
22
+ while (match = search.exec(query)) {
23
+ this.vars[decode(match[1])] = decode(match[2]);
24
+ }
25
+ // @ts-ignore
26
+ if (window.objJS && window.self === window.top) {
27
+ // @ts-ignore
28
+ console.log("Existe objJS en window -->" + JSON.stringify(window.objJS));
29
+ // @ts-ignore
30
+ window.sendToIframefromNet = function (target, iframeID, objData) {
31
+ console.log("sendToIframefromNet->", JSON.stringify(target));
32
+ switch (target) {
33
+ case "SMO.setDatasource":
34
+ _this.events.setDatasource.next(objData);
35
+ break;
36
+ case "SMO.checkHealthPrinter":
37
+ _this.events.checkHealthPrinter.next(objData);
38
+ break;
39
+ }
40
+ };
41
+ // @ts-ignore
42
+ window.external = {
43
+ // @ts-ignore
44
+ URLNext: window.objJS.urlNext,
45
+ // @ts-ignore
46
+ LimpiaCapa: window.objJS.limpiaCapa,
47
+ // @ts-ignore
48
+ LogFlash: window.objJS.logFlash,
49
+ // @ts-ignore
50
+ PageInit: window.objJS.pageInit,
51
+ // @ts-ignore
52
+ FinAviso: window.objJS.finAviso,
53
+ // @ts-ignore
54
+ ExitInteractivity: window.objJS.exitInteractivity,
55
+ // @ts-ignore
56
+ LogWeb: window.objJS.logWeb,
57
+ // @ts-ignore
58
+ RefreshPage: window.objJS.refreshPage,
59
+ // @ts-ignore
60
+ RefreshPageByError: window.objJS.refreshPageByError,
61
+ // @ts-ignore
62
+ RefreshPageByVideoEvent: window.objJS.refreshPageByVideoEvent,
63
+ // @ts-ignore
64
+ AuditarRecurso: window.objJS.auditarRecurso,
65
+ // @ts-ignore
66
+ InitSMO: window.objJS.initSMO,
67
+ // @ts-ignore
68
+ GetFile: window.objJS.getFile,
69
+ // @ts-ignore
70
+ ShowBrowser: window.objJS.showBrowser,
71
+ // @ts-ignore
72
+ closeBrowser: window.objJS.closeBrowser,
73
+ // @ts-ignore
74
+ RefreshDataSource: window.objJS.refreshDataSource,
75
+ // @ts-ignore
76
+ SetVariable: window.objJS.setVariable,
77
+ // @ts-ignore
78
+ GetVariable: window.objJS.getVariable,
79
+ // @ts-ignore
80
+ GetLocation: window.objJS.getLocation,
81
+ // @ts-ignore
82
+ SalirApp: window.objJS.salirApp,
83
+ // @ts-ignore
84
+ SetLocalData: window.objJS.setLocalData,
85
+ // @ts-ignore
86
+ GetLocalData: window.objJS.getLocalData,
87
+ // @ts-ignore
88
+ GetSalidaData: window.objJS.getSalidaData,
89
+ // @ts-ignore
90
+ EjecutaFuncion: window.objJS.ejecutaFuncion,
91
+ // @ts-ignore
92
+ AddObserver: window.objJS.addObserver,
93
+ // @ts-ignore
94
+ NotifyToObservers: window.objJS.notifyToObservers,
95
+ // @ts-ignore
96
+ PrintTextLine: window.objJS.printTextLine,
97
+ // @ts-ignore
98
+ PrintBarcode: window.objJS.printBarcode,
99
+ // @ts-ignore
100
+ CutPaper: window.objJS.cutPaper,
101
+ // @ts-ignore
102
+ PrintImage: window.objJS.printImage,
103
+ // @ts-ignore
104
+ CheckHealthPrinter: window.objJS.checkHealthPrinter,
105
+ // @ts-ignore
106
+ CheckHealth: window.objJS.checkHealth
107
+ };
108
+ }
109
+ else {
110
+ console.log("No existe objJS en window");
111
+ if (this.vars.idSmo) {
112
+ this.id = this.vars.idSmo;
113
+ if (this.vars["LowPower"] == "true" && (this.vars["url"] != undefined || this.vars["LocalData"] != undefined)) {
114
+ this.smoCallBacks.onSmoLoad();
115
+ return;
116
+ }
117
+ if (this.vars["url"] != undefined) {
118
+ this.smoCallBacks.getFile(this.vars["url"]);
119
+ this.intervalsubscriptionDataSource = this.intervalDataSource$.subscribe(function () {
120
+ _this.smoCallBacks.getFile(_this.vars["url"]);
121
+ });
122
+ return;
123
+ }
124
+ if (this.vars["LocalData"] != undefined) {
125
+ this.smoCallBacks.getLocalData(this.vars["LocalData"]);
126
+ this.intervalsubscriptionDataSource = this.intervalDataSource$.subscribe(function () {
127
+ _this.smoCallBacks.getLocalData(_this.vars["LocalData"]);
128
+ });
129
+ return;
130
+ }
131
+ return;
132
+ }
133
+ console.warn("No idSmo found in URL");
134
+ return;
135
+ }
136
+ if (this.vars.idSmo) {
137
+ this.id = this.vars.idSmo;
138
+ return;
139
+ }
140
+ console.warn("No idSmo found in URL");
141
+ };
142
+ SMO.prototype.initOnMessage = function () {
143
+ var selft = this;
144
+ window.onmessage = function (e) {
145
+ if (e.data.target) {
146
+ var targets = e.data.target.split('.');
147
+ var func = targets[targets.length - 1];
148
+ if (func == SMO_EVENT_TYPE.start) {
149
+ selft.start();
150
+ return;
151
+ }
152
+ if (func == SMO_EVENT_TYPE.setDatasource) {
153
+ selft.setDatasource(e.data.objData);
154
+ return;
155
+ }
156
+ if (func == SMO_EVENT_TYPE.getVariable) {
157
+ selft.getVariable(e.data.objData);
158
+ return;
159
+ }
160
+ if (func == SMO_EVENT_TYPE.setCurrentStream) {
161
+ selft.setCurrentStream(e.data.objData);
162
+ return;
163
+ }
164
+ if (func == SMO_EVENT_TYPE.infoCurrentLocation) {
165
+ selft.infoCurrentLocation(e.data.objData);
166
+ return;
167
+ }
168
+ if (func == SMO_EVENT_TYPE.setSalidaData) {
169
+ selft.setSalidaData(e.data.objData);
170
+ return;
171
+ }
172
+ if (func == SMO_EVENT_TYPE.updatefromsalida) {
173
+ selft.updatefromsalida(e.data.objData);
174
+ return;
175
+ }
176
+ if (func == SMO_EVENT_TYPE.getRecursosByCodigo) {
177
+ selft.getRecursosByCodigo(e.data.objData);
178
+ return;
179
+ }
180
+ if (func == SMO_EVENT_TYPE.getRecursos) {
181
+ selft.getRecursos(e.data.objData);
182
+ }
183
+ if (func == SMO_EVENT_TYPE.getRecursosDefault) {
184
+ selft.getRecursosDefault(e.data.objData);
185
+ }
186
+ if (func == SMO_EVENT_TYPE.getRecursosRelleno) {
187
+ selft.getRecursosRelleno(e.data.objData);
188
+ return;
189
+ }
190
+ if (func == SMO_EVENT_TYPE.getVariableStorage) {
191
+ selft.getVariableStorage(e.data.objData);
192
+ return;
193
+ }
194
+ if (func == SMO_EVENT_TYPE.checkHealth) {
195
+ selft.checkHealth(e.data.objData);
196
+ return;
197
+ }
198
+ if (func == SMO_EVENT_TYPE.checkHealthPrinter) {
199
+ selft.checkHealthPrinter(e.data.objData);
200
+ return;
201
+ }
202
+ console.warn("message not implemented!!" + func);
203
+ }
204
+ };
205
+ };
206
+ SMO.prototype.start = function () {
207
+ this.events.start.next({});
208
+ };
209
+ SMO.prototype.setDatasource = function (datasource) {
210
+ this.events.setDatasource.next(datasource);
211
+ this.events.setDatasourceJson.next(this.utils.xmlToJSON(datasource.xml));
212
+ };
213
+ SMO.prototype.getVariable = function (variable) {
214
+ this.events.getVariable.next(variable);
215
+ };
216
+ SMO.prototype.setCurrentStream = function (stream) {
217
+ this.events.setCurrentStream.next(stream);
218
+ };
219
+ SMO.prototype.infoCurrentLocation = function (location) {
220
+ this.events.infoCurrentLocation.next(location);
221
+ };
222
+ SMO.prototype.setSalidaData = function (data) {
223
+ this.events.setSalidaData.next(data);
224
+ };
225
+ SMO.prototype.updatefromsalida = function (data) {
226
+ this.events.updatefromsalida.next(data);
227
+ };
228
+ SMO.prototype.getRecursosByCodigo = function (data) {
229
+ this.events.getRecursosByCodigo.next(data);
230
+ };
231
+ SMO.prototype.getRecursos = function (data) {
232
+ this.events.getRecursos.next(data);
233
+ };
234
+ SMO.prototype.getRecursosDefault = function (data) {
235
+ this.events.getRecursosDefault.next(data);
236
+ };
237
+ SMO.prototype.getRecursosRelleno = function (data) {
238
+ this.events.getRecursosRelleno.next(data);
239
+ };
240
+ SMO.prototype.getVariableStorage = function (variable) {
241
+ this.events.getVariableStorage.next(variable);
242
+ };
243
+ SMO.prototype.checkHealth = function (json) {
244
+ this.events.checkHealth.next(json);
245
+ };
246
+ SMO.prototype.checkHealthPrinter = function (json) {
247
+ this.events.checkHealthPrinter.next(json);
248
+ };
249
+ return SMO;
250
+ }());
251
+ exports.SMO = SMO;
252
+ var SmoEvents = /** @class */ (function () {
253
+ function SmoEvents(smo) {
254
+ this.start = new rxjs_1.Subject();
255
+ this.setDatasource = new rxjs_1.Subject();
256
+ this.setDatasourceJson = new rxjs_1.Subject();
257
+ this.getVariable = new rxjs_1.Subject();
258
+ this.setCurrentStream = new rxjs_1.Subject();
259
+ this.infoCurrentLocation = new rxjs_1.Subject();
260
+ this.setSalidaData = new rxjs_1.Subject();
261
+ this.updatefromsalida = new rxjs_1.Subject();
262
+ this.getRecursosByCodigo = new rxjs_1.Subject();
263
+ this.getRecursos = new rxjs_1.Subject();
264
+ this.getRecursosDefault = new rxjs_1.Subject();
265
+ this.getRecursosRelleno = new rxjs_1.Subject();
266
+ this.getVariableStorage = new rxjs_1.Subject();
267
+ this.checkHealth = new rxjs_1.Subject();
268
+ this.checkHealthPrinter = new rxjs_1.Subject();
269
+ }
270
+ return SmoEvents;
271
+ }());
272
+ var smoCallBacks = /** @class */ (function () {
273
+ function smoCallBacks(_smo) {
274
+ this.smo = _smo;
275
+ }
276
+ smoCallBacks.prototype.onSmoLoad = function () {
277
+ this.smo.utils.sendToParent({
278
+ target: "Dnv.smoCallbacks.onSmoLoad",
279
+ objData: undefined,
280
+ idSmo: this.smo.id
281
+ }, "*");
282
+ };
283
+ smoCallBacks.prototype.onSmoReady = function () {
284
+ this.smo.utils.sendToParent({
285
+ target: "Dnv.smoCallbacks.onSmoReady",
286
+ objData: undefined,
287
+ idSmo: this.smo.id
288
+ }, "*");
289
+ };
290
+ smoCallBacks.prototype.smoLog = function (msn, level) {
291
+ if (level == undefined) {
292
+ level = LogLevel.Info;
293
+ }
294
+ //level = Dnv.LogLevel.Debug...
295
+ if (level == LogLevel.Debug) {
296
+ console.debug(msn);
297
+ }
298
+ if (level == LogLevel.Info) {
299
+ console.log(msn);
300
+ }
301
+ if (level == LogLevel.Warning) {
302
+ console.warn(msn);
303
+ }
304
+ if (level == LogLevel.Error) {
305
+ console.error(msn);
306
+ }
307
+ if (window.parent != window) {
308
+ this.smo.utils.sendToParent({
309
+ target: "Dnv.smoCallbacks.smoLog",
310
+ objData: {
311
+ level: level,
312
+ txt: msn
313
+ },
314
+ idSmo: this.smo.id
315
+ }, "*");
316
+ }
317
+ };
318
+ smoCallBacks.prototype.smoAlarma = function (msn, level) {
319
+ this.smo.utils.sendToParent({
320
+ target: "Dnv.smoCallbacks.smoAlarma",
321
+ objData: {
322
+ level: level,
323
+ txt: msn
324
+ },
325
+ idSmo: this.smo.id
326
+ }, "*");
327
+ };
328
+ smoCallBacks.prototype.smoLogStash = function (msn) {
329
+ this.smo.utils.sendToParent({
330
+ target: "Dnv.smoCallbacks.smoLogStash",
331
+ objData: {
332
+ txt: msn
333
+ },
334
+ idSmo: this.smo.id
335
+ }, "*");
336
+ };
337
+ smoCallBacks.prototype.smoLogNowShowing = function (msn) {
338
+ this.smo.utils.sendToParent({
339
+ target: "Dnv.smoCallbacks.smoNowShowing",
340
+ objData: msn,
341
+ idSmo: this.smo.id
342
+ }, "*");
343
+ };
344
+ smoCallBacks.prototype.reiniciarDispositivo = function (msn) {
345
+ //Permite reiniciar el player, proporcionando una razón para el reinicio. Solo Player HTML5
346
+ this.smo.utils.sendToParent({
347
+ target: "Dnv.smoCallbacks.reiniciarDispositivo",
348
+ objData: {
349
+ txt: msn // Razón del reinicio
350
+ },
351
+ idSmo: this.smo.id
352
+ }, "*");
353
+ };
354
+ smoCallBacks.prototype.urlNext = function () {
355
+ //Permite avanzar plantilla. Solo si Reloj Maestro activado.
356
+ this.smo.utils.sendToParent({
357
+ target: "Dnv.smoCallbacks.urlNext",
358
+ objData: undefined,
359
+ idSmo: this.smo.id
360
+ }, "*");
361
+ };
362
+ smoCallBacks.prototype.exitInteractivity = function () {
363
+ //Para canales interactivos, vuelve al canal de reposo. Solo Android y Player PC.
364
+ this.smo.utils.sendToParent({
365
+ target: "Dnv.smoCallbacks.exitInteractivity",
366
+ objData: undefined,
367
+ idSmo: this.smo.id
368
+ }, "*");
369
+ };
370
+ smoCallBacks.prototype.showBrowser = function () {
371
+ /* DEPRECATED NOT IMPLEMENTED */
372
+ };
373
+ smoCallBacks.prototype.closeBrowser = function () {
374
+ /* DEPRECATED NOT IMPLEMENTED */
375
+ };
376
+ smoCallBacks.prototype.urlNextDirectamente = function () {
377
+ /* NOT IMPLEMENTED */
378
+ };
379
+ smoCallBacks.prototype.setVariable = function (variable, valor) {
380
+ this.smo.utils.sendToParent({
381
+ target: "Dnv.smoCallbacks.setVariable",
382
+ objData: {
383
+ variable: variable,
384
+ valor: valor
385
+ },
386
+ idSmo: this.smo.id
387
+ }, "*");
388
+ };
389
+ smoCallBacks.prototype.getVariable = function (variable) {
390
+ this.smo.utils.sendToParent({
391
+ target: "Dnv.smoCallbacks.getVariable",
392
+ objData: {
393
+ variable: variable
394
+ },
395
+ idSmo: this.smo.id
396
+ }, "*");
397
+ /* MIRAR SMO.getVariable */
398
+ };
399
+ smoCallBacks.prototype.getFile = function (file) {
400
+ this.smo.utils.sendToParent({
401
+ target: "Dnv.smoCallbacks.getFile",
402
+ objData: file,
403
+ idSmo: this.smo.id
404
+ }, "*");
405
+ };
406
+ smoCallBacks.prototype.setLocalData = function (variable, valor) {
407
+ this.smo.utils.sendToParent({
408
+ target: "Dnv.smoCallbacks.setLocalData",
409
+ objData: {
410
+ nameData: variable,
411
+ data: valor
412
+ },
413
+ idSmo: this.smo.id
414
+ }, "*");
415
+ };
416
+ smoCallBacks.prototype.getLocalData = function (variable) {
417
+ this.smo.utils.sendToParent({
418
+ target: "Dnv.smoCallbacks.getLocalData",
419
+ objData: variable,
420
+ idSmo: this.smo.id
421
+ }, "*");
422
+ /* MIRAR SMO.setDatasource */
423
+ };
424
+ smoCallBacks.prototype.getCurrentStream = function () {
425
+ this.smo.utils.sendToParent({
426
+ target: "Dnv.smoCallbacks.getCurrentStream",
427
+ objData: undefined,
428
+ idSmo: this.smo.id
429
+ }, "*");
430
+ /* MIRAR SMO.setCurrentStream' */
431
+ };
432
+ smoCallBacks.prototype.finAviso = function (id) {
433
+ this.smo.utils.sendToParent({
434
+ target: "Dnv.smoCallbacks.finAviso",
435
+ objData: id,
436
+ idSmo: this.smo.id
437
+ }, "*");
438
+ };
439
+ smoCallBacks.prototype.refreshDatasource = function (codigo) {
440
+ this.smo.utils.sendToParent({
441
+ target: "Dnv.smoCallbacks.refreshDatasource",
442
+ objData: codigo,
443
+ idSmo: this.smo.id
444
+ }, "*");
445
+ };
446
+ smoCallBacks.prototype.getLocation = function () {
447
+ this.smo.utils.sendToParent({
448
+ target: "Dnv.smoCallbacks.getLocation",
449
+ objData: undefined,
450
+ idSmo: this.smo.id
451
+ }, "*");
452
+ /* MIRAR SMO.infoCurrentLocation */
453
+ };
454
+ smoCallBacks.prototype.getSalidaData = function (data) {
455
+ this.smo.utils.sendToParent({
456
+ target: "Dnv.smoCallbacks.getSalidaData",
457
+ objData: data,
458
+ idSmo: this.smo.id
459
+ }, "*");
460
+ /* MIRAR SMO.setSalidaData */
461
+ };
462
+ smoCallBacks.prototype.ejecutaFuncion = function (data) {
463
+ /*data ={
464
+ funcion: "", // Nombre de la función que se debe ejecutar
465
+ params: "" // Parámetros que debemos enviarle a la funcion. sin separadores ni nada, un string y se usa como tal. Solo esta implementada en un caso y se usa como tal sin parsear ni nada
466
+ } */
467
+ this.smo.utils.sendToParent({
468
+ target: "Dnv.smoCallbacks.ejecutaFuncion",
469
+ objData: data,
470
+ idSmo: this.smo.id
471
+ }, "*");
472
+ };
473
+ smoCallBacks.prototype.addObserver = function (data) {
474
+ /*data ="fruta"
475
+ */
476
+ this.smo.utils.sendToParent({
477
+ target: "Dnv.smoCallbacks.addObserver",
478
+ objData: data,
479
+ idSmo: this.smo.id
480
+ }, "*");
481
+ };
482
+ smoCallBacks.prototype.notify = function (data) {
483
+ /*data ={
484
+ destino: "fruta",
485
+ value: "{'fruta':'manzana', 'color':'roja'}"
486
+ } */
487
+ this.smo.utils.sendToParent({
488
+ target: "Dnv.smoCallbacks.notify",
489
+ objData: data,
490
+ idSmo: this.smo.id
491
+ }, "*");
492
+ };
493
+ smoCallBacks.prototype.playOnceChannelByTrigger = function (trigger) {
494
+ this.smo.utils.sendToParent({
495
+ target: "Dnv.smoCallbacks.playOnceChannelByTrigger",
496
+ objData: { triggerCanal: trigger },
497
+ idSmo: this.smo.id
498
+ }, "*");
499
+ };
500
+ smoCallBacks.prototype.stopPlayOnceChannelByTrigger = function () {
501
+ this.smo.utils.sendToParent({ target: "Dnv.smoCallbacks.stopPlayOnceChannelByTrigger", objData: {}, idSmo: this.smo.id }, "*");
502
+ };
503
+ smoCallBacks.prototype.playOnceChannel = function (codigoCanal) {
504
+ this.smo.utils.sendToParent({ target: "Dnv.smoCallbacks.playOnceChannel", objData: { codigoCanal: codigoCanal, params: "PLAYONCE_CHANNEL|" + codigoCanal }, idSmo: this.smo.id }, "*");
505
+ };
506
+ smoCallBacks.prototype.stopPlayChannel = function () {
507
+ this.smo.utils.sendToParent({ target: "Dnv.smoCallbacks.stopPlayOnceChannel", objData: {}, idSmo: this.smo.id }, "*");
508
+ };
509
+ smoCallBacks.prototype.editWrapperStyle = function (obj) {
510
+ /*{"posX": "0px","posY": "0px","alto": "0px","ancho": "0px","overflow": "hidden","scale": 0.1,"zindex": 0.1,"opacidad": 0.1,"isMaestro": true,duracionTransition: "1s", transitionTiming: "lineal", css: string} */
511
+ this.smo.utils.sendToParent({
512
+ target: "Dnv.smoCallbacks.editWrapperStyle",
513
+ objData: obj,
514
+ idSmo: this.smo.id
515
+ }, "*");
516
+ };
517
+ smoCallBacks.prototype.getRecursosByCodigo = function (codigos) {
518
+ /** ["123456","654321"] */
519
+ this.smo.utils.sendToParent({
520
+ target: "Dnv.smoCallbacks.getRecursosByCodigo",
521
+ objData: {
522
+ recursos: codigos
523
+ },
524
+ idSmo: this.smo.id
525
+ }, "*");
526
+ };
527
+ smoCallBacks.prototype.getRecursos = function () {
528
+ this.smo.utils.sendToParent({
529
+ target: "Dnv.smoCallbacks.getRecursos",
530
+ idSmo: this.smo.id
531
+ }, "*");
532
+ };
533
+ smoCallBacks.prototype.getRecursosDefault = function () {
534
+ this.smo.utils.sendToParent({
535
+ target: "Dnv.smoCallbacks.getRecursosDefault",
536
+ idSmo: this.smo.id
537
+ }, "*");
538
+ };
539
+ smoCallBacks.prototype.getRecursosRelleno = function () {
540
+ this.smo.utils.sendToParent({
541
+ target: "Dnv.smoCallbacks.getRecursosRelleno",
542
+ idSmo: this.smo.id
543
+ }, "*");
544
+ };
545
+ smoCallBacks.prototype.setVariableStorage = function (variable, valor) {
546
+ this.smo.utils.sendToParent({
547
+ target: "Dnv.smoCallbacks.setVariableStorage",
548
+ objData: {
549
+ variable: variable,
550
+ valor: valor
551
+ },
552
+ idSmo: this.smo.id
553
+ }, "*");
554
+ };
555
+ smoCallBacks.prototype.getVariableStorage = function (variable) {
556
+ this.smo.utils.sendToParent({
557
+ target: "Dnv.smoCallbacks.getVariableStorage",
558
+ objData: {
559
+ variable: variable
560
+ },
561
+ idSmo: this.smo.id
562
+ }, "*");
563
+ /* MIRAR SMO.getVariable */
564
+ };
565
+ smoCallBacks.prototype.printTextLine = function (txt) {
566
+ this.smo.utils.sendToParent({
567
+ target: "Dnv.smoCallbacks.printTextLine",
568
+ objData: {
569
+ txt: txt
570
+ },
571
+ idSmo: this.smo.id
572
+ }, "*");
573
+ };
574
+ smoCallBacks.prototype.printBarcode = function (code, width, height) {
575
+ this.smo.utils.sendToParent({
576
+ target: "Dnv.smoCallbacks.printBarcode",
577
+ objData: {
578
+ code: code,
579
+ width: width,
580
+ height: height
581
+ },
582
+ idSmo: this.smo.id
583
+ }, "*");
584
+ };
585
+ smoCallBacks.prototype.cutPaper = function (percent) {
586
+ this.smo.utils.sendToParent({
587
+ target: "Dnv.smoCallbacks.cutPaper",
588
+ objData: {
589
+ percent: percent
590
+ },
591
+ idSmo: this.smo.id
592
+ }, "*");
593
+ };
594
+ smoCallBacks.prototype.checkHealth = function () {
595
+ this.smo.utils.sendToParent({
596
+ target: "Dnv.smoCallbacks.checkHealth",
597
+ idSmo: this.smo.id
598
+ }, "*");
599
+ };
600
+ smoCallBacks.prototype.checkHealthPrinter = function () {
601
+ this.smo.utils.sendToParent({
602
+ target: "Dnv.smoCallbacks.checkHealthPrinter",
603
+ idSmo: this.smo.id
604
+ }, "*");
605
+ };
606
+ smoCallBacks.prototype.printImage = function (image) {
607
+ this.smo.utils.sendToParent({
608
+ target: "Dnv.smoCallbacks.printImage",
609
+ objData: {
610
+ image: image
611
+ },
612
+ idSmo: this.smo.id
613
+ }, "*");
614
+ };
615
+ return smoCallBacks;
616
+ }());
617
+ var Utils = /** @class */ (function () {
618
+ function Utils(_smo, _smoCallBacks) {
619
+ this.smo = _smo;
620
+ this.smoCallBacks = _smoCallBacks;
621
+ }
622
+ // Funciones para XML to JSON
623
+ Utils.prototype.xmlToJSON = function (xml) {
624
+ var getxml = new DOMParser();
625
+ var sinSaltosYTabulaciones = xml.replace(/[\n\r\t]/g, '');
626
+ var sinEspaciosEntreTags = sinSaltosYTabulaciones.replace(/>\s*</g, '><');
627
+ var xmlDoc = getxml.parseFromString(sinEspaciosEntreTags, "text/xml");
628
+ // gets the JSON string
629
+ var json_str = this.jsonToStr(this.setJsonObj(xmlDoc));
630
+ // sets and returns the JSON object, if "rstr" undefined (not passed), else, returns JSON string
631
+ return json_str;
632
+ };
633
+ Utils.prototype.jsonToStr = function (js_obj) {
634
+ var rejsn = JSON.stringify(js_obj, undefined, 2).replace(/(\\t|\\r|\\n)/g, '').replace(/"",[\n\t\r\s]+""[,]*/g, '').replace(/(\n[\t\s\r]*\n)/g, '').replace(/[\s\t]{2,}""[,]{0,1}/g, '').replace(/"[\s\t]{1,}"[,]{0,1}/g, '').replace(/\[[\t\s]*\]/g, '""');
635
+ return (rejsn.indexOf('"parsererror": {') == -1) ? rejsn : 'Invalid XML format';
636
+ };
637
+ Utils.prototype.sendToParent = function (obj, dest) {
638
+ console.log('sendToParent->', JSON.stringify(obj));
639
+ //@ts-ignore
640
+ if (window.objJS) {
641
+ switch (obj.target) {
642
+ case "Dnv.smoCallbacks.onSmoLoad":
643
+ // @ts-ignore
644
+ window.objJS.onSmoLoad();
645
+ break;
646
+ case "Dnv.smoCallbacks.printTextLine":
647
+ // @ts-ignore
648
+ window.objJS.printTextLine(obj.objData.txt);
649
+ break;
650
+ case "Dnv.smoCallbacks.printBarcode":
651
+ // @ts-ignore
652
+ window.objJS.printBarcode(obj.objData.code, obj.objData.width, obj.objData.height);
653
+ break;
654
+ case "Dnv.smoCallbacks.cutPaper":
655
+ // @ts-ignore
656
+ window.objJS.cutPaper(obj.objData.percent);
657
+ break;
658
+ case "Dnv.smoCallbacks.printImage":
659
+ // @ts-ignore
660
+ window.objJS.printImage(obj.idSmo, obj.objData.image);
661
+ break;
662
+ case "Dnv.smoCallbacks.checkHealthPrinter":
663
+ console.log('llamo a checkhealthprinter');
664
+ // @ts-ignore
665
+ window.objJS.checkHealthPrinter(obj.idSmo);
666
+ break;
667
+ case "Dnv.smoCallbacks.checkHealth":
668
+ // @ts-ignore
669
+ window.objJS.checkHealth();
670
+ break;
671
+ case "Dnv.smoCallbacks.getFile":
672
+ // @ts-ignore
673
+ window.objJS.getFile(dest, obj.objData);
674
+ break;
675
+ }
676
+ return;
677
+ }
678
+ /* // @ts-ignore
679
+ window.parent.postMessage = (target,objData,idSmo)=> {
680
+ switch (target.target) {
681
+ case "Dnv.smoCallbacks.onSmoLoad":
682
+ // @ts-ignore
683
+ window.objJS.onSmoLoad();
684
+ break;
685
+
686
+ case "Dnv.smoCallbacks.printTextLine":
687
+ // @ts-ignore
688
+ window.objJS.printTextLine(objData.txt);
689
+ break;
690
+ case "Dnv.smoCallbacks.printBarcode":
691
+ // @ts-ignore
692
+ window.objJS.printBarcode(objData.code, objData.width, objData.height);
693
+ break;
694
+ case "Dnv.smoCallbacks.cutPaper":
695
+ // @ts-ignore
696
+ window.objJS.cutPaper(objData.percent);
697
+ break;
698
+ case "Dnv.smoCallbacks.printImage":
699
+ // @ts-ignore
700
+ window.objJS.printImage(idSmo, objData.image);
701
+ break;
702
+ case "Dnv.smoCallbacks.checkHealthPrinter":
703
+ console.log('llamo a checkhealthprinter');
704
+ // @ts-ignore
705
+
706
+ window.objJS.checkHealthPrinter(idSmo);
707
+ break;
708
+ case "Dnv.smoCallbacks.checkHealth":
709
+ // @ts-ignore
710
+ window.objJS.checkHealth();
711
+ break;
712
+
713
+
714
+ }
715
+ }*/
716
+ window.parent.postMessage(obj, dest);
717
+ };
718
+ Utils.prototype.setJsonObj = function (xml) {
719
+ var jsonObj = {};
720
+ if (xml.nodeType == 1) { // Element
721
+ if (xml.attributes.length > 0) {
722
+ jsonObj["attributes"] = {};
723
+ for (var j = 0; j < xml.attributes.length; j++) {
724
+ var attribute = xml.attributes.item(j);
725
+ jsonObj["attributes"][attribute.nodeName] = attribute.nodeValue;
726
+ }
727
+ }
728
+ }
729
+ else if (xml.nodeType == 3) { // Text
730
+ jsonObj = xml.nodeValue.trim();
731
+ }
732
+ else if (xml.nodeType == 4) { // CDATA
733
+ jsonObj = xml.nodeValue.trim();
734
+ }
735
+ if (xml.hasChildNodes()) {
736
+ for (var i = 0; i < xml.childNodes.length; i++) {
737
+ var item = xml.childNodes[i];
738
+ var nodeName = item.nodeName;
739
+ if (nodeName == "#text" && item.nodeType == 3) {
740
+ jsonObj = item.nodeValue.trim();
741
+ }
742
+ else if (nodeName == "#cdata-section" && (item.nodeType == 4 || item.nodeType == 3)) { //Para que quede bonito
743
+ jsonObj["cdata"] = this.setJsonObj(item);
744
+ }
745
+ else if (typeof jsonObj[nodeName] === "undefined") {
746
+ jsonObj[nodeName] = this.setJsonObj(item);
747
+ }
748
+ else {
749
+ if (!Array.isArray(jsonObj[nodeName])) {
750
+ jsonObj[nodeName] = [jsonObj[nodeName]];
751
+ }
752
+ jsonObj[nodeName].push(this.setJsonObj(item));
753
+ }
754
+ }
755
+ }
756
+ return jsonObj;
757
+ };
758
+ Utils.prototype.dataToJSON = function (data) {
759
+ try {
760
+ var parser = new DOMParser();
761
+ var xmlDoc = parser.parseFromString(data.xml, "text/xml");
762
+ var dataForJSON = xmlDoc.getElementsByTagName("item")[0].innerHTML;
763
+ dataForJSON = dataForJSON.replace(/{'/g, '{"').replace(/'}/g, '"}').replace(/:'/g, ':"').replace(/':/g, '":').replace(/,'/g, ',"').replace(/',/g, '",').replace(/\['/g, '["').replace(/'\]/g, '"]').replace(/(\r\n|\n|\r)/gm, "");
764
+ return JSON.parse(dataForJSON);
765
+ }
766
+ catch (error) {
767
+ return {};
768
+ }
769
+ };
770
+ return Utils;
771
+ }());
772
+ var SMO_EVENT_TYPE;
773
+ (function (SMO_EVENT_TYPE) {
774
+ SMO_EVENT_TYPE["start"] = "start";
775
+ SMO_EVENT_TYPE["setDatasource"] = "setDatasource";
776
+ SMO_EVENT_TYPE["getVariable"] = "getVariable";
777
+ SMO_EVENT_TYPE["setCurrentStream"] = "setCurrentStream";
778
+ SMO_EVENT_TYPE["infoCurrentLocation"] = "infoCurrentLocation";
779
+ SMO_EVENT_TYPE["setSalidaData"] = "setSalidaData";
780
+ SMO_EVENT_TYPE["updatefromsalida"] = "updatefromsalida";
781
+ SMO_EVENT_TYPE["setDatasourceJson"] = "setDatasourceJson";
782
+ SMO_EVENT_TYPE["getRecursosByCodigo"] = "getRecursosByCodigo";
783
+ SMO_EVENT_TYPE["getRecursos"] = "getRecursos";
784
+ SMO_EVENT_TYPE["getRecursosDefault"] = "getRecursosDefault";
785
+ SMO_EVENT_TYPE["getRecursosRelleno"] = "getRecursosRelleno";
786
+ SMO_EVENT_TYPE["getVariableStorage"] = "getVariableStorage";
787
+ SMO_EVENT_TYPE["checkHealth"] = "checkHealth";
788
+ SMO_EVENT_TYPE["checkHealthPrinter"] = "checkHealthPrinter";
789
+ })(SMO_EVENT_TYPE = exports.SMO_EVENT_TYPE || (exports.SMO_EVENT_TYPE = {}));
790
+ var LogLevel;
791
+ (function (LogLevel) {
792
+ LogLevel[LogLevel["Debug"] = 0] = "Debug";
793
+ LogLevel[LogLevel["Info"] = 1] = "Info";
794
+ LogLevel[LogLevel["Warning"] = 2] = "Warning";
795
+ LogLevel[LogLevel["Error"] = 3] = "Error";
796
+ })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
797
+ var AlarmaLevel;
798
+ (function (AlarmaLevel) {
799
+ AlarmaLevel[AlarmaLevel["Ok_off"] = 0] = "Ok_off";
800
+ AlarmaLevel[AlarmaLevel["Ok"] = 1] = "Ok";
801
+ AlarmaLevel[AlarmaLevel["Scanning"] = 2] = "Scanning";
802
+ AlarmaLevel[AlarmaLevel["Timeout"] = 3] = "Timeout";
803
+ AlarmaLevel[AlarmaLevel["Warning"] = 4] = "Warning";
804
+ AlarmaLevel[AlarmaLevel["Error"] = 5] = "Error";
805
+ })(AlarmaLevel = exports.AlarmaLevel || (exports.AlarmaLevel = {}));