Showing
21 changed files
with
876 additions
and
452 deletions
build/bundle.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +Object.defineProperty(exports, '__esModule', { value: true }); | ||
| 4 | + | ||
| 5 | +var domain; | ||
| 6 | + | ||
| 7 | +// This constructor is used to store event handlers. Instantiating this is | ||
| 8 | +// faster than explicitly calling `Object.create(null)` to get a "clean" empty | ||
| 9 | +// object (tested with v8 v4.9). | ||
| 10 | +function EventHandlers() {} | ||
| 11 | +EventHandlers.prototype = Object.create(null); | ||
| 12 | + | ||
| 13 | +function EventEmitter() { | ||
| 14 | + EventEmitter.init.call(this); | ||
| 15 | +} | ||
| 16 | +EventEmitter.usingDomains = false; | ||
| 17 | + | ||
| 18 | +EventEmitter.prototype.domain = undefined; | ||
| 19 | +EventEmitter.prototype._events = undefined; | ||
| 20 | +EventEmitter.prototype._maxListeners = undefined; | ||
| 21 | + | ||
| 22 | +// By default EventEmitters will print a warning if more than 10 listeners are | ||
| 23 | +// added to it. This is a useful default which helps finding memory leaks. | ||
| 24 | +EventEmitter.defaultMaxListeners = 10; | ||
| 25 | + | ||
| 26 | +EventEmitter.init = function() { | ||
| 27 | + this.domain = null; | ||
| 28 | + if (EventEmitter.usingDomains) { | ||
| 29 | + // if there is an active domain, then attach to it. | ||
| 30 | + if (domain.active && !(this instanceof domain.Domain)) { | ||
| 31 | + this.domain = domain.active; | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + if (!this._events || this._events === Object.getPrototypeOf(this)._events) { | ||
| 36 | + this._events = new EventHandlers(); | ||
| 37 | + this._eventsCount = 0; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + this._maxListeners = this._maxListeners || undefined; | ||
| 41 | +}; | ||
| 42 | + | ||
| 43 | +// Obviously not all Emitters should be limited to 10. This function allows | ||
| 44 | +// that to be increased. Set to zero for unlimited. | ||
| 45 | +EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { | ||
| 46 | + if (typeof n !== 'number' || n < 0 || isNaN(n)) | ||
| 47 | + throw new TypeError('"n" argument must be a positive number'); | ||
| 48 | + this._maxListeners = n; | ||
| 49 | + return this; | ||
| 50 | +}; | ||
| 51 | + | ||
| 52 | +function $getMaxListeners(that) { | ||
| 53 | + if (that._maxListeners === undefined) | ||
| 54 | + return EventEmitter.defaultMaxListeners; | ||
| 55 | + return that._maxListeners; | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { | ||
| 59 | + return $getMaxListeners(this); | ||
| 60 | +}; | ||
| 61 | + | ||
| 62 | +// These standalone emit* functions are used to optimize calling of event | ||
| 63 | +// handlers for fast cases because emit() itself often has a variable number of | ||
| 64 | +// arguments and can be deoptimized because of that. These functions always have | ||
| 65 | +// the same number of arguments and thus do not get deoptimized, so the code | ||
| 66 | +// inside them can execute faster. | ||
| 67 | +function emitNone(handler, isFn, self) { | ||
| 68 | + if (isFn) | ||
| 69 | + handler.call(self); | ||
| 70 | + else { | ||
| 71 | + var len = handler.length; | ||
| 72 | + var listeners = arrayClone(handler, len); | ||
| 73 | + for (var i = 0; i < len; ++i) | ||
| 74 | + listeners[i].call(self); | ||
| 75 | + } | ||
| 76 | +} | ||
| 77 | +function emitOne(handler, isFn, self, arg1) { | ||
| 78 | + if (isFn) | ||
| 79 | + handler.call(self, arg1); | ||
| 80 | + else { | ||
| 81 | + var len = handler.length; | ||
| 82 | + var listeners = arrayClone(handler, len); | ||
| 83 | + for (var i = 0; i < len; ++i) | ||
| 84 | + listeners[i].call(self, arg1); | ||
| 85 | + } | ||
| 86 | +} | ||
| 87 | +function emitTwo(handler, isFn, self, arg1, arg2) { | ||
| 88 | + if (isFn) | ||
| 89 | + handler.call(self, arg1, arg2); | ||
| 90 | + else { | ||
| 91 | + var len = handler.length; | ||
| 92 | + var listeners = arrayClone(handler, len); | ||
| 93 | + for (var i = 0; i < len; ++i) | ||
| 94 | + listeners[i].call(self, arg1, arg2); | ||
| 95 | + } | ||
| 96 | +} | ||
| 97 | +function emitThree(handler, isFn, self, arg1, arg2, arg3) { | ||
| 98 | + if (isFn) | ||
| 99 | + handler.call(self, arg1, arg2, arg3); | ||
| 100 | + else { | ||
| 101 | + var len = handler.length; | ||
| 102 | + var listeners = arrayClone(handler, len); | ||
| 103 | + for (var i = 0; i < len; ++i) | ||
| 104 | + listeners[i].call(self, arg1, arg2, arg3); | ||
| 105 | + } | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +function emitMany(handler, isFn, self, args) { | ||
| 109 | + if (isFn) | ||
| 110 | + handler.apply(self, args); | ||
| 111 | + else { | ||
| 112 | + var len = handler.length; | ||
| 113 | + var listeners = arrayClone(handler, len); | ||
| 114 | + for (var i = 0; i < len; ++i) | ||
| 115 | + listeners[i].apply(self, args); | ||
| 116 | + } | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +EventEmitter.prototype.emit = function emit(type) { | ||
| 120 | + var er, handler, len, args, i, events, domain; | ||
| 121 | + var needDomainExit = false; | ||
| 122 | + var doError = (type === 'error'); | ||
| 123 | + | ||
| 124 | + events = this._events; | ||
| 125 | + if (events) | ||
| 126 | + doError = (doError && events.error == null); | ||
| 127 | + else if (!doError) | ||
| 128 | + return false; | ||
| 129 | + | ||
| 130 | + domain = this.domain; | ||
| 131 | + | ||
| 132 | + // If there is no 'error' event listener then throw. | ||
| 133 | + if (doError) { | ||
| 134 | + er = arguments[1]; | ||
| 135 | + if (domain) { | ||
| 136 | + if (!er) | ||
| 137 | + er = new Error('Uncaught, unspecified "error" event'); | ||
| 138 | + er.domainEmitter = this; | ||
| 139 | + er.domain = domain; | ||
| 140 | + er.domainThrown = false; | ||
| 141 | + domain.emit('error', er); | ||
| 142 | + } else if (er instanceof Error) { | ||
| 143 | + throw er; // Unhandled 'error' event | ||
| 144 | + } else { | ||
| 145 | + // At least give some kind of context to the user | ||
| 146 | + var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); | ||
| 147 | + err.context = er; | ||
| 148 | + throw err; | ||
| 149 | + } | ||
| 150 | + return false; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + handler = events[type]; | ||
| 154 | + | ||
| 155 | + if (!handler) | ||
| 156 | + return false; | ||
| 157 | + | ||
| 158 | + var isFn = typeof handler === 'function'; | ||
| 159 | + len = arguments.length; | ||
| 160 | + switch (len) { | ||
| 161 | + // fast cases | ||
| 162 | + case 1: | ||
| 163 | + emitNone(handler, isFn, this); | ||
| 164 | + break; | ||
| 165 | + case 2: | ||
| 166 | + emitOne(handler, isFn, this, arguments[1]); | ||
| 167 | + break; | ||
| 168 | + case 3: | ||
| 169 | + emitTwo(handler, isFn, this, arguments[1], arguments[2]); | ||
| 170 | + break; | ||
| 171 | + case 4: | ||
| 172 | + emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]); | ||
| 173 | + break; | ||
| 174 | + // slower | ||
| 175 | + default: | ||
| 176 | + args = new Array(len - 1); | ||
| 177 | + for (i = 1; i < len; i++) | ||
| 178 | + args[i - 1] = arguments[i]; | ||
| 179 | + emitMany(handler, isFn, this, args); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + if (needDomainExit) | ||
| 183 | + domain.exit(); | ||
| 184 | + | ||
| 185 | + return true; | ||
| 186 | +}; | ||
| 187 | + | ||
| 188 | +function _addListener(target, type, listener, prepend) { | ||
| 189 | + var m; | ||
| 190 | + var events; | ||
| 191 | + var existing; | ||
| 192 | + | ||
| 193 | + if (typeof listener !== 'function') | ||
| 194 | + throw new TypeError('"listener" argument must be a function'); | ||
| 195 | + | ||
| 196 | + events = target._events; | ||
| 197 | + if (!events) { | ||
| 198 | + events = target._events = new EventHandlers(); | ||
| 199 | + target._eventsCount = 0; | ||
| 200 | + } else { | ||
| 201 | + // To avoid recursion in the case that type === "newListener"! Before | ||
| 202 | + // adding it to the listeners, first emit "newListener". | ||
| 203 | + if (events.newListener) { | ||
| 204 | + target.emit('newListener', type, | ||
| 205 | + listener.listener ? listener.listener : listener); | ||
| 206 | + | ||
| 207 | + // Re-assign `events` because a newListener handler could have caused the | ||
| 208 | + // this._events to be assigned to a new object | ||
| 209 | + events = target._events; | ||
| 210 | + } | ||
| 211 | + existing = events[type]; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + if (!existing) { | ||
| 215 | + // Optimize the case of one listener. Don't need the extra array object. | ||
| 216 | + existing = events[type] = listener; | ||
| 217 | + ++target._eventsCount; | ||
| 218 | + } else { | ||
| 219 | + if (typeof existing === 'function') { | ||
| 220 | + // Adding the second element, need to change to array. | ||
| 221 | + existing = events[type] = prepend ? [listener, existing] : | ||
| 222 | + [existing, listener]; | ||
| 223 | + } else { | ||
| 224 | + // If we've already got an array, just append. | ||
| 225 | + if (prepend) { | ||
| 226 | + existing.unshift(listener); | ||
| 227 | + } else { | ||
| 228 | + existing.push(listener); | ||
| 229 | + } | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + // Check for listener leak | ||
| 233 | + if (!existing.warned) { | ||
| 234 | + m = $getMaxListeners(target); | ||
| 235 | + if (m && m > 0 && existing.length > m) { | ||
| 236 | + existing.warned = true; | ||
| 237 | + var w = new Error('Possible EventEmitter memory leak detected. ' + | ||
| 238 | + existing.length + ' ' + type + ' listeners added. ' + | ||
| 239 | + 'Use emitter.setMaxListeners() to increase limit'); | ||
| 240 | + w.name = 'MaxListenersExceededWarning'; | ||
| 241 | + w.emitter = target; | ||
| 242 | + w.type = type; | ||
| 243 | + w.count = existing.length; | ||
| 244 | + emitWarning(w); | ||
| 245 | + } | ||
| 246 | + } | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + return target; | ||
| 250 | +} | ||
| 251 | +function emitWarning(e) { | ||
| 252 | + typeof console.warn === 'function' ? console.warn(e) : console.log(e); | ||
| 253 | +} | ||
| 254 | +EventEmitter.prototype.addListener = function addListener(type, listener) { | ||
| 255 | + return _addListener(this, type, listener, false); | ||
| 256 | +}; | ||
| 257 | + | ||
| 258 | +EventEmitter.prototype.on = EventEmitter.prototype.addListener; | ||
| 259 | + | ||
| 260 | +EventEmitter.prototype.prependListener = | ||
| 261 | + function prependListener(type, listener) { | ||
| 262 | + return _addListener(this, type, listener, true); | ||
| 263 | + }; | ||
| 264 | + | ||
| 265 | +function _onceWrap(target, type, listener) { | ||
| 266 | + var fired = false; | ||
| 267 | + function g() { | ||
| 268 | + target.removeListener(type, g); | ||
| 269 | + if (!fired) { | ||
| 270 | + fired = true; | ||
| 271 | + listener.apply(target, arguments); | ||
| 272 | + } | ||
| 273 | + } | ||
| 274 | + g.listener = listener; | ||
| 275 | + return g; | ||
| 276 | +} | ||
| 277 | + | ||
| 278 | +EventEmitter.prototype.once = function once(type, listener) { | ||
| 279 | + if (typeof listener !== 'function') | ||
| 280 | + throw new TypeError('"listener" argument must be a function'); | ||
| 281 | + this.on(type, _onceWrap(this, type, listener)); | ||
| 282 | + return this; | ||
| 283 | +}; | ||
| 284 | + | ||
| 285 | +EventEmitter.prototype.prependOnceListener = | ||
| 286 | + function prependOnceListener(type, listener) { | ||
| 287 | + if (typeof listener !== 'function') | ||
| 288 | + throw new TypeError('"listener" argument must be a function'); | ||
| 289 | + this.prependListener(type, _onceWrap(this, type, listener)); | ||
| 290 | + return this; | ||
| 291 | + }; | ||
| 292 | + | ||
| 293 | +// emits a 'removeListener' event iff the listener was removed | ||
| 294 | +EventEmitter.prototype.removeListener = | ||
| 295 | + function removeListener(type, listener) { | ||
| 296 | + var list, events, position, i, originalListener; | ||
| 297 | + | ||
| 298 | + if (typeof listener !== 'function') | ||
| 299 | + throw new TypeError('"listener" argument must be a function'); | ||
| 300 | + | ||
| 301 | + events = this._events; | ||
| 302 | + if (!events) | ||
| 303 | + return this; | ||
| 304 | + | ||
| 305 | + list = events[type]; | ||
| 306 | + if (!list) | ||
| 307 | + return this; | ||
| 308 | + | ||
| 309 | + if (list === listener || (list.listener && list.listener === listener)) { | ||
| 310 | + if (--this._eventsCount === 0) | ||
| 311 | + this._events = new EventHandlers(); | ||
| 312 | + else { | ||
| 313 | + delete events[type]; | ||
| 314 | + if (events.removeListener) | ||
| 315 | + this.emit('removeListener', type, list.listener || listener); | ||
| 316 | + } | ||
| 317 | + } else if (typeof list !== 'function') { | ||
| 318 | + position = -1; | ||
| 319 | + | ||
| 320 | + for (i = list.length; i-- > 0;) { | ||
| 321 | + if (list[i] === listener || | ||
| 322 | + (list[i].listener && list[i].listener === listener)) { | ||
| 323 | + originalListener = list[i].listener; | ||
| 324 | + position = i; | ||
| 325 | + break; | ||
| 326 | + } | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + if (position < 0) | ||
| 330 | + return this; | ||
| 331 | + | ||
| 332 | + if (list.length === 1) { | ||
| 333 | + list[0] = undefined; | ||
| 334 | + if (--this._eventsCount === 0) { | ||
| 335 | + this._events = new EventHandlers(); | ||
| 336 | + return this; | ||
| 337 | + } else { | ||
| 338 | + delete events[type]; | ||
| 339 | + } | ||
| 340 | + } else { | ||
| 341 | + spliceOne(list, position); | ||
| 342 | + } | ||
| 343 | + | ||
| 344 | + if (events.removeListener) | ||
| 345 | + this.emit('removeListener', type, originalListener || listener); | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + return this; | ||
| 349 | + }; | ||
| 350 | + | ||
| 351 | +EventEmitter.prototype.removeAllListeners = | ||
| 352 | + function removeAllListeners(type) { | ||
| 353 | + var listeners, events; | ||
| 354 | + | ||
| 355 | + events = this._events; | ||
| 356 | + if (!events) | ||
| 357 | + return this; | ||
| 358 | + | ||
| 359 | + // not listening for removeListener, no need to emit | ||
| 360 | + if (!events.removeListener) { | ||
| 361 | + if (arguments.length === 0) { | ||
| 362 | + this._events = new EventHandlers(); | ||
| 363 | + this._eventsCount = 0; | ||
| 364 | + } else if (events[type]) { | ||
| 365 | + if (--this._eventsCount === 0) | ||
| 366 | + this._events = new EventHandlers(); | ||
| 367 | + else | ||
| 368 | + delete events[type]; | ||
| 369 | + } | ||
| 370 | + return this; | ||
| 371 | + } | ||
| 372 | + | ||
| 373 | + // emit removeListener for all listeners on all events | ||
| 374 | + if (arguments.length === 0) { | ||
| 375 | + var keys = Object.keys(events); | ||
| 376 | + for (var i = 0, key; i < keys.length; ++i) { | ||
| 377 | + key = keys[i]; | ||
| 378 | + if (key === 'removeListener') continue; | ||
| 379 | + this.removeAllListeners(key); | ||
| 380 | + } | ||
| 381 | + this.removeAllListeners('removeListener'); | ||
| 382 | + this._events = new EventHandlers(); | ||
| 383 | + this._eventsCount = 0; | ||
| 384 | + return this; | ||
| 385 | + } | ||
| 386 | + | ||
| 387 | + listeners = events[type]; | ||
| 388 | + | ||
| 389 | + if (typeof listeners === 'function') { | ||
| 390 | + this.removeListener(type, listeners); | ||
| 391 | + } else if (listeners) { | ||
| 392 | + // LIFO order | ||
| 393 | + do { | ||
| 394 | + this.removeListener(type, listeners[listeners.length - 1]); | ||
| 395 | + } while (listeners[0]); | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + return this; | ||
| 399 | + }; | ||
| 400 | + | ||
| 401 | +EventEmitter.prototype.listeners = function listeners(type) { | ||
| 402 | + var evlistener; | ||
| 403 | + var ret; | ||
| 404 | + var events = this._events; | ||
| 405 | + | ||
| 406 | + if (!events) | ||
| 407 | + ret = []; | ||
| 408 | + else { | ||
| 409 | + evlistener = events[type]; | ||
| 410 | + if (!evlistener) | ||
| 411 | + ret = []; | ||
| 412 | + else if (typeof evlistener === 'function') | ||
| 413 | + ret = [evlistener.listener || evlistener]; | ||
| 414 | + else | ||
| 415 | + ret = unwrapListeners(evlistener); | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + return ret; | ||
| 419 | +}; | ||
| 420 | + | ||
| 421 | +EventEmitter.listenerCount = function(emitter, type) { | ||
| 422 | + if (typeof emitter.listenerCount === 'function') { | ||
| 423 | + return emitter.listenerCount(type); | ||
| 424 | + } else { | ||
| 425 | + return listenerCount.call(emitter, type); | ||
| 426 | + } | ||
| 427 | +}; | ||
| 428 | + | ||
| 429 | +EventEmitter.prototype.listenerCount = listenerCount; | ||
| 430 | +function listenerCount(type) { | ||
| 431 | + var events = this._events; | ||
| 432 | + | ||
| 433 | + if (events) { | ||
| 434 | + var evlistener = events[type]; | ||
| 435 | + | ||
| 436 | + if (typeof evlistener === 'function') { | ||
| 437 | + return 1; | ||
| 438 | + } else if (evlistener) { | ||
| 439 | + return evlistener.length; | ||
| 440 | + } | ||
| 441 | + } | ||
| 442 | + | ||
| 443 | + return 0; | ||
| 444 | +} | ||
| 445 | + | ||
| 446 | +EventEmitter.prototype.eventNames = function eventNames() { | ||
| 447 | + return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : []; | ||
| 448 | +}; | ||
| 449 | + | ||
| 450 | +// About 1.5x faster than the two-arg version of Array#splice(). | ||
| 451 | +function spliceOne(list, index) { | ||
| 452 | + for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) | ||
| 453 | + list[i] = list[k]; | ||
| 454 | + list.pop(); | ||
| 455 | +} | ||
| 456 | + | ||
| 457 | +function arrayClone(arr, i) { | ||
| 458 | + var copy = new Array(i); | ||
| 459 | + while (i--) | ||
| 460 | + copy[i] = arr[i]; | ||
| 461 | + return copy; | ||
| 462 | +} | ||
| 463 | + | ||
| 464 | +function unwrapListeners(arr) { | ||
| 465 | + var ret = new Array(arr.length); | ||
| 466 | + for (var i = 0; i < ret.length; ++i) { | ||
| 467 | + ret[i] = arr[i].listener || arr[i]; | ||
| 468 | + } | ||
| 469 | + return ret; | ||
| 470 | +} | ||
| 471 | + | ||
| 472 | +function __extends(d, b) { | ||
| 473 | + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
| 474 | + function __() { this.constructor = d; } | ||
| 475 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| 476 | +} | ||
| 477 | + | ||
| 478 | +var Util = (function () { | ||
| 479 | + function Util() { | ||
| 480 | + } | ||
| 481 | + Util.getISODate = function () { | ||
| 482 | + return (new Date()).toISOString().slice(0, 10); | ||
| 483 | + }; | ||
| 484 | + Util.getDateInMinutes = function () { | ||
| 485 | + var now = new Date(); | ||
| 486 | + return (now.getHours() * 60) + now.getMinutes(); | ||
| 487 | + }; | ||
| 488 | + /** | ||
| 489 | + * convert a time input to minutes | ||
| 490 | + * e.g. 23:59 = 1439 | ||
| 491 | + */ | ||
| 492 | + Util.convertToMinutes = function (time) { | ||
| 493 | + var times = time.split(":"); | ||
| 494 | + var convered = (parseInt(times[0]) * 60) + parseInt(times[1]); | ||
| 495 | + return (convered >= 0 && convered <= 1439) ? convered : 0; | ||
| 496 | + }; | ||
| 497 | + Util.calculateNextMinute = function () { | ||
| 498 | + return (60 - (Math.round((new Date()).getTime() / 1000) % 60)) * 1000; | ||
| 499 | + }; | ||
| 500 | + return Util; | ||
| 501 | +}()); | ||
| 502 | + | ||
| 503 | +var STATE_START = "start"; | ||
| 504 | +var STATE_STOP = "stop"; | ||
| 505 | +var Player = (function (_super) { | ||
| 506 | + __extends(Player, _super); | ||
| 507 | + function Player() { | ||
| 508 | + _super.apply(this, arguments); | ||
| 509 | + this._minutesReplication = 5; | ||
| 510 | + this._replicationRetry = 10000; | ||
| 511 | + this._currentProgramItemId = ''; | ||
| 512 | + this._currentReplicationCounter = 0; | ||
| 513 | + this._state = STATE_STOP; | ||
| 514 | + } | ||
| 515 | + Object.defineProperty(Player.prototype, "state", { | ||
| 516 | + set: function (st) { | ||
| 517 | + this._state = st; | ||
| 518 | + }, | ||
| 519 | + enumerable: true, | ||
| 520 | + configurable: true | ||
| 521 | + }); | ||
| 522 | + Object.defineProperty(Player.prototype, "programManager", { | ||
| 523 | + get: function () { | ||
| 524 | + return this._programManager; | ||
| 525 | + }, | ||
| 526 | + set: function (pm) { | ||
| 527 | + this._programManager = pm; | ||
| 528 | + }, | ||
| 529 | + enumerable: true, | ||
| 530 | + configurable: true | ||
| 531 | + }); | ||
| 532 | + Object.defineProperty(Player.prototype, "programRepository", { | ||
| 533 | + get: function () { | ||
| 534 | + return this._programRepository; | ||
| 535 | + }, | ||
| 536 | + set: function (pr) { | ||
| 537 | + this._programRepository = pr; | ||
| 538 | + }, | ||
| 539 | + enumerable: true, | ||
| 540 | + configurable: true | ||
| 541 | + }); | ||
| 542 | + Object.defineProperty(Player.prototype, "minutesReplication", { | ||
| 543 | + get: function () { | ||
| 544 | + return this._minutesReplication; | ||
| 545 | + }, | ||
| 546 | + set: function (mr) { | ||
| 547 | + this._minutesReplication = mr; | ||
| 548 | + }, | ||
| 549 | + enumerable: true, | ||
| 550 | + configurable: true | ||
| 551 | + }); | ||
| 552 | + Object.defineProperty(Player.prototype, "replicationRetry", { | ||
| 553 | + get: function () { | ||
| 554 | + return this._replicationRetry; | ||
| 555 | + }, | ||
| 556 | + set: function (rr) { | ||
| 557 | + this._replicationRetry = rr; | ||
| 558 | + }, | ||
| 559 | + enumerable: true, | ||
| 560 | + configurable: true | ||
| 561 | + }); | ||
| 562 | + Player.prototype.triggerReplication = function () { | ||
| 563 | + var _this = this; | ||
| 564 | + return this.programRepository.replicate() | ||
| 565 | + .then(function () { | ||
| 566 | + _this._currentReplicationCounter = 0; | ||
| 567 | + _this.trigger(_this.triggerProgramItemId, Util.calculateNextMinute()); | ||
| 568 | + }) | ||
| 569 | + .catch(function () { | ||
| 570 | + _this.trigger(_this.triggerReplication, _this.replicationRetry); | ||
| 571 | + }); | ||
| 572 | + }; | ||
| 573 | + Player.prototype.triggerProgramItemId = function () { | ||
| 574 | + var _this = this; | ||
| 575 | + this.programManager.getCurrentProgramItemId() | ||
| 576 | + .then(function (programItemId) { | ||
| 577 | + _this._currentReplicationCounter++; | ||
| 578 | + // if there is a new program item id trigger play | ||
| 579 | + // else (1) calculate next potential program change point | ||
| 580 | + // or (2) trigger replication | ||
| 581 | + if (programItemId != _this._currentProgramItemId) { | ||
| 582 | + _this._currentProgramItemId = programItemId; | ||
| 583 | + _this.emit('play', programItemId); | ||
| 584 | + } | ||
| 585 | + else if (_this._currentReplicationCounter >= _this._minutesReplication) { | ||
| 586 | + _this.triggerReplication(); | ||
| 587 | + } | ||
| 588 | + else { | ||
| 589 | + _this.trigger(_this.triggerProgramItemId, Util.calculateNextMinute()); | ||
| 590 | + } | ||
| 591 | + }); | ||
| 592 | + }; | ||
| 593 | + Player.prototype.trigger = function (func, milliseconds) { | ||
| 594 | + if (this._state === STATE_START) { | ||
| 595 | + setTimeout(function () { func(); }, milliseconds); | ||
| 596 | + } | ||
| 597 | + }; | ||
| 598 | + Player.prototype.start = function () { | ||
| 599 | + if (this._state === STATE_STOP) { | ||
| 600 | + this.triggerReplication(); | ||
| 601 | + this._state = STATE_START; | ||
| 602 | + } | ||
| 603 | + }; | ||
| 604 | + Player.prototype.stop = function () { | ||
| 605 | + this._state = STATE_STOP; | ||
| 606 | + }; | ||
| 607 | + return Player; | ||
| 608 | +}(EventEmitter)); | ||
| 609 | + | ||
| 610 | +var ProgramManager = (function () { | ||
| 611 | + function ProgramManager() { | ||
| 612 | + } | ||
| 613 | + Object.defineProperty(ProgramManager.prototype, "programRepository", { | ||
| 614 | + get: function () { | ||
| 615 | + return this._programRepository; | ||
| 616 | + }, | ||
| 617 | + set: function (pr) { | ||
| 618 | + this._programRepository = pr; | ||
| 619 | + }, | ||
| 620 | + enumerable: true, | ||
| 621 | + configurable: true | ||
| 622 | + }); | ||
| 623 | + ProgramManager.prototype.getCurrentProgramItemId = function () { | ||
| 624 | + var _this = this; | ||
| 625 | + return new Promise(function (resolve, reject) { | ||
| 626 | + _this.findCurrentProgramSegment().then(function (programSegment) { | ||
| 627 | + var currentProgramItemId = programSegment.default; | ||
| 628 | + if (programSegment.schedule) { | ||
| 629 | + currentProgramItemId = _this.findCurrentProgramItem(programSegment.schedule, Util.getDateInMinutes()); | ||
| 630 | + } | ||
| 631 | + resolve(currentProgramItemId); | ||
| 632 | + }); | ||
| 633 | + }); | ||
| 634 | + }; | ||
| 635 | + /** | ||
| 636 | + * find program item in schedule, which fits | ||
| 637 | + * according to current hh:mm | ||
| 638 | + */ | ||
| 639 | + ProgramManager.prototype.findCurrentProgramItem = function (schedule, dateInMinutes) { | ||
| 640 | + var timeList = []; | ||
| 641 | + var tmpSchedule = {}; | ||
| 642 | + for (var startTime in schedule) { | ||
| 643 | + if (schedule.hasOwnProperty(startTime)) { | ||
| 644 | + var minutes = Util.convertToMinutes(startTime); | ||
| 645 | + timeList.push(minutes); | ||
| 646 | + tmpSchedule[minutes] = schedule[startTime]; | ||
| 647 | + } | ||
| 648 | + } | ||
| 649 | + // sort ascending (-) | ||
| 650 | + timeList.sort(function (a, b) { return a - b; }); | ||
| 651 | + var last = 0; | ||
| 652 | + for (var i = 0; i < timeList.length; i++) { | ||
| 653 | + if (timeList[i] <= dateInMinutes) { | ||
| 654 | + last = timeList[i]; | ||
| 655 | + } | ||
| 656 | + else { | ||
| 657 | + break; | ||
| 658 | + } | ||
| 659 | + } | ||
| 660 | + return tmpSchedule[last]; | ||
| 661 | + }; | ||
| 662 | + /** | ||
| 663 | + * Find the program segment | ||
| 664 | + * This is dependent on the date set on the device | ||
| 665 | + */ | ||
| 666 | + ProgramManager.prototype.findCurrentProgramSegment = function () { | ||
| 667 | + var _this = this; | ||
| 668 | + return new Promise(function (resolve, reject) { | ||
| 669 | + var today = Util.getISODate(); | ||
| 670 | + _this.programRepository.findByType('program') | ||
| 671 | + .then(function (programs) { | ||
| 672 | + if (programs.length > 0) { | ||
| 673 | + var program = programs[0]; | ||
| 674 | + var programSegmentId = void 0; | ||
| 675 | + // if there is a program_segment for today else default | ||
| 676 | + if (program.schedule && program.schedule[today]) { | ||
| 677 | + programSegmentId = program.schedule[today]; | ||
| 678 | + } | ||
| 679 | + else { | ||
| 680 | + programSegmentId = program.default; | ||
| 681 | + } | ||
| 682 | + _this.programRepository | ||
| 683 | + .findById(programSegmentId) | ||
| 684 | + .then(function (programSegment) { | ||
| 685 | + resolve(programSegment); | ||
| 686 | + }).catch(function (error) { | ||
| 687 | + reject("program segment not found"); | ||
| 688 | + }); | ||
| 689 | + } | ||
| 690 | + else { | ||
| 691 | + reject('No Program found'); | ||
| 692 | + } | ||
| 693 | + }).catch(function (error) { | ||
| 694 | + reject(error); | ||
| 695 | + }); | ||
| 696 | + }); | ||
| 697 | + }; | ||
| 698 | + return ProgramManager; | ||
| 699 | +}()); | ||
| 700 | + | ||
| 701 | +var PROGRAM_ITEM_TYPE_SLIDESHOW = "slideshow"; | ||
| 702 | +var PROGRAM_ITEM_TYPE_VIDEO = "video"; | ||
| 703 | +var ProgramItem = (function () { | ||
| 704 | + function ProgramItem() { | ||
| 705 | + } | ||
| 706 | + Object.defineProperty(ProgramItem.prototype, "type", { | ||
| 707 | + get: function () { | ||
| 708 | + return this._type; | ||
| 709 | + }, | ||
| 710 | + set: function (t) { | ||
| 711 | + this._type = t; | ||
| 712 | + }, | ||
| 713 | + enumerable: true, | ||
| 714 | + configurable: true | ||
| 715 | + }); | ||
| 716 | + Object.defineProperty(ProgramItem.prototype, "data", { | ||
| 717 | + get: function () { | ||
| 718 | + return this._data; | ||
| 719 | + }, | ||
| 720 | + set: function (d) { | ||
| 721 | + this._data = d; | ||
| 722 | + }, | ||
| 723 | + enumerable: true, | ||
| 724 | + configurable: true | ||
| 725 | + }); | ||
| 726 | + return ProgramItem; | ||
| 727 | +}()); | ||
| 728 | + | ||
| 729 | +var ProgramItemFactory = (function () { | ||
| 730 | + function ProgramItemFactory() { | ||
| 731 | + } | ||
| 732 | + Object.defineProperty(ProgramItemFactory.prototype, "basePath", { | ||
| 733 | + get: function () { | ||
| 734 | + return this._basePath; | ||
| 735 | + }, | ||
| 736 | + set: function (bp) { | ||
| 737 | + this._basePath = bp; | ||
| 738 | + }, | ||
| 739 | + enumerable: true, | ||
| 740 | + configurable: true | ||
| 741 | + }); | ||
| 742 | + Object.defineProperty(ProgramItemFactory.prototype, "programRepository", { | ||
| 743 | + get: function () { | ||
| 744 | + return this._programRepository; | ||
| 745 | + }, | ||
| 746 | + set: function (pr) { | ||
| 747 | + this._programRepository = pr; | ||
| 748 | + }, | ||
| 749 | + enumerable: true, | ||
| 750 | + configurable: true | ||
| 751 | + }); | ||
| 752 | + ProgramItemFactory.prototype.getProgramItem = function (programItemId) { | ||
| 753 | + var _this = this; | ||
| 754 | + return this.programRepository | ||
| 755 | + .findById(programItemId) | ||
| 756 | + .then(function (programItem) { | ||
| 757 | + return _this.prepareProgramItem(programItem.program_item_type, programItem); | ||
| 758 | + }); | ||
| 759 | + }; | ||
| 760 | + ProgramItemFactory.prototype.prepareProgramItem = function (type, data) { | ||
| 761 | + var programItem = new ProgramItem(); | ||
| 762 | + programItem.type = type; | ||
| 763 | + if (type === PROGRAM_ITEM_TYPE_VIDEO) { | ||
| 764 | + return this.prepareVideoItem(programItem, data); | ||
| 765 | + } | ||
| 766 | + else if (type === PROGRAM_ITEM_TYPE_SLIDESHOW) { | ||
| 767 | + return this.prepareSlideshowItem(programItem, data); | ||
| 768 | + } | ||
| 769 | + else { | ||
| 770 | + return null; | ||
| 771 | + } | ||
| 772 | + }; | ||
| 773 | + ProgramItemFactory.prototype.prepareSlideshowItem = function (programItem, data) { | ||
| 774 | + var _this = this; | ||
| 775 | + return this._programRepository.findByIds(data.images) | ||
| 776 | + .then(function (images) { | ||
| 777 | + programItem.data = { | ||
| 778 | + speed: data.settings.speed, | ||
| 779 | + effect: data.settings.effect, | ||
| 780 | + images: [] | ||
| 781 | + }; | ||
| 782 | + for (var _i = 0, images_1 = images; _i < images_1.length; _i++) { | ||
| 783 | + var image = images_1[_i]; | ||
| 784 | + programItem.data.images.push(_this.basePath + image.filename); | ||
| 785 | + } | ||
| 786 | + return programItem; | ||
| 787 | + }); | ||
| 788 | + }; | ||
| 789 | + ProgramItemFactory.prototype.prepareVideoItem = function (programItem, data) { | ||
| 790 | + var _this = this; | ||
| 791 | + return this._programRepository.findById(data.video) | ||
| 792 | + .then(function (data) { | ||
| 793 | + programItem.data = { | ||
| 794 | + video: _this.basePath + data['filename'] | ||
| 795 | + }; | ||
| 796 | + return programItem; | ||
| 797 | + }); | ||
| 798 | + }; | ||
| 799 | + return ProgramItemFactory; | ||
| 800 | +}()); | ||
| 801 | + | ||
| 802 | +exports.Player = Player; | ||
| 803 | +exports.ProgramManager = ProgramManager; | ||
| 804 | +exports.PROGRAM_ITEM_TYPE_SLIDESHOW = PROGRAM_ITEM_TYPE_SLIDESHOW; | ||
| 805 | +exports.PROGRAM_ITEM_TYPE_VIDEO = PROGRAM_ITEM_TYPE_VIDEO; | ||
| 806 | +exports.ProgramItem = ProgramItem; | ||
| 807 | +exports.ProgramItemFactory = ProgramItemFactory; | ||
| 808 | +//# sourceMappingURL=bundle.js.map |
build/bundle.js.map
0 → 100644
| 1 | +{"version":3,"file":"bundle.js","sources":["../node_modules/rollup-plugin-node-builtins/src/es6/events.js","../src/util.ts","../src/player.ts","../src/program-manager.ts","../src/program-item/program-item.ts","../src/program-item/program-item-factory.ts"],"sourcesContent":["'use strict';\n\nvar domain;\n\n// This constructor is used to store event handlers. Instantiating this is\n// faster than explicitly calling `Object.create(null)` to get a \"clean\" empty\n// object (tested with v8 v4.9).\nfunction EventHandlers() {}\nEventHandlers.prototype = Object.create(null);\n\nfunction EventEmitter() {\n EventEmitter.init.call(this);\n}\nexport default EventEmitter;\nexport {EventEmitter};\n\nEventEmitter.usingDomains = false;\n\nEventEmitter.prototype.domain = undefined;\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nEventEmitter.defaultMaxListeners = 10;\n\nEventEmitter.init = function() {\n this.domain = null;\n if (EventEmitter.usingDomains) {\n // if there is an active domain, then attach to it.\n if (domain.active && !(this instanceof domain.Domain)) {\n this.domain = domain.active;\n }\n }\n\n if (!this._events || this._events === Object.getPrototypeOf(this)._events) {\n this._events = new EventHandlers();\n this._eventsCount = 0;\n }\n\n this._maxListeners = this._maxListeners || undefined;\n};\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {\n if (typeof n !== 'number' || n < 0 || isNaN(n))\n throw new TypeError('\"n\" argument must be a positive number');\n this._maxListeners = n;\n return this;\n};\n\nfunction $getMaxListeners(that) {\n if (that._maxListeners === undefined)\n return EventEmitter.defaultMaxListeners;\n return that._maxListeners;\n}\n\nEventEmitter.prototype.getMaxListeners = function getMaxListeners() {\n return $getMaxListeners(this);\n};\n\n// These standalone emit* functions are used to optimize calling of event\n// handlers for fast cases because emit() itself often has a variable number of\n// arguments and can be deoptimized because of that. These functions always have\n// the same number of arguments and thus do not get deoptimized, so the code\n// inside them can execute faster.\nfunction emitNone(handler, isFn, self) {\n if (isFn)\n handler.call(self);\n else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n listeners[i].call(self);\n }\n}\nfunction emitOne(handler, isFn, self, arg1) {\n if (isFn)\n handler.call(self, arg1);\n else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n listeners[i].call(self, arg1);\n }\n}\nfunction emitTwo(handler, isFn, self, arg1, arg2) {\n if (isFn)\n handler.call(self, arg1, arg2);\n else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n listeners[i].call(self, arg1, arg2);\n }\n}\nfunction emitThree(handler, isFn, self, arg1, arg2, arg3) {\n if (isFn)\n handler.call(self, arg1, arg2, arg3);\n else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n listeners[i].call(self, arg1, arg2, arg3);\n }\n}\n\nfunction emitMany(handler, isFn, self, args) {\n if (isFn)\n handler.apply(self, args);\n else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n listeners[i].apply(self, args);\n }\n}\n\nEventEmitter.prototype.emit = function emit(type) {\n var er, handler, len, args, i, events, domain;\n var needDomainExit = false;\n var doError = (type === 'error');\n\n events = this._events;\n if (events)\n doError = (doError && events.error == null);\n else if (!doError)\n return false;\n\n domain = this.domain;\n\n // If there is no 'error' event listener then throw.\n if (doError) {\n er = arguments[1];\n if (domain) {\n if (!er)\n er = new Error('Uncaught, unspecified \"error\" event');\n er.domainEmitter = this;\n er.domain = domain;\n er.domainThrown = false;\n domain.emit('error', er);\n } else if (er instanceof Error) {\n throw er; // Unhandled 'error' event\n } else {\n // At least give some kind of context to the user\n var err = new Error('Uncaught, unspecified \"error\" event. (' + er + ')');\n err.context = er;\n throw err;\n }\n return false;\n }\n\n handler = events[type];\n\n if (!handler)\n return false;\n\n var isFn = typeof handler === 'function';\n len = arguments.length;\n switch (len) {\n // fast cases\n case 1:\n emitNone(handler, isFn, this);\n break;\n case 2:\n emitOne(handler, isFn, this, arguments[1]);\n break;\n case 3:\n emitTwo(handler, isFn, this, arguments[1], arguments[2]);\n break;\n case 4:\n emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);\n break;\n // slower\n default:\n args = new Array(len - 1);\n for (i = 1; i < len; i++)\n args[i - 1] = arguments[i];\n emitMany(handler, isFn, this, args);\n }\n\n if (needDomainExit)\n domain.exit();\n\n return true;\n};\n\nfunction _addListener(target, type, listener, prepend) {\n var m;\n var events;\n var existing;\n\n if (typeof listener !== 'function')\n throw new TypeError('\"listener\" argument must be a function');\n\n events = target._events;\n if (!events) {\n events = target._events = new EventHandlers();\n target._eventsCount = 0;\n } else {\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (events.newListener) {\n target.emit('newListener', type,\n listener.listener ? listener.listener : listener);\n\n // Re-assign `events` because a newListener handler could have caused the\n // this._events to be assigned to a new object\n events = target._events;\n }\n existing = events[type];\n }\n\n if (!existing) {\n // Optimize the case of one listener. Don't need the extra array object.\n existing = events[type] = listener;\n ++target._eventsCount;\n } else {\n if (typeof existing === 'function') {\n // Adding the second element, need to change to array.\n existing = events[type] = prepend ? [listener, existing] :\n [existing, listener];\n } else {\n // If we've already got an array, just append.\n if (prepend) {\n existing.unshift(listener);\n } else {\n existing.push(listener);\n }\n }\n\n // Check for listener leak\n if (!existing.warned) {\n m = $getMaxListeners(target);\n if (m && m > 0 && existing.length > m) {\n existing.warned = true;\n var w = new Error('Possible EventEmitter memory leak detected. ' +\n existing.length + ' ' + type + ' listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit');\n w.name = 'MaxListenersExceededWarning';\n w.emitter = target;\n w.type = type;\n w.count = existing.length;\n emitWarning(w);\n }\n }\n }\n\n return target;\n}\nfunction emitWarning(e) {\n typeof console.warn === 'function' ? console.warn(e) : console.log(e);\n}\nEventEmitter.prototype.addListener = function addListener(type, listener) {\n return _addListener(this, type, listener, false);\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.prependListener =\n function prependListener(type, listener) {\n return _addListener(this, type, listener, true);\n };\n\nfunction _onceWrap(target, type, listener) {\n var fired = false;\n function g() {\n target.removeListener(type, g);\n if (!fired) {\n fired = true;\n listener.apply(target, arguments);\n }\n }\n g.listener = listener;\n return g;\n}\n\nEventEmitter.prototype.once = function once(type, listener) {\n if (typeof listener !== 'function')\n throw new TypeError('\"listener\" argument must be a function');\n this.on(type, _onceWrap(this, type, listener));\n return this;\n};\n\nEventEmitter.prototype.prependOnceListener =\n function prependOnceListener(type, listener) {\n if (typeof listener !== 'function')\n throw new TypeError('\"listener\" argument must be a function');\n this.prependListener(type, _onceWrap(this, type, listener));\n return this;\n };\n\n// emits a 'removeListener' event iff the listener was removed\nEventEmitter.prototype.removeListener =\n function removeListener(type, listener) {\n var list, events, position, i, originalListener;\n\n if (typeof listener !== 'function')\n throw new TypeError('\"listener\" argument must be a function');\n\n events = this._events;\n if (!events)\n return this;\n\n list = events[type];\n if (!list)\n return this;\n\n if (list === listener || (list.listener && list.listener === listener)) {\n if (--this._eventsCount === 0)\n this._events = new EventHandlers();\n else {\n delete events[type];\n if (events.removeListener)\n this.emit('removeListener', type, list.listener || listener);\n }\n } else if (typeof list !== 'function') {\n position = -1;\n\n for (i = list.length; i-- > 0;) {\n if (list[i] === listener ||\n (list[i].listener && list[i].listener === listener)) {\n originalListener = list[i].listener;\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (list.length === 1) {\n list[0] = undefined;\n if (--this._eventsCount === 0) {\n this._events = new EventHandlers();\n return this;\n } else {\n delete events[type];\n }\n } else {\n spliceOne(list, position);\n }\n\n if (events.removeListener)\n this.emit('removeListener', type, originalListener || listener);\n }\n\n return this;\n };\n\nEventEmitter.prototype.removeAllListeners =\n function removeAllListeners(type) {\n var listeners, events;\n\n events = this._events;\n if (!events)\n return this;\n\n // not listening for removeListener, no need to emit\n if (!events.removeListener) {\n if (arguments.length === 0) {\n this._events = new EventHandlers();\n this._eventsCount = 0;\n } else if (events[type]) {\n if (--this._eventsCount === 0)\n this._events = new EventHandlers();\n else\n delete events[type];\n }\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n var keys = Object.keys(events);\n for (var i = 0, key; i < keys.length; ++i) {\n key = keys[i];\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = new EventHandlers();\n this._eventsCount = 0;\n return this;\n }\n\n listeners = events[type];\n\n if (typeof listeners === 'function') {\n this.removeListener(type, listeners);\n } else if (listeners) {\n // LIFO order\n do {\n this.removeListener(type, listeners[listeners.length - 1]);\n } while (listeners[0]);\n }\n\n return this;\n };\n\nEventEmitter.prototype.listeners = function listeners(type) {\n var evlistener;\n var ret;\n var events = this._events;\n\n if (!events)\n ret = [];\n else {\n evlistener = events[type];\n if (!evlistener)\n ret = [];\n else if (typeof evlistener === 'function')\n ret = [evlistener.listener || evlistener];\n else\n ret = unwrapListeners(evlistener);\n }\n\n return ret;\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n if (typeof emitter.listenerCount === 'function') {\n return emitter.listenerCount(type);\n } else {\n return listenerCount.call(emitter, type);\n }\n};\n\nEventEmitter.prototype.listenerCount = listenerCount;\nfunction listenerCount(type) {\n var events = this._events;\n\n if (events) {\n var evlistener = events[type];\n\n if (typeof evlistener === 'function') {\n return 1;\n } else if (evlistener) {\n return evlistener.length;\n }\n }\n\n return 0;\n}\n\nEventEmitter.prototype.eventNames = function eventNames() {\n return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];\n};\n\n// About 1.5x faster than the two-arg version of Array#splice().\nfunction spliceOne(list, index) {\n for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)\n list[i] = list[k];\n list.pop();\n}\n\nfunction arrayClone(arr, i) {\n var copy = new Array(i);\n while (i--)\n copy[i] = arr[i];\n return copy;\n}\n\nfunction unwrapListeners(arr) {\n var ret = new Array(arr.length);\n for (var i = 0; i < ret.length; ++i) {\n ret[i] = arr[i].listener || arr[i];\n }\n return ret;\n}\n","export class Util {\n\n static getISODate() : string {\n return (new Date()).toISOString().slice(0,10);\n }\n\n static getDateInMinutes() : number {\n let now = new Date();\n return (now.getHours() * 60) + now.getMinutes();\n }\n\n /**\n * convert a time input to minutes\n * e.g. 23:59 = 1439\n */\n static convertToMinutes(time:string) : number {\n let times = time.split(\":\");\n let convered = (parseInt(times[0]) * 60) + parseInt(times[1]);\n return (convered >= 0 && convered <= 1439) ? convered : 0;\n }\n\n static calculateNextMinute() : number {\n return (60 - (Math.round((new Date()).getTime() / 1000) % 60)) * 1000;\n }\n\n}","import { EventEmitter } from 'events';\nimport {ProgramRepository} from './program-repository';\nimport {ProgramManager} from './program-manager';\nimport {Util} from './util';\n\nconst STATE_START = \"start\";\nconst STATE_STOP = \"stop\";\n\nexport class Player extends EventEmitter {\n\n protected _programRepository:ProgramRepository;\n protected _programManager:ProgramManager;\n protected _minutesReplication:number = 5;\n protected _replicationRetry:number = 10000;\n\n protected _currentProgramItemId:string = '';\n protected _currentReplicationCounter:number = 0;\n protected _state = STATE_STOP;\n\n set state(st:string) {\n this._state = st;\n }\n\n set programManager(pm:ProgramManager) {\n this._programManager = pm;\n }\n\n get programManager() : ProgramManager {\n return this._programManager;\n }\n\n set programRepository(pr:ProgramRepository) {\n this._programRepository = pr;\n }\n\n get programRepository() : ProgramRepository {\n return this._programRepository;\n }\n\n set minutesReplication(mr:number) {\n this._minutesReplication = mr;\n }\n\n get minutesReplication() : number {\n return this._minutesReplication;\n }\n\n set replicationRetry(rr:number) {\n this._replicationRetry = rr;\n }\n\n get replicationRetry() : number {\n return this._replicationRetry;\n }\n\n triggerReplication() : Promise<void> {\n return this.programRepository.replicate()\n .then(() => { \n this._currentReplicationCounter = 0;\n this.trigger(this.triggerProgramItemId, Util.calculateNextMinute());\n })\n .catch(() => {\n this.trigger(this.triggerReplication, this.replicationRetry);\n });\n }\n\n triggerProgramItemId() {\n this.programManager.getCurrentProgramItemId()\n .then(programItemId => {\n this._currentReplicationCounter++;\n\n // if there is a new program item id trigger play\n // else (1) calculate next potential program change point\n // or (2) trigger replication\n\n if (programItemId != this._currentProgramItemId) {\n this._currentProgramItemId = programItemId;\n this.emit('play', programItemId);\n } else if (this._currentReplicationCounter >= this._minutesReplication) {\n this.triggerReplication();\n } else {\n this.trigger(this.triggerProgramItemId, Util.calculateNextMinute());\n }\n });\n }\n\n trigger(func:Function, milliseconds:number) {\n if (this._state === STATE_START) { \n setTimeout(() => { func(); }, milliseconds);\n } \n }\n\n start() {\n if (this._state === STATE_STOP) {\n this.triggerReplication();\n this._state = STATE_START;\n }\n }\n\n stop() {\n this._state = STATE_STOP;\n }\n\n}","import {ProgramRepository} from './program-repository';\nimport {Util} from './util';\nimport {ProgramItem, PROGRAM_ITEM_TYPE_SLIDESHOW, PROGRAM_ITEM_TYPE_VIDEO } from './program-item/program-item'\n\nexport class ProgramManager {\n\n protected _programRepository:ProgramRepository;\n\n set programRepository(pr:ProgramRepository) {\n this._programRepository = pr;\n }\n\n get programRepository() : ProgramRepository {\n return this._programRepository;\n }\n\n getCurrentProgramItemId() : Promise<string> {\n return new Promise<string> ((resolve, reject) => {\n this.findCurrentProgramSegment().then(programSegment => {\n let currentProgramItemId = programSegment.default;\n if (programSegment.schedule) {\n currentProgramItemId = this.findCurrentProgramItem(programSegment.schedule, Util.getDateInMinutes());\n }\n resolve(currentProgramItemId);\n });\n }); \n }\n\n /**\n * find program item in schedule, which fits\n * according to current hh:mm\n */\n findCurrentProgramItem(schedule:any, dateInMinutes:number) : string {\n let timeList:any = [];\n let tmpSchedule:any = {};\n\n for (let startTime in schedule) {\n if (schedule.hasOwnProperty(startTime)) {\n let minutes = Util.convertToMinutes(startTime);\n timeList.push(minutes);\n tmpSchedule[minutes] = schedule[startTime];\n }\n }\n\n // sort ascending (-)\n timeList.sort((a,b) => { return a-b; });\n\n let last = 0;\n for (let i = 0; i < timeList.length; i++) {\n if (timeList[i] <= dateInMinutes) {\n last = timeList[i];\n } else {\n break;\n }\n }\n\n return tmpSchedule[last];\n }\n\n /**\n * Find the program segment\n * This is dependent on the date set on the device\n */\n findCurrentProgramSegment() : Promise<any> {\n return new Promise<any>((resolve, reject) => {\n let today = Util.getISODate();\n \n this.programRepository.findByType('program')\n .then(programs => {\n \n if (programs.length > 0) {\n let program:any = programs[0];\n let programSegmentId;\n\n // if there is a program_segment for today else default\n if (program.schedule && program.schedule[today]) {\n programSegmentId = program.schedule[today];\n } else {\n programSegmentId = program.default;\n }\n \n this.programRepository\n .findById(programSegmentId)\n .then(programSegment => { \n resolve(programSegment);\n }).catch(error => { \n reject(\"program segment not found\");\n });\n } else {\n reject('No Program found');\n }\n\n }).catch(error => {\n reject(error);\n });\n });\n }\n\n}","export const PROGRAM_ITEM_TYPE_SLIDESHOW = \"slideshow\";\nexport const PROGRAM_ITEM_TYPE_VIDEO = \"video\";\n\nexport class ProgramItem {\n\n protected _type:string;\n protected _data:any;\n\n set type(t:string) {\n this._type = t;\n }\n\n get type():string {\n return this._type;\n }\n\n set data(d:any) {\n this._data = d;\n }\n\n get data():any {\n return this._data;\n }\n\n}","import {ProgramItem, PROGRAM_ITEM_TYPE_SLIDESHOW, PROGRAM_ITEM_TYPE_VIDEO } from './program-item';\nimport { ProgramRepository } from './../program-repository';\n\nexport class ProgramItemFactory {\n\n protected _programRepository:ProgramRepository;\n protected _basePath:string;\n\n set basePath(bp:string) {\n this._basePath = bp;\n }\n \n get basePath() : string {\n return this._basePath;\n }\n\n set programRepository(pr:ProgramRepository) {\n this._programRepository = pr;\n }\n\n get programRepository() : ProgramRepository {\n return this._programRepository;\n }\n\n getProgramItem(programItemId:string) : Promise<ProgramItem> {\n return this.programRepository\n .findById(programItemId)\n .then((programItem) => {\n return this.prepareProgramItem(programItem.program_item_type, programItem);\n });\n }\n\n prepareProgramItem(type:string, data:any) : Promise<ProgramItem> {\n let programItem = new ProgramItem();\n programItem.type = type;\n\n if (type === PROGRAM_ITEM_TYPE_VIDEO) {\n return this.prepareVideoItem(programItem, data);\n } else if (type === PROGRAM_ITEM_TYPE_SLIDESHOW) {\n return this.prepareSlideshowItem(programItem, data);\n } else {\n return null;\n }\n } \n\n prepareSlideshowItem(programItem:ProgramItem, data:any) : Promise<ProgramItem> {\n return this._programRepository.findByIds(data.images)\n .then(images => { \n programItem.data = {\n speed : data.settings.speed ,\n effect : data.settings.effect ,\n images : []\n }; \n\n for (let image of images) {\n programItem.data.images.push(this.basePath + image.filename);\n }\n\n return programItem;\n });\n }\n\n prepareVideoItem(programItem:ProgramItem, data:any) : Promise<ProgramItem> {\n return this._programRepository.findById(data.video)\n .then((data) => { \n programItem.data = {\n video : this.basePath + data['filename']\n }; \n return programItem;\n });\n }\n\n}"],"names":[],"mappings":";;;;AAEA,IAAI,MAAM,CAAC;;;;;AAKX,SAAS,aAAa,GAAG,EAAE;AAC3B,aAAa,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;AAE9C,SAAS,YAAY,GAAG;EACtB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CAC9B;AACD,AACA,AAEA,YAAY,CAAC,YAAY,GAAG,KAAK,CAAC;;AAElC,YAAY,CAAC,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC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B,UAAqB,WAAuB,EAAE,IAAQ;QAAtD,iBAeC;QAdG,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;aAChD,IAAI,CAAC,UAAA,MAAM;YACR,WAAW,CAAC,IAAI,GAAG;gBACf,KAAK,EAAI,IAAI,CAAC,QAAQ,CAAC,KAAK;gBAC5B,MAAM,EAAG,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAC7B,MAAM,EAAG,EAAE;aACd,CAAC;YAEF,KAAkB,UAAM,EAAN,iBAAM,EAAN,oBAAM,EAAN,IAAM;gBAAnB,IAAI,KAAK,eAAA;gBACV,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;aAChE;YAED,OAAO,WAAW,CAAC;SACtB,CAAC,CAAC;KACV;IAED,6CAAgB,GAAhB,UAAiB,WAAuB,EAAE,IAAQ;QAAlD,iBAQC;QAPG,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;aAC9C,IAAI,CAAC,UAAC,IAAI;YACP,WAAW,CAAC,IAAI,GAAG;gBACf,KAAK,EAAG,KAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC;aAC3C,CAAC;YACF,OAAO,WAAW,CAAC;SACtB,CAAC,CAAC;KACV;IAEL,yBAAC;CAAA,IAAA,AACD;;;;;;;"} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
index.d.ts
0 → 100644
| 1 | +interface ProgramRepository { | ||
| 2 | + findById(id:string) : Promise<any>; | ||
| 3 | + findByIds(ids:Array<string>) : Promise<Array<any>>; | ||
| 4 | + findByType(type:string) : Promise<Array<any>>; | ||
| 5 | + replicate() : Promise<void>; | ||
| 6 | +} | ||
| 7 | + | ||
| 8 | +interface Player { | ||
| 9 | + on(name:string, any); | ||
| 10 | + start() : void; | ||
| 11 | + stop() : void; | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +interface ProgramManager { | ||
| 15 | + programRepository: ProgramRepository; | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +interface ProgramItemFactory { | ||
| 19 | + basePath: string; | ||
| 20 | + programRepository: ProgramRepository; | ||
| 21 | + getProgramItem(programItemId:string) : Promise<any>; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +declare var digsigPlayer: { | ||
| 25 | + ProgramRepository: ProgramRepository, | ||
| 26 | + ProgramManager: ProgramManager, | ||
| 27 | + Player : Player, | ||
| 28 | + ProgramItemFactory: ProgramItemFactory | ||
| 29 | +}; | ||
| 30 | + | ||
| 31 | +declare module "digsig-player-service" { | ||
| 32 | + export = digsigPlayer; | ||
| 33 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -2,13 +2,13 @@ | ... | @@ -2,13 +2,13 @@ |
| 2 | "name": "digsig-player-service", | 2 | "name": "digsig-player-service", |
| 3 | "version": "1.0.0", | 3 | "version": "1.0.0", |
| 4 | "description": "", | 4 | "description": "", |
| 5 | - "main": "target/index.js", | 5 | + "main": "build/bundle.js", |
| 6 | - "types": "types/index.d.ts", | 6 | + "types": "index.d.ts", |
| 7 | "scripts": { | 7 | "scripts": { |
| 8 | "pretest": "tsc --target es5 --outDir .tmp spec/index.ts", | 8 | "pretest": "tsc --target es5 --outDir .tmp spec/index.ts", |
| 9 | "test": "jasmine .tmp/spec/index.js", | 9 | "test": "jasmine .tmp/spec/index.js", |
| 10 | "posttest": "rm -R .tmp", | 10 | "posttest": "rm -R .tmp", |
| 11 | - "build:tsc": "tsc" | 11 | + "build:tsc": "rollup -c rollup.config.js" |
| 12 | }, | 12 | }, |
| 13 | "author": "Stefan Huber <stefan.huber@beyondit.at>", | 13 | "author": "Stefan Huber <stefan.huber@beyondit.at>", |
| 14 | "license": "ISC", | 14 | "license": "ISC", |
| ... | @@ -17,6 +17,11 @@ | ... | @@ -17,6 +17,11 @@ |
| 17 | "@types/jasmine": "^2.5.41", | 17 | "@types/jasmine": "^2.5.41", |
| 18 | "@types/node": "^7.0.0", | 18 | "@types/node": "^7.0.0", |
| 19 | "jasmine": "^2.5.3", | 19 | "jasmine": "^2.5.3", |
| 20 | + "rollup": "^0.41.4", | ||
| 21 | + "rollup-plugin-commonjs": "^7.0.0", | ||
| 22 | + "rollup-plugin-node-builtins": "^2.0.0", | ||
| 23 | + "rollup-plugin-node-globals": "^1.1.0", | ||
| 24 | + "rollup-plugin-typescript": "^0.8.1", | ||
| 20 | "typescript": "^2.1.5" | 25 | "typescript": "^2.1.5" |
| 21 | } | 26 | } |
| 22 | } | 27 | } | ... | ... |
rollup.config.js
0 → 100644
| 1 | +var typescript = require('rollup-plugin-typescript'); | ||
| 2 | +var builtins = require('rollup-plugin-node-builtins'); | ||
| 3 | +var globals = require('rollup-plugin-node-globals'); | ||
| 4 | + | ||
| 5 | +var rollupConfig = { | ||
| 6 | + | ||
| 7 | + moduleName : 'digsig', | ||
| 8 | + | ||
| 9 | + entry: 'src/index.ts', | ||
| 10 | + | ||
| 11 | + sourceMap: true, | ||
| 12 | + | ||
| 13 | + format: 'cjs', | ||
| 14 | + | ||
| 15 | + dest: 'build/bundle.js', | ||
| 16 | + | ||
| 17 | + plugins: [ | ||
| 18 | + builtins(), | ||
| 19 | + globals(), | ||
| 20 | + typescript() | ||
| 21 | + ] | ||
| 22 | + | ||
| 23 | +}; | ||
| 24 | + | ||
| 25 | +module.exports = rollupConfig; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | export * from './player'; | 1 | export * from './player'; |
| 2 | +export * from './program-manager'; | ||
| 2 | export * from './program-item/program-item'; | 3 | export * from './program-item/program-item'; |
| 3 | export * from './program-item/program-item-factory'; | 4 | export * from './program-item/program-item-factory'; |
| 4 | -export * from './program-manager'; | ||
| 5 | -export * from './program-repository'; | ||
| 6 | -export * from './util'; | ... | ... |
target/index.js
deleted
100644 → 0
| 1 | -"use strict"; | ||
| 2 | -function __export(m) { | ||
| 3 | - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
| 4 | -} | ||
| 5 | -__export(require("./player")); | ||
| 6 | -__export(require("./program-item/program-item")); | ||
| 7 | -__export(require("./program-item/program-item-factory")); | ||
| 8 | -__export(require("./program-manager")); | ||
| 9 | -__export(require("./util")); |
target/player.js
deleted
100644 → 0
| 1 | -"use strict"; | ||
| 2 | -var __extends = (this && this.__extends) || function (d, b) { | ||
| 3 | - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
| 4 | - function __() { this.constructor = d; } | ||
| 5 | - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| 6 | -}; | ||
| 7 | -var events_1 = require("events"); | ||
| 8 | -var util_1 = require("./util"); | ||
| 9 | -var STATE_START = "start"; | ||
| 10 | -var STATE_STOP = "stop"; | ||
| 11 | -var Player = (function (_super) { | ||
| 12 | - __extends(Player, _super); | ||
| 13 | - function Player() { | ||
| 14 | - var _this = _super !== null && _super.apply(this, arguments) || this; | ||
| 15 | - _this._minutesReplication = 5; | ||
| 16 | - _this._replicationRetry = 10000; | ||
| 17 | - _this._currentProgramItemId = ''; | ||
| 18 | - _this._currentReplicationCounter = 0; | ||
| 19 | - _this._state = STATE_STOP; | ||
| 20 | - return _this; | ||
| 21 | - } | ||
| 22 | - Object.defineProperty(Player.prototype, "state", { | ||
| 23 | - set: function (st) { | ||
| 24 | - this._state = st; | ||
| 25 | - }, | ||
| 26 | - enumerable: true, | ||
| 27 | - configurable: true | ||
| 28 | - }); | ||
| 29 | - Object.defineProperty(Player.prototype, "programManager", { | ||
| 30 | - get: function () { | ||
| 31 | - return this._programManager; | ||
| 32 | - }, | ||
| 33 | - set: function (pm) { | ||
| 34 | - this._programManager = pm; | ||
| 35 | - }, | ||
| 36 | - enumerable: true, | ||
| 37 | - configurable: true | ||
| 38 | - }); | ||
| 39 | - Object.defineProperty(Player.prototype, "programRepository", { | ||
| 40 | - get: function () { | ||
| 41 | - return this._programRepository; | ||
| 42 | - }, | ||
| 43 | - set: function (pr) { | ||
| 44 | - this._programRepository = pr; | ||
| 45 | - }, | ||
| 46 | - enumerable: true, | ||
| 47 | - configurable: true | ||
| 48 | - }); | ||
| 49 | - Object.defineProperty(Player.prototype, "minutesReplication", { | ||
| 50 | - get: function () { | ||
| 51 | - return this._minutesReplication; | ||
| 52 | - }, | ||
| 53 | - set: function (mr) { | ||
| 54 | - this._minutesReplication = mr; | ||
| 55 | - }, | ||
| 56 | - enumerable: true, | ||
| 57 | - configurable: true | ||
| 58 | - }); | ||
| 59 | - Object.defineProperty(Player.prototype, "replicationRetry", { | ||
| 60 | - get: function () { | ||
| 61 | - return this._replicationRetry; | ||
| 62 | - }, | ||
| 63 | - set: function (rr) { | ||
| 64 | - this._replicationRetry = rr; | ||
| 65 | - }, | ||
| 66 | - enumerable: true, | ||
| 67 | - configurable: true | ||
| 68 | - }); | ||
| 69 | - Player.prototype.triggerReplication = function () { | ||
| 70 | - var _this = this; | ||
| 71 | - return this.programRepository.replicate() | ||
| 72 | - .then(function () { | ||
| 73 | - _this._currentReplicationCounter = 0; | ||
| 74 | - _this.trigger(_this.triggerProgramItemId, util_1.Util.calculateNextMinute()); | ||
| 75 | - }) | ||
| 76 | - .catch(function () { | ||
| 77 | - _this.trigger(_this.triggerReplication, _this.replicationRetry); | ||
| 78 | - }); | ||
| 79 | - }; | ||
| 80 | - Player.prototype.triggerProgramItemId = function () { | ||
| 81 | - var _this = this; | ||
| 82 | - this.programManager.getCurrentProgramItemId() | ||
| 83 | - .then(function (programItemId) { | ||
| 84 | - _this._currentReplicationCounter++; | ||
| 85 | - // if there is a new program item id trigger play | ||
| 86 | - // else (1) calculate next potential program change point | ||
| 87 | - // or (2) trigger replication | ||
| 88 | - if (programItemId != _this._currentProgramItemId) { | ||
| 89 | - _this._currentProgramItemId = programItemId; | ||
| 90 | - _this.emit('play', programItemId); | ||
| 91 | - } | ||
| 92 | - else if (_this._currentReplicationCounter >= _this._minutesReplication) { | ||
| 93 | - _this.triggerReplication(); | ||
| 94 | - } | ||
| 95 | - else { | ||
| 96 | - _this.trigger(_this.triggerProgramItemId, util_1.Util.calculateNextMinute()); | ||
| 97 | - } | ||
| 98 | - }); | ||
| 99 | - }; | ||
| 100 | - Player.prototype.trigger = function (func, milliseconds) { | ||
| 101 | - if (this._state === STATE_START) { | ||
| 102 | - setTimeout(function () { func(); }, milliseconds); | ||
| 103 | - } | ||
| 104 | - }; | ||
| 105 | - Player.prototype.start = function () { | ||
| 106 | - if (this._state === STATE_STOP) { | ||
| 107 | - this.triggerReplication(); | ||
| 108 | - this._state = STATE_START; | ||
| 109 | - } | ||
| 110 | - }; | ||
| 111 | - Player.prototype.stop = function () { | ||
| 112 | - this._state = STATE_STOP; | ||
| 113 | - }; | ||
| 114 | - return Player; | ||
| 115 | -}(events_1.EventEmitter)); | ||
| 116 | -exports.Player = Player; |
| 1 | -"use strict"; | ||
| 2 | -var program_item_1 = require("./program-item"); | ||
| 3 | -var ProgramItemFactory = (function () { | ||
| 4 | - function ProgramItemFactory() { | ||
| 5 | - } | ||
| 6 | - Object.defineProperty(ProgramItemFactory.prototype, "basePath", { | ||
| 7 | - get: function () { | ||
| 8 | - return this._basePath; | ||
| 9 | - }, | ||
| 10 | - set: function (bp) { | ||
| 11 | - this._basePath = bp; | ||
| 12 | - }, | ||
| 13 | - enumerable: true, | ||
| 14 | - configurable: true | ||
| 15 | - }); | ||
| 16 | - Object.defineProperty(ProgramItemFactory.prototype, "programRepository", { | ||
| 17 | - get: function () { | ||
| 18 | - return this._programRepository; | ||
| 19 | - }, | ||
| 20 | - set: function (pr) { | ||
| 21 | - this._programRepository = pr; | ||
| 22 | - }, | ||
| 23 | - enumerable: true, | ||
| 24 | - configurable: true | ||
| 25 | - }); | ||
| 26 | - ProgramItemFactory.prototype.getProgramItem = function (programItemId) { | ||
| 27 | - var _this = this; | ||
| 28 | - return this.programRepository | ||
| 29 | - .findById(programItemId) | ||
| 30 | - .then(function (programItem) { | ||
| 31 | - return _this.prepareProgramItem(programItem.program_item_type, programItem); | ||
| 32 | - }); | ||
| 33 | - }; | ||
| 34 | - ProgramItemFactory.prototype.prepareProgramItem = function (type, data) { | ||
| 35 | - var programItem = new program_item_1.ProgramItem(); | ||
| 36 | - programItem.type = type; | ||
| 37 | - if (type === program_item_1.PROGRAM_ITEM_TYPE_VIDEO) { | ||
| 38 | - return this.prepareVideoItem(programItem, data); | ||
| 39 | - } | ||
| 40 | - else if (type === program_item_1.PROGRAM_ITEM_TYPE_SLIDESHOW) { | ||
| 41 | - return this.prepareSlideshowItem(programItem, data); | ||
| 42 | - } | ||
| 43 | - else { | ||
| 44 | - return null; | ||
| 45 | - } | ||
| 46 | - }; | ||
| 47 | - ProgramItemFactory.prototype.prepareSlideshowItem = function (programItem, data) { | ||
| 48 | - var _this = this; | ||
| 49 | - return this._programRepository.findByIds(data.images) | ||
| 50 | - .then(function (images) { | ||
| 51 | - programItem.data = { | ||
| 52 | - speed: data.settings.speed, | ||
| 53 | - effect: data.settings.effect, | ||
| 54 | - images: [] | ||
| 55 | - }; | ||
| 56 | - for (var _i = 0, images_1 = images; _i < images_1.length; _i++) { | ||
| 57 | - var image = images_1[_i]; | ||
| 58 | - programItem.data.images.push(_this.basePath + image.filename); | ||
| 59 | - } | ||
| 60 | - return programItem; | ||
| 61 | - }); | ||
| 62 | - }; | ||
| 63 | - ProgramItemFactory.prototype.prepareVideoItem = function (programItem, data) { | ||
| 64 | - var _this = this; | ||
| 65 | - return this._programRepository.findById(data.video) | ||
| 66 | - .then(function (data) { | ||
| 67 | - programItem.data = { | ||
| 68 | - video: _this.basePath + data['filename'] | ||
| 69 | - }; | ||
| 70 | - return programItem; | ||
| 71 | - }); | ||
| 72 | - }; | ||
| 73 | - return ProgramItemFactory; | ||
| 74 | -}()); | ||
| 75 | -exports.ProgramItemFactory = ProgramItemFactory; |
target/program-item/program-item.js
deleted
100644 → 0
| 1 | -"use strict"; | ||
| 2 | -exports.PROGRAM_ITEM_TYPE_SLIDESHOW = "slideshow"; | ||
| 3 | -exports.PROGRAM_ITEM_TYPE_VIDEO = "video"; | ||
| 4 | -var ProgramItem = (function () { | ||
| 5 | - function ProgramItem() { | ||
| 6 | - } | ||
| 7 | - Object.defineProperty(ProgramItem.prototype, "type", { | ||
| 8 | - get: function () { | ||
| 9 | - return this._type; | ||
| 10 | - }, | ||
| 11 | - set: function (t) { | ||
| 12 | - this._type = t; | ||
| 13 | - }, | ||
| 14 | - enumerable: true, | ||
| 15 | - configurable: true | ||
| 16 | - }); | ||
| 17 | - Object.defineProperty(ProgramItem.prototype, "data", { | ||
| 18 | - get: function () { | ||
| 19 | - return this._data; | ||
| 20 | - }, | ||
| 21 | - set: function (d) { | ||
| 22 | - this._data = d; | ||
| 23 | - }, | ||
| 24 | - enumerable: true, | ||
| 25 | - configurable: true | ||
| 26 | - }); | ||
| 27 | - return ProgramItem; | ||
| 28 | -}()); | ||
| 29 | -exports.ProgramItem = ProgramItem; |
target/program-manager.js
deleted
100644 → 0
| 1 | -"use strict"; | ||
| 2 | -var util_1 = require("./util"); | ||
| 3 | -var ProgramManager = (function () { | ||
| 4 | - function ProgramManager() { | ||
| 5 | - } | ||
| 6 | - Object.defineProperty(ProgramManager.prototype, "programRepository", { | ||
| 7 | - get: function () { | ||
| 8 | - return this._programRepository; | ||
| 9 | - }, | ||
| 10 | - set: function (pr) { | ||
| 11 | - this._programRepository = pr; | ||
| 12 | - }, | ||
| 13 | - enumerable: true, | ||
| 14 | - configurable: true | ||
| 15 | - }); | ||
| 16 | - ProgramManager.prototype.getCurrentProgramItemId = function () { | ||
| 17 | - var _this = this; | ||
| 18 | - return new Promise(function (resolve, reject) { | ||
| 19 | - _this.findCurrentProgramSegment().then(function (programSegment) { | ||
| 20 | - var currentProgramItemId = programSegment.default; | ||
| 21 | - if (programSegment.schedule) { | ||
| 22 | - currentProgramItemId = _this.findCurrentProgramItem(programSegment.schedule, util_1.Util.getDateInMinutes()); | ||
| 23 | - } | ||
| 24 | - resolve(currentProgramItemId); | ||
| 25 | - }); | ||
| 26 | - }); | ||
| 27 | - }; | ||
| 28 | - /** | ||
| 29 | - * find program item in schedule, which fits | ||
| 30 | - * according to current hh:mm | ||
| 31 | - */ | ||
| 32 | - ProgramManager.prototype.findCurrentProgramItem = function (schedule, dateInMinutes) { | ||
| 33 | - var timeList = []; | ||
| 34 | - var tmpSchedule = {}; | ||
| 35 | - for (var startTime in schedule) { | ||
| 36 | - if (schedule.hasOwnProperty(startTime)) { | ||
| 37 | - var minutes = util_1.Util.convertToMinutes(startTime); | ||
| 38 | - timeList.push(minutes); | ||
| 39 | - tmpSchedule[minutes] = schedule[startTime]; | ||
| 40 | - } | ||
| 41 | - } | ||
| 42 | - // sort ascending (-) | ||
| 43 | - timeList.sort(function (a, b) { return a - b; }); | ||
| 44 | - var last = 0; | ||
| 45 | - for (var i = 0; i < timeList.length; i++) { | ||
| 46 | - if (timeList[i] <= dateInMinutes) { | ||
| 47 | - last = timeList[i]; | ||
| 48 | - } | ||
| 49 | - else { | ||
| 50 | - break; | ||
| 51 | - } | ||
| 52 | - } | ||
| 53 | - return tmpSchedule[last]; | ||
| 54 | - }; | ||
| 55 | - /** | ||
| 56 | - * Find the program segment | ||
| 57 | - * This is dependent on the date set on the device | ||
| 58 | - */ | ||
| 59 | - ProgramManager.prototype.findCurrentProgramSegment = function () { | ||
| 60 | - var _this = this; | ||
| 61 | - return new Promise(function (resolve, reject) { | ||
| 62 | - var today = util_1.Util.getISODate(); | ||
| 63 | - _this.programRepository.findByType('program') | ||
| 64 | - .then(function (programs) { | ||
| 65 | - if (programs.length > 0) { | ||
| 66 | - var program = programs[0]; | ||
| 67 | - var programSegmentId = void 0; | ||
| 68 | - // if there is a program_segment for today else default | ||
| 69 | - if (program.schedule && program.schedule[today]) { | ||
| 70 | - programSegmentId = program.schedule[today]; | ||
| 71 | - } | ||
| 72 | - else { | ||
| 73 | - programSegmentId = program.default; | ||
| 74 | - } | ||
| 75 | - _this.programRepository | ||
| 76 | - .findById(programSegmentId) | ||
| 77 | - .then(function (programSegment) { | ||
| 78 | - resolve(programSegment); | ||
| 79 | - }).catch(function (error) { | ||
| 80 | - reject("program segment not found"); | ||
| 81 | - }); | ||
| 82 | - } | ||
| 83 | - else { | ||
| 84 | - reject('No Program found'); | ||
| 85 | - } | ||
| 86 | - }).catch(function (error) { | ||
| 87 | - reject(error); | ||
| 88 | - }); | ||
| 89 | - }); | ||
| 90 | - }; | ||
| 91 | - return ProgramManager; | ||
| 92 | -}()); | ||
| 93 | -exports.ProgramManager = ProgramManager; |
target/program-repository.js
deleted
100644 → 0
| 1 | -"use strict"; |
target/util.js
deleted
100644 → 0
| 1 | -"use strict"; | ||
| 2 | -var Util = (function () { | ||
| 3 | - function Util() { | ||
| 4 | - } | ||
| 5 | - Util.getISODate = function () { | ||
| 6 | - return (new Date()).toISOString().slice(0, 10); | ||
| 7 | - }; | ||
| 8 | - Util.getDateInMinutes = function () { | ||
| 9 | - var now = new Date(); | ||
| 10 | - return (now.getHours() * 60) + now.getMinutes(); | ||
| 11 | - }; | ||
| 12 | - /** | ||
| 13 | - * convert a time input to minutes | ||
| 14 | - * e.g. 23:59 = 1439 | ||
| 15 | - */ | ||
| 16 | - Util.convertToMinutes = function (time) { | ||
| 17 | - var times = time.split(":"); | ||
| 18 | - var convered = (parseInt(times[0]) * 60) + parseInt(times[1]); | ||
| 19 | - return (convered >= 0 && convered <= 1439) ? convered : 0; | ||
| 20 | - }; | ||
| 21 | - Util.calculateNextMinute = function () { | ||
| 22 | - return (60 - (Math.round((new Date()).getTime() / 1000) % 60)) * 1000; | ||
| 23 | - }; | ||
| 24 | - return Util; | ||
| 25 | -}()); | ||
| 26 | -exports.Util = Util; |
tsconfig.json
deleted
100644 → 0
types/index.d.ts
deleted
100644 → 0
types/player.d.ts
deleted
100644 → 0
| 1 | -/// <reference types="node" /> | ||
| 2 | -/// <reference types="es6-promise" /> | ||
| 3 | -import { EventEmitter } from 'events'; | ||
| 4 | -import { ProgramRepository } from './program-repository'; | ||
| 5 | -import { ProgramManager } from './program-manager'; | ||
| 6 | -export declare class Player extends EventEmitter { | ||
| 7 | - protected _programRepository: ProgramRepository; | ||
| 8 | - protected _programManager: ProgramManager; | ||
| 9 | - protected _minutesReplication: number; | ||
| 10 | - protected _replicationRetry: number; | ||
| 11 | - protected _currentProgramItemId: string; | ||
| 12 | - protected _currentReplicationCounter: number; | ||
| 13 | - protected _state: string; | ||
| 14 | - state: string; | ||
| 15 | - programManager: ProgramManager; | ||
| 16 | - programRepository: ProgramRepository; | ||
| 17 | - minutesReplication: number; | ||
| 18 | - replicationRetry: number; | ||
| 19 | - triggerReplication(): Promise<void>; | ||
| 20 | - triggerProgramItemId(): void; | ||
| 21 | - trigger(func: Function, milliseconds: number): void; | ||
| 22 | - start(): void; | ||
| 23 | - stop(): void; | ||
| 24 | -} |
| 1 | -/// <reference types="es6-promise" /> | ||
| 2 | -import { ProgramItem } from './program-item'; | ||
| 3 | -import { ProgramRepository } from './../program-repository'; | ||
| 4 | -export declare class ProgramItemFactory { | ||
| 5 | - protected _programRepository: ProgramRepository; | ||
| 6 | - protected _basePath: string; | ||
| 7 | - basePath: string; | ||
| 8 | - programRepository: ProgramRepository; | ||
| 9 | - getProgramItem(programItemId: string): Promise<ProgramItem>; | ||
| 10 | - prepareProgramItem(type: string, data: any): Promise<ProgramItem>; | ||
| 11 | - prepareSlideshowItem(programItem: ProgramItem, data: any): Promise<ProgramItem>; | ||
| 12 | - prepareVideoItem(programItem: ProgramItem, data: any): Promise<ProgramItem>; | ||
| 13 | -} |
types/program-item/program-item.d.ts
deleted
100644 → 0
types/program-manager.d.ts
deleted
100644 → 0
| 1 | -/// <reference types="es6-promise" /> | ||
| 2 | -import { ProgramRepository } from './program-repository'; | ||
| 3 | -export declare class ProgramManager { | ||
| 4 | - protected _programRepository: ProgramRepository; | ||
| 5 | - programRepository: ProgramRepository; | ||
| 6 | - getCurrentProgramItemId(): Promise<string>; | ||
| 7 | - /** | ||
| 8 | - * find program item in schedule, which fits | ||
| 9 | - * according to current hh:mm | ||
| 10 | - */ | ||
| 11 | - findCurrentProgramItem(schedule: any, dateInMinutes: number): string; | ||
| 12 | - /** | ||
| 13 | - * Find the program segment | ||
| 14 | - * This is dependent on the date set on the device | ||
| 15 | - */ | ||
| 16 | - findCurrentProgramSegment(): Promise<any>; | ||
| 17 | -} |
types/program-repository.d.ts
deleted
100644 → 0
types/util.d.ts
deleted
100644 → 0
-
Please register or login to post a comment