@denevads/dnv-smo 1.1.1 → 1.1.3

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