@denevads/dnv-smo 1.0.16 → 1.0.17

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