@denevads/dnv-smo 1.0.17 → 1.0.18

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