@denevads/dnv-smo 1.0.22 → 1.0.24

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,789 +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
- };
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->', 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(objData.txt);
637
- break;
638
- case "Dnv.smoCallbacks.printBarcode":
639
- // @ts-ignore
640
- window.objJS.printBarcode(objData.code, objData.width, objData.height);
641
- break;
642
- case "Dnv.smoCallbacks.cutPaper":
643
- // @ts-ignore
644
- window.objJS.cutPaper(objData.percent);
645
- break;
646
- case "Dnv.smoCallbacks.printImage":
647
- // @ts-ignore
648
- window.objJS.printImage(obj.idSmo, objData.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 = {}));
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.objData.txt);
637
+ break;
638
+ case "Dnv.smoCallbacks.printBarcode":
639
+ // @ts-ignore
640
+ window.objJS.printBarcode(obj.code, obj.objData.width, obj.objData.height);
641
+ break;
642
+ case "Dnv.smoCallbacks.cutPaper":
643
+ // @ts-ignore
644
+ window.objJS.cutPaper(obj.objData.percent);
645
+ break;
646
+ case "Dnv.smoCallbacks.printImage":
647
+ // @ts-ignore
648
+ window.objJS.printImage(obj.idSmo, obj.objData.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 = {}));