@denevads/dnv-smo 1.0.2 → 1.0.4

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,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/dnvsmo.iml" filepath="$PROJECT_DIR$/.idea/dnvsmo.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/dist/smo.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
1
  import { setDatasource, variable, location, DataSalida, ExecFunction, Notify, start } from "./interfaces/callbacks";
4
- import { Observable } from 'rxjs';
5
- export declare class SMO extends EventEmitter {
2
+ import { Subject } from 'rxjs';
3
+ export declare class SMO {
6
4
  vars: any;
7
5
  id: string;
8
6
  smoCallBacks: smoCallBacks;
@@ -20,13 +18,14 @@ export declare class SMO extends EventEmitter {
20
18
  updatefromsalida(data: any): void;
21
19
  }
22
20
  declare class SmoEvents {
23
- start: Observable<start>;
24
- setDatasource: Observable<setDatasource>;
25
- getVariable: Observable<variable>;
26
- setCurrentStream: Observable<string>;
27
- infoCurrentLocation: Observable<location>;
28
- setSalidaData: Observable<DataSalida>;
29
- updatefromsalida: Observable<any>;
21
+ start: Subject<start>;
22
+ setDatasource: Subject<setDatasource>;
23
+ setDatasourceJson: Subject<any>;
24
+ getVariable: Subject<variable>;
25
+ setCurrentStream: Subject<string>;
26
+ infoCurrentLocation: Subject<location>;
27
+ setSalidaData: Subject<DataSalida>;
28
+ updatefromsalida: Subject<any>;
30
29
  constructor(smo: SMO);
31
30
  }
32
31
  declare class smoCallBacks {
@@ -59,14 +58,18 @@ declare class smoCallBacks {
59
58
  stopPlayOnceChannelByTrigger(): void;
60
59
  playOnceChannel(codigoCanal: string): void;
61
60
  stopPlayChannel(): void;
61
+ editWrapperStyle(obj: any): void;
62
62
  }
63
63
  declare class Utils {
64
64
  smo: SMO;
65
65
  smoCallBacks: smoCallBacks;
66
66
  constructor(_smo: SMO, _smoCallBacks: smoCallBacks);
67
+ xmlToJSON(xml: string): string;
68
+ jsonToStr(js_obj: any): string;
69
+ setJsonObj(xml: any): any;
67
70
  dataToJSON(data: setDatasource): any;
68
71
  getDatasource(): void;
69
- startCheckDatasource(): void;
72
+ startCheckDatasource(timeout?: number): void;
70
73
  }
71
74
  export declare enum SMO_EVENT_TYPE {
72
75
  start = "start",
@@ -75,7 +78,8 @@ export declare enum SMO_EVENT_TYPE {
75
78
  setCurrentStream = "setCurrentStream",
76
79
  infoCurrentLocation = "infoCurrentLocation",
77
80
  setSalidaData = "setSalidaData",
78
- updatefromsalida = "updatefromsalida"
81
+ updatefromsalida = "updatefromsalida",
82
+ setDatasourceJson = "setDatasourceJson"
79
83
  }
80
84
  export declare enum LogLevel {
81
85
  Debug = 0,
package/dist/smo.js CHANGED
@@ -1,35 +1,16 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.AlarmaLevel = exports.LogLevel = exports.SMO_EVENT_TYPE = exports.SMO = void 0;
19
- var events_1 = require("events");
20
4
  var rxjs_1 = require("rxjs");
21
- var SMO = /** @class */ (function (_super) {
22
- __extends(SMO, _super);
5
+ var SMO = /** @class */ (function () {
23
6
  function SMO() {
24
- var _this = _super.call(this) || this;
25
- _this.vars = {};
26
- _this.id = "";
27
- _this.init();
28
- _this.initOnMessage();
29
- _this.smoCallBacks = new smoCallBacks(_this);
30
- _this.utils = new Utils(_this, _this.smoCallBacks);
31
- _this.events = new SmoEvents(_this);
32
- return _this;
7
+ this.vars = {};
8
+ this.id = "";
9
+ this.init();
10
+ this.initOnMessage();
11
+ this.smoCallBacks = new smoCallBacks(this);
12
+ this.utils = new Utils(this, this.smoCallBacks);
13
+ this.events = new SmoEvents(this);
33
14
  }
34
15
  SMO.prototype.init = function () {
35
16
  var match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function (s) {
@@ -38,6 +19,12 @@ var SMO = /** @class */ (function (_super) {
38
19
  while (match = search.exec(query)) {
39
20
  this.vars[decode(match[1])] = decode(match[2]);
40
21
  }
22
+ /* let hash;
23
+ let hashes = window.location.href.slice(window.location.href.indexOf("?") + 1).split("&");
24
+ for (var i = 0; i < hashes.length; i++) {
25
+ hash = hashes[i].split("=");
26
+ this.vars[hash[0]] = hash[1];
27
+ }*/
41
28
  if (this.vars.idSmo) {
42
29
  this.id = this.vars.idSmo;
43
30
  return;
@@ -79,55 +66,44 @@ var SMO = /** @class */ (function (_super) {
79
66
  return;
80
67
  }
81
68
  console.warn("message not implemented!!" + func);
82
- /* try {
83
- var targets = e.data.target.split('.');
84
- var fn = window;
85
- var obj = window;
86
- for (var i = 0; i < targets.length; i++) {
87
- obj = fn;
88
- fn = obj[targets[i]];
89
- }
90
- fn.call(obj, e.data.objData); // conservamos el valor de this
91
- } catch (ex) {
92
- //Si no ha podido llamar es porque no existe el entorno
93
-
94
- }*/
95
69
  }
96
70
  };
97
71
  };
98
72
  SMO.prototype.start = function () {
99
- this.emit(SMO_EVENT_TYPE.start);
73
+ this.events.start.next({});
100
74
  };
101
75
  SMO.prototype.setDatasource = function (datasource) {
102
- this.emit(SMO_EVENT_TYPE.setDatasource, datasource);
76
+ this.events.setDatasource.next(datasource);
77
+ this.events.setDatasourceJson.next(this.utils.xmlToJSON(datasource.xml));
103
78
  };
104
79
  SMO.prototype.getVariable = function (variable) {
105
- this.emit(SMO_EVENT_TYPE.getVariable, variable);
80
+ this.events.getVariable.next(variable);
106
81
  };
107
82
  SMO.prototype.setCurrentStream = function (stream) {
108
- this.emit(SMO_EVENT_TYPE.setCurrentStream, stream);
83
+ this.events.setCurrentStream.next(stream);
109
84
  };
110
85
  SMO.prototype.infoCurrentLocation = function (location) {
111
- this.emit(SMO_EVENT_TYPE.infoCurrentLocation, location);
86
+ this.events.infoCurrentLocation.next(location);
112
87
  };
113
88
  SMO.prototype.setSalidaData = function (data) {
114
- this.emit(SMO_EVENT_TYPE.setSalidaData, data);
89
+ this.events.setSalidaData.next(data);
115
90
  };
116
91
  SMO.prototype.updatefromsalida = function (data) {
117
- this.emit(SMO_EVENT_TYPE.updatefromsalida, data);
92
+ this.events.updatefromsalida.next(data);
118
93
  };
119
94
  return SMO;
120
- }(events_1.EventEmitter));
95
+ }());
121
96
  exports.SMO = SMO;
122
97
  var SmoEvents = /** @class */ (function () {
123
98
  function SmoEvents(smo) {
124
- this.start = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.start);
125
- this.setDatasource = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.setDatasource);
126
- this.getVariable = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.getVariable);
127
- this.setCurrentStream = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.setCurrentStream);
128
- this.infoCurrentLocation = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.infoCurrentLocation);
129
- this.setSalidaData = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.setSalidaData);
130
- this.updatefromsalida = (0, rxjs_1.fromEvent)(smo, SMO_EVENT_TYPE.updatefromsalida);
99
+ this.start = new rxjs_1.Subject();
100
+ this.setDatasource = new rxjs_1.Subject();
101
+ this.setDatasourceJson = new rxjs_1.Subject();
102
+ this.getVariable = new rxjs_1.Subject();
103
+ this.setCurrentStream = new rxjs_1.Subject();
104
+ this.infoCurrentLocation = new rxjs_1.Subject();
105
+ this.setSalidaData = new rxjs_1.Subject();
106
+ this.updatefromsalida = new rxjs_1.Subject();
131
107
  }
132
108
  return SmoEvents;
133
109
  }());
@@ -192,7 +168,7 @@ var smoCallBacks = /** @class */ (function () {
192
168
  window.parent.postMessage({
193
169
  target: "Dnv.smoCallbacks.reiniciarDispositivo",
194
170
  objData: {
195
- txt: msn // Razón del reinicio
171
+ txt: msn // Razón del reinicio
196
172
  },
197
173
  idSmo: this.smo.id
198
174
  }, "*");
@@ -352,6 +328,14 @@ var smoCallBacks = /** @class */ (function () {
352
328
  smoCallBacks.prototype.stopPlayChannel = function () {
353
329
  parent.postMessage({ target: "Dnv.smoCallbacks.stopPlayOnceChannel", objData: {}, idSmo: this.smo.id }, "*");
354
330
  };
331
+ smoCallBacks.prototype.editWrapperStyle = function (obj) {
332
+ /*{"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} */
333
+ parent.postMessage({
334
+ target: "Dnv.smoCallbacks.editWrapperStyle",
335
+ objData: obj,
336
+ idSmo: this.smo.id
337
+ }, "*");
338
+ };
355
339
  return smoCallBacks;
356
340
  }());
357
341
  var Utils = /** @class */ (function () {
@@ -359,6 +343,55 @@ var Utils = /** @class */ (function () {
359
343
  this.smo = _smo;
360
344
  this.smoCallBacks = _smoCallBacks;
361
345
  }
346
+ // Funciones para XML to JSON
347
+ Utils.prototype.xmlToJSON = function (xml) {
348
+ var getxml = new DOMParser();
349
+ var xmlDoc = getxml.parseFromString(xml, "text/xml");
350
+ // gets the JSON string
351
+ var json_str = this.jsonToStr(this.setJsonObj(xmlDoc));
352
+ // sets and returns the JSON object, if "rstr" undefined (not passed), else, returns JSON string
353
+ return json_str;
354
+ };
355
+ Utils.prototype.jsonToStr = function (js_obj) {
356
+ 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, '""');
357
+ return (rejsn.indexOf('"parsererror": {') == -1) ? rejsn : 'Invalid XML format';
358
+ };
359
+ Utils.prototype.setJsonObj = function (xml) {
360
+ var js_obj = {};
361
+ if (xml.nodeType == 1) { // Element
362
+ if (xml.attributes.length > 0) {
363
+ js_obj["@attributes"] = {};
364
+ for (var j = 0; j < xml.attributes.length; j++) {
365
+ var attribute = xml.attributes.item(j);
366
+ js_obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
367
+ }
368
+ }
369
+ }
370
+ else if (xml.nodeType == 3) { // Text
371
+ js_obj = xml.nodeValue;
372
+ }
373
+ else if (xml.nodeType == 4) { // CDATA
374
+ js_obj = xml.nodeValue;
375
+ }
376
+ if (xml.hasChildNodes()) {
377
+ for (var i = 0; i < xml.childNodes.length; i++) {
378
+ var item = xml.childNodes.item(i);
379
+ var nodeName = item.nodeName;
380
+ if (typeof (js_obj[nodeName]) == "undefined") {
381
+ js_obj[nodeName] = this.setJsonObj(item);
382
+ }
383
+ else {
384
+ if (typeof (js_obj[nodeName].push) == "undefined") {
385
+ var old = js_obj[nodeName];
386
+ js_obj[nodeName] = [];
387
+ js_obj[nodeName].push(old);
388
+ }
389
+ js_obj[nodeName].push(this.setJsonObj(item));
390
+ }
391
+ }
392
+ }
393
+ return js_obj;
394
+ };
362
395
  Utils.prototype.dataToJSON = function (data) {
363
396
  try {
364
397
  var parser = new DOMParser();
@@ -378,12 +411,13 @@ var Utils = /** @class */ (function () {
378
411
  }
379
412
  this.smoCallBacks.getFile(this.smo.vars.url);
380
413
  };
381
- Utils.prototype.startCheckDatasource = function () {
414
+ Utils.prototype.startCheckDatasource = function (timeout) {
415
+ if (timeout === void 0) { timeout = 10; }
382
416
  this.getDatasource();
383
417
  var self = this;
384
418
  setInterval(function () {
385
419
  self.getDatasource();
386
- }, 10000);
420
+ }, timeout * 1000);
387
421
  };
388
422
  return Utils;
389
423
  }());
@@ -396,6 +430,7 @@ var SMO_EVENT_TYPE;
396
430
  SMO_EVENT_TYPE["infoCurrentLocation"] = "infoCurrentLocation";
397
431
  SMO_EVENT_TYPE["setSalidaData"] = "setSalidaData";
398
432
  SMO_EVENT_TYPE["updatefromsalida"] = "updatefromsalida";
433
+ SMO_EVENT_TYPE["setDatasourceJson"] = "setDatasourceJson";
399
434
  })(SMO_EVENT_TYPE = exports.SMO_EVENT_TYPE || (exports.SMO_EVENT_TYPE = {}));
400
435
  /* start():void{
401
436
  this.emit("start");
@@ -415,7 +450,7 @@ var SMO_EVENT_TYPE;
415
450
  setSalidaData(data:DataSalida):void{
416
451
  this.emit("setSalidaData",data);
417
452
  }
418
-
453
+
419
454
  updatefromsalida(data:any):void{
420
455
  this.emit("updatefromsalida",data);
421
456
  } */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@denevads/dnv-smo",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "SMO module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -18,6 +18,7 @@
18
18
  "@types/node": "^17.0.42"
19
19
  },
20
20
  "dependencies": {
21
+ "mitt": "^3.0.0",
21
22
  "rxjs": "^7.5.6"
22
23
  }
23
24
  }
package/src/smo.ts CHANGED
@@ -1,14 +1,12 @@
1
- import {EventEmitter} from 'events';
2
1
  import { setDatasource,variable,location,DataSalida, ExecFunction, Notify, start } from "./interfaces/callbacks";
3
- import { fromEvent, Observable } from 'rxjs';
4
- export class SMO extends EventEmitter{
5
- public vars:any = {};
6
- public id:string ="";
2
+ import { Subject} from 'rxjs';
3
+ export class SMO {
4
+ public vars:any = {};
5
+ public id:string = "";
7
6
  public smoCallBacks:smoCallBacks;
8
7
  public utils:Utils;
9
8
  public events:SmoEvents;
10
9
  constructor(){
11
- super();
12
10
  this.init();
13
11
  this.initOnMessage();
14
12
  this.smoCallBacks = new smoCallBacks(this);
@@ -26,7 +24,12 @@ export class SMO extends EventEmitter{
26
24
  while (match = search.exec(query)) {
27
25
  this.vars[decode(match[1])] = decode(match[2]);
28
26
  }
29
-
27
+ /* let hash;
28
+ let hashes = window.location.href.slice(window.location.href.indexOf("?") + 1).split("&");
29
+ for (var i = 0; i < hashes.length; i++) {
30
+ hash = hashes[i].split("=");
31
+ this.vars[hash[0]] = hash[1];
32
+ }*/
30
33
  if (this.vars.idSmo) {
31
34
  this.id = this.vars.idSmo;
32
35
  return;
@@ -53,7 +56,7 @@ export class SMO extends EventEmitter{
53
56
  }
54
57
  if(func ==SMO_EVENT_TYPE.setCurrentStream){
55
58
  selft.setCurrentStream(e.data.objData);
56
- return;
59
+ return;
57
60
  }
58
61
  if(func==SMO_EVENT_TYPE.infoCurrentLocation){
59
62
  selft.infoCurrentLocation(e.data.objData);
@@ -68,63 +71,45 @@ export class SMO extends EventEmitter{
68
71
  return;
69
72
  }
70
73
  console.warn("message not implemented!!" +func);
71
- /* try {
72
- var targets = e.data.target.split('.');
73
- var fn = window;
74
- var obj = window;
75
- for (var i = 0; i < targets.length; i++) {
76
- obj = fn;
77
- fn = obj[targets[i]];
78
- }
79
- fn.call(obj, e.data.objData); // conservamos el valor de this
80
- } catch (ex) {
81
- //Si no ha podido llamar es porque no existe el entorno
82
-
83
- }*/
84
74
  }
85
75
  }
86
76
  }
87
77
  start():void{
88
- this.emit(SMO_EVENT_TYPE.start);
78
+ this.events.start.next({});
89
79
  }
90
80
  setDatasource(datasource:setDatasource):void {
91
- this.emit(SMO_EVENT_TYPE.setDatasource,datasource);
81
+ this.events.setDatasource.next(datasource);
82
+ this.events.setDatasourceJson.next(this.utils.xmlToJSON(datasource.xml));
92
83
  }
93
84
  getVariable(variable:variable):void{
94
- this.emit(SMO_EVENT_TYPE.getVariable,variable);
85
+ this.events.getVariable.next(variable);
95
86
  }
96
87
  setCurrentStream(stream:string):void{
97
- this.emit(SMO_EVENT_TYPE.setCurrentStream,stream);
88
+ this.events.setCurrentStream.next(stream);
98
89
  }
99
90
  infoCurrentLocation(location:location):void{
100
- this.emit(SMO_EVENT_TYPE.infoCurrentLocation,location);
91
+ this.events.infoCurrentLocation.next(location);
101
92
  }
102
93
  setSalidaData(data:DataSalida):void{
103
- this.emit(SMO_EVENT_TYPE.setSalidaData,data);
94
+ this.events.setSalidaData.next(data);
104
95
  }
105
-
96
+
106
97
  updatefromsalida(data:any):void{
107
- this.emit(SMO_EVENT_TYPE.updatefromsalida,data);
98
+ this.events.updatefromsalida.next(data);
108
99
  }
109
-
100
+
110
101
  }
102
+
111
103
  class SmoEvents{
112
- public start: Observable<start>;
113
- public setDatasource: Observable<setDatasource>;
114
- public getVariable: Observable<variable>;
115
- public setCurrentStream: Observable<string>;
116
- public infoCurrentLocation: Observable<location>;
117
- public setSalidaData: Observable<DataSalida>;
118
- public updatefromsalida: Observable<any>;
119
- constructor(smo:SMO){
120
- this.start = fromEvent<start>(smo,SMO_EVENT_TYPE.start);
121
- this.setDatasource = fromEvent<setDatasource>(smo,SMO_EVENT_TYPE.setDatasource);
122
- this.getVariable = fromEvent<variable>(smo,SMO_EVENT_TYPE.getVariable);
123
- this.setCurrentStream = fromEvent<string>(smo,SMO_EVENT_TYPE.setCurrentStream);
124
- this.infoCurrentLocation = fromEvent<location>(smo,SMO_EVENT_TYPE.infoCurrentLocation);
125
- this.setSalidaData = fromEvent<DataSalida>(smo,SMO_EVENT_TYPE.setSalidaData);
126
- this.updatefromsalida = fromEvent<any>(smo,SMO_EVENT_TYPE.updatefromsalida);
127
- }
104
+ public start: Subject<start> = new Subject<start>();
105
+ public setDatasource: Subject<setDatasource> = new Subject<setDatasource>();
106
+ public setDatasourceJson: Subject<any> = new Subject<any>();
107
+ public getVariable: Subject<variable> = new Subject<variable>();
108
+ public setCurrentStream: Subject<string> = new Subject<string>();
109
+ public infoCurrentLocation: Subject<location> = new Subject<location>();
110
+ public setSalidaData: Subject<DataSalida> = new Subject<DataSalida>();
111
+ public updatefromsalida: Subject<any> = new Subject<any>();
112
+ constructor(smo:SMO){}
128
113
  }
129
114
  class smoCallBacks{
130
115
  smo:SMO;
@@ -132,7 +117,7 @@ class smoCallBacks{
132
117
  this.smo =_smo;
133
118
  }
134
119
  public onSmoLoad():void {
135
-
120
+
136
121
  window.parent.postMessage({
137
122
  target: "Dnv.smoCallbacks.onSmoLoad",
138
123
  objData: undefined,
@@ -190,7 +175,7 @@ class smoCallBacks{
190
175
  window.parent.postMessage({
191
176
  target: "Dnv.smoCallbacks.reiniciarDispositivo",
192
177
  objData: {
193
- txt: msn // Razón del reinicio
178
+ txt: msn // Razón del reinicio
194
179
  },
195
180
  idSmo: this.smo.id
196
181
  }, "*");
@@ -260,7 +245,7 @@ class smoCallBacks{
260
245
  getLocalData(variable:string):void {
261
246
  parent.postMessage({
262
247
  target: "Dnv.smoCallbacks.getLocalData",
263
- objData: variable, // nameData
248
+ objData: variable, // nameData
264
249
  idSmo: this.smo.id
265
250
  }, "*");
266
251
  /* MIRAR SMO.setDatasource */
@@ -277,14 +262,14 @@ class smoCallBacks{
277
262
  finAviso(id:string):void {
278
263
  parent.postMessage({
279
264
  target: "Dnv.smoCallbacks.finAviso",
280
- objData: id, // id del aviso
265
+ objData: id, // id del aviso
281
266
  idSmo: this.smo.id
282
267
  }, "*");
283
268
  }
284
269
  refreshDatasource(codigo:string):void {
285
270
  parent.postMessage({
286
271
  target: "Dnv.smoCallbacks.refreshDatasource",
287
- objData: codigo, // Codigo del datasource
272
+ objData: codigo, // Codigo del datasource
288
273
  idSmo: this.smo.id
289
274
  }, "*");
290
275
  }
@@ -299,15 +284,15 @@ class smoCallBacks{
299
284
  getSalidaData(data:string):void {
300
285
  parent.postMessage({
301
286
  target: "Dnv.smoCallbacks.getSalidaData",
302
- 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.
287
+ 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.
303
288
  idSmo: this.smo.id
304
289
  }, "*");
305
290
  /* MIRAR SMO.setSalidaData */
306
291
  }
307
292
  ejecutaFuncion(data:ExecFunction):void {
308
293
  /*data ={
309
- funcion: "", // Nombre de la función que se debe ejecutar
310
- 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
294
+ funcion: "", // Nombre de la función que se debe ejecutar
295
+ 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
311
296
  } */
312
297
  parent.postMessage({
313
298
  target: "Dnv.smoCallbacks.ejecutaFuncion",
@@ -352,6 +337,14 @@ class smoCallBacks{
352
337
  stopPlayChannel():void {
353
338
  parent.postMessage({ target: "Dnv.smoCallbacks.stopPlayOnceChannel", objData: {}, idSmo: this.smo.id }, "*");
354
339
  }
340
+ editWrapperStyle(obj: any):void{
341
+ /*{"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} */
342
+ parent.postMessage({
343
+ target: "Dnv.smoCallbacks.editWrapperStyle",
344
+ objData: obj,
345
+ idSmo: this.smo.id
346
+ }, "*");
347
+ }
355
348
  }
356
349
  class Utils{
357
350
  smo:SMO;
@@ -360,6 +353,52 @@ class Utils{
360
353
  this.smo = _smo;
361
354
  this.smoCallBacks =_smoCallBacks;
362
355
  }
356
+ // Funciones para XML to JSON
357
+ xmlToJSON(xml:string) {
358
+ let getxml = new DOMParser();
359
+ let xmlDoc = getxml.parseFromString(xml,"text/xml");
360
+ // gets the JSON string
361
+ let json_str = this.jsonToStr(this.setJsonObj(xmlDoc));
362
+ // sets and returns the JSON object, if "rstr" undefined (not passed), else, returns JSON string
363
+ return json_str;
364
+ }
365
+ jsonToStr(js_obj:any) {
366
+ let 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, '""');
367
+ return (rejsn.indexOf('"parsererror": {') == -1) ? rejsn : 'Invalid XML format';
368
+ }
369
+ setJsonObj(xml: any) {
370
+ let js_obj = {} as any;
371
+ if (xml.nodeType == 1) { // Element
372
+ if (xml.attributes.length > 0) {
373
+ js_obj["@attributes"] = {};
374
+ for (let j = 0; j < xml.attributes.length; j++) {
375
+ let attribute = xml.attributes.item(j);
376
+ js_obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
377
+ }
378
+ }
379
+ } else if (xml.nodeType == 3) { // Text
380
+ js_obj = xml.nodeValue;
381
+ } else if (xml.nodeType == 4) { // CDATA
382
+ js_obj = xml.nodeValue;
383
+ }
384
+ if (xml.hasChildNodes()) {
385
+ for (let i = 0; i < xml.childNodes.length; i++) {
386
+ let item = xml.childNodes.item(i);
387
+ let nodeName = item.nodeName;
388
+ if (typeof (js_obj[nodeName]) == "undefined") {
389
+ js_obj[nodeName] = this.setJsonObj(item);
390
+ } else {
391
+ if (typeof (js_obj[nodeName].push) == "undefined") {
392
+ let old = js_obj[nodeName];
393
+ js_obj[nodeName] = [];
394
+ js_obj[nodeName].push(old);
395
+ }
396
+ js_obj[nodeName].push(this.setJsonObj(item));
397
+ }
398
+ }
399
+ }
400
+ return js_obj;
401
+ }
363
402
  dataToJSON(data:setDatasource):any {
364
403
  try {
365
404
  var parser = new DOMParser();
@@ -377,14 +416,14 @@ class Utils{
377
416
  return;
378
417
  }
379
418
  this.smoCallBacks.getFile(this.smo.vars.url);
380
-
419
+
381
420
  }
382
- startCheckDatasource():void{
421
+ startCheckDatasource(timeout: number = 10):void{
383
422
  this.getDatasource();
384
423
  let self = this;
385
424
  setInterval(function() {
386
425
  self.getDatasource();
387
- }, 10000);
426
+ }, timeout * 1000);
388
427
  }
389
428
  }
390
429
  export enum SMO_EVENT_TYPE{
@@ -394,7 +433,8 @@ export enum SMO_EVENT_TYPE{
394
433
  setCurrentStream = "setCurrentStream",
395
434
  infoCurrentLocation = "infoCurrentLocation",
396
435
  setSalidaData ="setSalidaData",
397
- updatefromsalida = "updatefromsalida"
436
+ updatefromsalida = "updatefromsalida",
437
+ setDatasourceJson = "setDatasourceJson"
398
438
  }
399
439
  /* start():void{
400
440
  this.emit("start");
@@ -414,7 +454,7 @@ export enum SMO_EVENT_TYPE{
414
454
  setSalidaData(data:DataSalida):void{
415
455
  this.emit("setSalidaData",data);
416
456
  }
417
-
457
+
418
458
  updatefromsalida(data:any):void{
419
459
  this.emit("updatefromsalida",data);
420
460
  } */
@@ -431,4 +471,4 @@ Scanning= 2,
431
471
  Timeout= 3,
432
472
  Warning= 4,
433
473
  Error= 5
434
- }
474
+ }