@monterosa/sdk-lvis 0.18.8 → 0.18.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm2017.js +204 -781
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +355 -1036
- package/dist/index.esm5.js.map +1 -1
- package/package.json +4 -4
package/dist/index.esm5.js
CHANGED
|
@@ -10,17 +10,18 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
10
10
|
import assignIn from 'lodash.assignin';
|
|
11
11
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
12
12
|
import _createClass from '@babel/runtime/helpers/createClass';
|
|
13
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
14
13
|
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
15
|
-
import
|
|
14
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
16
15
|
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
16
|
+
import _get from '@babel/runtime/helpers/get';
|
|
17
17
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
18
18
|
import Cookie from 'js-cookie';
|
|
19
|
+
import '@babel/runtime/helpers/readOnlyError';
|
|
19
20
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
20
21
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
21
22
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
22
23
|
|
|
23
|
-
var version = "0.18.
|
|
24
|
+
var version = "0.18.10";
|
|
24
25
|
|
|
25
26
|
var LViSDate = new Emitter();
|
|
26
27
|
LViSDate.trigger = LViSDate.emit;
|
|
@@ -31,16 +32,13 @@ LViSDate.ON_NEXT = 'next';
|
|
|
31
32
|
var serverTimestamp;
|
|
32
33
|
var lastTickTimestamp;
|
|
33
34
|
var tickTimeoutId = null;
|
|
34
|
-
|
|
35
35
|
var getCurrentTimestamp = function getCurrentTimestamp() {
|
|
36
36
|
return Date.now() / 1000;
|
|
37
37
|
};
|
|
38
|
-
|
|
39
38
|
var getMiddleTimestamp = function getMiddleTimestamp(timestamp) {
|
|
40
39
|
return Math.floor(timestamp) + 0.5;
|
|
41
40
|
};
|
|
42
|
-
|
|
43
|
-
var tick = function tick() {
|
|
41
|
+
var _tick = function tick() {
|
|
44
42
|
clearTimeout(tickTimeoutId);
|
|
45
43
|
var currentTimestamp = getCurrentTimestamp();
|
|
46
44
|
var timeSinceLastTick = currentTimestamp - lastTickTimestamp;
|
|
@@ -48,21 +46,18 @@ var tick = function tick() {
|
|
|
48
46
|
lastTickTimestamp = currentTimestamp;
|
|
49
47
|
var expect = getMiddleTimestamp(serverTimestamp) + 1;
|
|
50
48
|
var delay = (expect - serverTimestamp) * 1000;
|
|
51
|
-
tickTimeoutId = setTimeout(
|
|
49
|
+
tickTimeoutId = setTimeout(_tick, delay);
|
|
52
50
|
LViSDate.trigger(LViSDate.ON_TICK, serverTimestamp);
|
|
53
51
|
};
|
|
54
|
-
|
|
55
52
|
LViSDate.setTime = function (time) {
|
|
56
53
|
lastTickTimestamp = getCurrentTimestamp();
|
|
57
54
|
serverTimestamp = getMiddleTimestamp(time);
|
|
58
55
|
};
|
|
59
|
-
|
|
60
56
|
LViSDate.now = function () {
|
|
61
57
|
return Math.floor(serverTimestamp);
|
|
62
58
|
};
|
|
63
|
-
|
|
64
59
|
LViSDate.setTime(getCurrentTimestamp());
|
|
65
|
-
|
|
60
|
+
_tick();
|
|
66
61
|
|
|
67
62
|
var Sync = (function () {
|
|
68
63
|
var self = new Emitter();
|
|
@@ -74,129 +69,104 @@ var Sync = (function () {
|
|
|
74
69
|
var defaultDelay;
|
|
75
70
|
var maxDelay;
|
|
76
71
|
var Event;
|
|
77
|
-
|
|
78
72
|
var setDelay = function setDelay(value, force) {
|
|
79
73
|
var max = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
80
|
-
|
|
81
74
|
if (value > max) {
|
|
82
75
|
console.warn("User delay can't be greater than ".concat(max, " seconds"));
|
|
83
76
|
return;
|
|
84
77
|
}
|
|
85
|
-
|
|
86
78
|
if (value < 0) {
|
|
87
79
|
value = 0;
|
|
88
80
|
}
|
|
89
|
-
|
|
90
81
|
if (value > maxDelay) {
|
|
91
82
|
value = maxDelay;
|
|
92
83
|
}
|
|
93
|
-
|
|
94
84
|
if (force || value !== delay) {
|
|
95
85
|
delay = value;
|
|
96
86
|
self.trigger(self.ON_DELAY_CHANGE, delay);
|
|
97
87
|
}
|
|
98
88
|
};
|
|
99
|
-
|
|
100
89
|
self._resetSettings = function () {
|
|
101
90
|
delay = null;
|
|
102
91
|
defaultDelay = 0;
|
|
103
92
|
maxDelay = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
104
93
|
};
|
|
105
|
-
|
|
106
94
|
self.setMaxDelay = function (value) {
|
|
107
95
|
value = parseInt(value, 10);
|
|
108
|
-
|
|
109
96
|
if (value >= 0) {
|
|
110
97
|
maxDelay = value;
|
|
111
98
|
}
|
|
112
99
|
};
|
|
113
|
-
|
|
114
100
|
self.setDefaultDelay = function (value) {
|
|
115
101
|
value = parseInt(value, 10);
|
|
116
|
-
|
|
117
102
|
if (value > maxDelay) {
|
|
118
103
|
defaultDelay = maxDelay;
|
|
119
104
|
} else if (value > 0 && value <= maxDelay) {
|
|
120
105
|
defaultDelay = value;
|
|
121
106
|
}
|
|
122
107
|
};
|
|
123
|
-
|
|
124
108
|
self.setDelay = function () {
|
|
125
109
|
var value;
|
|
126
|
-
|
|
127
110
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
128
111
|
args[_key] = arguments[_key];
|
|
129
112
|
}
|
|
130
|
-
|
|
131
113
|
var force = [].concat(args).pop();
|
|
132
114
|
force = typeof force === 'boolean' ? force : false;
|
|
133
|
-
|
|
134
115
|
switch (args[0].constructor) {
|
|
135
116
|
// (<LViS.Event> event, <Integer> timecode, [<Boolen> force = true]);
|
|
136
117
|
case Event:
|
|
137
118
|
{
|
|
138
119
|
var event = args[0],
|
|
139
|
-
|
|
120
|
+
timecode = args[1];
|
|
140
121
|
value = LViSDate.now() - event.getOriginalStartAt() - timecode;
|
|
141
122
|
break;
|
|
142
123
|
}
|
|
143
|
-
// (<Date> time, [<Boolen> force = true]);
|
|
144
124
|
|
|
125
|
+
// (<Date> time, [<Boolen> force = true]);
|
|
145
126
|
case Date:
|
|
146
127
|
{
|
|
147
128
|
var time = args[0];
|
|
148
129
|
value = LViSDate.now() - Math.floor(time.getTime() / 1000);
|
|
149
130
|
break;
|
|
150
131
|
}
|
|
151
|
-
// (<Integer> delay, [<Boolen> force = true]);
|
|
152
132
|
|
|
133
|
+
// (<Integer> delay, [<Boolen> force = true]);
|
|
153
134
|
case Number:
|
|
154
135
|
{
|
|
155
136
|
value = args[0];
|
|
156
|
-
|
|
157
137
|
if (parseInt(value, 10) !== value) {
|
|
158
138
|
console.warn('User delay must be an integer');
|
|
159
139
|
return;
|
|
160
140
|
}
|
|
161
|
-
|
|
162
141
|
break;
|
|
163
142
|
}
|
|
164
|
-
|
|
165
143
|
default:
|
|
166
144
|
console.warn('Unknown interface of setDelay() method');
|
|
167
145
|
return;
|
|
168
146
|
}
|
|
169
|
-
|
|
170
147
|
setDelay(value, force);
|
|
171
148
|
};
|
|
172
|
-
|
|
173
149
|
self.getMaxDelay = function () {
|
|
174
150
|
return maxDelay;
|
|
175
151
|
};
|
|
176
|
-
|
|
177
152
|
self.getDelay = function () {
|
|
178
153
|
if (delay !== null) {
|
|
179
154
|
return delay;
|
|
180
155
|
}
|
|
181
|
-
|
|
182
156
|
return defaultDelay;
|
|
183
157
|
};
|
|
184
|
-
|
|
185
158
|
self._resetSettings();
|
|
186
|
-
|
|
187
159
|
self.init = function (config) {
|
|
188
160
|
// used to avoid cycle dependency:
|
|
189
161
|
// Event -> ConnectionAdaptor -> Sync -> Event
|
|
190
162
|
Event = config.Event;
|
|
191
163
|
};
|
|
192
|
-
|
|
193
164
|
return self;
|
|
194
165
|
})();
|
|
195
166
|
|
|
196
167
|
/* eslint @typescript-eslint/indent: "off" */
|
|
197
168
|
var regularQueue = [];
|
|
198
169
|
var priorityQueue = [];
|
|
199
|
-
|
|
200
170
|
var add = function add(queue) {
|
|
201
171
|
return function (func) {
|
|
202
172
|
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
@@ -206,13 +176,11 @@ var add = function add(queue) {
|
|
|
206
176
|
});
|
|
207
177
|
};
|
|
208
178
|
};
|
|
209
|
-
|
|
210
179
|
var execute = function execute() {
|
|
211
180
|
var queue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
212
181
|
return function () {
|
|
213
182
|
var item;
|
|
214
183
|
var total = queue.length;
|
|
215
|
-
|
|
216
184
|
while (total > 0) {
|
|
217
185
|
item = queue.shift();
|
|
218
186
|
item.func.apply(item.context);
|
|
@@ -220,20 +188,16 @@ var execute = function execute() {
|
|
|
220
188
|
}
|
|
221
189
|
};
|
|
222
190
|
};
|
|
223
|
-
|
|
224
191
|
var force = function force() {
|
|
225
192
|
executePriority();
|
|
226
193
|
executeRegular();
|
|
227
194
|
};
|
|
228
|
-
|
|
229
195
|
var handleDateTick = function handleDateTick() {
|
|
230
196
|
force();
|
|
231
197
|
};
|
|
232
|
-
|
|
233
198
|
var handleDateNext = function handleDateNext(func) {
|
|
234
199
|
nextRegular(func);
|
|
235
200
|
};
|
|
236
|
-
|
|
237
201
|
var nextRegular = add(regularQueue);
|
|
238
202
|
var nextPriority = add(priorityQueue);
|
|
239
203
|
var executeRegular = execute(regularQueue);
|
|
@@ -252,10 +216,12 @@ var ConnectionAdaptor = (function () {
|
|
|
252
216
|
/*
|
|
253
217
|
* Link to the current scope
|
|
254
218
|
*/
|
|
219
|
+
|
|
255
220
|
var self = new Emitter();
|
|
256
221
|
self.trigger = self.emit;
|
|
257
222
|
self.bind = self.on;
|
|
258
223
|
self.unbind = self.off;
|
|
224
|
+
|
|
259
225
|
/*
|
|
260
226
|
* Constants
|
|
261
227
|
*/
|
|
@@ -263,6 +229,7 @@ var ConnectionAdaptor = (function () {
|
|
|
263
229
|
self.ON_EOC = Enmasse.ON_EOC;
|
|
264
230
|
self.ON_MESSAGE = Enmasse.ON_MESSAGE;
|
|
265
231
|
self.ON_SETTINGS = 'settings';
|
|
232
|
+
|
|
266
233
|
/*
|
|
267
234
|
* Private variable
|
|
268
235
|
*/
|
|
@@ -270,177 +237,143 @@ var ConnectionAdaptor = (function () {
|
|
|
270
237
|
var queue = [];
|
|
271
238
|
var EOCs = {};
|
|
272
239
|
var processIsInThePriorityQueue = false;
|
|
273
|
-
|
|
274
240
|
var handleMessage = function handleMessage(message) {
|
|
275
241
|
deduplicate(message);
|
|
276
242
|
queue.push(message);
|
|
277
243
|
Run.nextPriority(function () {
|
|
278
|
-
return
|
|
244
|
+
return _process();
|
|
279
245
|
});
|
|
280
246
|
Run.force();
|
|
281
247
|
};
|
|
282
|
-
|
|
283
248
|
var handleDelayChange = function handleDelayChange() {
|
|
284
249
|
clearQueue();
|
|
285
250
|
};
|
|
286
|
-
|
|
287
251
|
var handleState = function handleState(state) {
|
|
288
252
|
switch (state) {
|
|
289
253
|
case Enmasse.STATE_DISCONNECTED:
|
|
290
254
|
clearEOCs();
|
|
291
255
|
break;
|
|
292
|
-
|
|
293
256
|
case Enmasse.STATE_CONNECTED:
|
|
294
257
|
break;
|
|
295
|
-
|
|
296
258
|
case Enmasse.STATE_CONNECTING:
|
|
297
259
|
break;
|
|
298
260
|
}
|
|
299
261
|
};
|
|
300
|
-
|
|
301
262
|
var handleEOC = function handleEOC(channel) {
|
|
302
263
|
EOCs[channel] = true;
|
|
303
264
|
self.trigger(self.ON_EOC, channel);
|
|
304
265
|
Run.nextPriority(function () {
|
|
305
|
-
return
|
|
266
|
+
return _process();
|
|
306
267
|
});
|
|
307
268
|
Run.force();
|
|
308
269
|
};
|
|
309
|
-
|
|
310
270
|
var deduplicate = function deduplicate(message) {
|
|
311
271
|
if (message.klass !== 'create') {
|
|
312
272
|
return;
|
|
313
273
|
}
|
|
314
|
-
|
|
315
274
|
var id;
|
|
316
|
-
|
|
317
275
|
try {
|
|
318
276
|
id = JSON.parse(message.body[0]).id;
|
|
319
277
|
} catch (e) {
|
|
320
278
|
return;
|
|
321
279
|
}
|
|
322
|
-
|
|
323
280
|
var itemId = null;
|
|
324
|
-
|
|
325
281
|
for (var idx = 0; idx < queue.length; idx++) {
|
|
326
282
|
try {
|
|
327
283
|
itemId = JSON.parse(queue[idx].body[0]).id;
|
|
328
284
|
} catch (e) {
|
|
329
285
|
continue;
|
|
330
286
|
}
|
|
331
|
-
|
|
332
287
|
if (itemId === id) {
|
|
333
288
|
queue.splice(idx, 1);
|
|
334
289
|
break;
|
|
335
290
|
}
|
|
336
291
|
}
|
|
337
292
|
};
|
|
338
|
-
|
|
339
|
-
var process = function process() {
|
|
293
|
+
var _process = function process() {
|
|
340
294
|
var idx = 0;
|
|
341
295
|
var message;
|
|
342
|
-
|
|
343
296
|
while (idx < queue.length) {
|
|
344
297
|
if (canAdapt(queue[idx])) {
|
|
345
298
|
var _queue$splice = queue.splice(idx, 1);
|
|
346
|
-
|
|
347
299
|
var _queue$splice2 = _slicedToArray(_queue$splice, 1);
|
|
348
|
-
|
|
349
300
|
message = _queue$splice2[0];
|
|
350
301
|
adaptMessage(message);
|
|
351
302
|
self.trigger(self.ON_MESSAGE, message);
|
|
352
303
|
} else {
|
|
353
304
|
idx++;
|
|
354
305
|
}
|
|
355
|
-
}
|
|
356
|
-
|
|
306
|
+
}
|
|
357
307
|
|
|
308
|
+
// if there are still left message in queue
|
|
358
309
|
if (queue.length > 0 && !processIsInThePriorityQueue) {
|
|
359
310
|
processIsInThePriorityQueue = true;
|
|
360
311
|
Run.nextPriority(function () {
|
|
361
312
|
processIsInThePriorityQueue = false;
|
|
362
|
-
|
|
313
|
+
_process();
|
|
363
314
|
});
|
|
364
315
|
}
|
|
365
316
|
};
|
|
366
|
-
|
|
367
317
|
var canAdapt = function canAdapt(message) {
|
|
368
318
|
var checker = function () {
|
|
369
319
|
switch (message.klass) {
|
|
370
320
|
case 'create':
|
|
371
321
|
return canAdaptCreate;
|
|
372
|
-
|
|
373
322
|
case 'reveal':
|
|
374
323
|
return canAdaptReveal;
|
|
375
|
-
|
|
376
324
|
case 'revoke':
|
|
377
325
|
return canAdaptRevoke;
|
|
378
|
-
|
|
379
326
|
case 'stop':
|
|
380
327
|
return canAdaptStop;
|
|
381
|
-
|
|
382
328
|
case 'p':
|
|
383
329
|
return canAdaptPoll;
|
|
384
|
-
|
|
385
330
|
case 'subscounter':
|
|
386
331
|
return canAdaptSubsCounter;
|
|
387
|
-
|
|
388
332
|
default:
|
|
389
333
|
return canAdaptOther;
|
|
390
334
|
}
|
|
391
335
|
}();
|
|
392
|
-
|
|
393
336
|
return checker(message);
|
|
394
337
|
};
|
|
395
|
-
|
|
396
338
|
var canAdaptCreate = function canAdaptCreate(message) {
|
|
397
339
|
var data;
|
|
398
|
-
|
|
399
340
|
try {
|
|
400
341
|
data = JSON.parse(message.body[0]);
|
|
401
342
|
} catch (e) {
|
|
402
343
|
return false;
|
|
403
344
|
}
|
|
404
|
-
|
|
405
345
|
return canAdaptGeneric(message.channel, data.published_at);
|
|
406
346
|
};
|
|
407
|
-
|
|
408
347
|
var canAdaptReveal = function canAdaptReveal(message) {
|
|
409
348
|
return canAdaptGeneric(message.channel, parseInt(message.body[2], 10));
|
|
410
349
|
};
|
|
411
|
-
|
|
412
350
|
var canAdaptRevoke = function canAdaptRevoke(message) {
|
|
413
351
|
var data;
|
|
414
|
-
|
|
415
352
|
try {
|
|
416
353
|
data = JSON.parse(message.body[0]);
|
|
417
354
|
} catch (e) {
|
|
418
355
|
return false;
|
|
419
356
|
}
|
|
420
|
-
|
|
421
357
|
return canAdaptGeneric(message.channel, data.sent_at);
|
|
422
358
|
};
|
|
423
|
-
|
|
424
359
|
var canAdaptStop = function canAdaptStop(message) {
|
|
425
360
|
return canAdaptGeneric(message.channel, parseInt(message.body[1], 10));
|
|
426
361
|
};
|
|
427
|
-
|
|
428
362
|
var canAdaptPoll = function canAdaptPoll(message) {
|
|
429
363
|
return canAdaptGeneric(message.channel, parseInt(message.body[1], 10));
|
|
430
364
|
};
|
|
431
|
-
|
|
432
365
|
var canAdaptSubsCounter = function canAdaptSubsCounter(message) {
|
|
433
366
|
return canAdaptGeneric(message.channel, parseInt(message.sent_at, 10));
|
|
434
367
|
};
|
|
435
|
-
|
|
436
368
|
var canAdaptOther = function canAdaptOther() {
|
|
437
369
|
return true;
|
|
438
370
|
};
|
|
439
|
-
|
|
440
371
|
var canAdaptGeneric = function canAdaptGeneric(channel, publishAt) {
|
|
441
372
|
var now = LViSDate.now();
|
|
442
373
|
var hasEOC = EOCs[channel] !== undefined;
|
|
443
|
-
var publishAtDelayed = publishAt + Sync.getDelay();
|
|
374
|
+
var publishAtDelayed = publishAt + Sync.getDelay();
|
|
375
|
+
|
|
376
|
+
// Can publish whether:
|
|
444
377
|
// a. publishedAt is in the past,
|
|
445
378
|
// b. publishedAt is now, but only if we already received EOC. If we
|
|
446
379
|
// have not yet received EOC then there is a risk that we will receive
|
|
@@ -450,188 +383,161 @@ var ConnectionAdaptor = (function () {
|
|
|
450
383
|
// element into history rather than trigger ON_PUBLISHED. With this
|
|
451
384
|
// check we guarantee that if create and EOC arrive at the same second
|
|
452
385
|
// we do not trigger elements until we handled EOC.
|
|
453
|
-
|
|
454
386
|
return publishAtDelayed < now || publishAtDelayed === now && hasEOC;
|
|
455
387
|
};
|
|
456
|
-
|
|
457
388
|
var adaptMessage = function adaptMessage(message) {
|
|
458
389
|
var adaptor = function () {
|
|
459
390
|
switch (message.klass) {
|
|
460
391
|
case 'snapshot':
|
|
461
392
|
return adaptSnapshot;
|
|
462
|
-
|
|
463
393
|
case 'listings':
|
|
464
394
|
return adaptListings;
|
|
465
|
-
|
|
466
395
|
case 'create':
|
|
467
396
|
return adaptCreate;
|
|
468
|
-
|
|
469
397
|
case 'reveal':
|
|
470
398
|
return adaptReveal;
|
|
471
|
-
|
|
472
399
|
case 'revoke':
|
|
473
400
|
return adaptRevoke;
|
|
474
|
-
|
|
475
401
|
case 'stop':
|
|
476
402
|
return adaptStop;
|
|
477
|
-
|
|
478
403
|
case 'p':
|
|
479
404
|
return adaptPoll;
|
|
480
|
-
|
|
481
405
|
case 'subscounter':
|
|
482
406
|
return adaptSubsCounter;
|
|
483
|
-
|
|
484
407
|
default:
|
|
485
408
|
return adaptOther;
|
|
486
409
|
}
|
|
487
410
|
}();
|
|
488
|
-
|
|
489
411
|
adaptor(message);
|
|
490
412
|
};
|
|
491
|
-
|
|
492
413
|
var adaptSnapshot = function adaptSnapshot(message) {
|
|
493
414
|
// console.log('ConnectionAdaptor::adaptSnapshot', message);
|
|
494
|
-
var snapshot;
|
|
495
415
|
|
|
416
|
+
var snapshot;
|
|
496
417
|
try {
|
|
497
418
|
snapshot = JSON.parse(message.body[0]);
|
|
498
|
-
} catch (e) {
|
|
419
|
+
} catch (e) {
|
|
420
|
+
// console.error('ConnectionAdaptor: Unable to parse listings data');
|
|
499
421
|
}
|
|
500
|
-
|
|
501
422
|
adaptSnapshotData(snapshot);
|
|
502
423
|
message.body[0] = JSON.stringify(snapshot);
|
|
503
424
|
};
|
|
504
|
-
|
|
505
425
|
var adaptSnapshotData = function adaptSnapshotData(snapshot) {
|
|
506
426
|
snapshot.published_at += Sync.getDelay();
|
|
507
427
|
snapshot.published_at_iso = new Date(snapshot.published_at * 1000).toISOString();
|
|
508
|
-
|
|
509
428
|
var adapter = function () {
|
|
510
429
|
switch (snapshot.type) {
|
|
511
430
|
case 'prediction':
|
|
512
431
|
return adaptPredictionSnapshot;
|
|
513
|
-
|
|
514
432
|
default:
|
|
515
433
|
return adaptOtherSnapshot;
|
|
516
434
|
}
|
|
517
435
|
}();
|
|
518
|
-
|
|
519
436
|
adapter(snapshot);
|
|
520
437
|
};
|
|
521
|
-
|
|
522
438
|
var adaptPredictionSnapshot = function adaptPredictionSnapshot(snapshot) {
|
|
523
439
|
var data = snapshot.data;
|
|
524
440
|
var delay = Sync.getDelay();
|
|
525
441
|
data.start_at += delay;
|
|
526
442
|
data.start_at_iso = new Date(data.start_at * 1000).toISOString();
|
|
527
|
-
|
|
528
443
|
if (data.stop_at) {
|
|
529
444
|
data.stop_at += delay;
|
|
530
445
|
data.stop_at_iso = new Date(data.stop_at * 1000).toISOString();
|
|
531
446
|
}
|
|
532
|
-
|
|
533
447
|
if (data.reveal_answer_at) {
|
|
534
448
|
data.reveal_answer_at += delay;
|
|
535
449
|
data.reveal_answer_at_iso = new Date(data.reveal_answer_at * 1000).toISOString();
|
|
536
450
|
}
|
|
537
451
|
};
|
|
538
|
-
|
|
539
|
-
|
|
452
|
+
var adaptOtherSnapshot = function adaptOtherSnapshot() {
|
|
453
|
+
// console.log('ConnectionAdaptor::adaptOtherSnapshot', snapshot);
|
|
540
454
|
};
|
|
541
|
-
|
|
542
455
|
var adaptListings = function adaptListings(message) {
|
|
543
456
|
// console.log('ConnectionAdaptor::adaptListings');
|
|
544
|
-
var listings;
|
|
545
457
|
|
|
458
|
+
var listings;
|
|
546
459
|
try {
|
|
547
460
|
listings = JSON.parse(message.body[0]);
|
|
548
|
-
} catch (e) {
|
|
461
|
+
} catch (e) {
|
|
462
|
+
// console.error('ConnectionAdaptor: Unable to parse listings data');
|
|
549
463
|
}
|
|
550
|
-
|
|
551
464
|
Sync.setMaxDelay(listings.project.audio_sync_max_delay);
|
|
552
465
|
Sync.setDefaultDelay(listings.project.audio_sync_default_delay);
|
|
553
|
-
|
|
554
466
|
for (var uuid in listings.events) {
|
|
555
467
|
if ({}.hasOwnProperty.call(listings.events, uuid)) {
|
|
556
468
|
adaptEvent(listings.events[uuid]);
|
|
557
469
|
}
|
|
558
470
|
}
|
|
559
|
-
|
|
560
471
|
message.body[0] = JSON.stringify(listings);
|
|
561
472
|
};
|
|
562
|
-
|
|
563
473
|
var adaptEvent = function adaptEvent(event) {
|
|
564
474
|
var delay = Sync.getDelay();
|
|
565
475
|
event.start_at += delay;
|
|
566
476
|
event.start_at_iso = new Date(event.start_at * 1000).toISOString();
|
|
567
477
|
event.end_at += delay;
|
|
568
|
-
event.end_at_iso = new Date(event.end_at * 1000).toISOString();
|
|
478
|
+
event.end_at_iso = new Date(event.end_at * 1000).toISOString();
|
|
569
479
|
|
|
480
|
+
// store delay
|
|
570
481
|
event.__delay = delay;
|
|
571
482
|
};
|
|
572
|
-
|
|
573
483
|
var adaptCreate = function adaptCreate(message) {
|
|
574
484
|
// console.log('ConnectionAdaptor::adaptCreate', message);
|
|
575
|
-
var data;
|
|
576
485
|
|
|
486
|
+
var data;
|
|
577
487
|
try {
|
|
578
488
|
data = JSON.parse(message.body[0]);
|
|
579
|
-
} catch (e) {
|
|
489
|
+
} catch (e) {
|
|
490
|
+
// console.error('ConnectionAdaptor: Unable to parse create data');
|
|
580
491
|
}
|
|
581
|
-
|
|
582
492
|
data.published_at += Sync.getDelay();
|
|
583
493
|
data.published_at_iso = new Date(data.published_at * 1000).toISOString();
|
|
584
494
|
message.body[0] = JSON.stringify(data);
|
|
585
495
|
};
|
|
586
|
-
|
|
587
496
|
var adaptPoll = function adaptPoll(message) {
|
|
588
497
|
// console.log('ConnectionAdaptor::adaptPoll', message);
|
|
498
|
+
|
|
589
499
|
message.body[1] = parseInt(message.body[1], 10) + Sync.getDelay();
|
|
590
500
|
};
|
|
591
|
-
|
|
592
501
|
var adaptStop = function adaptStop(message) {
|
|
593
502
|
// console.log('ConnectionAdaptor::adaptStop', message);
|
|
503
|
+
|
|
594
504
|
message.body[1] = parseInt(message.body[1], 10) + Sync.getDelay();
|
|
595
505
|
};
|
|
596
|
-
|
|
597
506
|
var adaptReveal = function adaptReveal(message) {
|
|
598
507
|
// console.log('ConnectionAdaptor::adaptReveal', message);
|
|
508
|
+
|
|
599
509
|
message.body[2] = parseInt(message.body[2], 10) + Sync.getDelay();
|
|
600
510
|
};
|
|
601
|
-
|
|
602
511
|
var adaptRevoke = function adaptRevoke(message) {
|
|
603
512
|
// console.log('ConnectionAdaptor::adaptRevoke', message);
|
|
604
|
-
var data;
|
|
605
513
|
|
|
514
|
+
var data;
|
|
606
515
|
try {
|
|
607
516
|
data = JSON.parse(message.body[0]);
|
|
608
|
-
} catch (e) {
|
|
517
|
+
} catch (e) {
|
|
518
|
+
// console.error('ConnectionAdaptor: Unable to parse revoke data');
|
|
609
519
|
}
|
|
610
|
-
|
|
611
520
|
data.sent_at += Sync.getDelay();
|
|
612
521
|
data.sent_at_iso = new Date(data.sent_at * 1000).toISOString();
|
|
613
522
|
message.body[0] = JSON.stringify(data);
|
|
614
523
|
};
|
|
615
|
-
|
|
616
524
|
var adaptSubsCounter = function adaptSubsCounter(message) {
|
|
617
525
|
try {
|
|
618
526
|
var data = JSON.parse(message.body[0]);
|
|
619
527
|
data.next_update_at += Sync.getDelay();
|
|
620
528
|
message.body[0] = JSON.stringify(data);
|
|
621
|
-
} catch (e) {
|
|
529
|
+
} catch (e) {
|
|
530
|
+
// why do we fail silently?
|
|
622
531
|
}
|
|
623
532
|
};
|
|
624
|
-
|
|
625
533
|
var adaptOther = function adaptOther() {
|
|
626
534
|
return 0;
|
|
627
535
|
};
|
|
628
|
-
|
|
629
536
|
var clearQueue = function clearQueue() {
|
|
630
537
|
while (queue.length) {
|
|
631
538
|
queue.pop();
|
|
632
539
|
}
|
|
633
540
|
};
|
|
634
|
-
|
|
635
541
|
var clearEOCs = function clearEOCs() {
|
|
636
542
|
for (var eoc in EOCs) {
|
|
637
543
|
if ({}.hasOwnProperty.call(EOCs, eoc)) {
|
|
@@ -639,11 +545,9 @@ var ConnectionAdaptor = (function () {
|
|
|
639
545
|
}
|
|
640
546
|
}
|
|
641
547
|
};
|
|
642
|
-
|
|
643
548
|
self.subscribe = function (channel) {
|
|
644
549
|
Enmasse.subscribe(channel);
|
|
645
550
|
};
|
|
646
|
-
|
|
647
551
|
self.unsubscribe = function (channel) {
|
|
648
552
|
queue.forEach(function (message, idx) {
|
|
649
553
|
if (message.channel === channel) {
|
|
@@ -653,15 +557,12 @@ var ConnectionAdaptor = (function () {
|
|
|
653
557
|
delete EOCs[channel];
|
|
654
558
|
Enmasse.unsubscribe(channel);
|
|
655
559
|
};
|
|
656
|
-
|
|
657
560
|
self.adaptSnapshotData = function (message) {
|
|
658
561
|
return adaptSnapshotData(message);
|
|
659
562
|
};
|
|
660
|
-
|
|
661
563
|
self.adaptEvent = function (event) {
|
|
662
564
|
return adaptEvent(event);
|
|
663
565
|
};
|
|
664
|
-
|
|
665
566
|
Enmasse.bind(Enmasse.ON_MESSAGE, handleMessage);
|
|
666
567
|
Enmasse.bind(Enmasse.ON_STATE, handleState);
|
|
667
568
|
Enmasse.bind(Enmasse.ON_EOC, handleEOC);
|
|
@@ -669,29 +570,21 @@ var ConnectionAdaptor = (function () {
|
|
|
669
570
|
return self;
|
|
670
571
|
})();
|
|
671
572
|
|
|
672
|
-
function
|
|
673
|
-
|
|
674
|
-
function _isNativeReflectConstruct$l() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
675
|
-
|
|
573
|
+
function _callSuper$l(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$l() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
574
|
+
function _isNativeReflectConstruct$l() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$l = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
676
575
|
var Base = /*#__PURE__*/function (_Emitter) {
|
|
677
|
-
_inherits(Base, _Emitter);
|
|
678
|
-
|
|
679
|
-
var _super = _createSuper$l(Base);
|
|
680
|
-
|
|
681
576
|
function Base() {
|
|
682
577
|
var _this;
|
|
683
|
-
|
|
684
578
|
_classCallCheck(this, Base);
|
|
685
|
-
|
|
686
|
-
_this = _super.call(this);
|
|
579
|
+
_this = _callSuper$l(this, Base);
|
|
687
580
|
_this.instances = {};
|
|
688
581
|
_this.trigger = _this.emit;
|
|
689
582
|
_this.bind = _this.on;
|
|
690
583
|
_this.unbind = _this.off;
|
|
691
584
|
return _this;
|
|
692
585
|
}
|
|
693
|
-
|
|
694
|
-
_createClass(Base, [{
|
|
586
|
+
_inherits(Base, _Emitter);
|
|
587
|
+
return _createClass(Base, [{
|
|
695
588
|
key: "get",
|
|
696
589
|
value: function get(id) {
|
|
697
590
|
return this.instances[id] || false;
|
|
@@ -721,36 +614,25 @@ var Base = /*#__PURE__*/function (_Emitter) {
|
|
|
721
614
|
}
|
|
722
615
|
}
|
|
723
616
|
}]);
|
|
724
|
-
|
|
725
|
-
return Base;
|
|
726
617
|
}(Emitter);
|
|
727
618
|
|
|
728
|
-
function
|
|
729
|
-
|
|
730
|
-
function _isNativeReflectConstruct$k() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
731
|
-
|
|
619
|
+
function _callSuper$k(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$k() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
620
|
+
function _isNativeReflectConstruct$k() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$k = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
732
621
|
var FrameFactory = /*#__PURE__*/function (_BaseFactory) {
|
|
733
|
-
_inherits(FrameFactory, _BaseFactory);
|
|
734
|
-
|
|
735
|
-
var _super = _createSuper$k(FrameFactory);
|
|
736
|
-
|
|
737
622
|
function FrameFactory() {
|
|
738
623
|
_classCallCheck(this, FrameFactory);
|
|
739
|
-
|
|
740
|
-
return _super.apply(this, arguments);
|
|
624
|
+
return _callSuper$k(this, FrameFactory, arguments);
|
|
741
625
|
}
|
|
742
|
-
|
|
743
|
-
_createClass(FrameFactory, [{
|
|
626
|
+
_inherits(FrameFactory, _BaseFactory);
|
|
627
|
+
return _createClass(FrameFactory, [{
|
|
744
628
|
key: "getByEnmasseId",
|
|
745
629
|
value: function getByEnmasseId(enmasseId) {
|
|
746
630
|
for (var _i = 0, _Object$values = Object.values(this.instances); _i < _Object$values.length; _i++) {
|
|
747
631
|
var instance = _Object$values[_i];
|
|
748
|
-
|
|
749
632
|
if (instance.getEnmasseId() === enmasseId) {
|
|
750
633
|
return instance;
|
|
751
634
|
}
|
|
752
635
|
}
|
|
753
|
-
|
|
754
636
|
return false;
|
|
755
637
|
}
|
|
756
638
|
}, {
|
|
@@ -762,27 +644,16 @@ var FrameFactory = /*#__PURE__*/function (_BaseFactory) {
|
|
|
762
644
|
instance.update(data);
|
|
763
645
|
}
|
|
764
646
|
}]);
|
|
765
|
-
|
|
766
|
-
return FrameFactory;
|
|
767
647
|
}(Base);
|
|
768
648
|
|
|
769
|
-
function
|
|
770
|
-
|
|
771
|
-
function _isNativeReflectConstruct$j() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
772
|
-
|
|
649
|
+
function _callSuper$j(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$j() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
650
|
+
function _isNativeReflectConstruct$j() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$j = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
773
651
|
var Entity = /*#__PURE__*/function (_Emitter) {
|
|
774
|
-
_inherits(Entity, _Emitter);
|
|
775
|
-
|
|
776
|
-
var _super = _createSuper$j(Entity);
|
|
777
|
-
|
|
778
652
|
function Entity() {
|
|
779
653
|
var _this;
|
|
780
|
-
|
|
781
654
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
782
|
-
|
|
783
655
|
_classCallCheck(this, Entity);
|
|
784
|
-
|
|
785
|
-
_this = _super.call(this, config);
|
|
656
|
+
_this = _callSuper$j(this, Entity, [config]);
|
|
786
657
|
_this.id = config.id;
|
|
787
658
|
_this.enmasseId = config.data.id - 0 || 0;
|
|
788
659
|
_this.publishedAt = config.published_at - 0 || 0;
|
|
@@ -793,8 +664,8 @@ var Entity = /*#__PURE__*/function (_Emitter) {
|
|
|
793
664
|
_this.unbind = _this.off;
|
|
794
665
|
return _this;
|
|
795
666
|
}
|
|
796
|
-
|
|
797
|
-
_createClass(Entity, [{
|
|
667
|
+
_inherits(Entity, _Emitter);
|
|
668
|
+
return _createClass(Entity, [{
|
|
798
669
|
key: "getId",
|
|
799
670
|
value: function getId() {
|
|
800
671
|
return this.id;
|
|
@@ -832,18 +703,16 @@ var Entity = /*#__PURE__*/function (_Emitter) {
|
|
|
832
703
|
}
|
|
833
704
|
}, {
|
|
834
705
|
key: "destroy",
|
|
835
|
-
value: function destroy() {
|
|
706
|
+
value: function destroy() {
|
|
707
|
+
// console.log("Entity::destroy id=%s" + this.getId());
|
|
836
708
|
}
|
|
837
709
|
}]);
|
|
838
|
-
|
|
839
|
-
return Entity;
|
|
840
710
|
}(Emitter);
|
|
841
711
|
|
|
842
712
|
/* global QUOTA_EXCEEDED_ERR */
|
|
843
713
|
var globals = getGlobal();
|
|
844
714
|
var StorageLocalDriver = function () {
|
|
845
715
|
var self = {};
|
|
846
|
-
|
|
847
716
|
self.hasSupport = function () {
|
|
848
717
|
try {
|
|
849
718
|
return 'localStorage' in global && globals.localStorage !== null;
|
|
@@ -851,7 +720,6 @@ var StorageLocalDriver = function () {
|
|
|
851
720
|
return false;
|
|
852
721
|
}
|
|
853
722
|
};
|
|
854
|
-
|
|
855
723
|
self.set = function (name, value) {
|
|
856
724
|
try {
|
|
857
725
|
globals.localStorage.setItem(name, value);
|
|
@@ -861,23 +729,18 @@ var StorageLocalDriver = function () {
|
|
|
861
729
|
}
|
|
862
730
|
}
|
|
863
731
|
};
|
|
864
|
-
|
|
865
732
|
self.get = function (name) {
|
|
866
733
|
return globals.localStorage.getItem(name);
|
|
867
734
|
};
|
|
868
|
-
|
|
869
735
|
self.remove = function (name) {
|
|
870
736
|
return globals.localStorage.removeItem(name);
|
|
871
737
|
};
|
|
872
|
-
|
|
873
738
|
return self;
|
|
874
739
|
}();
|
|
875
740
|
var StorageCookieDriver = function () {
|
|
876
741
|
var self = {};
|
|
877
|
-
|
|
878
742
|
self.hasSupport = function () {
|
|
879
743
|
var probe = 'probe';
|
|
880
|
-
|
|
881
744
|
try {
|
|
882
745
|
self.set(probe, probe);
|
|
883
746
|
var stored = self.get(probe);
|
|
@@ -887,33 +750,25 @@ var StorageCookieDriver = function () {
|
|
|
887
750
|
return false;
|
|
888
751
|
}
|
|
889
752
|
};
|
|
890
|
-
|
|
891
753
|
self.set = function (name, value, expires) {
|
|
892
754
|
var args = [name, value];
|
|
893
|
-
|
|
894
755
|
if (typeof expires !== 'undefined') {
|
|
895
756
|
args.push({
|
|
896
757
|
expires: expires
|
|
897
758
|
});
|
|
898
759
|
}
|
|
899
|
-
|
|
900
760
|
return Cookie.set.apply(Cookie, args);
|
|
901
761
|
};
|
|
902
|
-
|
|
903
762
|
self.get = function (name) {
|
|
904
763
|
var value = Cookie.get(name);
|
|
905
|
-
|
|
906
764
|
if (typeof value === 'undefined') {
|
|
907
765
|
return null;
|
|
908
766
|
}
|
|
909
|
-
|
|
910
767
|
return value;
|
|
911
768
|
};
|
|
912
|
-
|
|
913
769
|
self.remove = function (name) {
|
|
914
770
|
return Cookie.remove(name);
|
|
915
771
|
};
|
|
916
|
-
|
|
917
772
|
return self;
|
|
918
773
|
}();
|
|
919
774
|
var Storage = function () {
|
|
@@ -921,50 +776,39 @@ var Storage = function () {
|
|
|
921
776
|
var self = {};
|
|
922
777
|
var driver = null;
|
|
923
778
|
var prefix = 'lvis';
|
|
924
|
-
|
|
925
779
|
for (var i = 0; i < DRIVERS.length; i++) {
|
|
926
780
|
if (DRIVERS[i].hasSupport()) {
|
|
927
781
|
driver = DRIVERS[i];
|
|
928
782
|
break;
|
|
929
783
|
}
|
|
930
784
|
}
|
|
931
|
-
|
|
932
785
|
var enabled = function enabled() {
|
|
933
786
|
return driver !== null;
|
|
934
787
|
};
|
|
935
|
-
|
|
936
788
|
var toStoredName = function toStoredName(name) {
|
|
937
789
|
return [prefix, name].join('-');
|
|
938
790
|
};
|
|
939
|
-
|
|
940
791
|
self.setPrefix = function (newPrefix) {
|
|
941
792
|
prefix = newPrefix;
|
|
942
793
|
};
|
|
943
|
-
|
|
944
794
|
self.set = function (name, value, expires) {
|
|
945
795
|
if (enabled()) {
|
|
946
796
|
return driver.set(toStoredName(name), value, expires);
|
|
947
797
|
}
|
|
948
|
-
|
|
949
798
|
return undefined;
|
|
950
799
|
};
|
|
951
|
-
|
|
952
800
|
self.get = function (name) {
|
|
953
801
|
if (enabled()) {
|
|
954
802
|
return driver.get(toStoredName(name));
|
|
955
803
|
}
|
|
956
|
-
|
|
957
804
|
return undefined;
|
|
958
805
|
};
|
|
959
|
-
|
|
960
806
|
self.remove = function (name) {
|
|
961
807
|
if (enabled()) {
|
|
962
808
|
return driver.remove(toStoredName(name));
|
|
963
809
|
}
|
|
964
|
-
|
|
965
810
|
return undefined;
|
|
966
811
|
};
|
|
967
|
-
|
|
968
812
|
return self;
|
|
969
813
|
}();
|
|
970
814
|
|
|
@@ -981,13 +825,11 @@ var Project = (function () {
|
|
|
981
825
|
self.unbind = self.off;
|
|
982
826
|
self.ON_SUBS_COUNT = 'subs_count';
|
|
983
827
|
self.ON_SUBS_COUNT_MISSING = 'subs_count_missing';
|
|
984
|
-
|
|
985
828
|
var getDefaultLanguage = function getDefaultLanguage() {
|
|
986
829
|
return data.locales.find(function (locale) {
|
|
987
830
|
return !!locale.default;
|
|
988
831
|
});
|
|
989
832
|
};
|
|
990
|
-
|
|
991
833
|
var loadAppSettings = function loadAppSettings() {
|
|
992
834
|
var url = "".concat(host, "/projects/").concat(uuid.substr(0, 2), "/").concat(uuid, "/settings.json");
|
|
993
835
|
var dfd = new Deferred();
|
|
@@ -997,7 +839,6 @@ var Project = (function () {
|
|
|
997
839
|
var settingsData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
998
840
|
var status = resp.statusCode;
|
|
999
841
|
var isSuccess = status >= 200 && status <= 300 || status === 0 || status === '';
|
|
1000
|
-
|
|
1001
842
|
if (isSuccess) {
|
|
1002
843
|
settings = settingsData;
|
|
1003
844
|
dfd.resolve();
|
|
@@ -1007,23 +848,19 @@ var Project = (function () {
|
|
|
1007
848
|
});
|
|
1008
849
|
return dfd.promise();
|
|
1009
850
|
};
|
|
1010
|
-
|
|
1011
851
|
var hasLanguage = function hasLanguage(language) {
|
|
1012
852
|
return data.locales.some(function (_ref) {
|
|
1013
853
|
var key = _ref.key;
|
|
1014
854
|
return key === language;
|
|
1015
855
|
});
|
|
1016
856
|
};
|
|
1017
|
-
|
|
1018
857
|
var handleSubsMissing = function handleSubsMissing() {
|
|
1019
858
|
self.trigger(self.ON_SUBS_COUNT_MISSING);
|
|
1020
859
|
};
|
|
1021
|
-
|
|
1022
860
|
var handleSubsCount = function handleSubsCount(message) {
|
|
1023
861
|
if (message.klass !== 'subscounter') {
|
|
1024
862
|
return;
|
|
1025
863
|
}
|
|
1026
|
-
|
|
1027
864
|
try {
|
|
1028
865
|
var subsData = JSON.parse(message.body[0]);
|
|
1029
866
|
var nextSubsUpdate = subsData.next_update_at;
|
|
@@ -1034,22 +871,21 @@ var Project = (function () {
|
|
|
1034
871
|
console.warn("Couldn't parse subscounter message.");
|
|
1035
872
|
}
|
|
1036
873
|
};
|
|
1037
|
-
|
|
1038
874
|
self.setData = function (d) {
|
|
1039
875
|
data = d || {};
|
|
1040
876
|
Storage.setPrefix("lvis-".concat(uuid));
|
|
1041
|
-
var storedLanguage = Storage.get('lang');
|
|
877
|
+
var storedLanguage = Storage.get('lang');
|
|
1042
878
|
|
|
879
|
+
// trying to set stored language
|
|
1043
880
|
if (storedLanguage) {
|
|
1044
881
|
self.setCurrentLanguage(storedLanguage);
|
|
1045
|
-
}
|
|
1046
|
-
|
|
882
|
+
}
|
|
1047
883
|
|
|
884
|
+
// if current is not set yet using default language
|
|
1048
885
|
if (currentLanguage === null) {
|
|
1049
886
|
currentLanguage = getDefaultLanguage().key;
|
|
1050
887
|
}
|
|
1051
888
|
};
|
|
1052
|
-
|
|
1053
889
|
self.setCurrentLanguage = function (language) {
|
|
1054
890
|
if (hasLanguage(language)) {
|
|
1055
891
|
currentLanguage = language;
|
|
@@ -1058,67 +894,51 @@ var Project = (function () {
|
|
|
1058
894
|
console.warn("Attempt to set unknown language \"".concat(language, "\""));
|
|
1059
895
|
}
|
|
1060
896
|
};
|
|
1061
|
-
|
|
1062
897
|
self.get = function (name) {
|
|
1063
898
|
if (typeof name === 'undefined') {
|
|
1064
899
|
// return full dataset if parameter name is not set
|
|
1065
900
|
return data;
|
|
1066
901
|
}
|
|
1067
|
-
|
|
1068
902
|
if (typeof data[name] !== 'undefined') {
|
|
1069
903
|
// return value that matches passed parameter name in dataset
|
|
1070
904
|
return data[name];
|
|
1071
905
|
}
|
|
1072
|
-
|
|
1073
906
|
return null;
|
|
1074
907
|
};
|
|
1075
|
-
|
|
1076
908
|
self.getSettings = function (name) {
|
|
1077
909
|
var values = self.localise(settings);
|
|
1078
|
-
|
|
1079
910
|
if (typeof name === 'undefined') {
|
|
1080
911
|
return values;
|
|
1081
912
|
}
|
|
1082
|
-
|
|
1083
913
|
if (typeof values[name] !== 'undefined') {
|
|
1084
914
|
return values[name];
|
|
1085
915
|
}
|
|
1086
|
-
|
|
1087
916
|
return null;
|
|
1088
917
|
};
|
|
1089
|
-
|
|
1090
918
|
self.getUUID = function () {
|
|
1091
919
|
return uuid;
|
|
1092
920
|
};
|
|
1093
|
-
|
|
1094
921
|
self.getLanguages = function () {
|
|
1095
922
|
return self.get('locales');
|
|
1096
923
|
};
|
|
1097
|
-
|
|
1098
924
|
self.getCurrentLanguage = function () {
|
|
1099
925
|
return currentLanguage;
|
|
1100
926
|
};
|
|
1101
|
-
|
|
1102
927
|
self.getEmbedUrl = function () {
|
|
1103
928
|
return self.get('embed');
|
|
1104
929
|
};
|
|
1105
|
-
|
|
1106
930
|
self.isLocalisationSupported = function () {
|
|
1107
931
|
return self.get('is_localisation_supported');
|
|
1108
932
|
};
|
|
1109
|
-
|
|
1110
933
|
self.localise = function (value) {
|
|
1111
934
|
if ({}.hasOwnProperty.call(value, currentLanguage)) {
|
|
1112
935
|
return value[currentLanguage];
|
|
1113
936
|
}
|
|
1114
|
-
|
|
1115
937
|
if ({}.hasOwnProperty.call(value, 'all')) {
|
|
1116
938
|
return value.all;
|
|
1117
939
|
}
|
|
1118
|
-
|
|
1119
940
|
return value;
|
|
1120
941
|
};
|
|
1121
|
-
|
|
1122
942
|
self.init = function () {
|
|
1123
943
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1124
944
|
uuid = config.uuid;
|
|
@@ -1126,27 +946,18 @@ var Project = (function () {
|
|
|
1126
946
|
ConnectionAdaptor.bind(ConnectionAdaptor.ON_MESSAGE, handleSubsCount);
|
|
1127
947
|
return loadAppSettings();
|
|
1128
948
|
};
|
|
1129
|
-
|
|
1130
949
|
return self;
|
|
1131
950
|
})();
|
|
1132
951
|
|
|
1133
|
-
function
|
|
1134
|
-
|
|
1135
|
-
function
|
|
1136
|
-
|
|
952
|
+
function _callSuper$i(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$i() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
953
|
+
function _isNativeReflectConstruct$i() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$i = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
954
|
+
function _superPropGet$a(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
1137
955
|
var Frame = /*#__PURE__*/function (_Entity) {
|
|
1138
|
-
_inherits(Frame, _Entity);
|
|
1139
|
-
|
|
1140
|
-
var _super = _createSuper$i(Frame);
|
|
1141
|
-
|
|
1142
956
|
function Frame() {
|
|
1143
957
|
var _this;
|
|
1144
|
-
|
|
1145
958
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1146
|
-
|
|
1147
959
|
_classCallCheck(this, Frame);
|
|
1148
|
-
|
|
1149
|
-
_this = _super.call(this, config);
|
|
960
|
+
_this = _callSuper$i(this, Frame, [config]);
|
|
1150
961
|
_this.state = null;
|
|
1151
962
|
_this.aborted = false;
|
|
1152
963
|
_this.enmasseId = config.data.id;
|
|
@@ -1155,16 +966,16 @@ var Frame = /*#__PURE__*/function (_Entity) {
|
|
|
1155
966
|
_this.type = config.type;
|
|
1156
967
|
_this.fixed = config.fixed;
|
|
1157
968
|
_this.contentType = config.content_type || null;
|
|
1158
|
-
_this.customFields = config.custom_fields || {};
|
|
969
|
+
_this.customFields = config.custom_fields || {};
|
|
1159
970
|
|
|
971
|
+
// calculate real duration left only for fixed frames
|
|
1160
972
|
if (_this.fixed) {
|
|
1161
973
|
_this.updateDurationLeft();
|
|
1162
974
|
}
|
|
1163
|
-
|
|
1164
975
|
return _this;
|
|
1165
976
|
}
|
|
1166
|
-
|
|
1167
|
-
_createClass(Frame, [{
|
|
977
|
+
_inherits(Frame, _Entity);
|
|
978
|
+
return _createClass(Frame, [{
|
|
1168
979
|
key: "getEnmasseId",
|
|
1169
980
|
value: function getEnmasseId() {
|
|
1170
981
|
return this.enmasseId;
|
|
@@ -1194,19 +1005,18 @@ var Frame = /*#__PURE__*/function (_Entity) {
|
|
|
1194
1005
|
key: "getCustomFields",
|
|
1195
1006
|
value: function getCustomFields(field) {
|
|
1196
1007
|
var values = Project.localise(this.customFields);
|
|
1197
|
-
|
|
1198
1008
|
if (typeof field === 'undefined') {
|
|
1199
1009
|
// return full set of custom fields if field name wasn't passed
|
|
1200
1010
|
return values;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1011
|
+
}
|
|
1203
1012
|
|
|
1013
|
+
// custom field was passed
|
|
1204
1014
|
if (typeof values[field] !== 'undefined') {
|
|
1205
1015
|
// return specific field if field exists in object
|
|
1206
1016
|
return values[field];
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1017
|
+
}
|
|
1209
1018
|
|
|
1019
|
+
// otherwise return null
|
|
1210
1020
|
return null;
|
|
1211
1021
|
}
|
|
1212
1022
|
}, {
|
|
@@ -1237,13 +1047,11 @@ var Frame = /*#__PURE__*/function (_Entity) {
|
|
|
1237
1047
|
if (this.aborted) {
|
|
1238
1048
|
return;
|
|
1239
1049
|
}
|
|
1240
|
-
|
|
1241
1050
|
var self = this;
|
|
1242
1051
|
var endAt = this.publishedAt + this.duration;
|
|
1243
1052
|
var now = LViSDate.now();
|
|
1244
1053
|
var left = endAt - now;
|
|
1245
1054
|
this.setDurationLeft(left);
|
|
1246
|
-
|
|
1247
1055
|
if (this.durationLeft > 0) {
|
|
1248
1056
|
Run.nextPriority(function () {
|
|
1249
1057
|
return self.updateDurationLeft();
|
|
@@ -1256,32 +1064,21 @@ var Frame = /*#__PURE__*/function (_Entity) {
|
|
|
1256
1064
|
key: "update",
|
|
1257
1065
|
value: function update() {
|
|
1258
1066
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1259
|
-
|
|
1260
|
-
_get(_getPrototypeOf(Frame.prototype), "update", this).call(this, config);
|
|
1261
|
-
|
|
1067
|
+
_superPropGet$a(Frame, "update", this, 3)([config]);
|
|
1262
1068
|
this.duration = config.duration - 0 || 0;
|
|
1263
1069
|
this.customFields = config.custom_fields || {};
|
|
1264
1070
|
}
|
|
1265
1071
|
}]);
|
|
1266
|
-
|
|
1267
|
-
return Frame;
|
|
1268
1072
|
}(Entity);
|
|
1269
1073
|
|
|
1270
|
-
function
|
|
1271
|
-
|
|
1272
|
-
function
|
|
1273
|
-
|
|
1074
|
+
function _callSuper$h(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$h() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1075
|
+
function _isNativeReflectConstruct$h() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$h = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1076
|
+
function _superPropGet$9(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
1274
1077
|
var Poll = /*#__PURE__*/function (_Frame) {
|
|
1275
|
-
_inherits(Poll, _Frame);
|
|
1276
|
-
|
|
1277
|
-
var _super = _createSuper$h(Poll);
|
|
1278
|
-
|
|
1279
1078
|
function Poll(config) {
|
|
1280
1079
|
var _this;
|
|
1281
|
-
|
|
1282
1080
|
_classCallCheck(this, Poll);
|
|
1283
|
-
|
|
1284
|
-
_this = _super.call(this, config);
|
|
1081
|
+
_this = _callSuper$h(this, Poll, [config]);
|
|
1285
1082
|
_this.question = config.data.question;
|
|
1286
1083
|
_this.options = config.data.options;
|
|
1287
1084
|
_this.rawResults = config.data.results || null;
|
|
@@ -1291,13 +1088,11 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1291
1088
|
_this.state = config.data.state || Poll.STATE_STARTED;
|
|
1292
1089
|
_this.requiresValidatedUser = config.data.requires_validated_user;
|
|
1293
1090
|
_this.resultsTriggerPostponed = false;
|
|
1294
|
-
|
|
1295
1091
|
_this.restoreVote();
|
|
1296
|
-
|
|
1297
1092
|
return _this;
|
|
1298
1093
|
}
|
|
1299
|
-
|
|
1300
|
-
_createClass(Poll, [{
|
|
1094
|
+
_inherits(Poll, _Frame);
|
|
1095
|
+
return _createClass(Poll, [{
|
|
1301
1096
|
key: "getQuestion",
|
|
1302
1097
|
value: function getQuestion() {
|
|
1303
1098
|
return Project.localise(this.question);
|
|
@@ -1313,14 +1108,12 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1313
1108
|
if (!this.canReveal()) {
|
|
1314
1109
|
return [];
|
|
1315
1110
|
}
|
|
1316
|
-
|
|
1317
1111
|
return this.results;
|
|
1318
1112
|
}
|
|
1319
1113
|
}, {
|
|
1320
1114
|
key: "getResultsPerSource",
|
|
1321
1115
|
value: function getResultsPerSource(source) {
|
|
1322
1116
|
var results = null;
|
|
1323
|
-
|
|
1324
1117
|
if (typeof source === 'undefined') {
|
|
1325
1118
|
results = this.resultsPerSource;
|
|
1326
1119
|
} else {
|
|
@@ -1330,7 +1123,6 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1330
1123
|
}
|
|
1331
1124
|
}
|
|
1332
1125
|
}
|
|
1333
|
-
|
|
1334
1126
|
return results;
|
|
1335
1127
|
}
|
|
1336
1128
|
}, {
|
|
@@ -1367,18 +1159,15 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1367
1159
|
key: "vote",
|
|
1368
1160
|
value: function vote() {
|
|
1369
1161
|
var _vote = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1370
|
-
|
|
1371
1162
|
var indices = Object.keys(_vote);
|
|
1372
1163
|
var options = this.getOptions();
|
|
1373
1164
|
var nonexistantVotes = indices.filter(function (idx) {
|
|
1374
1165
|
return typeof options[idx] === 'undefined';
|
|
1375
1166
|
});
|
|
1376
|
-
|
|
1377
1167
|
if (nonexistantVotes.length > 0) {
|
|
1378
1168
|
console.warn("Can't vote for nonexistant %s (%s)", nonexistantVotes.length === 1 ? 'option' : 'options', nonexistantVotes.join(', '));
|
|
1379
1169
|
return false;
|
|
1380
1170
|
}
|
|
1381
|
-
|
|
1382
1171
|
this.storeVote(_vote);
|
|
1383
1172
|
this.trigger(Poll.ON_VOTE, _vote);
|
|
1384
1173
|
return true;
|
|
@@ -1390,15 +1179,15 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1390
1179
|
if (state === undefined || state === this.state) {
|
|
1391
1180
|
return;
|
|
1392
1181
|
}
|
|
1393
|
-
|
|
1394
1182
|
this.state = state;
|
|
1395
|
-
this.trigger(Poll.ON_STATE_CHANGE, state);
|
|
1183
|
+
this.trigger(Poll.ON_STATE_CHANGE, state);
|
|
1184
|
+
|
|
1185
|
+
// Order of messages from enmasse is not guaranteed.
|
|
1396
1186
|
// Stop or reveal messages can be after feedback message.
|
|
1397
1187
|
// If feedback message is received before user is able to see results are saved
|
|
1398
1188
|
// and set resultsTriggerPostponed true.
|
|
1399
1189
|
// When state(stop, reveal) allows reveal results and reveal results was postponed
|
|
1400
1190
|
// action ON_RESULTS triggered.
|
|
1401
|
-
|
|
1402
1191
|
if (this.canReveal() && this.resultsTriggerPostponed) {
|
|
1403
1192
|
this.resultsTriggerPostponed = false;
|
|
1404
1193
|
this.trigger(Poll.ON_RESULTS);
|
|
@@ -1411,10 +1200,8 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1411
1200
|
if (JSON.stringify(results) === JSON.stringify(this.rawResults)) {
|
|
1412
1201
|
return;
|
|
1413
1202
|
}
|
|
1414
|
-
|
|
1415
1203
|
this.rawResults = results;
|
|
1416
1204
|
this.populateResults(results);
|
|
1417
|
-
|
|
1418
1205
|
if (this.hasResults()) {
|
|
1419
1206
|
this.trigger(Poll.ON_RESULTS);
|
|
1420
1207
|
} else {
|
|
@@ -1441,8 +1228,9 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1441
1228
|
value: function stop(time) {
|
|
1442
1229
|
this.abort(time);
|
|
1443
1230
|
this.setState(Poll.STATE_CLOSED);
|
|
1444
|
-
}
|
|
1231
|
+
}
|
|
1445
1232
|
|
|
1233
|
+
// TODO: Combine populateResults() and populateResultsFromSnapshot() methods
|
|
1446
1234
|
}, {
|
|
1447
1235
|
key: "populateResults",
|
|
1448
1236
|
value: function populateResults(results) {
|
|
@@ -1481,7 +1269,6 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1481
1269
|
key: "restoreVote",
|
|
1482
1270
|
value: function restoreVote() {
|
|
1483
1271
|
var name = "frame-".concat(this.getId());
|
|
1484
|
-
|
|
1485
1272
|
try {
|
|
1486
1273
|
this.votedFor = JSON.parse(Storage.get(name));
|
|
1487
1274
|
} catch (exception) {
|
|
@@ -1492,75 +1279,48 @@ var Poll = /*#__PURE__*/function (_Frame) {
|
|
|
1492
1279
|
key: "update",
|
|
1493
1280
|
value: function update() {
|
|
1494
1281
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1495
|
-
|
|
1496
|
-
_get(_getPrototypeOf(Poll.prototype), "update", this).call(this, config);
|
|
1497
|
-
|
|
1282
|
+
_superPropGet$9(Poll, "update", this, 3)([config]);
|
|
1498
1283
|
this.question = config.data.question;
|
|
1499
1284
|
this.options = config.data.options;
|
|
1500
1285
|
}
|
|
1501
1286
|
}]);
|
|
1502
|
-
|
|
1503
|
-
return Poll;
|
|
1504
1287
|
}(Frame);
|
|
1505
|
-
|
|
1506
1288
|
_defineProperty(Poll, "EXPIRE", 7 * 24 * 60 * 60);
|
|
1507
|
-
|
|
1508
1289
|
_defineProperty(Poll, "STATE_STARTED", 'started');
|
|
1509
|
-
|
|
1510
1290
|
_defineProperty(Poll, "STATE_CLOSED", 'stopped');
|
|
1511
|
-
|
|
1512
1291
|
_defineProperty(Poll, "ON_VOTE", 'voted');
|
|
1513
|
-
|
|
1514
1292
|
_defineProperty(Poll, "ON_RESULTS", 'results');
|
|
1515
|
-
|
|
1516
1293
|
_defineProperty(Poll, "ON_STATE_CHANGE", 'state');
|
|
1517
1294
|
|
|
1518
|
-
function
|
|
1519
|
-
|
|
1520
|
-
function _isNativeReflectConstruct$g() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1521
|
-
|
|
1295
|
+
function _callSuper$g(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$g() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1296
|
+
function _isNativeReflectConstruct$g() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$g = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1522
1297
|
var Fadeable = function Fadeable(superclass) {
|
|
1523
1298
|
return /*#__PURE__*/function (_superclass) {
|
|
1524
|
-
_inherits(_class, _superclass);
|
|
1525
|
-
|
|
1526
|
-
var _super = _createSuper$g(_class);
|
|
1527
|
-
|
|
1528
1299
|
function _class(config) {
|
|
1529
1300
|
var _this;
|
|
1530
|
-
|
|
1531
1301
|
_classCallCheck(this, _class);
|
|
1532
|
-
|
|
1533
|
-
_this = _super.call(this, config);
|
|
1302
|
+
_this = _callSuper$g(this, _class, [config]);
|
|
1534
1303
|
_this.fade = config.data.fade;
|
|
1535
1304
|
return _this;
|
|
1536
1305
|
}
|
|
1537
|
-
|
|
1538
|
-
_createClass(_class, [{
|
|
1306
|
+
_inherits(_class, _superclass);
|
|
1307
|
+
return _createClass(_class, [{
|
|
1539
1308
|
key: "getFade",
|
|
1540
1309
|
value: function getFade() {
|
|
1541
1310
|
return this.fade;
|
|
1542
1311
|
}
|
|
1543
1312
|
}]);
|
|
1544
|
-
|
|
1545
|
-
return _class;
|
|
1546
1313
|
}(superclass);
|
|
1547
1314
|
};
|
|
1548
1315
|
|
|
1549
|
-
function
|
|
1550
|
-
|
|
1551
|
-
function _isNativeReflectConstruct$f() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1552
|
-
|
|
1316
|
+
function _callSuper$f(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$f() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1317
|
+
function _isNativeReflectConstruct$f() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$f = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1553
1318
|
var Powerbar = /*#__PURE__*/function (_Fadeable) {
|
|
1554
|
-
_inherits(Powerbar, _Fadeable);
|
|
1555
|
-
|
|
1556
|
-
var _super = _createSuper$f(Powerbar);
|
|
1557
|
-
|
|
1558
1319
|
function Powerbar(config) {
|
|
1559
1320
|
var _this;
|
|
1560
|
-
|
|
1561
1321
|
_classCallCheck(this, Powerbar);
|
|
1322
|
+
_this = _callSuper$f(this, Powerbar, [config]);
|
|
1562
1323
|
|
|
1563
|
-
_this = _super.call(this, config);
|
|
1564
1324
|
/**
|
|
1565
1325
|
* Array of plain objects which represent result history for Powerbar element
|
|
1566
1326
|
*
|
|
@@ -1573,23 +1333,20 @@ var Powerbar = /*#__PURE__*/function (_Fadeable) {
|
|
|
1573
1333
|
* @property history
|
|
1574
1334
|
* @type {Array}
|
|
1575
1335
|
*/
|
|
1576
|
-
|
|
1577
1336
|
_this.results = [];
|
|
1578
1337
|
_this.resultsPerSource = {};
|
|
1579
1338
|
return _this;
|
|
1580
1339
|
}
|
|
1581
|
-
|
|
1582
|
-
_createClass(Powerbar, [{
|
|
1340
|
+
_inherits(Powerbar, _Fadeable);
|
|
1341
|
+
return _createClass(Powerbar, [{
|
|
1583
1342
|
key: "getResultsPerSource",
|
|
1584
1343
|
value: function getResultsPerSource(source) {
|
|
1585
1344
|
var results = null;
|
|
1586
|
-
|
|
1587
1345
|
if (typeof source === 'undefined') {
|
|
1588
1346
|
results = this.resultsPerSource;
|
|
1589
1347
|
} else if (typeof this.resultsPerSource[source] !== 'undefined') {
|
|
1590
1348
|
results = this.resultsPerSource[source];
|
|
1591
1349
|
}
|
|
1592
|
-
|
|
1593
1350
|
return results;
|
|
1594
1351
|
}
|
|
1595
1352
|
}, {
|
|
@@ -1603,14 +1360,11 @@ var Powerbar = /*#__PURE__*/function (_Fadeable) {
|
|
|
1603
1360
|
key: "setResultsPerSource",
|
|
1604
1361
|
value: function setResultsPerSource(results) {
|
|
1605
1362
|
var _this2 = this;
|
|
1606
|
-
|
|
1607
1363
|
results.forEach(function (result) {
|
|
1608
1364
|
var item = _this2.resultsToHistoryItem(result.results);
|
|
1609
|
-
|
|
1610
1365
|
if (!_this2.resultsPerSource[result.source]) {
|
|
1611
1366
|
_this2.resultsPerSource[result.source] = [];
|
|
1612
1367
|
}
|
|
1613
|
-
|
|
1614
1368
|
_this2.resultsPerSource[result.source].push(item);
|
|
1615
1369
|
}, this);
|
|
1616
1370
|
}
|
|
@@ -1622,19 +1376,18 @@ var Powerbar = /*#__PURE__*/function (_Fadeable) {
|
|
|
1622
1376
|
volume: 0,
|
|
1623
1377
|
average: 0,
|
|
1624
1378
|
responses: 0
|
|
1625
|
-
};
|
|
1379
|
+
};
|
|
1626
1380
|
|
|
1381
|
+
// option's index starts with 1
|
|
1627
1382
|
for (var i = 0, l = 9; i <= l; i++) {
|
|
1628
1383
|
if (typeof results[i] !== 'undefined') {
|
|
1629
1384
|
item.volume += results[i] * (i + 1);
|
|
1630
1385
|
item.responses += results[i];
|
|
1631
1386
|
}
|
|
1632
1387
|
}
|
|
1633
|
-
|
|
1634
1388
|
if (item.responses !== 0) {
|
|
1635
1389
|
item.average = Math.round(item.volume / item.responses);
|
|
1636
1390
|
}
|
|
1637
|
-
|
|
1638
1391
|
return item;
|
|
1639
1392
|
}
|
|
1640
1393
|
}, {
|
|
@@ -1643,73 +1396,50 @@ var Powerbar = /*#__PURE__*/function (_Fadeable) {
|
|
|
1643
1396
|
return this.results.length > 0;
|
|
1644
1397
|
}
|
|
1645
1398
|
}]);
|
|
1646
|
-
|
|
1647
|
-
return Powerbar;
|
|
1648
1399
|
}(Fadeable(Poll));
|
|
1649
|
-
|
|
1650
1400
|
_defineProperty(Powerbar, "TYPE", 'powerbar');
|
|
1651
|
-
|
|
1652
1401
|
_defineProperty(Powerbar, "STATE_STARTED", Poll.STATE_STARTED);
|
|
1653
|
-
|
|
1654
1402
|
_defineProperty(Powerbar, "STATE_CLOSED", Poll.STATE_CLOSED);
|
|
1655
|
-
|
|
1656
1403
|
_defineProperty(Powerbar, "ON_VOLUME_UPDATE", 'volume');
|
|
1657
|
-
|
|
1658
1404
|
_defineProperty(Powerbar, "ON_VOTE", Poll.ON_VOTE);
|
|
1659
|
-
|
|
1660
1405
|
_defineProperty(Powerbar, "ON_RESULTS", Poll.ON_RESULTS);
|
|
1661
|
-
|
|
1662
1406
|
_defineProperty(Powerbar, "ON_STATE_CHANGE", Poll.ON_STATE_CHANGE);
|
|
1663
1407
|
|
|
1664
|
-
function
|
|
1665
|
-
|
|
1666
|
-
function
|
|
1667
|
-
|
|
1408
|
+
function _callSuper$e(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$e() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1409
|
+
function _isNativeReflectConstruct$e() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$e = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1410
|
+
function _superPropGet$8(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
1668
1411
|
var REVEAL_RESULTS_ON_VOTE = 'vote';
|
|
1669
1412
|
var REVEAL_RESULTS_ON_CLOSE = 'close';
|
|
1670
1413
|
var REVEAL_RESULTS_ON_EVENT_END = 'event_end';
|
|
1671
1414
|
var REVEAL_RESULTS_MANUALLY = 'manual';
|
|
1672
1415
|
var REVEAL_RESULTS_NEVER = 'never';
|
|
1673
1416
|
var REVEAL_RESULTS_ALWAYS = 'always';
|
|
1674
|
-
|
|
1675
1417
|
var Revealable = function Revealable(superclass) {
|
|
1676
1418
|
return /*#__PURE__*/function (_superclass) {
|
|
1677
|
-
_inherits(_class, _superclass);
|
|
1678
|
-
|
|
1679
|
-
var _super = _createSuper$e(_class);
|
|
1680
|
-
|
|
1681
1419
|
function _class(config) {
|
|
1682
1420
|
var _this;
|
|
1683
|
-
|
|
1684
1421
|
_classCallCheck(this, _class);
|
|
1685
|
-
|
|
1686
|
-
_this = _super.call(this, config);
|
|
1422
|
+
_this = _callSuper$e(this, _class, [config]);
|
|
1687
1423
|
_this.revealResultsMode = config.data.reveal_results_mode || REVEAL_RESULTS_ON_VOTE;
|
|
1688
1424
|
return _this;
|
|
1689
1425
|
}
|
|
1690
|
-
|
|
1691
|
-
_createClass(_class, [{
|
|
1426
|
+
_inherits(_class, _superclass);
|
|
1427
|
+
return _createClass(_class, [{
|
|
1692
1428
|
key: "setResults",
|
|
1693
1429
|
value: function setResults() {
|
|
1694
|
-
var _get2;
|
|
1695
|
-
|
|
1696
1430
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1697
1431
|
args[_key] = arguments[_key];
|
|
1698
1432
|
}
|
|
1699
|
-
|
|
1700
|
-
(_get2 = _get(_getPrototypeOf(_class.prototype), "setResults", this)).call.apply(_get2, [this].concat(args));
|
|
1433
|
+
_superPropGet$8(_class, "setResults", this, 3)(args);
|
|
1701
1434
|
}
|
|
1702
1435
|
}, {
|
|
1703
1436
|
key: "setResultsPerSource",
|
|
1704
1437
|
value: function setResultsPerSource() {
|
|
1705
1438
|
if (this.canReveal()) {
|
|
1706
|
-
var _get3;
|
|
1707
|
-
|
|
1708
1439
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1709
1440
|
args[_key2] = arguments[_key2];
|
|
1710
1441
|
}
|
|
1711
|
-
|
|
1712
|
-
(_get3 = _get(_getPrototypeOf(_class.prototype), "setResultsPerSource", this)).call.apply(_get3, [this].concat(args));
|
|
1442
|
+
_superPropGet$8(_class, "setResultsPerSource", this, 3)(args);
|
|
1713
1443
|
}
|
|
1714
1444
|
}
|
|
1715
1445
|
}, {
|
|
@@ -1718,51 +1448,38 @@ var Revealable = function Revealable(superclass) {
|
|
|
1718
1448
|
switch (this.revealResultsMode) {
|
|
1719
1449
|
case REVEAL_RESULTS_ON_VOTE:
|
|
1720
1450
|
return this.hasUserVoted() || this.isClosed();
|
|
1721
|
-
|
|
1722
1451
|
case REVEAL_RESULTS_ON_CLOSE:
|
|
1723
1452
|
return this.isClosed();
|
|
1724
|
-
|
|
1725
1453
|
case REVEAL_RESULTS_ON_EVENT_END:
|
|
1726
1454
|
case REVEAL_RESULTS_MANUALLY:
|
|
1727
1455
|
case REVEAL_RESULTS_ALWAYS:
|
|
1728
1456
|
// assume that method is called upon setting results
|
|
1729
1457
|
return true;
|
|
1730
|
-
|
|
1731
1458
|
case REVEAL_RESULTS_NEVER:
|
|
1732
1459
|
return false;
|
|
1733
|
-
|
|
1734
1460
|
default:
|
|
1735
1461
|
return false;
|
|
1736
1462
|
}
|
|
1737
1463
|
}
|
|
1738
1464
|
}]);
|
|
1739
|
-
|
|
1740
|
-
return _class;
|
|
1741
1465
|
}(superclass);
|
|
1742
1466
|
};
|
|
1743
1467
|
|
|
1744
|
-
function
|
|
1745
|
-
|
|
1746
|
-
function
|
|
1747
|
-
|
|
1468
|
+
function _callSuper$d(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$d() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1469
|
+
function _isNativeReflectConstruct$d() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$d = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1470
|
+
function _superPropGet$7(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
1748
1471
|
var MultiVotable = function MultiVotable(superclass) {
|
|
1749
1472
|
return /*#__PURE__*/function (_superclass) {
|
|
1750
|
-
_inherits(_class, _superclass);
|
|
1751
|
-
|
|
1752
|
-
var _super = _createSuper$d(_class);
|
|
1753
|
-
|
|
1754
1473
|
function _class(config) {
|
|
1755
1474
|
var _this;
|
|
1756
|
-
|
|
1757
1475
|
_classCallCheck(this, _class);
|
|
1758
|
-
|
|
1759
|
-
_this = _super.call(this, config);
|
|
1476
|
+
_this = _callSuper$d(this, _class, [config]);
|
|
1760
1477
|
_this.maxVotesPerUser = config.data.max_votes_per_user;
|
|
1761
1478
|
_this.maxVotesPerOption = config.data.max_votes_per_option;
|
|
1762
1479
|
return _this;
|
|
1763
1480
|
}
|
|
1764
|
-
|
|
1765
|
-
_createClass(_class, [{
|
|
1481
|
+
_inherits(_class, _superclass);
|
|
1482
|
+
return _createClass(_class, [{
|
|
1766
1483
|
key: "getMaxVotesPerUser",
|
|
1767
1484
|
value: function getMaxVotesPerUser() {
|
|
1768
1485
|
return this.maxVotesPerUser;
|
|
@@ -1791,60 +1508,45 @@ var MultiVotable = function MultiVotable(superclass) {
|
|
|
1791
1508
|
return votes[idx] > maxPerOption;
|
|
1792
1509
|
});
|
|
1793
1510
|
var exceedsMaxPerUser = total > maxPerUser;
|
|
1794
|
-
|
|
1795
1511
|
if (hasEmptyVote) {
|
|
1796
1512
|
console.warn("Can't vote because one of the vote is equal or less than 0");
|
|
1797
1513
|
return false;
|
|
1798
1514
|
}
|
|
1799
|
-
|
|
1800
1515
|
if (hasNonIntVote) {
|
|
1801
1516
|
console.warn("Can't vote because all votes must be integers");
|
|
1802
1517
|
return false;
|
|
1803
1518
|
}
|
|
1804
|
-
|
|
1805
1519
|
if (exceedsMaxPerOption) {
|
|
1806
1520
|
console.warn('poll:%s option:%s exceeds allowed maximum:%s', this.getFullId(), +exceedsMaxPerOption + 1, maxPerOption);
|
|
1807
1521
|
return false;
|
|
1808
1522
|
}
|
|
1809
|
-
|
|
1810
1523
|
if (exceedsMaxPerUser) {
|
|
1811
1524
|
console.warn('poll:%s votes:%s exceeds allowed maximum:%s', this.getFullId(), total, maxPerUser);
|
|
1812
1525
|
return false;
|
|
1813
1526
|
}
|
|
1814
|
-
|
|
1815
1527
|
if (total === 0) {
|
|
1816
1528
|
console.warn("Votes can't be empty");
|
|
1817
1529
|
return false;
|
|
1818
1530
|
}
|
|
1819
|
-
|
|
1820
|
-
return _get(_getPrototypeOf(_class.prototype), "vote", this).call(this, votes);
|
|
1531
|
+
return _superPropGet$7(_class, "vote", this, 3)([votes]);
|
|
1821
1532
|
}
|
|
1822
1533
|
}]);
|
|
1823
|
-
|
|
1824
|
-
return _class;
|
|
1825
1534
|
}(superclass);
|
|
1826
1535
|
};
|
|
1827
1536
|
|
|
1828
|
-
function
|
|
1829
|
-
|
|
1830
|
-
function
|
|
1831
|
-
|
|
1537
|
+
function _callSuper$c(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$c() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1538
|
+
function _isNativeReflectConstruct$c() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$c = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1539
|
+
function _superPropGet$6(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
1832
1540
|
var Quiz = /*#__PURE__*/function (_Revealable) {
|
|
1833
|
-
_inherits(Quiz, _Revealable);
|
|
1834
|
-
|
|
1835
|
-
var _super = _createSuper$c(Quiz);
|
|
1836
|
-
|
|
1837
1541
|
function Quiz(config) {
|
|
1838
1542
|
var _this;
|
|
1839
|
-
|
|
1840
1543
|
_classCallCheck(this, Quiz);
|
|
1841
|
-
|
|
1842
|
-
_this = _super.call(this, config);
|
|
1544
|
+
_this = _callSuper$c(this, Quiz, [config]);
|
|
1843
1545
|
_this.correctOption = {}.hasOwnProperty.call(config.data, 'correct_option') ? config.data.correct_option - 1 : null;
|
|
1844
1546
|
return _this;
|
|
1845
1547
|
}
|
|
1846
|
-
|
|
1847
|
-
_createClass(Quiz, [{
|
|
1548
|
+
_inherits(Quiz, _Revealable);
|
|
1549
|
+
return _createClass(Quiz, [{
|
|
1848
1550
|
key: "isClosed",
|
|
1849
1551
|
value: function isClosed() {
|
|
1850
1552
|
return this.isStopped() || this.isRevealed();
|
|
@@ -1884,26 +1586,21 @@ var Quiz = /*#__PURE__*/function (_Revealable) {
|
|
|
1884
1586
|
key: "vote",
|
|
1885
1587
|
value: function vote() {
|
|
1886
1588
|
var votes = {};
|
|
1887
|
-
|
|
1888
1589
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1889
1590
|
args[_key] = arguments[_key];
|
|
1890
1591
|
}
|
|
1891
|
-
|
|
1892
1592
|
switch (args[0].constructor) {
|
|
1893
1593
|
case Number:
|
|
1894
1594
|
votes[args[0]] = 1;
|
|
1895
1595
|
break;
|
|
1896
|
-
|
|
1897
1596
|
case Object:
|
|
1898
1597
|
// keep as it is
|
|
1899
1598
|
votes = args[0];
|
|
1900
1599
|
break;
|
|
1901
|
-
|
|
1902
1600
|
default:
|
|
1903
1601
|
console.warn('Incorrect votes format');
|
|
1904
1602
|
return false;
|
|
1905
1603
|
}
|
|
1906
|
-
|
|
1907
1604
|
var indices = Object.keys(votes);
|
|
1908
1605
|
var hasEmptyVote = indices.some(function (idx) {
|
|
1909
1606
|
return votes[idx] <= 0;
|
|
@@ -1911,127 +1608,80 @@ var Quiz = /*#__PURE__*/function (_Revealable) {
|
|
|
1911
1608
|
var hasNonIntVote = indices.some(function (idx) {
|
|
1912
1609
|
return !(typeof votes[idx] === 'number' && Math.floor(votes[idx]) === votes[idx]);
|
|
1913
1610
|
});
|
|
1914
|
-
|
|
1915
1611
|
if (hasEmptyVote) {
|
|
1916
1612
|
console.warn("Can't vote because one of the vote is equal or less than 0");
|
|
1917
1613
|
return false;
|
|
1918
1614
|
}
|
|
1919
|
-
|
|
1920
1615
|
if (hasNonIntVote) {
|
|
1921
1616
|
console.warn("Can't vote because all votes must be integers");
|
|
1922
1617
|
return false;
|
|
1923
1618
|
}
|
|
1924
|
-
|
|
1925
1619
|
if (indices.length > 1) {
|
|
1926
1620
|
console.warn('Can cast vote only for one (1) option');
|
|
1927
1621
|
return false;
|
|
1928
1622
|
}
|
|
1929
|
-
|
|
1930
|
-
return _get(_getPrototypeOf(Quiz.prototype), "vote", this).call(this, votes);
|
|
1623
|
+
return _superPropGet$6(Quiz, "vote", this, 3)([votes]);
|
|
1931
1624
|
}
|
|
1932
1625
|
}]);
|
|
1933
|
-
|
|
1934
|
-
return Quiz;
|
|
1935
1626
|
}(Revealable(MultiVotable(Poll)));
|
|
1936
|
-
|
|
1937
1627
|
_defineProperty(Quiz, "ON_VOTE", Poll.ON_VOTE);
|
|
1938
|
-
|
|
1939
1628
|
_defineProperty(Quiz, "ON_STATE_CHANGE", Poll.ON_STATE_CHANGE);
|
|
1940
|
-
|
|
1941
1629
|
_defineProperty(Quiz, "ON_RESULTS", Poll.ON_RESULTS);
|
|
1942
|
-
|
|
1943
1630
|
_defineProperty(Quiz, "STATE_STARTED", Poll.STATE_STARTED);
|
|
1944
|
-
|
|
1945
1631
|
_defineProperty(Quiz, "STATE_STOPPED", Poll.STATE_CLOSED);
|
|
1946
|
-
|
|
1947
1632
|
_defineProperty(Quiz, "STATE_REVEALED", 'revealed');
|
|
1948
1633
|
|
|
1949
|
-
function
|
|
1950
|
-
|
|
1951
|
-
function _isNativeReflectConstruct$b() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1952
|
-
|
|
1634
|
+
function _callSuper$b(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$b() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1635
|
+
function _isNativeReflectConstruct$b() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$b = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1953
1636
|
var Prediction = /*#__PURE__*/function (_Quiz) {
|
|
1954
|
-
_inherits(Prediction, _Quiz);
|
|
1955
|
-
|
|
1956
|
-
var _super = _createSuper$b(Prediction);
|
|
1957
|
-
|
|
1958
1637
|
function Prediction() {
|
|
1959
1638
|
_classCallCheck(this, Prediction);
|
|
1960
|
-
|
|
1961
|
-
return _super.apply(this, arguments);
|
|
1639
|
+
return _callSuper$b(this, Prediction, arguments);
|
|
1962
1640
|
}
|
|
1963
|
-
|
|
1964
|
-
return Prediction;
|
|
1641
|
+
_inherits(Prediction, _Quiz);
|
|
1642
|
+
return _createClass(Prediction);
|
|
1965
1643
|
}(Quiz);
|
|
1966
|
-
|
|
1967
1644
|
_defineProperty(Prediction, "TYPE", 'prediction');
|
|
1968
|
-
|
|
1969
1645
|
_defineProperty(Prediction, "STATE_STARTED", Quiz.STATE_STARTED);
|
|
1970
|
-
|
|
1971
1646
|
_defineProperty(Prediction, "STATE_STOPPED", Quiz.STATE_STOPPED);
|
|
1972
|
-
|
|
1973
1647
|
_defineProperty(Prediction, "STATE_REVEALED", Quiz.STATE_REVEALED);
|
|
1974
|
-
|
|
1975
1648
|
_defineProperty(Prediction, "ON_VOTE", Quiz.ON_VOTE);
|
|
1976
|
-
|
|
1977
1649
|
_defineProperty(Prediction, "ON_STATE_CHANGE", Quiz.ON_STATE_CHANGE);
|
|
1978
|
-
|
|
1979
1650
|
_defineProperty(Prediction, "ON_RESULTS", Quiz.ON_RESULTS);
|
|
1980
1651
|
|
|
1981
|
-
function
|
|
1982
|
-
|
|
1983
|
-
function _isNativeReflectConstruct$a() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1984
|
-
|
|
1652
|
+
function _callSuper$a(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$a() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1653
|
+
function _isNativeReflectConstruct$a() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$a = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1985
1654
|
var Trivia = /*#__PURE__*/function (_Quiz) {
|
|
1986
|
-
_inherits(Trivia, _Quiz);
|
|
1987
|
-
|
|
1988
|
-
var _super = _createSuper$a(Trivia);
|
|
1989
|
-
|
|
1990
1655
|
function Trivia() {
|
|
1991
1656
|
_classCallCheck(this, Trivia);
|
|
1992
|
-
|
|
1993
|
-
return _super.apply(this, arguments);
|
|
1657
|
+
return _callSuper$a(this, Trivia, arguments);
|
|
1994
1658
|
}
|
|
1995
|
-
|
|
1996
|
-
return Trivia;
|
|
1659
|
+
_inherits(Trivia, _Quiz);
|
|
1660
|
+
return _createClass(Trivia);
|
|
1997
1661
|
}(Quiz);
|
|
1998
|
-
|
|
1999
1662
|
_defineProperty(Trivia, "TYPE", 'trivia');
|
|
2000
|
-
|
|
2001
1663
|
_defineProperty(Trivia, "STATE_STARTED", Quiz.STATE_STARTED);
|
|
2002
|
-
|
|
2003
1664
|
_defineProperty(Trivia, "STATE_STOPPED", Quiz.STATE_STOPPED);
|
|
2004
|
-
|
|
2005
1665
|
_defineProperty(Trivia, "STATE_REVEALED", Quiz.STATE_REVEALED);
|
|
2006
|
-
|
|
2007
1666
|
_defineProperty(Trivia, "ON_VOTE", Quiz.ON_VOTE);
|
|
2008
|
-
|
|
2009
1667
|
_defineProperty(Trivia, "ON_STATE_CHANGE", Quiz.ON_STATE_CHANGE);
|
|
2010
|
-
|
|
2011
1668
|
_defineProperty(Trivia, "ON_RESULTS", Quiz.ON_RESULTS);
|
|
2012
1669
|
|
|
2013
|
-
function
|
|
2014
|
-
|
|
2015
|
-
function
|
|
2016
|
-
|
|
1670
|
+
function _callSuper$9(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$9() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1671
|
+
function _isNativeReflectConstruct$9() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$9 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1672
|
+
function _superPropGet$5(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
2017
1673
|
var Diametric = /*#__PURE__*/function (_Poll) {
|
|
2018
|
-
_inherits(Diametric, _Poll);
|
|
2019
|
-
|
|
2020
|
-
var _super = _createSuper$9(Diametric);
|
|
2021
|
-
|
|
2022
1674
|
function Diametric() {
|
|
2023
1675
|
_classCallCheck(this, Diametric);
|
|
2024
|
-
|
|
2025
|
-
return _super.apply(this, arguments);
|
|
1676
|
+
return _callSuper$9(this, Diametric, arguments);
|
|
2026
1677
|
}
|
|
2027
|
-
|
|
2028
|
-
_createClass(Diametric, [{
|
|
1678
|
+
_inherits(Diametric, _Poll);
|
|
1679
|
+
return _createClass(Diametric, [{
|
|
2029
1680
|
key: "getUserVote",
|
|
2030
1681
|
value: function getUserVote() {
|
|
2031
1682
|
if (this.votedFor === null) {
|
|
2032
1683
|
return null;
|
|
2033
1684
|
}
|
|
2034
|
-
|
|
2035
1685
|
return Math.floor(this.votedFor / Diametric.MAX_STRENGTH);
|
|
2036
1686
|
}
|
|
2037
1687
|
}, {
|
|
@@ -2040,44 +1690,38 @@ var Diametric = /*#__PURE__*/function (_Poll) {
|
|
|
2040
1690
|
if (this.votedFor === null) {
|
|
2041
1691
|
return null;
|
|
2042
1692
|
}
|
|
2043
|
-
|
|
2044
1693
|
return this.votedFor % Diametric.MAX_STRENGTH + 1;
|
|
2045
1694
|
}
|
|
2046
1695
|
}, {
|
|
2047
1696
|
key: "setResults",
|
|
2048
1697
|
value: function setResults(results) {
|
|
2049
1698
|
results = this.calculateWeightedResults(results);
|
|
2050
|
-
|
|
2051
|
-
_get(_getPrototypeOf(Diametric.prototype), "setResults", this).call(this, results);
|
|
1699
|
+
_superPropGet$5(Diametric, "setResults", this, 3)([results]);
|
|
2052
1700
|
}
|
|
2053
1701
|
}, {
|
|
2054
1702
|
key: "setResultsPerSource",
|
|
2055
1703
|
value: function setResultsPerSource(results) {
|
|
2056
1704
|
var _this = this;
|
|
2057
|
-
|
|
2058
1705
|
results.forEach(function (source) {
|
|
2059
1706
|
source.results = _this.calculateWeightedResults(source.results);
|
|
2060
1707
|
}, this);
|
|
2061
|
-
|
|
2062
|
-
_get(_getPrototypeOf(Diametric.prototype), "setResultsPerSource", this).call(this, results);
|
|
1708
|
+
_superPropGet$5(Diametric, "setResultsPerSource", this, 3)([results]);
|
|
2063
1709
|
}
|
|
2064
1710
|
}, {
|
|
2065
1711
|
key: "calculateWeightedResults",
|
|
2066
1712
|
value: function calculateWeightedResults(results) {
|
|
2067
|
-
var max = Diametric.MAX_STRENGTH;
|
|
1713
|
+
var max = Diametric.MAX_STRENGTH;
|
|
2068
1714
|
|
|
1715
|
+
// calculate weighted results
|
|
2069
1716
|
var weighted = [0, 0];
|
|
2070
|
-
|
|
2071
1717
|
for (var i = 0; i < max; i++) {
|
|
2072
1718
|
if (results[i]) {
|
|
2073
1719
|
weighted[0] += (i + 1) * results[i];
|
|
2074
1720
|
}
|
|
2075
|
-
|
|
2076
1721
|
if (results[i + max]) {
|
|
2077
1722
|
weighted[1] += (i + 1) * results[i + max];
|
|
2078
1723
|
}
|
|
2079
1724
|
}
|
|
2080
|
-
|
|
2081
1725
|
return weighted;
|
|
2082
1726
|
}
|
|
2083
1727
|
}, {
|
|
@@ -2086,35 +1730,28 @@ var Diametric = /*#__PURE__*/function (_Poll) {
|
|
|
2086
1730
|
var min = Diametric.MIN_STRENGTH;
|
|
2087
1731
|
var max = Diametric.MAX_STRENGTH;
|
|
2088
1732
|
var options = this.getOptions();
|
|
2089
|
-
|
|
2090
1733
|
if (typeof optionIdx === 'undefined') {
|
|
2091
1734
|
console.warn('Vote option is not set');
|
|
2092
1735
|
return;
|
|
2093
1736
|
}
|
|
2094
|
-
|
|
2095
1737
|
if (typeof strength === 'undefined') {
|
|
2096
1738
|
console.warn('Vote strength is not set');
|
|
2097
1739
|
return;
|
|
2098
1740
|
}
|
|
2099
|
-
|
|
2100
1741
|
if (strength < min) {
|
|
2101
1742
|
console.warn("Can't vote for the option %s with strength %s that is " + 'less than minimum allowed strength %s', optionIdx, strength, min);
|
|
2102
1743
|
return;
|
|
2103
1744
|
}
|
|
2104
|
-
|
|
2105
1745
|
if (strength > max) {
|
|
2106
1746
|
console.warn("Can't vote for the option %s with strength %s that is " + 'more than maximum allowed strength %s', optionIdx, strength, max);
|
|
2107
1747
|
return;
|
|
2108
1748
|
}
|
|
2109
|
-
|
|
2110
1749
|
if (optionIdx < 0 || optionIdx > options.length - 1) {
|
|
2111
1750
|
console.warn("Can't vote for inexistent option with idx %s", optionIdx);
|
|
2112
1751
|
return;
|
|
2113
1752
|
}
|
|
2114
|
-
|
|
2115
1753
|
var vote = optionIdx * max + strength - 1;
|
|
2116
|
-
|
|
2117
|
-
_get(_getPrototypeOf(Diametric.prototype), "vote", this).call(this, vote);
|
|
1754
|
+
_superPropGet$5(Diametric, "vote", this, 3)([vote]);
|
|
2118
1755
|
}
|
|
2119
1756
|
}, {
|
|
2120
1757
|
key: "isResultsRevealed",
|
|
@@ -2122,88 +1759,55 @@ var Diametric = /*#__PURE__*/function (_Poll) {
|
|
|
2122
1759
|
return true;
|
|
2123
1760
|
}
|
|
2124
1761
|
}]);
|
|
2125
|
-
|
|
2126
|
-
return Diametric;
|
|
2127
1762
|
}(Poll);
|
|
2128
|
-
|
|
2129
1763
|
_defineProperty(Diametric, "MIN_STRENGTH", 1);
|
|
2130
|
-
|
|
2131
1764
|
_defineProperty(Diametric, "MAX_STRENGTH", 5);
|
|
2132
|
-
|
|
2133
1765
|
_defineProperty(Diametric, "STATE_STARTED", Poll.STATE_STARTED);
|
|
2134
|
-
|
|
2135
1766
|
_defineProperty(Diametric, "STATE_CLOSED", Poll.STATE_CLOSED);
|
|
2136
1767
|
|
|
2137
|
-
function
|
|
2138
|
-
|
|
2139
|
-
function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2140
|
-
|
|
1768
|
+
function _callSuper$8(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$8() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1769
|
+
function _isNativeReflectConstruct$8() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$8 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2141
1770
|
var Swing = /*#__PURE__*/function (_Diametric) {
|
|
2142
|
-
_inherits(Swing, _Diametric);
|
|
2143
|
-
|
|
2144
|
-
var _super = _createSuper$8(Swing);
|
|
2145
|
-
|
|
2146
1771
|
function Swing() {
|
|
2147
1772
|
_classCallCheck(this, Swing);
|
|
2148
|
-
|
|
2149
|
-
return _super.apply(this, arguments);
|
|
1773
|
+
return _callSuper$8(this, Swing, arguments);
|
|
2150
1774
|
}
|
|
2151
|
-
|
|
2152
|
-
return Swing;
|
|
1775
|
+
_inherits(Swing, _Diametric);
|
|
1776
|
+
return _createClass(Swing);
|
|
2153
1777
|
}(Diametric);
|
|
2154
|
-
|
|
2155
1778
|
_defineProperty(Swing, "TYPE", 'dpoll');
|
|
2156
|
-
|
|
2157
1779
|
_defineProperty(Swing, "STATE_STARTED", Diametric.STATE_STARTED);
|
|
2158
|
-
|
|
2159
1780
|
_defineProperty(Swing, "STATE_CLOSED", Diametric.STATE_CLOSED);
|
|
2160
1781
|
|
|
2161
|
-
function
|
|
2162
|
-
|
|
2163
|
-
function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2164
|
-
|
|
1782
|
+
function _callSuper$7(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$7() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1783
|
+
function _isNativeReflectConstruct$7() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$7 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2165
1784
|
var Emoting = /*#__PURE__*/function (_Fadeable) {
|
|
2166
|
-
_inherits(Emoting, _Fadeable);
|
|
2167
|
-
|
|
2168
|
-
var _super = _createSuper$7(Emoting);
|
|
2169
|
-
|
|
2170
1785
|
function Emoting() {
|
|
2171
1786
|
_classCallCheck(this, Emoting);
|
|
2172
|
-
|
|
2173
|
-
return _super.apply(this, arguments);
|
|
1787
|
+
return _callSuper$7(this, Emoting, arguments);
|
|
2174
1788
|
}
|
|
2175
|
-
|
|
2176
|
-
return Emoting;
|
|
1789
|
+
_inherits(Emoting, _Fadeable);
|
|
1790
|
+
return _createClass(Emoting);
|
|
2177
1791
|
}(Fadeable(Diametric));
|
|
2178
|
-
|
|
2179
1792
|
_defineProperty(Emoting, "TYPE", 'emo');
|
|
2180
|
-
|
|
2181
1793
|
_defineProperty(Emoting, "STATE_STARTED", Diametric.STATE_STARTED);
|
|
2182
|
-
|
|
2183
1794
|
_defineProperty(Emoting, "STATE_CLOSED", Diametric.STATE_CLOSED);
|
|
2184
1795
|
|
|
2185
|
-
function
|
|
2186
|
-
|
|
2187
|
-
function
|
|
2188
|
-
|
|
1796
|
+
function _callSuper$6(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$6() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1797
|
+
function _isNativeReflectConstruct$6() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$6 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1798
|
+
function _superPropGet$4(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
2189
1799
|
var Regular = /*#__PURE__*/function (_Revealable) {
|
|
2190
|
-
_inherits(Regular, _Revealable);
|
|
2191
|
-
|
|
2192
|
-
var _super = _createSuper$6(Regular);
|
|
2193
|
-
|
|
2194
1800
|
function Regular(config) {
|
|
2195
1801
|
var _this;
|
|
2196
|
-
|
|
2197
1802
|
_classCallCheck(this, Regular);
|
|
2198
|
-
|
|
2199
|
-
_this = _super.call(this, config);
|
|
1803
|
+
_this = _callSuper$6(this, Regular, [config]);
|
|
2200
1804
|
_this.qualifyingHashtags = config.data.qualifying_hashtags;
|
|
2201
1805
|
_this.minOptionsPerVote = config.data.min_options_per_vote;
|
|
2202
1806
|
_this.maxOptionsPerVote = config.data.max_options_per_vote;
|
|
2203
1807
|
return _this;
|
|
2204
1808
|
}
|
|
2205
|
-
|
|
2206
|
-
_createClass(Regular, [{
|
|
1809
|
+
_inherits(Regular, _Revealable);
|
|
1810
|
+
return _createClass(Regular, [{
|
|
2207
1811
|
key: "getQualifyingHashtags",
|
|
2208
1812
|
value: function getQualifyingHashtags() {
|
|
2209
1813
|
return this.qualifyingHashtags;
|
|
@@ -2225,87 +1829,58 @@ var Regular = /*#__PURE__*/function (_Revealable) {
|
|
|
2225
1829
|
var min = this.getMinOptionsPerVote();
|
|
2226
1830
|
var max = this.getMaxOptionsPerVote();
|
|
2227
1831
|
var indices = Object.keys(votes);
|
|
2228
|
-
|
|
2229
1832
|
if (indices.length < min) {
|
|
2230
1833
|
console.warn("Count of options (%s) can't be less than minimum options per vote (%s)", indices.length, min);
|
|
2231
1834
|
return false;
|
|
2232
1835
|
}
|
|
2233
|
-
|
|
2234
1836
|
if (indices.length > max) {
|
|
2235
1837
|
console.warn("Count of options (%s) can't be more than maximum options per vote (%s)", indices.length, max);
|
|
2236
1838
|
return false;
|
|
2237
1839
|
}
|
|
2238
|
-
|
|
2239
|
-
return _get(_getPrototypeOf(Regular.prototype), "vote", this).call(this, votes);
|
|
1840
|
+
return _superPropGet$4(Regular, "vote", this, 3)([votes]);
|
|
2240
1841
|
}
|
|
2241
1842
|
}]);
|
|
2242
|
-
|
|
2243
|
-
return Regular;
|
|
2244
1843
|
}(Revealable(MultiVotable(Poll)));
|
|
2245
|
-
|
|
2246
1844
|
_defineProperty(Regular, "TYPE", 'rpoll');
|
|
2247
|
-
|
|
2248
1845
|
_defineProperty(Regular, "STATE_STARTED", Poll.STATE_STARTED);
|
|
2249
|
-
|
|
2250
1846
|
_defineProperty(Regular, "STATE_CLOSED", Poll.STATE_CLOSED);
|
|
2251
|
-
|
|
2252
1847
|
_defineProperty(Regular, "ON_VOTE", Poll.ON_VOTE);
|
|
2253
|
-
|
|
2254
1848
|
_defineProperty(Regular, "ON_RESULTS", Poll.ON_RESULTS);
|
|
2255
|
-
|
|
2256
1849
|
_defineProperty(Regular, "ON_STATE_CHANGE", Poll.ON_STATE_CHANGE);
|
|
2257
1850
|
|
|
2258
|
-
function
|
|
2259
|
-
|
|
2260
|
-
function _isNativeReflectConstruct$5() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2261
|
-
|
|
1851
|
+
function _callSuper$5(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$5() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1852
|
+
function _isNativeReflectConstruct$5() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$5 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2262
1853
|
var FlexiPoll = /*#__PURE__*/function (_Regular) {
|
|
2263
|
-
_inherits(FlexiPoll, _Regular);
|
|
2264
|
-
|
|
2265
|
-
var _super = _createSuper$5(FlexiPoll);
|
|
2266
|
-
|
|
2267
1854
|
function FlexiPoll() {
|
|
2268
1855
|
_classCallCheck(this, FlexiPoll);
|
|
2269
|
-
|
|
2270
|
-
return _super.apply(this, arguments);
|
|
1856
|
+
return _callSuper$5(this, FlexiPoll, arguments);
|
|
2271
1857
|
}
|
|
2272
|
-
|
|
2273
|
-
return FlexiPoll;
|
|
1858
|
+
_inherits(FlexiPoll, _Regular);
|
|
1859
|
+
return _createClass(FlexiPoll);
|
|
2274
1860
|
}(Regular);
|
|
2275
|
-
|
|
2276
1861
|
_defineProperty(FlexiPoll, "TYPE", 'poll');
|
|
2277
|
-
|
|
2278
1862
|
_defineProperty(FlexiPoll, "STATE_STARTED", Regular.STATE_STARTED);
|
|
2279
|
-
|
|
2280
1863
|
_defineProperty(FlexiPoll, "STATE_CLOSED", Regular.STATE_CLOSED);
|
|
2281
|
-
|
|
2282
1864
|
_defineProperty(FlexiPoll, "ON_VOTE", Regular.ON_VOTE);
|
|
2283
|
-
|
|
2284
1865
|
_defineProperty(FlexiPoll, "ON_RESULTS", Regular.ON_RESULTS);
|
|
2285
|
-
|
|
2286
1866
|
_defineProperty(FlexiPoll, "ON_STATE_CHANGE", Regular.ON_STATE_CHANGE);
|
|
2287
1867
|
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
function _isNativeReflectConstruct$4() {
|
|
2291
|
-
|
|
1868
|
+
var _PollFactory;
|
|
1869
|
+
function _callSuper$4(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$4() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1870
|
+
function _isNativeReflectConstruct$4() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$4 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
1871
|
+
function _superPropGet$3(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
2292
1872
|
var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
2293
|
-
_inherits(PollFactory, _FrameFactory);
|
|
2294
|
-
|
|
2295
|
-
var _super = _createSuper$4(PollFactory);
|
|
2296
|
-
|
|
2297
1873
|
function PollFactory() {
|
|
2298
1874
|
var _this;
|
|
2299
|
-
|
|
2300
1875
|
_classCallCheck(this, PollFactory);
|
|
1876
|
+
_this = _callSuper$4(this, PollFactory);
|
|
2301
1877
|
|
|
2302
|
-
|
|
2303
|
-
|
|
1878
|
+
// a queue of messages on poll's channel
|
|
2304
1879
|
_this.messages = [];
|
|
2305
1880
|
return _this;
|
|
2306
1881
|
}
|
|
2307
|
-
|
|
2308
|
-
_createClass(PollFactory, [{
|
|
1882
|
+
_inherits(PollFactory, _FrameFactory);
|
|
1883
|
+
return _createClass(PollFactory, [{
|
|
2309
1884
|
key: "vote",
|
|
2310
1885
|
value: function vote(enmasseId, _vote) {
|
|
2311
1886
|
var poll = this.getByEnmasseId(enmasseId);
|
|
@@ -2316,53 +1891,49 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2316
1891
|
key: "processMessages",
|
|
2317
1892
|
value: function processMessages() {
|
|
2318
1893
|
var i = 0;
|
|
2319
|
-
var message;
|
|
1894
|
+
var message;
|
|
2320
1895
|
|
|
1896
|
+
// loop through the loop and process each item
|
|
2321
1897
|
while (i < this.messages.length) {
|
|
2322
|
-
message = this.messages[i];
|
|
1898
|
+
message = this.messages[i];
|
|
2323
1899
|
|
|
1900
|
+
// trying to find existent instance
|
|
2324
1901
|
var enmasseId = parseInt(message.body[0], 10);
|
|
2325
|
-
var poll = this.getByEnmasseId(enmasseId);
|
|
1902
|
+
var poll = this.getByEnmasseId(enmasseId);
|
|
2326
1903
|
|
|
1904
|
+
// if poll doesn't exist
|
|
2327
1905
|
if (!poll) {
|
|
2328
1906
|
i++;
|
|
2329
1907
|
continue;
|
|
2330
1908
|
}
|
|
1909
|
+
this.instances[poll.getId()]._channel = message.channel;
|
|
2331
1910
|
|
|
2332
|
-
|
|
2333
|
-
|
|
1911
|
+
// remove processed item from the queue
|
|
2334
1912
|
this.messages.splice(i, 1);
|
|
2335
|
-
|
|
2336
1913
|
switch (message.klass) {
|
|
2337
1914
|
case PollFactory.MSG_CLASS_POLL:
|
|
2338
1915
|
this.processPollMessage(poll, message);
|
|
2339
1916
|
break;
|
|
2340
|
-
|
|
2341
1917
|
case PollFactory.MSG_CLASS_FB:
|
|
2342
1918
|
this.processFeedbackMessage(poll, message);
|
|
2343
1919
|
break;
|
|
2344
|
-
|
|
2345
1920
|
case PollFactory.MSG_CLASS_STOP:
|
|
2346
1921
|
this.processStopMessage(poll, message);
|
|
2347
1922
|
break;
|
|
2348
|
-
|
|
2349
1923
|
case PollFactory.MSG_CLASS_REVEAL:
|
|
2350
1924
|
this.processRevealMessage(poll, message);
|
|
2351
1925
|
break;
|
|
2352
1926
|
}
|
|
2353
1927
|
}
|
|
2354
1928
|
}
|
|
2355
|
-
/* eslint-disable no-unused-vars */
|
|
2356
1929
|
|
|
1930
|
+
/* eslint-disable no-unused-vars */
|
|
2357
1931
|
}, {
|
|
2358
1932
|
key: "processPollMessage",
|
|
2359
|
-
value: function processPollMessage(poll
|
|
2360
|
-
/* , message */
|
|
2361
|
-
) {
|
|
1933
|
+
value: function processPollMessage(poll /* , message */) {
|
|
2362
1934
|
poll.finalize();
|
|
2363
1935
|
}
|
|
2364
1936
|
/* eslint-enable no-unused-vars */
|
|
2365
|
-
|
|
2366
1937
|
}, {
|
|
2367
1938
|
key: "processFeedbackMessage",
|
|
2368
1939
|
value: function processFeedbackMessage(poll, message) {
|
|
@@ -2372,8 +1943,9 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2372
1943
|
var sources = hasSource ? message.body[2].split(':') : [];
|
|
2373
1944
|
var counters = hasCounters ? message.body[3].split(':') : [];
|
|
2374
1945
|
var results = [];
|
|
2375
|
-
var resultsPerSource = [];
|
|
1946
|
+
var resultsPerSource = [];
|
|
2376
1947
|
|
|
1948
|
+
// converting counters to integer
|
|
2377
1949
|
counters = counters.map(function (counter) {
|
|
2378
1950
|
return +counter;
|
|
2379
1951
|
});
|
|
@@ -2382,7 +1954,6 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2382
1954
|
var idx = i % total;
|
|
2383
1955
|
results[idx] = +counter + (results[idx] || 0);
|
|
2384
1956
|
});
|
|
2385
|
-
|
|
2386
1957
|
for (var i = 0, l = sources.length / 2; i < l; i++) {
|
|
2387
1958
|
var total = counters.length / (sources.length / 2);
|
|
2388
1959
|
resultsPerSource.push({
|
|
@@ -2391,7 +1962,6 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2391
1962
|
results: counters.slice(total * i, total * i + total)
|
|
2392
1963
|
});
|
|
2393
1964
|
}
|
|
2394
|
-
|
|
2395
1965
|
if (results.length > 0 || isFinal) {
|
|
2396
1966
|
poll.setResultsPerSource(resultsPerSource);
|
|
2397
1967
|
poll.setResults(results);
|
|
@@ -2406,13 +1976,13 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2406
1976
|
key: "processRevealMessage",
|
|
2407
1977
|
value: function processRevealMessage(poll, message) {
|
|
2408
1978
|
poll.reveal(message.body[1] - 1);
|
|
2409
|
-
}
|
|
1979
|
+
}
|
|
2410
1980
|
|
|
1981
|
+
// TODO: combine create() and createSnapshot() methods
|
|
2411
1982
|
}, {
|
|
2412
1983
|
key: "create",
|
|
2413
1984
|
value: function create(data) {
|
|
2414
|
-
|
|
2415
|
-
|
|
1985
|
+
_superPropGet$3(PollFactory, "create", this, 3)([data]);
|
|
2416
1986
|
var Constructor = this.getConstructorByType(data.type);
|
|
2417
1987
|
var poll = new Constructor(data);
|
|
2418
1988
|
this.instances[data.id] = poll;
|
|
@@ -2423,8 +1993,7 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2423
1993
|
}, {
|
|
2424
1994
|
key: "createSnapshot",
|
|
2425
1995
|
value: function createSnapshot(data) {
|
|
2426
|
-
|
|
2427
|
-
|
|
1996
|
+
_superPropGet$3(PollFactory, "createSnapshot", this, 3)([data]);
|
|
2428
1997
|
var Constructor = this.getConstructorByType(data.type);
|
|
2429
1998
|
var poll = new Constructor(data);
|
|
2430
1999
|
this.instances[data.id] = poll;
|
|
@@ -2437,7 +2006,6 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2437
2006
|
if (PollFactory.MSG_CLASSES.indexOf(message.klass) === -1) {
|
|
2438
2007
|
return;
|
|
2439
2008
|
}
|
|
2440
|
-
|
|
2441
2009
|
this.messages.push(message);
|
|
2442
2010
|
this.processMessages();
|
|
2443
2011
|
}
|
|
@@ -2447,25 +2015,18 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2447
2015
|
switch (type) {
|
|
2448
2016
|
case Powerbar.TYPE:
|
|
2449
2017
|
return Powerbar;
|
|
2450
|
-
|
|
2451
2018
|
case Prediction.TYPE:
|
|
2452
2019
|
return Prediction;
|
|
2453
|
-
|
|
2454
2020
|
case Trivia.TYPE:
|
|
2455
2021
|
return Trivia;
|
|
2456
|
-
|
|
2457
2022
|
case Swing.TYPE:
|
|
2458
2023
|
return Swing;
|
|
2459
|
-
|
|
2460
2024
|
case Emoting.TYPE:
|
|
2461
2025
|
return Emoting;
|
|
2462
|
-
|
|
2463
2026
|
case Regular.TYPE:
|
|
2464
2027
|
return Regular;
|
|
2465
|
-
|
|
2466
2028
|
case FlexiPoll.TYPE:
|
|
2467
2029
|
return FlexiPoll;
|
|
2468
|
-
|
|
2469
2030
|
default:
|
|
2470
2031
|
return undefined;
|
|
2471
2032
|
}
|
|
@@ -2475,60 +2036,44 @@ var PollFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2475
2036
|
value: function handleVote(instance, vote) {
|
|
2476
2037
|
var idx;
|
|
2477
2038
|
var cast = [];
|
|
2478
|
-
|
|
2479
2039
|
switch (instance.getType()) {
|
|
2480
2040
|
case Regular.TYPE:
|
|
2481
2041
|
case FlexiPoll.TYPE:
|
|
2482
2042
|
case Prediction.TYPE:
|
|
2483
2043
|
case Trivia.TYPE:
|
|
2484
2044
|
break;
|
|
2485
|
-
|
|
2486
2045
|
default:
|
|
2487
2046
|
idx = vote;
|
|
2488
2047
|
vote = {};
|
|
2489
2048
|
vote[idx] = 1;
|
|
2490
2049
|
break;
|
|
2491
2050
|
}
|
|
2492
|
-
|
|
2493
2051
|
for (idx in vote) {
|
|
2494
2052
|
if ({}.hasOwnProperty.call(vote, idx)) {
|
|
2495
2053
|
cast = cast.concat([+idx + 1, vote[idx]]);
|
|
2496
2054
|
}
|
|
2497
2055
|
}
|
|
2498
|
-
|
|
2499
2056
|
this.vote(instance.getEnmasseId(), cast.join(':'));
|
|
2500
2057
|
}
|
|
2501
2058
|
}]);
|
|
2502
|
-
|
|
2503
|
-
return PollFactory;
|
|
2504
2059
|
}(FrameFactory);
|
|
2505
|
-
|
|
2060
|
+
_PollFactory = PollFactory;
|
|
2506
2061
|
_defineProperty(PollFactory, "MSG_CLASS_POLL", 'p');
|
|
2507
|
-
|
|
2508
2062
|
_defineProperty(PollFactory, "MSG_CLASS_FB", 'fb');
|
|
2509
|
-
|
|
2510
2063
|
_defineProperty(PollFactory, "MSG_CLASS_STOP", 'stop');
|
|
2511
|
-
|
|
2512
2064
|
_defineProperty(PollFactory, "MSG_CLASS_REVEAL", 'reveal');
|
|
2065
|
+
_defineProperty(PollFactory, "MSG_CLASSES", [_PollFactory.MSG_CLASS_POLL, _PollFactory.MSG_CLASS_FB, _PollFactory.MSG_CLASS_STOP, _PollFactory.MSG_CLASS_REVEAL]);
|
|
2513
2066
|
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
function
|
|
2517
|
-
|
|
2518
|
-
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2519
|
-
|
|
2067
|
+
function _callSuper$3(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$3() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2068
|
+
function _isNativeReflectConstruct$3() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$3 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2069
|
+
function _superPropGet$2(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
2520
2070
|
var Data = /*#__PURE__*/function (_Frame) {
|
|
2521
|
-
_inherits(Data, _Frame);
|
|
2522
|
-
|
|
2523
|
-
var _super = _createSuper$3(Data);
|
|
2524
|
-
|
|
2525
2071
|
function Data() {
|
|
2526
2072
|
_classCallCheck(this, Data);
|
|
2527
|
-
|
|
2528
|
-
return _super.apply(this, arguments);
|
|
2073
|
+
return _callSuper$3(this, Data, arguments);
|
|
2529
2074
|
}
|
|
2530
|
-
|
|
2531
|
-
_createClass(Data, [{
|
|
2075
|
+
_inherits(Data, _Frame);
|
|
2076
|
+
return _createClass(Data, [{
|
|
2532
2077
|
key: "getState",
|
|
2533
2078
|
value: function getState() {
|
|
2534
2079
|
return this.state;
|
|
@@ -2540,15 +2085,13 @@ var Data = /*#__PURE__*/function (_Frame) {
|
|
|
2540
2085
|
if (state === this.state) {
|
|
2541
2086
|
return;
|
|
2542
2087
|
}
|
|
2543
|
-
|
|
2544
2088
|
this.state = state;
|
|
2545
2089
|
this.trigger(Data.ON_STATE_CHANGE, state);
|
|
2546
2090
|
}
|
|
2547
2091
|
}, {
|
|
2548
2092
|
key: "updateDurationLeft",
|
|
2549
2093
|
value: function updateDurationLeft() {
|
|
2550
|
-
|
|
2551
|
-
|
|
2094
|
+
_superPropGet$2(Data, "updateDurationLeft", this, 3)([]);
|
|
2552
2095
|
if (this.durationLeft > 0) {
|
|
2553
2096
|
this.setState(Data.STATE_STARTED);
|
|
2554
2097
|
} else {
|
|
@@ -2559,48 +2102,32 @@ var Data = /*#__PURE__*/function (_Frame) {
|
|
|
2559
2102
|
key: "update",
|
|
2560
2103
|
value: function update() {
|
|
2561
2104
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2562
|
-
|
|
2563
|
-
_get(_getPrototypeOf(Data.prototype), "update", this).call(this, config);
|
|
2564
|
-
|
|
2105
|
+
_superPropGet$2(Data, "update", this, 3)([config]);
|
|
2565
2106
|
this.publishedAt = config.published_at - 0 || 0;
|
|
2566
|
-
|
|
2567
2107
|
if (this.fixed) {
|
|
2568
2108
|
this.updateDurationLeft();
|
|
2569
2109
|
}
|
|
2570
2110
|
}
|
|
2571
2111
|
}]);
|
|
2572
|
-
|
|
2573
|
-
return Data;
|
|
2574
2112
|
}(Frame);
|
|
2575
|
-
|
|
2576
2113
|
_defineProperty(Data, "TYPE", 'data');
|
|
2577
|
-
|
|
2578
2114
|
_defineProperty(Data, "STATE_STARTED", 'started');
|
|
2579
|
-
|
|
2580
2115
|
_defineProperty(Data, "STATE_CLOSED", 'closed');
|
|
2581
|
-
|
|
2582
2116
|
_defineProperty(Data, "ON_STATE_CHANGE", 'state');
|
|
2583
2117
|
|
|
2584
|
-
function
|
|
2585
|
-
|
|
2586
|
-
function
|
|
2587
|
-
|
|
2118
|
+
function _callSuper$2(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$2() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2119
|
+
function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2120
|
+
function _superPropGet$1(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
2588
2121
|
var DataFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
2589
|
-
_inherits(DataFactory, _FrameFactory);
|
|
2590
|
-
|
|
2591
|
-
var _super = _createSuper$2(DataFactory);
|
|
2592
|
-
|
|
2593
2122
|
function DataFactory() {
|
|
2594
2123
|
_classCallCheck(this, DataFactory);
|
|
2595
|
-
|
|
2596
|
-
return _super.apply(this, arguments);
|
|
2124
|
+
return _callSuper$2(this, DataFactory, arguments);
|
|
2597
2125
|
}
|
|
2598
|
-
|
|
2599
|
-
_createClass(DataFactory, [{
|
|
2126
|
+
_inherits(DataFactory, _FrameFactory);
|
|
2127
|
+
return _createClass(DataFactory, [{
|
|
2600
2128
|
key: "create",
|
|
2601
2129
|
value: function create(data) {
|
|
2602
|
-
|
|
2603
|
-
|
|
2130
|
+
_superPropGet$1(DataFactory, "create", this, 3)([data]);
|
|
2604
2131
|
var element = new Data(data);
|
|
2605
2132
|
element.finalize();
|
|
2606
2133
|
this.instances[data.id] = element;
|
|
@@ -2609,30 +2136,19 @@ var DataFactory = /*#__PURE__*/function (_FrameFactory) {
|
|
|
2609
2136
|
}, {
|
|
2610
2137
|
key: "createSnapshot",
|
|
2611
2138
|
value: function createSnapshot(data) {
|
|
2612
|
-
|
|
2613
|
-
|
|
2139
|
+
_superPropGet$1(DataFactory, "createSnapshot", this, 3)([data]);
|
|
2614
2140
|
return this.create(data);
|
|
2615
2141
|
}
|
|
2616
2142
|
}]);
|
|
2617
|
-
|
|
2618
|
-
return DataFactory;
|
|
2619
2143
|
}(FrameFactory);
|
|
2620
2144
|
|
|
2621
|
-
function
|
|
2622
|
-
|
|
2623
|
-
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2624
|
-
|
|
2145
|
+
function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2146
|
+
function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2625
2147
|
var Curation = /*#__PURE__*/function (_Entity) {
|
|
2626
|
-
_inherits(Curation, _Entity);
|
|
2627
|
-
|
|
2628
|
-
var _super = _createSuper$1(Curation);
|
|
2629
|
-
|
|
2630
2148
|
function Curation(config) {
|
|
2631
2149
|
var _this;
|
|
2632
|
-
|
|
2633
2150
|
_classCallCheck(this, Curation);
|
|
2634
|
-
|
|
2635
|
-
_this = _super.call(this, config);
|
|
2151
|
+
_this = _callSuper$1(this, Curation, [config]);
|
|
2636
2152
|
_this.text = config.data.text;
|
|
2637
2153
|
_this.sender = config.data.sender;
|
|
2638
2154
|
_this.senderName = config.data.sender_name;
|
|
@@ -2640,8 +2156,8 @@ var Curation = /*#__PURE__*/function (_Entity) {
|
|
|
2640
2156
|
_this.source = config.data.source;
|
|
2641
2157
|
return _this;
|
|
2642
2158
|
}
|
|
2643
|
-
|
|
2644
|
-
_createClass(Curation, [{
|
|
2159
|
+
_inherits(Curation, _Entity);
|
|
2160
|
+
return _createClass(Curation, [{
|
|
2645
2161
|
key: "getText",
|
|
2646
2162
|
value: function getText() {
|
|
2647
2163
|
return this.text;
|
|
@@ -2667,34 +2183,23 @@ var Curation = /*#__PURE__*/function (_Entity) {
|
|
|
2667
2183
|
return this.source;
|
|
2668
2184
|
}
|
|
2669
2185
|
}]);
|
|
2670
|
-
|
|
2671
|
-
return Curation;
|
|
2672
2186
|
}(Entity);
|
|
2673
|
-
|
|
2674
2187
|
_defineProperty(Curation, "TYPE", 'curation');
|
|
2675
|
-
|
|
2676
2188
|
_defineProperty(Curation, "SOURCE_TWITTER", 'twitter');
|
|
2677
2189
|
|
|
2678
|
-
function
|
|
2679
|
-
|
|
2680
|
-
function
|
|
2681
|
-
|
|
2190
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2191
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2192
|
+
function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
|
|
2682
2193
|
var CurationFactory = /*#__PURE__*/function (_BaseFactory) {
|
|
2683
|
-
_inherits(CurationFactory, _BaseFactory);
|
|
2684
|
-
|
|
2685
|
-
var _super = _createSuper(CurationFactory);
|
|
2686
|
-
|
|
2687
2194
|
function CurationFactory() {
|
|
2688
2195
|
_classCallCheck(this, CurationFactory);
|
|
2689
|
-
|
|
2690
|
-
return _super.apply(this, arguments);
|
|
2196
|
+
return _callSuper(this, CurationFactory, arguments);
|
|
2691
2197
|
}
|
|
2692
|
-
|
|
2693
|
-
_createClass(CurationFactory, [{
|
|
2198
|
+
_inherits(CurationFactory, _BaseFactory);
|
|
2199
|
+
return _createClass(CurationFactory, [{
|
|
2694
2200
|
key: "create",
|
|
2695
2201
|
value: function create(data) {
|
|
2696
|
-
|
|
2697
|
-
|
|
2202
|
+
_superPropGet(CurationFactory, "create", this, 3)([data]);
|
|
2698
2203
|
var curation = new Curation(data);
|
|
2699
2204
|
this.instances[data.id] = curation;
|
|
2700
2205
|
return curation;
|
|
@@ -2702,74 +2207,50 @@ var CurationFactory = /*#__PURE__*/function (_BaseFactory) {
|
|
|
2702
2207
|
}, {
|
|
2703
2208
|
key: "createSnapshot",
|
|
2704
2209
|
value: function createSnapshot(data) {
|
|
2705
|
-
|
|
2706
|
-
|
|
2210
|
+
_superPropGet(CurationFactory, "createSnapshot", this, 3)([data]);
|
|
2707
2211
|
return this.create(data);
|
|
2708
2212
|
}
|
|
2709
2213
|
}]);
|
|
2710
|
-
|
|
2711
|
-
return CurationFactory;
|
|
2712
2214
|
}(Base);
|
|
2713
2215
|
|
|
2714
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2715
|
-
|
|
2716
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
2717
|
-
|
|
2718
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
2719
2216
|
var Factories = (function () {
|
|
2720
2217
|
var self = {};
|
|
2721
2218
|
var channels = {};
|
|
2722
2219
|
var factories = [];
|
|
2723
|
-
var factoriesByChannel = {};
|
|
2220
|
+
var factoriesByChannel = {};
|
|
2724
2221
|
|
|
2222
|
+
// Hash of factories instances keyed on frame type.
|
|
2725
2223
|
self.items = {};
|
|
2726
|
-
|
|
2727
2224
|
var handleMessage = function handleMessage(msg) {
|
|
2728
2225
|
// console.log("Factories::handleMessage", msg);
|
|
2226
|
+
|
|
2729
2227
|
// get factory by channel id
|
|
2730
2228
|
var factory = getFactoryByChannel(msg.channel);
|
|
2731
|
-
|
|
2732
2229
|
if (factory !== null) {
|
|
2733
2230
|
factory.setMessage(msg);
|
|
2734
2231
|
}
|
|
2735
|
-
|
|
2736
2232
|
return null;
|
|
2737
2233
|
};
|
|
2738
|
-
|
|
2739
2234
|
var getFactoryByChannel = function getFactoryByChannel(channel) {
|
|
2740
2235
|
for (var key in channels) {
|
|
2741
2236
|
if ({}.hasOwnProperty.call(channels, key) && channels[key] === channel) {
|
|
2742
2237
|
return factoriesByChannel[key] || null;
|
|
2743
2238
|
}
|
|
2744
2239
|
}
|
|
2745
|
-
|
|
2746
2240
|
return null;
|
|
2747
2241
|
};
|
|
2748
|
-
|
|
2749
2242
|
self.destroyInstances = function () {
|
|
2750
|
-
var
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
try {
|
|
2754
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2755
|
-
var factory = _step.value;
|
|
2756
|
-
factory.destroyInstances();
|
|
2757
|
-
}
|
|
2758
|
-
} catch (err) {
|
|
2759
|
-
_iterator.e(err);
|
|
2760
|
-
} finally {
|
|
2761
|
-
_iterator.f();
|
|
2243
|
+
for (var _i = 0, _factories = factories; _i < _factories.length; _i++) {
|
|
2244
|
+
var factory = _factories[_i];
|
|
2245
|
+
factory.destroyInstances();
|
|
2762
2246
|
}
|
|
2763
2247
|
};
|
|
2764
|
-
|
|
2765
2248
|
self.setChannels = function (ch) {
|
|
2766
2249
|
channels = ch;
|
|
2767
2250
|
};
|
|
2768
|
-
|
|
2769
2251
|
self.get = function (type) {
|
|
2770
2252
|
return self.items[type];
|
|
2771
2253
|
};
|
|
2772
|
-
|
|
2773
2254
|
self.init = function () {
|
|
2774
2255
|
var data = [{
|
|
2775
2256
|
Constructor: PollFactory,
|
|
@@ -2787,68 +2268,58 @@ var Factories = (function () {
|
|
|
2787
2268
|
data.forEach(function (item) {
|
|
2788
2269
|
var factory = new item.Constructor();
|
|
2789
2270
|
factories.push(factory);
|
|
2790
|
-
|
|
2791
2271
|
if (item.channel !== null) {
|
|
2792
2272
|
factoriesByChannel[item.channel] = factory;
|
|
2793
2273
|
}
|
|
2794
|
-
|
|
2795
2274
|
item.types.forEach(function (type) {
|
|
2796
2275
|
self.items[type] = factory;
|
|
2797
2276
|
});
|
|
2798
2277
|
});
|
|
2799
2278
|
ConnectionAdaptor.bind(ConnectionAdaptor.ON_MESSAGE, handleMessage);
|
|
2800
2279
|
};
|
|
2801
|
-
|
|
2802
2280
|
return self;
|
|
2803
2281
|
})();
|
|
2804
2282
|
|
|
2283
|
+
// Listens on control channel for create and delete messages.
|
|
2805
2284
|
// Constructor takes main control channel id. No methods.
|
|
2806
|
-
|
|
2807
2285
|
function Control(config) {
|
|
2808
2286
|
config = config || {};
|
|
2809
2287
|
var self = this;
|
|
2810
2288
|
var _config = config,
|
|
2811
|
-
|
|
2289
|
+
channel = _config.channel;
|
|
2812
2290
|
this.trigger = this.emit;
|
|
2813
2291
|
this.bind = this.on;
|
|
2814
2292
|
this.unbind = this.off;
|
|
2815
|
-
|
|
2816
2293
|
var handleMessage = function handleMessage(message) {
|
|
2817
2294
|
// channel and type should match settings
|
|
2818
2295
|
if (message.channel !== channel) {
|
|
2819
2296
|
return;
|
|
2820
2297
|
}
|
|
2821
|
-
|
|
2822
2298
|
switch (message.klass) {
|
|
2823
2299
|
case Control.MSG_TYPE_CREATE:
|
|
2824
2300
|
handleMessageCreate(message);
|
|
2825
2301
|
break;
|
|
2826
|
-
|
|
2827
2302
|
case Control.MSG_TYPE_REVOKE:
|
|
2828
2303
|
handleMessageRevoke(message);
|
|
2829
2304
|
break;
|
|
2830
2305
|
}
|
|
2831
2306
|
};
|
|
2832
|
-
|
|
2833
2307
|
var handleEOC = function handleEOC(_channel) {
|
|
2834
2308
|
// channel and type should match settings
|
|
2835
2309
|
if (_channel !== channel) {
|
|
2836
2310
|
return;
|
|
2837
2311
|
}
|
|
2838
|
-
|
|
2839
2312
|
self.trigger(Control.MSG_TYPE_EOC);
|
|
2840
2313
|
};
|
|
2841
|
-
|
|
2842
2314
|
var handleMessageCreate = function handleMessageCreate(message) {
|
|
2843
2315
|
var data = JSON.parse(message.body[0]);
|
|
2844
2316
|
var factory = Factories.get(data.type);
|
|
2845
|
-
|
|
2846
2317
|
if (typeof factory === 'undefined') {
|
|
2847
2318
|
return;
|
|
2848
2319
|
}
|
|
2320
|
+
var instance = factory.get(data.id);
|
|
2849
2321
|
|
|
2850
|
-
|
|
2851
|
-
|
|
2322
|
+
// secure runtime against broken data
|
|
2852
2323
|
try {
|
|
2853
2324
|
if (instance) {
|
|
2854
2325
|
self.update(data);
|
|
@@ -2859,55 +2330,45 @@ function Control(config) {
|
|
|
2859
2330
|
console.error(e);
|
|
2860
2331
|
}
|
|
2861
2332
|
};
|
|
2862
|
-
|
|
2863
2333
|
var handleMessageRevoke = function handleMessageRevoke(message) {
|
|
2864
2334
|
var data = JSON.parse(message.body[0]);
|
|
2865
2335
|
self.revoke(data);
|
|
2866
2336
|
};
|
|
2867
|
-
|
|
2868
2337
|
self.create = function (data) {
|
|
2869
2338
|
var factory = Factories.get(data.type);
|
|
2870
|
-
var instance = factory.create(data);
|
|
2339
|
+
var instance = factory.create(data);
|
|
2871
2340
|
|
|
2341
|
+
// trigger MSG_TYPE_CREATE only if instance is finalized
|
|
2872
2342
|
Deferred.when(instance.finalized).done(function () {
|
|
2873
2343
|
self.trigger(Control.MSG_TYPE_CREATE, instance);
|
|
2874
2344
|
});
|
|
2875
2345
|
};
|
|
2876
|
-
|
|
2877
2346
|
self.update = function (data) {
|
|
2878
2347
|
var factory = Factories.get(data.type);
|
|
2879
2348
|
var instance = factory.get(data.id);
|
|
2880
2349
|
factory.update(instance, data);
|
|
2881
2350
|
self.trigger(Control.MSG_TYPE_UPDATE, instance);
|
|
2882
2351
|
};
|
|
2883
|
-
|
|
2884
2352
|
self.revoke = function (data) {
|
|
2885
2353
|
var factory = Factories.get(data.type);
|
|
2886
|
-
|
|
2887
2354
|
if (typeof factory === 'undefined') {
|
|
2888
2355
|
return;
|
|
2889
2356
|
}
|
|
2890
|
-
|
|
2891
2357
|
var instance = factory.get(data.id);
|
|
2892
|
-
|
|
2893
2358
|
if (!instance) {
|
|
2894
2359
|
return;
|
|
2895
2360
|
}
|
|
2896
|
-
|
|
2897
2361
|
factory.revoke(data.id);
|
|
2898
2362
|
self.trigger(Control.MSG_TYPE_REVOKE, instance);
|
|
2899
2363
|
};
|
|
2900
|
-
|
|
2901
2364
|
self.destroy = function () {
|
|
2902
2365
|
// destroy all elements instances
|
|
2903
2366
|
Factories.destroyInstances();
|
|
2904
2367
|
ConnectionAdaptor.unbind(ConnectionAdaptor.ON_MESSAGE, handleMessage);
|
|
2905
2368
|
};
|
|
2906
|
-
|
|
2907
2369
|
ConnectionAdaptor.bind(ConnectionAdaptor.ON_MESSAGE, handleMessage);
|
|
2908
2370
|
ConnectionAdaptor.bind(ConnectionAdaptor.ON_EOC, handleEOC);
|
|
2909
2371
|
}
|
|
2910
|
-
|
|
2911
2372
|
Control.prototype = assignIn(Control.prototype, new Emitter());
|
|
2912
2373
|
Control.MSG_TYPE_CREATE = 'create';
|
|
2913
2374
|
Control.MSG_TYPE_UPDATE = 'update';
|
|
@@ -2924,75 +2385,66 @@ var MIC_CONFIG_FILE = 'miccfg.json';
|
|
|
2924
2385
|
|
|
2925
2386
|
var Event = function Event(uuid) {
|
|
2926
2387
|
var _this = this;
|
|
2927
|
-
|
|
2928
2388
|
/*
|
|
2929
2389
|
* Settings
|
|
2930
2390
|
*/
|
|
2931
2391
|
uuid = uuid || null;
|
|
2392
|
+
|
|
2932
2393
|
/*
|
|
2933
2394
|
* Private properties
|
|
2934
2395
|
*/
|
|
2935
|
-
|
|
2936
2396
|
var self = this;
|
|
2937
2397
|
var state = Event.STATE_PENDING;
|
|
2938
2398
|
var data = {};
|
|
2939
2399
|
var history = []; // list of all past and current elements in this episode
|
|
2940
|
-
|
|
2941
2400
|
var control = null;
|
|
2942
2401
|
this.trigger = this.emit;
|
|
2943
2402
|
this.bind = this.on;
|
|
2944
2403
|
this.unbind = this.off;
|
|
2404
|
+
|
|
2945
2405
|
/*
|
|
2946
2406
|
* Public properties
|
|
2947
2407
|
*/
|
|
2948
|
-
|
|
2949
2408
|
self.ready = new Deferred();
|
|
2409
|
+
|
|
2950
2410
|
/*
|
|
2951
2411
|
* Private methods
|
|
2952
2412
|
*/
|
|
2953
2413
|
|
|
2954
|
-
var
|
|
2414
|
+
var _calculateState = function calculateState() {
|
|
2955
2415
|
var now = LViSDate.now();
|
|
2956
2416
|
var endAt = self.get('end_at');
|
|
2957
2417
|
var startAt = self.get('start_at');
|
|
2958
2418
|
var delay = self.get('__delay');
|
|
2959
2419
|
var extraTime = self.get('extra_time');
|
|
2960
|
-
|
|
2961
2420
|
var newState = function () {
|
|
2962
2421
|
if (isDataEmpty()) {
|
|
2963
|
-
return Event.STATE_PENDING;
|
|
2422
|
+
return Event.STATE_PENDING;
|
|
2423
|
+
// flag `started` is used to determine if event is manual,
|
|
2964
2424
|
// in this case start time is ahead of current timestamp
|
|
2965
2425
|
}
|
|
2966
|
-
|
|
2967
2426
|
if (!self.get('started') || now < startAt) {
|
|
2968
2427
|
return Event.STATE_UPCOMING;
|
|
2969
2428
|
}
|
|
2970
|
-
|
|
2971
2429
|
if (now < endAt) {
|
|
2972
2430
|
return Event.STATE_ACTIVE;
|
|
2973
2431
|
}
|
|
2974
|
-
|
|
2975
2432
|
if (now < endAt - delay + extraTime) {
|
|
2976
2433
|
return Event.STATE_PROLONGED;
|
|
2977
2434
|
}
|
|
2978
|
-
|
|
2979
2435
|
return Event.STATE_FINISHED;
|
|
2980
2436
|
}();
|
|
2981
|
-
|
|
2982
2437
|
if (newState !== state) {
|
|
2983
2438
|
setState(newState);
|
|
2984
2439
|
}
|
|
2985
|
-
|
|
2986
2440
|
Run.nextPriority(function () {
|
|
2987
|
-
return
|
|
2441
|
+
return _calculateState();
|
|
2988
2442
|
});
|
|
2989
2443
|
};
|
|
2990
|
-
|
|
2991
2444
|
var initControl = function initControl() {
|
|
2992
2445
|
if (control !== null) {
|
|
2993
2446
|
return;
|
|
2994
2447
|
}
|
|
2995
|
-
|
|
2996
2448
|
control = new Control({
|
|
2997
2449
|
channel: self.getChannels(CHANNEL_CONTROL)
|
|
2998
2450
|
});
|
|
@@ -3001,30 +2453,28 @@ var Event = function Event(uuid) {
|
|
|
3001
2453
|
control.bind(Control.MSG_TYPE_REVOKE, handleControlRevoke);
|
|
3002
2454
|
control.bind(Control.MSG_TYPE_EOC, handleControlEOC);
|
|
3003
2455
|
};
|
|
3004
|
-
|
|
3005
2456
|
var setState = function setState(newState) {
|
|
3006
2457
|
var oldState = self.getState();
|
|
3007
2458
|
state = newState;
|
|
3008
|
-
|
|
3009
2459
|
if (oldState !== self.getState()) {
|
|
3010
2460
|
self.trigger(Event.ON_STATE, self.getState());
|
|
3011
2461
|
}
|
|
3012
|
-
|
|
3013
2462
|
self.trigger(Event.ON_SUBSTATE, self.getSubstate());
|
|
3014
2463
|
};
|
|
3015
|
-
|
|
3016
2464
|
var processHistory = function processHistory(_ref) {
|
|
3017
2465
|
var timeline = _ref.timeline,
|
|
3018
|
-
|
|
2466
|
+
config = _ref.config;
|
|
3019
2467
|
var snapshots = timeline.map(function (item) {
|
|
3020
2468
|
return item;
|
|
3021
2469
|
});
|
|
3022
|
-
snapshots.forEach(ConnectionAdaptor.adaptSnapshotData);
|
|
2470
|
+
snapshots.forEach(ConnectionAdaptor.adaptSnapshotData);
|
|
2471
|
+
|
|
2472
|
+
// elements to revoke
|
|
3023
2473
|
//
|
|
3024
2474
|
// skipping this phase as `/revoke` message is preserved on enmasse
|
|
3025
2475
|
// channels until the end of an event
|
|
3026
|
-
// elements to create
|
|
3027
2476
|
|
|
2477
|
+
// elements to create
|
|
3028
2478
|
snapshots.filter(function (snapshot) {
|
|
3029
2479
|
return !getElementFromHistory(snapshot.id);
|
|
3030
2480
|
}).map(function (snapshot) {
|
|
@@ -3040,55 +2490,50 @@ var Event = function Event(uuid) {
|
|
|
3040
2490
|
factory.update(element, snapshot);
|
|
3041
2491
|
return element;
|
|
3042
2492
|
}).forEach(handleControlUpdate);
|
|
3043
|
-
|
|
3044
2493
|
if (isDataEmpty()) {
|
|
3045
2494
|
ConnectionAdaptor.adaptEvent(config);
|
|
3046
2495
|
self.setData(config);
|
|
3047
2496
|
}
|
|
3048
2497
|
};
|
|
3049
|
-
|
|
3050
2498
|
var isDataEmpty = function isDataEmpty() {
|
|
3051
2499
|
if (!data || _typeof(data) !== 'object' || Array.isArray(data)) {
|
|
3052
2500
|
return false;
|
|
3053
2501
|
}
|
|
3054
|
-
|
|
3055
2502
|
return !Object.keys(data).length;
|
|
3056
2503
|
};
|
|
3057
|
-
|
|
3058
2504
|
var isReady = function isReady() {
|
|
3059
2505
|
return self.ready.state() === 'resolved';
|
|
3060
2506
|
};
|
|
3061
|
-
|
|
3062
2507
|
var isElementInHistory = function isElementInHistory(element) {
|
|
3063
2508
|
return history.some(function (historyElement) {
|
|
3064
2509
|
return historyElement.getId() === element.getId();
|
|
3065
2510
|
});
|
|
3066
2511
|
};
|
|
3067
|
-
|
|
3068
2512
|
var canLoadHistory = function canLoadHistory() {
|
|
3069
2513
|
// time to ignore history loading
|
|
3070
|
-
var ignore = parseInt(Project.get('history_ignore'), 10) || 60;
|
|
2514
|
+
var ignore = parseInt(Project.get('history_ignore'), 10) || 60;
|
|
3071
2515
|
|
|
3072
|
-
|
|
2516
|
+
// delay at the moment of time when event's data were adapted
|
|
2517
|
+
var delay = self.get('__delay');
|
|
3073
2518
|
|
|
3074
|
-
|
|
2519
|
+
// even'ts start time (including delay)
|
|
2520
|
+
var start = self.get('start_at');
|
|
3075
2521
|
|
|
2522
|
+
// do not load history if now before this time
|
|
3076
2523
|
var threshold = start - delay + ignore;
|
|
3077
2524
|
return self.isPending() || LViSDate.now() > threshold;
|
|
3078
2525
|
};
|
|
3079
|
-
|
|
3080
2526
|
var addElementToHistory = function addElementToHistory(element) {
|
|
3081
2527
|
if (isElementInHistory(element)) {
|
|
3082
2528
|
return;
|
|
3083
|
-
}
|
|
3084
|
-
|
|
2529
|
+
}
|
|
3085
2530
|
|
|
2531
|
+
// sort by published at and id
|
|
3086
2532
|
for (var i = history.length - 1; i >= 0; i--) {
|
|
3087
2533
|
if (history[i].publishedAt < element.publishedAt) {
|
|
3088
2534
|
history.splice(i + 1, 0, element);
|
|
3089
2535
|
return;
|
|
3090
2536
|
}
|
|
3091
|
-
|
|
3092
2537
|
if (history[i].publishedAt === element.publishedAt) {
|
|
3093
2538
|
if (history[i].id < element.id) {
|
|
3094
2539
|
history.splice(i + 1, 0, element);
|
|
@@ -3096,162 +2541,130 @@ var Event = function Event(uuid) {
|
|
|
3096
2541
|
}
|
|
3097
2542
|
}
|
|
3098
2543
|
}
|
|
3099
|
-
|
|
3100
2544
|
history.unshift(element);
|
|
3101
2545
|
};
|
|
3102
|
-
|
|
3103
2546
|
var getElementFromHistory = function getElementFromHistory(id) {
|
|
3104
2547
|
return history.find(function (element) {
|
|
3105
2548
|
return element.getId() === id;
|
|
3106
2549
|
});
|
|
3107
2550
|
};
|
|
3108
|
-
|
|
3109
2551
|
var removeElementFromHistory = function removeElementFromHistory(element) {
|
|
3110
2552
|
var index = history.indexOf(element);
|
|
3111
|
-
|
|
3112
2553
|
if (index > -1) {
|
|
3113
2554
|
history.splice(index, 1);
|
|
3114
2555
|
}
|
|
3115
2556
|
};
|
|
3116
|
-
|
|
3117
2557
|
var sortElementsInHistory = function sortElementsInHistory() {
|
|
3118
2558
|
history.sort(function (a, b) {
|
|
3119
2559
|
return a.getPublishedAt() - b.getPublishedAt();
|
|
3120
2560
|
});
|
|
3121
2561
|
};
|
|
3122
|
-
|
|
3123
2562
|
var handleControlCreate = function handleControlCreate(instance) {
|
|
3124
2563
|
addElementToHistory(instance);
|
|
3125
|
-
|
|
3126
2564
|
if (isReady()) {
|
|
3127
2565
|
self.trigger(Event.ON_ELEMENT_PUBLISH, instance);
|
|
3128
2566
|
}
|
|
3129
2567
|
};
|
|
3130
|
-
|
|
3131
2568
|
var handleControlUpdate = function handleControlUpdate(instance) {
|
|
3132
2569
|
sortElementsInHistory();
|
|
3133
|
-
|
|
3134
2570
|
if (isReady()) {
|
|
3135
2571
|
self.trigger(Event.ON_ELEMENT_UPDATE, instance);
|
|
3136
2572
|
}
|
|
3137
2573
|
};
|
|
3138
|
-
|
|
3139
2574
|
var handleControlRevoke = function handleControlRevoke(instance) {
|
|
3140
2575
|
removeElementFromHistory(instance);
|
|
3141
|
-
|
|
3142
2576
|
if (isReady()) {
|
|
3143
2577
|
self.trigger(Event.ON_ELEMENT_REVOKE, instance);
|
|
3144
2578
|
}
|
|
3145
2579
|
};
|
|
3146
|
-
|
|
3147
2580
|
var handleControlEOC = function handleControlEOC() {
|
|
3148
2581
|
self.trigger(Event.ON_EOC);
|
|
3149
2582
|
};
|
|
2583
|
+
|
|
3150
2584
|
/*
|
|
3151
2585
|
* Getters
|
|
3152
2586
|
*/
|
|
3153
2587
|
|
|
3154
|
-
|
|
3155
2588
|
this.get = function (param) {
|
|
3156
2589
|
if (typeof param === 'undefined') {
|
|
3157
2590
|
// return full dataset if parameter is not set
|
|
3158
2591
|
return data;
|
|
3159
2592
|
}
|
|
3160
|
-
|
|
3161
2593
|
if (typeof data[param] !== 'undefined') {
|
|
3162
2594
|
// return value that matches passed parameter in dataset
|
|
3163
2595
|
return data[param];
|
|
3164
2596
|
}
|
|
3165
|
-
|
|
3166
2597
|
return null;
|
|
3167
2598
|
};
|
|
3168
|
-
|
|
3169
2599
|
this.getUUID = function () {
|
|
3170
2600
|
return uuid;
|
|
3171
2601
|
};
|
|
3172
|
-
|
|
3173
2602
|
this.getChannels = function (type) {
|
|
3174
2603
|
var channelId = function channelId(t) {
|
|
3175
2604
|
return "".concat(t, "-").concat(uuid);
|
|
3176
2605
|
};
|
|
3177
|
-
|
|
3178
2606
|
if (typeof type === 'undefined') {
|
|
3179
2607
|
return {
|
|
3180
2608
|
poll: channelId(CHANNEL_POLL),
|
|
3181
2609
|
control: channelId(CHANNEL_CONTROL)
|
|
3182
2610
|
};
|
|
3183
2611
|
}
|
|
3184
|
-
|
|
3185
2612
|
if (type === CHANNEL_POLL || type === CHANNEL_CONTROL) {
|
|
3186
2613
|
return channelId(type);
|
|
3187
2614
|
}
|
|
3188
|
-
|
|
3189
2615
|
throw new Error("Unknown channel type ".concat(type));
|
|
3190
2616
|
};
|
|
3191
|
-
|
|
3192
2617
|
this.getName = function () {
|
|
3193
2618
|
return _this.get('name');
|
|
3194
2619
|
};
|
|
3195
|
-
|
|
3196
2620
|
this.getStartAt = function () {
|
|
3197
2621
|
return _this.get('start_at');
|
|
3198
2622
|
};
|
|
3199
|
-
|
|
3200
2623
|
this.getOriginalStartAt = function () {
|
|
3201
2624
|
var startAt = _this.getStartAt();
|
|
3202
|
-
|
|
3203
2625
|
if (startAt === null) {
|
|
3204
2626
|
return null;
|
|
3205
2627
|
}
|
|
3206
|
-
|
|
3207
2628
|
return startAt - data.__delay;
|
|
3208
2629
|
};
|
|
3209
|
-
|
|
3210
2630
|
this.getEndAt = function () {
|
|
3211
2631
|
return _this.get('end_at');
|
|
3212
2632
|
};
|
|
3213
|
-
|
|
3214
2633
|
this.getState = function () {
|
|
3215
2634
|
switch (state) {
|
|
3216
2635
|
case Event.STATE_PROLONGED:
|
|
3217
2636
|
return Event.STATE_FINISHED;
|
|
3218
|
-
|
|
3219
2637
|
default:
|
|
3220
2638
|
return state;
|
|
3221
2639
|
}
|
|
3222
2640
|
};
|
|
3223
|
-
|
|
3224
2641
|
this.getSubstate = function () {
|
|
3225
2642
|
return state;
|
|
3226
2643
|
};
|
|
3227
|
-
|
|
3228
2644
|
this.getCustomFields = function (field) {
|
|
3229
2645
|
var fields = _this.get('custom_fields');
|
|
3230
|
-
|
|
3231
2646
|
if (fields === null) {
|
|
3232
2647
|
return null;
|
|
3233
2648
|
}
|
|
3234
|
-
|
|
3235
2649
|
var values = Project.localise(fields);
|
|
3236
|
-
|
|
3237
2650
|
if (typeof field === 'undefined') {
|
|
3238
2651
|
// return full set of custom fields if field name wasn't passed
|
|
3239
2652
|
return values;
|
|
3240
|
-
}
|
|
3241
|
-
|
|
2653
|
+
}
|
|
3242
2654
|
|
|
2655
|
+
// custom field was passed
|
|
3243
2656
|
if (typeof values[field] !== 'undefined') {
|
|
3244
2657
|
// return specific field if field exists in object
|
|
3245
2658
|
return values[field];
|
|
3246
|
-
}
|
|
3247
|
-
|
|
2659
|
+
}
|
|
3248
2660
|
|
|
2661
|
+
// otherwise return null
|
|
3249
2662
|
return null;
|
|
3250
2663
|
};
|
|
3251
|
-
|
|
3252
2664
|
this.getCountdown = function (format) {
|
|
3253
|
-
format = format || TIME_FORMAT_SECONDS;
|
|
2665
|
+
format = format || TIME_FORMAT_SECONDS;
|
|
3254
2666
|
|
|
2667
|
+
// countdown values
|
|
3255
2668
|
var countdown = {
|
|
3256
2669
|
years: 0,
|
|
3257
2670
|
months: 0,
|
|
@@ -3261,18 +2674,17 @@ var Event = function Event(uuid) {
|
|
|
3261
2674
|
seconds: 0
|
|
3262
2675
|
};
|
|
3263
2676
|
var diffSeconds = _this.get('start_at') - LViSDate.now();
|
|
3264
|
-
|
|
3265
2677
|
if (diffSeconds < 0) {
|
|
3266
2678
|
diffSeconds = 0;
|
|
3267
2679
|
}
|
|
3268
|
-
|
|
3269
2680
|
if (format === TIME_FORMAT_SECONDS) {
|
|
3270
2681
|
return diffSeconds;
|
|
3271
|
-
}
|
|
3272
|
-
|
|
2682
|
+
}
|
|
3273
2683
|
|
|
3274
|
-
|
|
2684
|
+
// calculate difference between event start at and now dates relatively to the Unix Epoch time
|
|
2685
|
+
var diff = new Date(diffSeconds * 1000);
|
|
3275
2686
|
|
|
2687
|
+
// methods to be casted on diff date
|
|
3276
2688
|
var methods = {
|
|
3277
2689
|
years: 'getUTCFullYear',
|
|
3278
2690
|
months: 'getUTCMonth',
|
|
@@ -3282,104 +2694,80 @@ var Event = function Event(uuid) {
|
|
|
3282
2694
|
seconds: 'getUTCSeconds'
|
|
3283
2695
|
};
|
|
3284
2696
|
var value;
|
|
3285
|
-
|
|
3286
2697
|
for (var _i = 0, _Object$entries = Object.entries(methods); _i < _Object$entries.length; _i++) {
|
|
3287
2698
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
2699
|
+
key = _Object$entries$_i[0],
|
|
2700
|
+
method = _Object$entries$_i[1];
|
|
3291
2701
|
value = diff[method]();
|
|
3292
|
-
|
|
3293
2702
|
switch (method) {
|
|
3294
2703
|
case 'getUTCDate':
|
|
3295
2704
|
value--; // date starts with 1 not 0
|
|
3296
|
-
|
|
3297
2705
|
break;
|
|
3298
|
-
|
|
3299
2706
|
case 'getUTCFullYear':
|
|
3300
2707
|
value -= 1970; // year when Unix Epoch started
|
|
3301
|
-
|
|
3302
2708
|
break;
|
|
3303
2709
|
}
|
|
3304
|
-
|
|
3305
2710
|
countdown[key] = value;
|
|
3306
2711
|
}
|
|
3307
|
-
|
|
3308
2712
|
switch (format) {
|
|
3309
2713
|
case TIME_FORMAT_OBJECT:
|
|
3310
2714
|
return countdown;
|
|
3311
|
-
|
|
3312
2715
|
case TIME_FORMAT_ARRAY:
|
|
3313
2716
|
return [countdown.seconds, countdown.minutes, countdown.hours, countdown.days, countdown.months, countdown.years];
|
|
3314
|
-
|
|
3315
2717
|
default:
|
|
3316
2718
|
// undefined format?
|
|
3317
2719
|
return null;
|
|
3318
2720
|
}
|
|
3319
2721
|
};
|
|
3320
|
-
|
|
3321
2722
|
this.getHistory = function () {
|
|
3322
2723
|
return history;
|
|
3323
2724
|
};
|
|
3324
|
-
|
|
3325
2725
|
this.getLastFromHistory = function () {
|
|
3326
2726
|
if (history.length > 0) {
|
|
3327
2727
|
return history[history.length - 1];
|
|
3328
2728
|
}
|
|
3329
|
-
|
|
3330
2729
|
return null;
|
|
3331
2730
|
};
|
|
2731
|
+
|
|
3332
2732
|
/*
|
|
3333
2733
|
* Public methods
|
|
3334
2734
|
*/
|
|
3335
2735
|
|
|
3336
|
-
|
|
3337
2736
|
this.setData = function (newData) {
|
|
3338
2737
|
var oldDigest = data.digest;
|
|
3339
2738
|
var oldDelay = data.__delay;
|
|
3340
2739
|
data = newData || {};
|
|
3341
|
-
|
|
3342
2740
|
if (oldDigest !== newData.digest || oldDelay !== newData.__delay) {
|
|
3343
2741
|
self.trigger(Event.ON_UPDATE);
|
|
3344
2742
|
}
|
|
3345
|
-
|
|
3346
|
-
calculateState();
|
|
2743
|
+
_calculateState();
|
|
3347
2744
|
};
|
|
3348
|
-
|
|
3349
2745
|
this.isPending = function () {
|
|
3350
2746
|
return state === Event.STATE_PENDING;
|
|
3351
2747
|
};
|
|
3352
|
-
|
|
3353
2748
|
this.isReady = function () {
|
|
3354
2749
|
return isReady();
|
|
3355
2750
|
};
|
|
3356
|
-
|
|
3357
2751
|
this.addDemographicsCounter = function (segmentName, segmentValue, counter, round, min, max) {
|
|
3358
2752
|
if (_this.isPending()) {
|
|
3359
2753
|
console.error("Can't add demographics counter while event is in the pending state.");
|
|
3360
2754
|
return;
|
|
3361
2755
|
}
|
|
3362
|
-
|
|
3363
2756
|
var channel = _this.getChannels(CHANNEL_CONTROL);
|
|
3364
|
-
|
|
3365
2757
|
var segment = [segmentName, segmentValue];
|
|
3366
2758
|
Enmasse.Demographics.addCounter(channel, uuid, segment, counter, round, min, max);
|
|
3367
2759
|
};
|
|
3368
|
-
|
|
3369
2760
|
this.markAsReady = function () {
|
|
3370
2761
|
if (isReady()) {
|
|
3371
2762
|
return;
|
|
3372
2763
|
}
|
|
3373
|
-
|
|
3374
2764
|
self.ready.resolve();
|
|
3375
2765
|
self.trigger(Event.ON_READY);
|
|
3376
2766
|
};
|
|
3377
|
-
|
|
3378
2767
|
this.markAsNotReady = function () {
|
|
3379
2768
|
if (!isReady()) {
|
|
3380
2769
|
return;
|
|
3381
2770
|
}
|
|
3382
|
-
|
|
3383
2771
|
history.map(function (element) {
|
|
3384
2772
|
return {
|
|
3385
2773
|
id: element.getId(),
|
|
@@ -3391,6 +2779,7 @@ var Event = function Event(uuid) {
|
|
|
3391
2779
|
self.ready = new Deferred();
|
|
3392
2780
|
self.trigger(Event.ON_NOT_READY);
|
|
3393
2781
|
};
|
|
2782
|
+
|
|
3394
2783
|
/**
|
|
3395
2784
|
* Loads event's history from CDN
|
|
3396
2785
|
*
|
|
@@ -3400,11 +2789,8 @@ var Event = function Event(uuid) {
|
|
|
3400
2789
|
* @param {boolean} [reconnect=false] Indicates that history is loading on reconnect
|
|
3401
2790
|
* @return {deferred} of ajax request
|
|
3402
2791
|
*/
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
2792
|
this.loadHistory = function (host, reconnect) {
|
|
3406
2793
|
var deferred = new Deferred();
|
|
3407
|
-
|
|
3408
2794
|
var success = function success(historyData) {
|
|
3409
2795
|
try {
|
|
3410
2796
|
// secure code against the bad data
|
|
@@ -3412,18 +2798,14 @@ var Event = function Event(uuid) {
|
|
|
3412
2798
|
} catch (exception) {
|
|
3413
2799
|
console.error(exception);
|
|
3414
2800
|
}
|
|
3415
|
-
|
|
3416
2801
|
deferred.resolve();
|
|
3417
2802
|
};
|
|
3418
|
-
|
|
3419
2803
|
var error = function error() {
|
|
3420
2804
|
if (self.isPending()) {
|
|
3421
2805
|
setState(Event.STATE_FAILURE);
|
|
3422
2806
|
}
|
|
3423
|
-
|
|
3424
2807
|
deferred.reject();
|
|
3425
2808
|
};
|
|
3426
|
-
|
|
3427
2809
|
if (canLoadHistory()) {
|
|
3428
2810
|
var url = "".concat(host, "/events/").concat(uuid.substr(0, 2), "/").concat(uuid, "/history.json");
|
|
3429
2811
|
xhr.get(url, {
|
|
@@ -3433,13 +2815,13 @@ var Event = function Event(uuid) {
|
|
|
3433
2815
|
var status = resp.statusCode;
|
|
3434
2816
|
var isSuccess = status >= 200 && status <= 300 || status === 0 || status === '';
|
|
3435
2817
|
var hasTimeline = {}.hasOwnProperty.call(historyData, 'timeline');
|
|
3436
|
-
var hasConfig = {}.hasOwnProperty.call(historyData, 'config');
|
|
3437
|
-
// history is loaded. Not applicable on reconnect.
|
|
2818
|
+
var hasConfig = {}.hasOwnProperty.call(historyData, 'config');
|
|
3438
2819
|
|
|
2820
|
+
// Assert on race condition when the event becomes ready before
|
|
2821
|
+
// history is loaded. Not applicable on reconnect.
|
|
3439
2822
|
if (isReady() && !reconnect) {
|
|
3440
2823
|
console.warn('Event is ready before history is loaded');
|
|
3441
2824
|
}
|
|
3442
|
-
|
|
3443
2825
|
if (isSuccess && hasTimeline && hasConfig) {
|
|
3444
2826
|
success(historyData);
|
|
3445
2827
|
} else {
|
|
@@ -3449,14 +2831,11 @@ var Event = function Event(uuid) {
|
|
|
3449
2831
|
} else {
|
|
3450
2832
|
deferred.resolve();
|
|
3451
2833
|
}
|
|
3452
|
-
|
|
3453
2834
|
return deferred;
|
|
3454
2835
|
};
|
|
3455
|
-
|
|
3456
|
-
calculateState();
|
|
2836
|
+
_calculateState();
|
|
3457
2837
|
initControl();
|
|
3458
2838
|
};
|
|
3459
|
-
|
|
3460
2839
|
Event.prototype = assignIn(Event.prototype, new Emitter());
|
|
3461
2840
|
Event.ON_READY = 'ready';
|
|
3462
2841
|
Event.ON_NOT_READY = 'not-ready';
|
|
@@ -3472,27 +2851,28 @@ Event.STATE_PENDING = 'pending';
|
|
|
3472
2851
|
Event.STATE_UPCOMING = 'upcoming';
|
|
3473
2852
|
Event.STATE_ACTIVE = 'active';
|
|
3474
2853
|
Event.STATE_PROLONGED = 'prolonged'; // substate of STATE_FINISHED
|
|
3475
|
-
|
|
3476
2854
|
Event.STATE_FINISHED = 'finished';
|
|
3477
2855
|
Event.HISTORY_LOCALISATION = 1;
|
|
3478
2856
|
Event.HISTORY_VERSIONS = {
|
|
3479
2857
|
2: Event.HISTORY_LOCALISATION
|
|
3480
2858
|
};
|
|
3481
2859
|
|
|
2860
|
+
// properties
|
|
3482
2861
|
var channel$1 = null;
|
|
3483
2862
|
var events = [];
|
|
3484
2863
|
var assets = {};
|
|
3485
2864
|
var instances = {}; // cache of instances
|
|
3486
|
-
|
|
3487
2865
|
var ready = false;
|
|
3488
2866
|
var Listings = new Emitter();
|
|
3489
2867
|
Listings.trigger = Listings.emit;
|
|
3490
2868
|
Listings.bind = Listings.on;
|
|
3491
|
-
Listings.unbind = Listings.off;
|
|
2869
|
+
Listings.unbind = Listings.off;
|
|
3492
2870
|
|
|
2871
|
+
// constants
|
|
3493
2872
|
Listings.ON_READY = 'ready';
|
|
3494
2873
|
Listings.ON_UPDATE = 'update';
|
|
3495
2874
|
Listings.MSG_CLASS = 'listings';
|
|
2875
|
+
|
|
3496
2876
|
/*
|
|
3497
2877
|
* Private methods
|
|
3498
2878
|
*/
|
|
@@ -3502,7 +2882,6 @@ var handleMessage = function handleMessage(msg) {
|
|
|
3502
2882
|
if (msg.channel !== channel$1) {
|
|
3503
2883
|
return;
|
|
3504
2884
|
}
|
|
3505
|
-
|
|
3506
2885
|
switch (msg.klass) {
|
|
3507
2886
|
case Listings.MSG_CLASS:
|
|
3508
2887
|
{
|
|
@@ -3512,53 +2891,50 @@ var handleMessage = function handleMessage(msg) {
|
|
|
3512
2891
|
}
|
|
3513
2892
|
}
|
|
3514
2893
|
};
|
|
3515
|
-
|
|
3516
2894
|
var handleEOC = function handleEOC(_channel) {
|
|
3517
2895
|
if (_channel !== channel$1) {
|
|
3518
2896
|
return;
|
|
3519
|
-
}
|
|
3520
|
-
|
|
2897
|
+
}
|
|
3521
2898
|
|
|
2899
|
+
// do not expose ON_READY event if listings were initialised already
|
|
3522
2900
|
if (!ready) {
|
|
3523
2901
|
ready = true;
|
|
3524
2902
|
Listings.trigger(Listings.ON_READY);
|
|
3525
2903
|
}
|
|
3526
2904
|
};
|
|
3527
|
-
|
|
3528
2905
|
var findById = function findById(collection, id) {
|
|
3529
2906
|
for (var i = 0, l = collection.length; i < l; i++) {
|
|
3530
2907
|
if (collection[i].id === id) {
|
|
3531
2908
|
return collection[i];
|
|
3532
2909
|
}
|
|
3533
2910
|
}
|
|
3534
|
-
|
|
3535
2911
|
return null;
|
|
3536
|
-
};
|
|
3537
|
-
|
|
2912
|
+
};
|
|
3538
2913
|
|
|
2914
|
+
// check if there are any changes in listings data
|
|
3539
2915
|
var haveChanged = function haveChanged(data) {
|
|
3540
2916
|
var i;
|
|
3541
2917
|
var l;
|
|
3542
|
-
var event;
|
|
2918
|
+
var event;
|
|
3543
2919
|
|
|
2920
|
+
// iterate over came events data
|
|
3544
2921
|
for (i = 0, l = data.events.length; i < l; i++) {
|
|
3545
|
-
event = findById(events, data.events[i].id);
|
|
2922
|
+
event = findById(events, data.events[i].id);
|
|
3546
2923
|
|
|
2924
|
+
// new episode OR digest of the existant event has changed
|
|
3547
2925
|
if (event === null || event.digest !== data.events[i].digest) {
|
|
3548
2926
|
return true;
|
|
3549
2927
|
}
|
|
3550
|
-
}
|
|
3551
|
-
|
|
2928
|
+
}
|
|
3552
2929
|
|
|
2930
|
+
// check if event was removed
|
|
3553
2931
|
for (i = 0, l = events.length; i < l; i++) {
|
|
3554
2932
|
if (findById(data.events, events[i].id) === null) {
|
|
3555
2933
|
return true;
|
|
3556
2934
|
}
|
|
3557
2935
|
}
|
|
3558
|
-
|
|
3559
2936
|
return false;
|
|
3560
2937
|
};
|
|
3561
|
-
|
|
3562
2938
|
var handleData = function handleData(data) {
|
|
3563
2939
|
var isChanges = ready && haveChanged(data);
|
|
3564
2940
|
events = data.events;
|
|
@@ -3566,170 +2942,153 @@ var handleData = function handleData(data) {
|
|
|
3566
2942
|
if (a.start_at < b.start_at) {
|
|
3567
2943
|
return -1;
|
|
3568
2944
|
}
|
|
3569
|
-
|
|
3570
2945
|
if (a.start_at > b.start_at) {
|
|
3571
2946
|
return 1;
|
|
3572
2947
|
}
|
|
3573
|
-
|
|
3574
2948
|
return 0;
|
|
3575
|
-
});
|
|
2949
|
+
});
|
|
3576
2950
|
|
|
2951
|
+
// populate project object with the data
|
|
3577
2952
|
Project.setData(data.project);
|
|
3578
|
-
|
|
3579
2953
|
if (!ready) {
|
|
3580
2954
|
// load assets only once
|
|
3581
2955
|
// and cache them permanently
|
|
3582
2956
|
assets = data.assets;
|
|
3583
|
-
}
|
|
3584
|
-
|
|
2957
|
+
}
|
|
3585
2958
|
|
|
2959
|
+
// update instances
|
|
3586
2960
|
for (var i = 0, l = events.length; i < l; i++) {
|
|
3587
2961
|
var event = events[i];
|
|
3588
|
-
|
|
3589
2962
|
if (instances[event.id]) {
|
|
3590
2963
|
instances[event.id].setData(event);
|
|
3591
2964
|
}
|
|
3592
2965
|
}
|
|
3593
|
-
|
|
3594
2966
|
if (isChanges) {
|
|
3595
2967
|
Listings.trigger(Listings.ON_UPDATE);
|
|
3596
2968
|
}
|
|
3597
2969
|
};
|
|
2970
|
+
|
|
3598
2971
|
/*
|
|
3599
2972
|
* Public methods
|
|
3600
2973
|
*/
|
|
3601
|
-
// returns object of the LViS event by Id
|
|
3602
|
-
|
|
3603
2974
|
|
|
2975
|
+
// returns object of the LViS event by Id
|
|
3604
2976
|
Listings.get = function (id) {
|
|
3605
2977
|
// lazy return if instance already exists
|
|
3606
2978
|
if (typeof instances[id] !== 'undefined') {
|
|
3607
2979
|
return instances[id];
|
|
3608
2980
|
}
|
|
3609
|
-
|
|
3610
2981
|
var data = findById(events, id);
|
|
3611
|
-
var event = new Event(id);
|
|
3612
|
-
// Setting data from listings if data exists
|
|
2982
|
+
var event = new Event(id);
|
|
3613
2983
|
|
|
2984
|
+
// Data from Enmasse has priority over data from CDN
|
|
2985
|
+
// Setting data from listings if data exists
|
|
3614
2986
|
if (data) {
|
|
3615
2987
|
event.setData(data);
|
|
3616
2988
|
}
|
|
3617
|
-
|
|
3618
2989
|
instances[id] = event;
|
|
3619
2990
|
return event;
|
|
3620
|
-
};
|
|
2991
|
+
};
|
|
2992
|
+
|
|
2993
|
+
// Current episode is the episode start time
|
|
3621
2994
|
// of which in the past and end time in future.
|
|
3622
2995
|
// Returns:
|
|
3623
2996
|
// 1) array of the currently active LViS Events
|
|
3624
2997
|
// 2) NULL if there are no any LViS Event
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
2998
|
Listings.getCurrent = function () {
|
|
3628
2999
|
var list = [];
|
|
3629
|
-
var now = LViSDate.now();
|
|
3000
|
+
var now = LViSDate.now();
|
|
3630
3001
|
|
|
3002
|
+
// loop through the raw data
|
|
3631
3003
|
for (var i = 0, l = events.length; i < l; i++) {
|
|
3632
3004
|
if (events[i].start_at <= now && now < events[i].end_at) {
|
|
3633
3005
|
list.push(Listings.get(events[i].id));
|
|
3634
3006
|
}
|
|
3635
|
-
}
|
|
3636
|
-
|
|
3007
|
+
}
|
|
3637
3008
|
|
|
3009
|
+
// return NULL if nothing found
|
|
3638
3010
|
return list.length ? list : null;
|
|
3639
|
-
};
|
|
3011
|
+
};
|
|
3012
|
+
|
|
3013
|
+
// Returns:
|
|
3640
3014
|
// 1) array of the LViS Events that are
|
|
3641
3015
|
// scheduled to start next
|
|
3642
3016
|
// 2) NULL if there are no any LViS Event
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
3017
|
Listings.getNext = function () {
|
|
3646
3018
|
// time till the next event
|
|
3647
3019
|
var nextStartAt = Number.POSITIVE_INFINITY;
|
|
3648
|
-
var list = [];
|
|
3649
|
-
// the minimal time till the upcoming event
|
|
3020
|
+
var list = [];
|
|
3650
3021
|
|
|
3022
|
+
// loop through the raw data and find
|
|
3023
|
+
// the minimal time till the upcoming event
|
|
3651
3024
|
var i;
|
|
3652
3025
|
var l;
|
|
3653
3026
|
var now = LViSDate.now();
|
|
3654
|
-
|
|
3655
3027
|
for (i = 0, l = events.length; i < l; i++) {
|
|
3656
3028
|
if (now < events[i].start_at && events[i].start_at < nextStartAt) {
|
|
3657
3029
|
nextStartAt = events[i].start_at;
|
|
3658
3030
|
}
|
|
3659
3031
|
}
|
|
3660
|
-
|
|
3661
3032
|
if (nextStartAt < Number.POSITIVE_INFINITY) {
|
|
3662
3033
|
for (i = 0, l = events.length; i < l; i++) {
|
|
3663
3034
|
if (events[i].start_at === nextStartAt) {
|
|
3664
3035
|
list.push(Listings.get(events[i].id));
|
|
3665
3036
|
}
|
|
3666
3037
|
}
|
|
3667
|
-
}
|
|
3668
|
-
|
|
3038
|
+
}
|
|
3669
3039
|
|
|
3040
|
+
// return NULL if nothing found
|
|
3670
3041
|
return list.length ? list : null;
|
|
3671
|
-
};
|
|
3042
|
+
};
|
|
3043
|
+
|
|
3044
|
+
// can't be realized now due to absence of
|
|
3672
3045
|
// the ended events in the list
|
|
3673
3046
|
// Listings.getPrevious = function () {};
|
|
3047
|
+
|
|
3674
3048
|
// returns the list of all events sorted by start time
|
|
3675
3049
|
// eslint-disable-next-line
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
3050
|
Listings.getList = function () {
|
|
3679
3051
|
var event;
|
|
3680
3052
|
var list = [];
|
|
3681
|
-
|
|
3682
3053
|
for (var i = 0, l = events.length; i < l; i++) {
|
|
3683
3054
|
event = this.get(events[i].id);
|
|
3684
|
-
|
|
3685
3055
|
if (event !== null) {
|
|
3686
3056
|
list.push(event);
|
|
3687
3057
|
}
|
|
3688
3058
|
}
|
|
3689
|
-
|
|
3690
3059
|
return list;
|
|
3691
3060
|
};
|
|
3692
|
-
|
|
3693
3061
|
Listings.getAssets = function (id) {
|
|
3694
3062
|
if (typeof id === 'undefined') {
|
|
3695
3063
|
return assets;
|
|
3696
3064
|
}
|
|
3697
|
-
|
|
3698
3065
|
return assets[id] || null;
|
|
3699
3066
|
};
|
|
3700
|
-
|
|
3701
3067
|
Listings.fetchListings = /*#__PURE__*/function () {
|
|
3702
|
-
var _ref = _asyncToGenerator(
|
|
3068
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(host, project) {
|
|
3703
3069
|
var response, data;
|
|
3704
|
-
return _regeneratorRuntime.wrap(function
|
|
3705
|
-
while (1) {
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
case 7:
|
|
3721
|
-
case "end":
|
|
3722
|
-
return _context.stop();
|
|
3723
|
-
}
|
|
3070
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
3071
|
+
while (1) switch (_context.prev = _context.next) {
|
|
3072
|
+
case 0:
|
|
3073
|
+
_context.next = 1;
|
|
3074
|
+
return fetch("https://".concat(host, "/projects/").concat(project.substr(0, 2), "/").concat(project, "/listings.json"));
|
|
3075
|
+
case 1:
|
|
3076
|
+
response = _context.sent;
|
|
3077
|
+
_context.next = 2;
|
|
3078
|
+
return response.json();
|
|
3079
|
+
case 2:
|
|
3080
|
+
data = _context.sent;
|
|
3081
|
+
handleData(data);
|
|
3082
|
+
case 3:
|
|
3083
|
+
case "end":
|
|
3084
|
+
return _context.stop();
|
|
3724
3085
|
}
|
|
3725
3086
|
}, _callee);
|
|
3726
3087
|
}));
|
|
3727
|
-
|
|
3728
3088
|
return function (_x, _x2) {
|
|
3729
3089
|
return _ref.apply(this, arguments);
|
|
3730
3090
|
};
|
|
3731
3091
|
}();
|
|
3732
|
-
|
|
3733
3092
|
Listings.init = function (config) {
|
|
3734
3093
|
config = config || {};
|
|
3735
3094
|
channel$1 = config.channel || null;
|
|
@@ -3740,22 +3099,19 @@ Listings.init = function (config) {
|
|
|
3740
3099
|
var User = (function () {
|
|
3741
3100
|
// pointer to `this` object
|
|
3742
3101
|
var self = {};
|
|
3743
|
-
|
|
3744
3102
|
self.getSessionId = function () {
|
|
3745
3103
|
return Enmasse.getSessionId();
|
|
3746
3104
|
};
|
|
3747
|
-
|
|
3748
3105
|
self.signIn = function () {
|
|
3749
3106
|
return Enmasse.signIn.apply(Enmasse, arguments);
|
|
3750
3107
|
};
|
|
3751
|
-
|
|
3752
3108
|
self.login = function () {
|
|
3753
3109
|
return Enmasse.login.apply(Enmasse, arguments);
|
|
3754
3110
|
};
|
|
3755
|
-
|
|
3756
3111
|
return self;
|
|
3757
3112
|
})();
|
|
3758
3113
|
|
|
3114
|
+
// properties
|
|
3759
3115
|
var host = null;
|
|
3760
3116
|
var channel = null;
|
|
3761
3117
|
var lvisEvent = null;
|
|
@@ -3775,8 +3131,9 @@ var ON_READY = 'ready';
|
|
|
3775
3131
|
var ON_ERROR = 'error';
|
|
3776
3132
|
LViS.trigger = trigger;
|
|
3777
3133
|
LViS.bind = bind;
|
|
3778
|
-
LViS.unbind = unbind;
|
|
3134
|
+
LViS.unbind = unbind;
|
|
3779
3135
|
|
|
3136
|
+
// attach xhr library to make it possible to mock it in unit tests
|
|
3780
3137
|
LViS._xhr = xhr;
|
|
3781
3138
|
LViS.VERSION = version;
|
|
3782
3139
|
LViS.ON_READY = ON_READY;
|
|
@@ -3820,6 +3177,7 @@ LViS.Trivia = Trivia;
|
|
|
3820
3177
|
LViS.Diametric = Diametric;
|
|
3821
3178
|
LViS.Swing = Swing;
|
|
3822
3179
|
LViS.Emoting = Emoting;
|
|
3180
|
+
|
|
3823
3181
|
/*
|
|
3824
3182
|
* Private methods
|
|
3825
3183
|
*/
|
|
@@ -3828,34 +3186,27 @@ var embedAssets = function embedAssets() {
|
|
|
3828
3186
|
var jsLoaded = new Deferred();
|
|
3829
3187
|
var i;
|
|
3830
3188
|
var files = {}; // list of files grouped by type
|
|
3831
|
-
|
|
3832
3189
|
var assets = getAssets();
|
|
3833
|
-
|
|
3834
3190
|
for (var key in assets) {
|
|
3835
3191
|
if ({}.hasOwnProperty.call(assets, key)) {
|
|
3836
3192
|
for (i = 0; i < assets[key].length; i++) {
|
|
3837
3193
|
var asset = assets[key][i];
|
|
3838
3194
|
var type = asset.autoload;
|
|
3839
|
-
|
|
3840
3195
|
if (typeof type === 'undefined') {
|
|
3841
3196
|
continue;
|
|
3842
3197
|
}
|
|
3843
|
-
|
|
3844
3198
|
if (typeof files[type] === 'undefined') {
|
|
3845
3199
|
files[type] = [];
|
|
3846
3200
|
}
|
|
3847
|
-
|
|
3848
3201
|
files[type].push(asset.data);
|
|
3849
3202
|
}
|
|
3850
3203
|
}
|
|
3851
3204
|
}
|
|
3852
|
-
|
|
3853
3205
|
if (typeof files.js !== 'undefined' && files.js.length > 0) {
|
|
3854
3206
|
$script(files.js, jsLoaded.resolve());
|
|
3855
3207
|
} else {
|
|
3856
3208
|
jsLoaded.resolve();
|
|
3857
3209
|
}
|
|
3858
|
-
|
|
3859
3210
|
if (typeof files.css !== 'undefined' && files.css.length > 0) {
|
|
3860
3211
|
for (i = 0; i < files.css.length; i++) {
|
|
3861
3212
|
if (document.createStyleSheet) {
|
|
@@ -3870,23 +3221,20 @@ var embedAssets = function embedAssets() {
|
|
|
3870
3221
|
}
|
|
3871
3222
|
}
|
|
3872
3223
|
}
|
|
3873
|
-
|
|
3874
3224
|
return Deferred.when(jsLoaded);
|
|
3875
3225
|
};
|
|
3876
|
-
|
|
3877
3226
|
var handleEventState = function handleEventState() {
|
|
3878
3227
|
if (lvisEvent === null) {
|
|
3879
3228
|
return;
|
|
3880
|
-
}
|
|
3229
|
+
}
|
|
3881
3230
|
|
|
3231
|
+
// console.log("LViS::handleEventState", lvisEvent.getSubstate());
|
|
3882
3232
|
|
|
3883
3233
|
var state = lvisEvent.getSubstate();
|
|
3884
|
-
|
|
3885
3234
|
if ([Event.STATE_FAILURE, Event.STATE_UPCOMING, Event.STATE_FINISHED].indexOf(state) >= 0) {
|
|
3886
3235
|
// no more data to load
|
|
3887
3236
|
lvisEvent.markAsReady();
|
|
3888
3237
|
}
|
|
3889
|
-
|
|
3890
3238
|
switch (state) {
|
|
3891
3239
|
// case Event.STATE_PENDING: break;
|
|
3892
3240
|
// case Event.STATE_FAILURE:
|
|
@@ -3895,88 +3243,78 @@ var handleEventState = function handleEventState() {
|
|
|
3895
3243
|
case Event.STATE_ACTIVE:
|
|
3896
3244
|
handleEventActiveState();
|
|
3897
3245
|
break;
|
|
3898
|
-
|
|
3899
3246
|
case Event.STATE_PROLONGED:
|
|
3900
3247
|
handleEventProlongedState();
|
|
3901
3248
|
break;
|
|
3902
|
-
|
|
3903
3249
|
case Event.STATE_FINISHED:
|
|
3904
3250
|
handleEventFinishedState();
|
|
3905
3251
|
break;
|
|
3906
3252
|
}
|
|
3907
3253
|
};
|
|
3908
|
-
|
|
3909
3254
|
var handleEventEOC = function handleEventEOC() {
|
|
3910
3255
|
lvisEvent.markAsReady();
|
|
3911
3256
|
};
|
|
3912
|
-
|
|
3913
3257
|
var handleEventActiveState = function handleEventActiveState() {
|
|
3914
3258
|
// console.log("LViS::handleEventActiveState");
|
|
3915
3259
|
var channels = lvisEvent.getChannels();
|
|
3916
|
-
Factories.setChannels(channels);
|
|
3260
|
+
Factories.setChannels(channels);
|
|
3917
3261
|
|
|
3262
|
+
// subscribe to all channels and kick the things off
|
|
3918
3263
|
for (var key in channels) {
|
|
3919
3264
|
if ({}.hasOwnProperty.call(channels, key)) {
|
|
3920
3265
|
ConnectionAdaptor.subscribe(channels[key]);
|
|
3921
3266
|
}
|
|
3922
3267
|
}
|
|
3923
3268
|
};
|
|
3924
|
-
|
|
3925
3269
|
var handleEventProlongedState = function handleEventProlongedState() {
|
|
3926
3270
|
// console.log("LViS::handleEventProlongedState");
|
|
3927
3271
|
var channels = lvisEvent.getChannels();
|
|
3928
|
-
Factories.setChannels(channels);
|
|
3272
|
+
Factories.setChannels(channels);
|
|
3929
3273
|
|
|
3274
|
+
// subscribe to all channels
|
|
3930
3275
|
for (var key in channels) {
|
|
3931
3276
|
if ({}.hasOwnProperty.call(channels, key)) {
|
|
3932
3277
|
ConnectionAdaptor.subscribe(channels[key]);
|
|
3933
3278
|
}
|
|
3934
3279
|
}
|
|
3935
3280
|
};
|
|
3936
|
-
|
|
3937
3281
|
var handleEventFinishedState = function handleEventFinishedState() {
|
|
3938
3282
|
// console.log("LViS::handleEventFinishedState");
|
|
3939
|
-
var channels = lvisEvent.getChannels();
|
|
3283
|
+
var channels = lvisEvent.getChannels();
|
|
3940
3284
|
|
|
3285
|
+
// unsubscribe from all channels
|
|
3941
3286
|
for (var key in channels) {
|
|
3942
3287
|
if ({}.hasOwnProperty.call(channels, key)) {
|
|
3943
3288
|
ConnectionAdaptor.unsubscribe(channels[key]);
|
|
3944
3289
|
}
|
|
3945
3290
|
}
|
|
3946
3291
|
};
|
|
3947
|
-
|
|
3948
3292
|
var handleEnmasseState = function handleEnmasseState() {
|
|
3949
3293
|
var state = arguments.length <= 0 ? undefined : arguments[0];
|
|
3950
|
-
|
|
3951
3294
|
switch (state) {
|
|
3952
3295
|
case Enmasse.STATE_CONNECTED:
|
|
3953
3296
|
{
|
|
3954
3297
|
var time = arguments.length <= 1 ? undefined : arguments[1];
|
|
3955
3298
|
LViSDate.setTime(time);
|
|
3956
3299
|
ConnectionAdaptor.subscribe(channel);
|
|
3957
|
-
|
|
3958
3300
|
if (lvisEvent && lvisEvent.isReady()) {
|
|
3959
3301
|
lvisEvent.loadHistory(getHost(), true).always(handleEventState);
|
|
3960
3302
|
} else {
|
|
3961
3303
|
handleEventState();
|
|
3962
3304
|
}
|
|
3963
|
-
|
|
3964
3305
|
break;
|
|
3965
3306
|
}
|
|
3966
3307
|
}
|
|
3967
3308
|
};
|
|
3968
|
-
|
|
3969
3309
|
var handleEnmasseReady = function handleEnmasseReady() {
|
|
3970
3310
|
// console.log("API::handleEnmasseReady");
|
|
3971
3311
|
enmasseReady.resolve();
|
|
3972
3312
|
Enmasse.connect();
|
|
3973
3313
|
};
|
|
3974
|
-
|
|
3975
3314
|
var handleEnmasseError = function handleEnmasseError() {
|
|
3976
3315
|
// console.log("API::handleEnmasseError");
|
|
3977
3316
|
enmasseReady.reject();
|
|
3978
3317
|
};
|
|
3979
|
-
|
|
3980
3318
|
var handleListingsReady = function handleListingsReady() {
|
|
3981
3319
|
embedAssets().done(function () {
|
|
3982
3320
|
return assetsReady.resolve();
|
|
@@ -3984,51 +3322,43 @@ var handleListingsReady = function handleListingsReady() {
|
|
|
3984
3322
|
return assetsReady.reject();
|
|
3985
3323
|
});
|
|
3986
3324
|
};
|
|
3987
|
-
|
|
3988
3325
|
var handleSyncDelayChange = function handleSyncDelayChange() {
|
|
3989
3326
|
LViS.resetEvent();
|
|
3990
3327
|
};
|
|
3991
|
-
|
|
3992
3328
|
var initWithConfig = function initWithConfig() {
|
|
3993
3329
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3994
3330
|
var UUIDSchema = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
3995
3331
|
var hostSchema = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/i;
|
|
3996
|
-
|
|
3997
3332
|
if (typeof config.host === 'undefined' || config.host === null) {
|
|
3998
3333
|
LViS.trigger(LViS.ON_ERROR);
|
|
3999
3334
|
console.error('Host is not set');
|
|
4000
3335
|
return;
|
|
4001
3336
|
}
|
|
4002
|
-
|
|
4003
3337
|
if (typeof config.project === 'undefined' || config.project === null) {
|
|
4004
3338
|
LViS.trigger(LViS.ON_ERROR);
|
|
4005
3339
|
console.error('Project UUID is not set');
|
|
4006
3340
|
return;
|
|
4007
3341
|
}
|
|
4008
|
-
|
|
4009
3342
|
if (!UUIDSchema.test(config.project)) {
|
|
4010
3343
|
LViS.trigger(LViS.ON_ERROR);
|
|
4011
3344
|
console.error('Project UUID has incorrect format');
|
|
4012
3345
|
return;
|
|
4013
3346
|
}
|
|
4014
|
-
|
|
4015
3347
|
if (!hostSchema.test(config.host)) {
|
|
4016
3348
|
LViS.trigger(LViS.ON_ERROR);
|
|
4017
3349
|
console.error('Host has incorrect format');
|
|
4018
3350
|
return;
|
|
4019
3351
|
}
|
|
4020
|
-
|
|
4021
3352
|
if (initialised) {
|
|
4022
3353
|
console.warn('Attempt to initialise library when it was already initialised');
|
|
4023
3354
|
return;
|
|
4024
3355
|
}
|
|
4025
|
-
|
|
4026
3356
|
if (typeof config.forceSecure === 'boolean') {
|
|
4027
3357
|
forceSecure = config.forceSecure;
|
|
4028
3358
|
}
|
|
3359
|
+
channel = "".concat(CHANNEL_CONTROL, "-").concat(config.project);
|
|
4029
3360
|
|
|
4030
|
-
|
|
4031
|
-
|
|
3361
|
+
// remove leading //, http:// or https://
|
|
4032
3362
|
host = config.host.replace(/^(.*:)?(\/+)?/gi, '');
|
|
4033
3363
|
Enmasse.bind(Enmasse.ON_READY, handleEnmasseReady);
|
|
4034
3364
|
Enmasse.bind(Enmasse.ON_ERROR, handleEnmasseError);
|
|
@@ -4071,31 +3401,28 @@ var initWithConfig = function initWithConfig() {
|
|
|
4071
3401
|
});
|
|
4072
3402
|
initialised = true;
|
|
4073
3403
|
};
|
|
3404
|
+
|
|
4074
3405
|
/*
|
|
4075
3406
|
* Public methods
|
|
4076
3407
|
*/
|
|
4077
3408
|
|
|
4078
|
-
|
|
4079
3409
|
var getHost = function getHost() {
|
|
4080
3410
|
var protocol = forceSecure || document.location.protocol.indexOf('https') === 0 ? 'https' : 'http';
|
|
4081
3411
|
return "".concat(protocol, "://").concat(host);
|
|
4082
3412
|
};
|
|
4083
|
-
|
|
4084
3413
|
var getAssets = function getAssets() {
|
|
4085
3414
|
return Listings.getAssets.apply(Listings, arguments);
|
|
4086
3415
|
};
|
|
4087
|
-
|
|
4088
3416
|
var getEvent = function getEvent() {
|
|
4089
3417
|
return lvisEvent;
|
|
4090
3418
|
};
|
|
4091
|
-
|
|
4092
3419
|
var setEvent = function setEvent(newEvent) {
|
|
4093
3420
|
// console.log("LVIS::setEvent", newEvent);
|
|
3421
|
+
|
|
4094
3422
|
// new event mustn't be set if it was already
|
|
4095
3423
|
if (lvisEvent === newEvent) {
|
|
4096
3424
|
return;
|
|
4097
3425
|
}
|
|
4098
|
-
|
|
4099
3426
|
unsetEvent();
|
|
4100
3427
|
lvisEvent = newEvent;
|
|
4101
3428
|
newEvent.loadHistory(getHost()).always(function () {
|
|
@@ -4107,74 +3434,66 @@ var setEvent = function setEvent(newEvent) {
|
|
|
4107
3434
|
handleEventState();
|
|
4108
3435
|
});
|
|
4109
3436
|
};
|
|
4110
|
-
|
|
4111
3437
|
var unsetEvent = function unsetEvent() {
|
|
4112
3438
|
if (lvisEvent === null) {
|
|
4113
3439
|
return;
|
|
4114
3440
|
}
|
|
3441
|
+
var channels = lvisEvent.getChannels();
|
|
4115
3442
|
|
|
4116
|
-
|
|
4117
|
-
|
|
3443
|
+
// unsubscribe from all channels
|
|
4118
3444
|
for (var key in channels) {
|
|
4119
3445
|
if ({}.hasOwnProperty.call(channels, key)) {
|
|
4120
3446
|
ConnectionAdaptor.unsubscribe(channels[key]);
|
|
4121
3447
|
}
|
|
4122
3448
|
}
|
|
4123
|
-
|
|
4124
3449
|
lvisEvent.unbind(Event.ON_SUBSTATE, handleEventState);
|
|
4125
3450
|
lvisEvent.unbind(Event.ON_EOC, handleEventEOC);
|
|
4126
3451
|
lvisEvent.markAsNotReady();
|
|
4127
3452
|
lvisEvent = null;
|
|
4128
3453
|
};
|
|
4129
|
-
|
|
4130
3454
|
var resetEvent = function resetEvent() {
|
|
4131
3455
|
ConnectionAdaptor.unsubscribe(channel);
|
|
4132
3456
|
ConnectionAdaptor.subscribe(channel);
|
|
4133
|
-
|
|
4134
3457
|
if (lvisEvent === null) {
|
|
4135
3458
|
return;
|
|
4136
3459
|
}
|
|
3460
|
+
var channels = lvisEvent.getChannels();
|
|
4137
3461
|
|
|
4138
|
-
|
|
4139
|
-
|
|
3462
|
+
// unsubscribe from events channels
|
|
4140
3463
|
for (var key in channels) {
|
|
4141
3464
|
if ({}.hasOwnProperty.call(channels, key)) {
|
|
4142
3465
|
ConnectionAdaptor.unsubscribe(channels[key]);
|
|
4143
3466
|
ConnectionAdaptor.subscribe(channels[key]);
|
|
4144
3467
|
}
|
|
4145
3468
|
}
|
|
4146
|
-
|
|
4147
3469
|
lvisEvent.markAsNotReady();
|
|
4148
3470
|
};
|
|
4149
|
-
|
|
4150
3471
|
var init = function init() {
|
|
4151
3472
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4152
3473
|
var initDone = new Deferred();
|
|
4153
|
-
|
|
4154
3474
|
if (config.host && config.project) {
|
|
4155
3475
|
initWithConfig(config);
|
|
4156
3476
|
return initDone.resolve();
|
|
4157
|
-
}
|
|
4158
|
-
|
|
3477
|
+
}
|
|
4159
3478
|
|
|
3479
|
+
// Load miccfg.json file for initialisation config.
|
|
4160
3480
|
fetch(MIC_CONFIG_FILE).then(function (response) {
|
|
4161
3481
|
return response.json();
|
|
4162
3482
|
}).then(function (data) {
|
|
4163
3483
|
if (data.project) {
|
|
4164
3484
|
config.project = data.project;
|
|
4165
3485
|
}
|
|
4166
|
-
|
|
4167
3486
|
if (data.static_host) {
|
|
4168
3487
|
config.host = data.static_host;
|
|
4169
3488
|
}
|
|
4170
|
-
}).catch(function () {
|
|
3489
|
+
}).catch(function () {
|
|
3490
|
+
// Ignore loading error, as the file only available when custom URL is set.
|
|
4171
3491
|
}).finally(function () {
|
|
4172
3492
|
initWithConfig(config);
|
|
4173
3493
|
initDone.resolve();
|
|
4174
3494
|
});
|
|
4175
3495
|
return initDone;
|
|
4176
3496
|
};
|
|
4177
|
-
|
|
4178
3497
|
LViS.getHost = getHost;
|
|
4179
3498
|
LViS.getAssets = getAssets;
|
|
4180
3499
|
LViS.getEvent = getEvent;
|