@denevads/dnv-smo 1.0.21 → 1.0.23

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