@denevads/dnv-smo 1.0.16 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,80 +1,18 @@
1
- #Introducción
2
- Librería de interfaz de comunicaciones entre un objeto HTML5 y las funciones de un player de DenevaDS.
1
+ # DnvSMO
2
+ Libreria de conexión con la API de la salida.
3
3
 
4
- Aquí definiremos el uso de la librería y las funciones que la misma provee
4
+ ## Conexión con NPM
5
5
 
6
+ Para conexión con NPM se deben de ejecutar los siguientes comandos. La cuenta de login es denevads
6
7
 
7
- # Instalación
8
- La librería esta pensada para ser usada junto con Angular, de manera que si no contamos con el cli de angular en el sistema conviene instalarlo para inicializar el proyecto.
9
- ```sh
10
- npm install -g @angular/cli
11
- ```
12
- Inicializamos un proyecto de prueba llamado html-deneva en la ruta en la que estemos.
13
- ```sh
14
- ng new html-deneva
15
- ```
16
- Una vez que ya tenemos la estructura básica del proyecto podemos instalar la librería en el proyecto ejecutando la siguiente liena dentro de la carpeta del mismo:
17
- ```sh
18
- npm install @denevads/dnv-smo
19
- ```
20
8
 
21
- # Inicialización
9
+ npm run build
22
10
 
23
- Una vez que tengamos el proyecto de angular inicializado, procedemos importar el módulo.
11
+ npm login
24
12
 
25
- Dentro de la definición del app.module en la carpeta app, importamos la librería.
26
- ```ts
27
- import { SMO } from '@denevads/dnv-smo/dist/smo';
28
- ```
29
- y lo añadimos como provider en @NgModule
30
- ```ts
31
- providers: [SMO]
32
- ```
13
+ npm publish
33
14
 
34
- Ahora ya solo bastaría con añadirlo al componente del angular y empezar a usarlo.
15
+ ## Instalación.
35
16
 
36
- De nuevo en app.component importamos la librería
37
- ```js
38
- import { LogLevel, SMO } from '@denevads/dnv-smo/dist/smo'
39
- ```
40
- Y en la exportación de la clase AppComponent añadimos el constructor
41
- ```js
42
- constructor(private smo:SMO){ }
43
- ```
44
- De esta manera ya tendríamos disponible para su uso todas las llamadas que aporta la librería usando
45
- ```js
46
- this.smo.
47
- ```
48
- También en la importacion hemos traído la enumeración de los niveles de log, que sirven para loggear en el disco del equipo.
49
- El uso sería de la siguiente forma.
50
- ```js
51
- this.smo.smoCallBacks.smoLog('Mensaje de prueba',LogLevel.Info);
52
- ```
17
+ Para instalar la librería hay que ejecutar: npm install @denevads/dnv-smo
53
18
 
54
- # Compilación y empaquetado.
55
-
56
- Para que el proyecto pueda funcionar en un equipo sin problemas hay que hacer un par de cambios en el código del proyecto por defecto.
57
-
58
- El primero de ellos es modificar el tsconfig.json para que el "target" sea "ES5" en lugar de "ES2022"
59
-
60
-
61
- Y el segundo cambio es en archivo de index. Aquí haremos dos cosas.
62
- -Borraremos la importación del favicon (además de borrarlo de la carpeta de archivos).
63
- -Y cambiamos la línea
64
- ```html
65
- <base href="/">
66
- ```
67
- por
68
- ```html
69
- <script>document.write('<base href="' + document.location + '" />');</script>
70
- ```
71
- Con estos cambios hechos, podemos compilar el proyecto ejecutando la línea
72
- ```sh
73
- ng b
74
- ```
75
- Esto nos generara una carpeta dist, con el contenido de nuestro HTML5 compilado.
76
-
77
- Para poder subirlo al player de deneva, simplemente tenemos que crear un zip con el contenido en la raíz, y le cambiaremos la extensión por
78
- ```sh
79
- .wgt
80
- ```
package/dist/smo.d.ts CHANGED
@@ -126,4 +126,38 @@ export declare enum AlarmaLevel {
126
126
  Warning = 4,
127
127
  Error = 5
128
128
  }
129
+ export interface ObjJSType {
130
+ urlNext: () => void;
131
+ limpiaCapa: () => void;
132
+ logFlash: () => void;
133
+ pageInit: () => void;
134
+ finAviso: () => void;
135
+ exitInteractivity: () => void;
136
+ logWeb: () => void;
137
+ refreshPage: () => void;
138
+ refreshPageByError: () => void;
139
+ refreshPageByVideoEvent: () => void;
140
+ auditarRecurso: () => void;
141
+ initSMO: () => void;
142
+ getFile: () => void;
143
+ showBrowser: () => void;
144
+ closeBrowser: () => void;
145
+ refreshDataSource: () => void;
146
+ setVariable: () => void;
147
+ getVariable: () => void;
148
+ getLocation: () => void;
149
+ salirApp: () => void;
150
+ setLocalData: () => void;
151
+ getLocalData: () => void;
152
+ getSalidaData: () => void;
153
+ ejecutaFuncion: () => void;
154
+ addObserver: () => void;
155
+ notifyToObservers: () => void;
156
+ printTextLine: () => void;
157
+ printBarcode: () => void;
158
+ cutPaper: () => void;
159
+ printImage: () => void;
160
+ checkHealthPrinter: () => void;
161
+ checkHealth: () => void;
162
+ }
129
163
  export {};
package/dist/smo.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AlarmaLevel = exports.LogLevel = exports.SMO_EVENT_TYPE = exports.SMO = void 0;
4
4
  var rxjs_1 = require("rxjs");
5
+ // @ts-ignore
5
6
  var SMO = /** @class */ (function () {
6
7
  function SMO() {
7
8
  this.vars = {};
@@ -21,6 +22,121 @@ var SMO = /** @class */ (function () {
21
22
  while (match = search.exec(query)) {
22
23
  this.vars[decode(match[1])] = decode(match[2]);
23
24
  }
25
+ // @ts-ignore
26
+ if (window.objJS) {
27
+ // @ts-ignore
28
+ window.sendToIframefromNet = function (target, iframeID, objData) {
29
+ console.log("sendToIframefromNet->", target);
30
+ switch (target) {
31
+ case "SMO.setDatasource":
32
+ _this.events.setDatasource.next(objData);
33
+ break;
34
+ case "SMO.checkHealthPrinter":
35
+ _this.events.checkHealthPrinter.next(objData);
36
+ break;
37
+ }
38
+ // @ts-ignore
39
+ window.parent.postMessage = function (target, objData, idSmo) {
40
+ switch (target.target) {
41
+ case "Dnv.smoCallbacks.onSmoLoad":
42
+ // @ts-ignore
43
+ window.objJS.onSmoLoad();
44
+ break;
45
+ case "Dnv.smoCallbacks.printTextLine":
46
+ // @ts-ignore
47
+ window.objJS.printTextLine(objData.txt);
48
+ break;
49
+ case "Dnv.smoCallbacks.printBarcode":
50
+ // @ts-ignore
51
+ window.objJS.printBarcode(objData.code, objData.width, objData.height);
52
+ break;
53
+ case "Dnv.smoCallbacks.cutPaper":
54
+ // @ts-ignore
55
+ window.objJS.cutPaper(objData.percent);
56
+ break;
57
+ case "Dnv.smoCallbacks.printImage":
58
+ // @ts-ignore
59
+ window.objJS.printImage(idSmo, objData.image);
60
+ break;
61
+ case "Dnv.smoCallbacks.checkHealthPrinter":
62
+ console.log('llamo a checkhealthprinter');
63
+ // @ts-ignore
64
+ window.objJS.checkHealthPrinter(idSmo);
65
+ break;
66
+ case "Dnv.smoCallbacks.checkHealth":
67
+ // @ts-ignore
68
+ window.objJS.checkHealth();
69
+ break;
70
+ }
71
+ };
72
+ };
73
+ window.external = {
74
+ // @ts-ignore
75
+ URLNext: window.objJS.urlNext,
76
+ // @ts-ignore
77
+ LimpiaCapa: window.objJS.limpiaCapa,
78
+ // @ts-ignore
79
+ LogFlash: window.objJS.logFlash,
80
+ // @ts-ignore
81
+ PageInit: window.objJS.pageInit,
82
+ // @ts-ignore
83
+ FinAviso: window.objJS.finAviso,
84
+ // @ts-ignore
85
+ ExitInteractivity: window.objJS.exitInteractivity,
86
+ // @ts-ignore
87
+ LogWeb: window.objJS.logWeb,
88
+ // @ts-ignore
89
+ RefreshPage: window.objJS.refreshPage,
90
+ // @ts-ignore
91
+ RefreshPageByError: window.objJS.refreshPageByError,
92
+ // @ts-ignore
93
+ RefreshPageByVideoEvent: window.objJS.refreshPageByVideoEvent,
94
+ // @ts-ignore
95
+ AuditarRecurso: window.objJS.auditarRecurso,
96
+ // @ts-ignore
97
+ InitSMO: window.objJS.initSMO,
98
+ // @ts-ignore
99
+ GetFile: window.objJS.getFile,
100
+ // @ts-ignore
101
+ ShowBrowser: window.objJS.showBrowser,
102
+ // @ts-ignore
103
+ closeBrowser: window.objJS.closeBrowser,
104
+ // @ts-ignore
105
+ RefreshDataSource: window.objJS.refreshDataSource,
106
+ // @ts-ignore
107
+ SetVariable: window.objJS.setVariable,
108
+ // @ts-ignore
109
+ GetVariable: window.objJS.getVariable,
110
+ // @ts-ignore
111
+ GetLocation: window.objJS.getLocation,
112
+ // @ts-ignore
113
+ SalirApp: window.objJS.salirApp,
114
+ // @ts-ignore
115
+ SetLocalData: window.objJS.setLocalData,
116
+ // @ts-ignore
117
+ GetLocalData: window.objJS.getLocalData,
118
+ // @ts-ignore
119
+ GetSalidaData: window.objJS.getSalidaData,
120
+ // @ts-ignore
121
+ EjecutaFuncion: window.objJS.ejecutaFuncion,
122
+ // @ts-ignore
123
+ AddObserver: window.objJS.addObserver,
124
+ // @ts-ignore
125
+ NotifyToObservers: window.objJS.notifyToObservers,
126
+ // @ts-ignore
127
+ PrintTextLine: window.objJS.printTextLine,
128
+ // @ts-ignore
129
+ PrintBarcode: window.objJS.printBarcode,
130
+ // @ts-ignore
131
+ CutPaper: window.objJS.cutPaper,
132
+ // @ts-ignore
133
+ PrintImage: window.objJS.printImage,
134
+ // @ts-ignore
135
+ CheckHealthPrinter: window.objJS.checkHealthPrinter,
136
+ // @ts-ignore
137
+ CheckHealth: window.objJS.checkHealth
138
+ };
139
+ }
24
140
  if (this.vars.idSmo) {
25
141
  this.id = this.vars.idSmo;
26
142
  if (this.vars["LowPower"] == "true" && (this.vars["url"] != undefined || this.vars["LocalData"] != undefined)) {
@@ -510,7 +626,7 @@ var Utils = /** @class */ (function () {
510
626
  // Funciones para XML to JSON
511
627
  Utils.prototype.xmlToJSON = function (xml) {
512
628
  var getxml = new DOMParser();
513
- var xmlDoc = getxml.parseFromString(xml, "text/xml");
629
+ var xmlDoc = getxml.parseFromString(xml.replace(/\n/g, ''), "text/xml");
514
630
  // gets the JSON string
515
631
  var json_str = this.jsonToStr(this.setJsonObj(xmlDoc));
516
632
  // sets and returns the JSON object, if "rstr" undefined (not passed), else, returns JSON string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@denevads/dnv-smo",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "SMO module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/smo.ts CHANGED
@@ -9,6 +9,12 @@ import {
9
9
  GetRecursos, GetRecursosRelleno
10
10
  } from "./interfaces/callbacks";
11
11
  import {interval, Subject, Subscription} from 'rxjs';
12
+ interface Window {
13
+ external:ObjJSType;
14
+ objJS:ObjJSType;
15
+ }
16
+ // @ts-ignore
17
+
12
18
  export class SMO {
13
19
  public vars:any = {};
14
20
  public id:string = "";
@@ -17,6 +23,7 @@ export class SMO {
17
23
  public smoCallBacks:smoCallBacks;
18
24
  public utils:Utils;
19
25
  public events:SmoEvents;
26
+
20
27
  constructor(){
21
28
 
22
29
  this.initOnMessage();
@@ -36,6 +43,127 @@ export class SMO {
36
43
  while (match = search.exec(query)) {
37
44
  this.vars[decode(match[1])] = decode(match[2]);
38
45
  }
46
+ // @ts-ignore
47
+ if(window.objJS){
48
+ // @ts-ignore
49
+ window.sendToIframefromNet = (target, iframeID, objData) => {
50
+ console.log("sendToIframefromNet->",target);
51
+ switch (target) {
52
+ case "SMO.setDatasource":
53
+ this.events.setDatasource.next(objData)
54
+ break;
55
+ case "SMO.checkHealthPrinter":
56
+ this.events.checkHealthPrinter.next(objData);
57
+ break;
58
+ }
59
+ // @ts-ignore
60
+ window.parent.postMessage = (target,objData,idSmo)=> {
61
+ switch (target.target) {
62
+ case "Dnv.smoCallbacks.onSmoLoad":
63
+ // @ts-ignore
64
+ window.objJS.onSmoLoad();
65
+ break;
66
+
67
+ case "Dnv.smoCallbacks.printTextLine":
68
+ // @ts-ignore
69
+ window.objJS.printTextLine(objData.txt);
70
+ break;
71
+ case "Dnv.smoCallbacks.printBarcode":
72
+ // @ts-ignore
73
+ window.objJS.printBarcode(objData.code, objData.width, objData.height);
74
+ break;
75
+ case "Dnv.smoCallbacks.cutPaper":
76
+ // @ts-ignore
77
+ window.objJS.cutPaper(objData.percent);
78
+ break;
79
+ case "Dnv.smoCallbacks.printImage":
80
+ // @ts-ignore
81
+ window.objJS.printImage(idSmo, objData.image);
82
+ break;
83
+ case "Dnv.smoCallbacks.checkHealthPrinter":
84
+ console.log('llamo a checkhealthprinter');
85
+ // @ts-ignore
86
+
87
+ window.objJS.checkHealthPrinter(idSmo);
88
+ break;
89
+ case "Dnv.smoCallbacks.checkHealth":
90
+ // @ts-ignore
91
+ window.objJS.checkHealth();
92
+ break;
93
+
94
+
95
+ }
96
+ }
97
+
98
+ }
99
+
100
+ window.external = {
101
+ // @ts-ignore
102
+ URLNext: window.objJS.urlNext,
103
+ // @ts-ignore
104
+ LimpiaCapa: window.objJS.limpiaCapa,
105
+ // @ts-ignore
106
+ LogFlash: window.objJS.logFlash,
107
+ // @ts-ignore
108
+ PageInit: window.objJS.pageInit,
109
+ // @ts-ignore
110
+ FinAviso: window.objJS.finAviso,
111
+ // @ts-ignore
112
+ ExitInteractivity: window.objJS.exitInteractivity,
113
+ // @ts-ignore
114
+ LogWeb: window.objJS.logWeb,
115
+ // @ts-ignore
116
+ RefreshPage: window.objJS.refreshPage,
117
+ // @ts-ignore
118
+ RefreshPageByError: window.objJS.refreshPageByError,
119
+ // @ts-ignore
120
+ RefreshPageByVideoEvent: window.objJS.refreshPageByVideoEvent,
121
+ // @ts-ignore
122
+ AuditarRecurso: window.objJS.auditarRecurso,
123
+ // @ts-ignore
124
+ InitSMO: window.objJS.initSMO,
125
+ // @ts-ignore
126
+ GetFile: window.objJS.getFile,
127
+ // @ts-ignore
128
+ ShowBrowser: window.objJS.showBrowser,
129
+ // @ts-ignore
130
+ closeBrowser: window.objJS.closeBrowser,
131
+ // @ts-ignore
132
+ RefreshDataSource: window.objJS.refreshDataSource,
133
+ // @ts-ignore
134
+ SetVariable: window.objJS.setVariable,
135
+ // @ts-ignore
136
+ GetVariable: window.objJS.getVariable,
137
+ // @ts-ignore
138
+ GetLocation: window.objJS.getLocation,
139
+ // @ts-ignore
140
+ SalirApp: window.objJS.salirApp,
141
+ // @ts-ignore
142
+ SetLocalData: window.objJS.setLocalData,
143
+ // @ts-ignore
144
+ GetLocalData: window.objJS.getLocalData,
145
+ // @ts-ignore
146
+ GetSalidaData: window.objJS.getSalidaData,
147
+ // @ts-ignore
148
+ EjecutaFuncion: window.objJS.ejecutaFuncion,
149
+ // @ts-ignore
150
+ AddObserver: window.objJS.addObserver,
151
+ // @ts-ignore
152
+ NotifyToObservers: window.objJS.notifyToObservers,
153
+ // @ts-ignore
154
+ PrintTextLine: window.objJS.printTextLine,
155
+ // @ts-ignore
156
+ PrintBarcode: window.objJS.printBarcode,
157
+ // @ts-ignore
158
+ CutPaper: window.objJS.cutPaper,
159
+ // @ts-ignore
160
+ PrintImage: window.objJS.printImage,
161
+ // @ts-ignore
162
+ CheckHealthPrinter: window.objJS.checkHealthPrinter,
163
+ // @ts-ignore
164
+ CheckHealth: window.objJS.checkHealth
165
+ };
166
+ }
39
167
  if (this.vars.idSmo) {
40
168
  this.id = this.vars.idSmo;
41
169
  if(this.vars["LowPower"] == "true" && (this.vars["url"] != undefined || this.vars["LocalData"] != undefined)){
@@ -186,7 +314,6 @@ class smoCallBacks{
186
314
  this.smo =_smo;
187
315
  }
188
316
  public onSmoLoad():void {
189
-
190
317
  window.parent.postMessage({
191
318
  target: "Dnv.smoCallbacks.onSmoLoad",
192
319
  objData: undefined,
@@ -530,7 +657,7 @@ class Utils{
530
657
  // Funciones para XML to JSON
531
658
  xmlToJSON(xml:string) {
532
659
  let getxml = new DOMParser();
533
- let xmlDoc = getxml.parseFromString(xml,"text/xml");
660
+ let xmlDoc = getxml.parseFromString(xml.replace(/\n/g, ''),"text/xml");
534
661
  // gets the JSON string
535
662
  let json_str = this.jsonToStr(this.setJsonObj(xmlDoc));
536
663
  // sets and returns the JSON object, if "rstr" undefined (not passed), else, returns JSON string
@@ -630,3 +757,38 @@ Timeout= 3,
630
757
  Warning= 4,
631
758
  Error= 5
632
759
  }
760
+ export interface ObjJSType {
761
+ urlNext: () => void;
762
+ limpiaCapa: () => void;
763
+ logFlash: () => void;
764
+ pageInit: () => void;
765
+ finAviso: () => void;
766
+ exitInteractivity: () => void;
767
+ logWeb: () => void;
768
+ refreshPage: () => void;
769
+ refreshPageByError: () => void;
770
+ refreshPageByVideoEvent: () => void;
771
+ auditarRecurso: () => void;
772
+ initSMO: () => void;
773
+ getFile: () => void;
774
+ showBrowser: () => void;
775
+ closeBrowser: () => void;
776
+ refreshDataSource: () => void;
777
+ setVariable: () => void;
778
+ getVariable: () => void;
779
+ getLocation: () => void;
780
+ salirApp: () => void;
781
+ setLocalData: () => void;
782
+ getLocalData: () => void;
783
+ getSalidaData: () => void;
784
+ ejecutaFuncion: () => void;
785
+ addObserver: () => void;
786
+ notifyToObservers: () => void;
787
+ printTextLine: () => void;
788
+ printBarcode: () => void;
789
+ cutPaper: () => void;
790
+ printImage: () => void;
791
+ checkHealthPrinter: () => void;
792
+ checkHealth: () => void;
793
+ }
794
+