@denevads/dnv-smo 1.0.28 → 1.0.29

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