@jayesol/jayeson.lib.sports 2.2.7-beta → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -113
- package/lib/basketball_codec.d.ts +11 -0
- package/lib/basketball_codec.js +209 -0
- package/lib/client.d.ts +202 -0
- package/lib/client.js +686 -0
- package/lib/codec.d.ts +57 -0
- package/lib/codec.js +129 -0
- package/lib/core.d.ts +159 -0
- package/lib/core.js +497 -0
- package/lib/data_structure.d.ts +113 -0
- package/lib/data_structure.js +208 -0
- package/lib/dispatch.d.ts +126 -0
- package/lib/dispatch.js +324 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +27 -0
- package/lib/merge.d.ts +33 -0
- package/lib/merge.js +569 -0
- package/lib/message_class.d.ts +152 -0
- package/lib/message_class.js +466 -0
- package/lib/module.d.ts +12 -0
- package/lib/module.js +87 -0
- package/lib/mutable.d.ts +118 -0
- package/lib/mutable.js +1061 -0
- package/lib/receive.d.ts +88 -0
- package/lib/receive.js +484 -0
- package/lib/soccer_codec.d.ts +13 -0
- package/lib/soccer_codec.js +168 -0
- package/lib/tennis_codec.d.ts +13 -0
- package/lib/tennis_codec.js +177 -0
- package/package.json +49 -49
package/lib/client.js
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
34
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
35
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
36
|
+
};
|
|
37
|
+
var MemoryDispatcher_1;
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.SportsFeedClient = exports.MemoryDispatcher = exports.AbstractComparableEPDispatcher = exports.FeedView = exports.Reset = exports.DeleteOdd = exports.UpdateOdd = exports.InsertOdd = exports.DeleteEvent = exports.UpdateEvent = exports.InsertEvent = exports.DeleteMatch = exports.UpdateMatch = exports.InsertMatch = void 0;
|
|
40
|
+
const dispatch_1 = require("./dispatch");
|
|
41
|
+
const codec_1 = require("./codec");
|
|
42
|
+
const core_1 = require("./core");
|
|
43
|
+
const delivery = __importStar(require("@jayesol/jayeson.lib.delivery"));
|
|
44
|
+
const jayeson_lib_delivery_1 = require("@jayesol/jayeson.lib.delivery");
|
|
45
|
+
const Collections = __importStar(require("typescript-collections"));
|
|
46
|
+
const T = __importStar(require("ts-promise"));
|
|
47
|
+
const data_structure_1 = require("./data_structure");
|
|
48
|
+
const receive_1 = require("./receive");
|
|
49
|
+
const message_class_1 = require("./message_class");
|
|
50
|
+
//imports required for dependency injection
|
|
51
|
+
require("reflect-metadata");
|
|
52
|
+
const injection_js_1 = require("injection-js");
|
|
53
|
+
class InsertMatch {
|
|
54
|
+
constructor(_after, _get) {
|
|
55
|
+
this._after = _after;
|
|
56
|
+
this._get = _get;
|
|
57
|
+
}
|
|
58
|
+
after() {
|
|
59
|
+
return this._after;
|
|
60
|
+
}
|
|
61
|
+
get() {
|
|
62
|
+
return this._get;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.InsertMatch = InsertMatch;
|
|
66
|
+
class UpdateMatch {
|
|
67
|
+
constructor(_after, _get) {
|
|
68
|
+
this._after = _after;
|
|
69
|
+
this._get = _get;
|
|
70
|
+
}
|
|
71
|
+
after() {
|
|
72
|
+
return this._after;
|
|
73
|
+
}
|
|
74
|
+
get() {
|
|
75
|
+
return this._get;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.UpdateMatch = UpdateMatch;
|
|
79
|
+
class DeleteMatch {
|
|
80
|
+
constructor(_after, _get) {
|
|
81
|
+
this._after = _after;
|
|
82
|
+
this._get = _get;
|
|
83
|
+
}
|
|
84
|
+
after() {
|
|
85
|
+
return this._after;
|
|
86
|
+
}
|
|
87
|
+
get() {
|
|
88
|
+
return this._get;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.DeleteMatch = DeleteMatch;
|
|
92
|
+
class InsertEvent {
|
|
93
|
+
constructor(_after, _get) {
|
|
94
|
+
this._after = _after;
|
|
95
|
+
this._get = _get;
|
|
96
|
+
}
|
|
97
|
+
after() {
|
|
98
|
+
return this._after;
|
|
99
|
+
}
|
|
100
|
+
get() {
|
|
101
|
+
return this._get;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.InsertEvent = InsertEvent;
|
|
105
|
+
class UpdateEvent {
|
|
106
|
+
constructor(_after, _get) {
|
|
107
|
+
this._after = _after;
|
|
108
|
+
this._get = _get;
|
|
109
|
+
}
|
|
110
|
+
after() {
|
|
111
|
+
return this._after;
|
|
112
|
+
}
|
|
113
|
+
get() {
|
|
114
|
+
return this._get;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.UpdateEvent = UpdateEvent;
|
|
118
|
+
class DeleteEvent {
|
|
119
|
+
constructor(_after, _get) {
|
|
120
|
+
this._after = _after;
|
|
121
|
+
this._get = _get;
|
|
122
|
+
}
|
|
123
|
+
after() {
|
|
124
|
+
return this._after;
|
|
125
|
+
}
|
|
126
|
+
get() {
|
|
127
|
+
return this._get;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.DeleteEvent = DeleteEvent;
|
|
131
|
+
class InsertOdd {
|
|
132
|
+
constructor(_after, _get) {
|
|
133
|
+
this._after = _after;
|
|
134
|
+
this._get = _get;
|
|
135
|
+
}
|
|
136
|
+
after() {
|
|
137
|
+
return this._after;
|
|
138
|
+
}
|
|
139
|
+
get() {
|
|
140
|
+
return this._get;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.InsertOdd = InsertOdd;
|
|
144
|
+
class UpdateOdd {
|
|
145
|
+
constructor(_after, _get) {
|
|
146
|
+
this._after = _after;
|
|
147
|
+
this._get = _get;
|
|
148
|
+
}
|
|
149
|
+
after() {
|
|
150
|
+
return this._after;
|
|
151
|
+
}
|
|
152
|
+
get() {
|
|
153
|
+
return this._get;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.UpdateOdd = UpdateOdd;
|
|
157
|
+
class DeleteOdd {
|
|
158
|
+
constructor(_after, _get) {
|
|
159
|
+
this._after = _after;
|
|
160
|
+
this._get = _get;
|
|
161
|
+
}
|
|
162
|
+
after() {
|
|
163
|
+
return this._after;
|
|
164
|
+
}
|
|
165
|
+
get() {
|
|
166
|
+
return this._get;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.DeleteOdd = DeleteOdd;
|
|
170
|
+
class Reset {
|
|
171
|
+
constructor(_after, _get) {
|
|
172
|
+
this._after = _after;
|
|
173
|
+
this._get = _get;
|
|
174
|
+
}
|
|
175
|
+
after() {
|
|
176
|
+
return this._after;
|
|
177
|
+
}
|
|
178
|
+
get() {
|
|
179
|
+
return this._get;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.Reset = Reset;
|
|
183
|
+
let FeedView = class FeedView {
|
|
184
|
+
constructor(manager, repo, grp) {
|
|
185
|
+
this._epgm = manager;
|
|
186
|
+
this._fsRepo = repo;
|
|
187
|
+
this._grp = grp;
|
|
188
|
+
this._handlers = [];
|
|
189
|
+
}
|
|
190
|
+
fsRepo() {
|
|
191
|
+
return this._fsRepo;
|
|
192
|
+
}
|
|
193
|
+
epgm() {
|
|
194
|
+
return this._epgm;
|
|
195
|
+
}
|
|
196
|
+
grp() {
|
|
197
|
+
return this._grp;
|
|
198
|
+
}
|
|
199
|
+
snapshot() {
|
|
200
|
+
return this._fsRepo.getSnapshot("");
|
|
201
|
+
}
|
|
202
|
+
register(listener) {
|
|
203
|
+
if (this.hasHandler(listener)) {
|
|
204
|
+
console.warn("Handler already registered.");
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
let disp = new MemoryDispatcher(this._fsRepo, this._grp, listener);
|
|
208
|
+
this._epgm.registerEPD(disp);
|
|
209
|
+
this._handlers.push(new HandlerDispatcherTuple(listener, disp));
|
|
210
|
+
}
|
|
211
|
+
unregister(listener) {
|
|
212
|
+
let disp = this.removeHandler(listener);
|
|
213
|
+
if (disp != null) {
|
|
214
|
+
this._epgm.deregisterEPD(disp);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
hasHandler(handler) {
|
|
218
|
+
return this._handlers.some(o => o.handler === handler);
|
|
219
|
+
}
|
|
220
|
+
removeHandler(handler) {
|
|
221
|
+
let disp = null;
|
|
222
|
+
let tuple = this._handlers.find(o => o.handler === handler);
|
|
223
|
+
if (tuple !== undefined) {
|
|
224
|
+
//remove the handler from the handlers array
|
|
225
|
+
let index = this._handlers.indexOf(tuple);
|
|
226
|
+
this._handlers.splice(index, 1);
|
|
227
|
+
//return the dispatcher associated with the handler
|
|
228
|
+
return tuple.dispatch;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
handlerSize() {
|
|
235
|
+
return this._handlers.length;
|
|
236
|
+
}
|
|
237
|
+
cleanUp() {
|
|
238
|
+
//clone the handlers array to avoid concurrent modification when removing the handlers.
|
|
239
|
+
let tuples = this._handlers.slice(0);
|
|
240
|
+
//deregister all the handlers
|
|
241
|
+
for (let tuple of tuples) {
|
|
242
|
+
this.unregister(tuple.handler);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
FeedView = __decorate([
|
|
247
|
+
(0, injection_js_1.Injectable)(),
|
|
248
|
+
__param(0, (0, injection_js_1.Inject)(dispatch_1.EPGM_IMPL)),
|
|
249
|
+
__param(1, (0, injection_js_1.Inject)(core_1.FSREPO_IMPL)),
|
|
250
|
+
__metadata("design:paramtypes", [Object, Object, message_class_1.SportsFeedMessageGroup])
|
|
251
|
+
], FeedView);
|
|
252
|
+
exports.FeedView = FeedView;
|
|
253
|
+
class HandlerDispatcherTuple {
|
|
254
|
+
constructor(handler, dispatch) {
|
|
255
|
+
this.handler = handler;
|
|
256
|
+
this.dispatch = dispatch;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
class AbstractComparableEPDispatcher {
|
|
260
|
+
id() {
|
|
261
|
+
throw new Error("Method not implemented.");
|
|
262
|
+
}
|
|
263
|
+
submit(out) {
|
|
264
|
+
throw new Error("Method not implemented.");
|
|
265
|
+
}
|
|
266
|
+
onException(e) {
|
|
267
|
+
throw new Error("Method not implemented.");
|
|
268
|
+
}
|
|
269
|
+
constructor(_stream, _grp) {
|
|
270
|
+
this._stream = _stream;
|
|
271
|
+
this._grp = _grp;
|
|
272
|
+
}
|
|
273
|
+
stream() {
|
|
274
|
+
return this._stream;
|
|
275
|
+
}
|
|
276
|
+
grp() {
|
|
277
|
+
return this._grp;
|
|
278
|
+
}
|
|
279
|
+
isInitialized() {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
readyToDispatch() {
|
|
283
|
+
this._readyToDispatch = true;
|
|
284
|
+
}
|
|
285
|
+
isReadyToDispatch() {
|
|
286
|
+
return this._readyToDispatch;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.AbstractComparableEPDispatcher = AbstractComparableEPDispatcher;
|
|
290
|
+
let MemoryDispatcher = MemoryDispatcher_1 = class MemoryDispatcher extends AbstractComparableEPDispatcher {
|
|
291
|
+
constructor(_fsRepo, _grp, _handler) {
|
|
292
|
+
super(MemoryDispatcher_1.MEMORY_STREAM, _grp);
|
|
293
|
+
this._fsRepo = _fsRepo;
|
|
294
|
+
this.lastPushedSs = data_structure_1.IndexedSnapshotImpl.EMPTY_SNAPSHOT;
|
|
295
|
+
this._grp = _grp;
|
|
296
|
+
this._handler = _handler;
|
|
297
|
+
this._id = delivery.generateUUID();
|
|
298
|
+
}
|
|
299
|
+
grp() {
|
|
300
|
+
return this._grp;
|
|
301
|
+
}
|
|
302
|
+
handler() {
|
|
303
|
+
return this._handler;
|
|
304
|
+
}
|
|
305
|
+
id() {
|
|
306
|
+
return this._id;
|
|
307
|
+
}
|
|
308
|
+
submit(out) {
|
|
309
|
+
if (this.isInitialized().isFulfilled() && this.isInitialized().value()) {
|
|
310
|
+
this.handleMessage(out);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
onException(e) {
|
|
314
|
+
console.error("Exception when dispatching outgoing messages to dispatchers:" + e);
|
|
315
|
+
}
|
|
316
|
+
handleMessage(msg) {
|
|
317
|
+
if (this.grp().isIndicatorMessage(msg.msgType())) {
|
|
318
|
+
if (msg.msgType() == this._grp.SWITCH_FILTER_START()) {
|
|
319
|
+
let requestId = Number(msg.msg());
|
|
320
|
+
this.pushSwitchFilterStart(requestId);
|
|
321
|
+
}
|
|
322
|
+
else if (msg.msgType() == this._grp.SWITCH_FILTER_END()) {
|
|
323
|
+
this.pushSwitchFilterEnd();
|
|
324
|
+
}
|
|
325
|
+
else if (msg.msgType() == this._grp.FULLSNAPSHOT_START()) {
|
|
326
|
+
this.pushFullSnapshotStart();
|
|
327
|
+
}
|
|
328
|
+
else if (msg.msgType() == this._grp.FULLSNAPSHOT_END()) {
|
|
329
|
+
this.pushFullSnapshotEnd();
|
|
330
|
+
}
|
|
331
|
+
else if (msg.msgType() == this._grp.SWITCH_FILTER_FAIL()) {
|
|
332
|
+
let requestId = Number(msg.msg());
|
|
333
|
+
this.pushSwitchFilterFail(requestId);
|
|
334
|
+
}
|
|
335
|
+
else if (msg.msgType() == this._grp.TTL_RESTORE_START()) {
|
|
336
|
+
this.pushFullSnapshotStart();
|
|
337
|
+
}
|
|
338
|
+
else if (msg.msgType() == this._grp.TTL_RESTORE_END()) {
|
|
339
|
+
this.pushFullSnapshotEnd();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
let out = msg;
|
|
344
|
+
if (this.isSame(out.msgType(), this._grp.DATA_INSERT_MATCH())) {
|
|
345
|
+
this.pushInsertMatch(out);
|
|
346
|
+
}
|
|
347
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_INSERT_EVENT())) {
|
|
348
|
+
this.pushInsertEvent(out);
|
|
349
|
+
}
|
|
350
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_INSERT_ODD())) {
|
|
351
|
+
this.pushInsertOdd(out);
|
|
352
|
+
}
|
|
353
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_UPDATE_MATCH())) {
|
|
354
|
+
this.pushUpdateMatch(out);
|
|
355
|
+
}
|
|
356
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_UPDATE_EVENT())) {
|
|
357
|
+
this.pushUpdateEvent(out);
|
|
358
|
+
}
|
|
359
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_UPDATE_ODD())) {
|
|
360
|
+
this.pushUpdateOdd(out);
|
|
361
|
+
}
|
|
362
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_DELETE_MATCH())) {
|
|
363
|
+
this.pushDeleteMatch(out);
|
|
364
|
+
}
|
|
365
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_DELETE_EVENT())) {
|
|
366
|
+
this.pushDeleteEvent(out);
|
|
367
|
+
}
|
|
368
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_DELETE_ODD())) {
|
|
369
|
+
this.pushDeleteOdd(out);
|
|
370
|
+
}
|
|
371
|
+
else if (this.isSame(out.msgType(), this._grp.DATA_RESET())) {
|
|
372
|
+
this.pushReset(out);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
pushSwitchFilterStart(requestId) {
|
|
377
|
+
this._handler.onSwitchFilterStart(requestId);
|
|
378
|
+
}
|
|
379
|
+
pushSwitchFilterEnd() {
|
|
380
|
+
this._handler.onSwitchFilterEnd();
|
|
381
|
+
}
|
|
382
|
+
pushFullSnapshotStart() {
|
|
383
|
+
this._handler.onFullSnapshotStart();
|
|
384
|
+
}
|
|
385
|
+
pushFullSnapshotEnd() {
|
|
386
|
+
this._handler.onFullSnapshotEnd();
|
|
387
|
+
}
|
|
388
|
+
pushSwitchFilterFail(requestId) {
|
|
389
|
+
this._handler.onSwitchFilterFail(requestId);
|
|
390
|
+
}
|
|
391
|
+
pushInsertMatch(ds) {
|
|
392
|
+
let insert = [];
|
|
393
|
+
let update = [];
|
|
394
|
+
for (let m of ds.delta().matches()) {
|
|
395
|
+
if (ds.before().hasMatch(m.id())) {
|
|
396
|
+
update.push(m);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
insert.push(m);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (insert.length != 0) {
|
|
403
|
+
let im = new InsertMatch(ds.after(), insert);
|
|
404
|
+
this._handler.onInsertMatch(im);
|
|
405
|
+
}
|
|
406
|
+
if (update.length != 0) {
|
|
407
|
+
let um = new UpdateMatch(ds.after(), update);
|
|
408
|
+
this._handler.onUpdateMatch(um);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
pushInsertEvent(ds) {
|
|
412
|
+
let insert = [];
|
|
413
|
+
let update = [];
|
|
414
|
+
for (let e of this.events(ds.delta().matches())) {
|
|
415
|
+
let existingMatch = ds.before().match(e.matchId());
|
|
416
|
+
if (existingMatch != null && existingMatch.hasEvent(e.id())) {
|
|
417
|
+
update.push(e);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
insert.push(e);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (insert.length != 0) {
|
|
424
|
+
let ie = new InsertEvent(ds.after(), insert);
|
|
425
|
+
this._handler.onInsertEvent(ie);
|
|
426
|
+
}
|
|
427
|
+
if (update.length > 0) {
|
|
428
|
+
let ue = new UpdateEvent(ds.after(), update);
|
|
429
|
+
this._handler.onUpdateEvent(ue);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
pushInsertOdd(ds) {
|
|
433
|
+
let records = this.records(this.events(ds.delta().matches()));
|
|
434
|
+
if (records.length > 0) {
|
|
435
|
+
let io = new InsertOdd(ds.after(), records);
|
|
436
|
+
this._handler.onInsertOdd(io);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
pushUpdateMatch(ds) {
|
|
440
|
+
let matches = ds.delta().matches();
|
|
441
|
+
if (matches.length > 0) {
|
|
442
|
+
let um = new UpdateMatch(ds.after(), matches);
|
|
443
|
+
this._handler.onUpdateMatch(um);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
pushUpdateEvent(ds) {
|
|
447
|
+
let events = this.events(ds.delta().matches());
|
|
448
|
+
if (events.length > 0) {
|
|
449
|
+
let ue = new UpdateEvent(ds.after(), events);
|
|
450
|
+
this._handler.onUpdateEvent(ue);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
pushUpdateOdd(ds) {
|
|
454
|
+
let records = this.records(this.events(ds.delta().matches()));
|
|
455
|
+
if (records.length > 0) {
|
|
456
|
+
let uo = new UpdateOdd(ds.after(), records);
|
|
457
|
+
this._handler.onUpdateOdd(uo);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
pushDeleteMatch(ds) {
|
|
461
|
+
let update = [];
|
|
462
|
+
let delete_m = [];
|
|
463
|
+
for (let match of ds.delta().matches()) {
|
|
464
|
+
if (ds.after().hasMatch(match.id())) {
|
|
465
|
+
update.push(match);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
delete_m.push(match);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (delete_m.length != 0) {
|
|
472
|
+
let dm = new DeleteMatch(ds.after(), delete_m);
|
|
473
|
+
this._handler.onDeleteMatch(dm);
|
|
474
|
+
}
|
|
475
|
+
if (update.length != 0) {
|
|
476
|
+
let um = new UpdateMatch(ds.after(), update);
|
|
477
|
+
this._handler.onUpdateMatch(um);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
pushDeleteEvent(ds) {
|
|
481
|
+
let update = [];
|
|
482
|
+
let delete_e = [];
|
|
483
|
+
for (let event of this.events(ds.delta().matches())) {
|
|
484
|
+
let existingMatch = ds.after().match(event.matchId());
|
|
485
|
+
if (existingMatch != null && existingMatch.hasEvent(event.id())) {
|
|
486
|
+
update.push(event);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
delete_e.push(event);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (delete_e.length != 0) {
|
|
493
|
+
let dm = new DeleteEvent(ds.after(), delete_e);
|
|
494
|
+
this._handler.onDeleteEvent(dm);
|
|
495
|
+
}
|
|
496
|
+
if (update.length != 0) {
|
|
497
|
+
let um = new UpdateEvent(ds.after(), update);
|
|
498
|
+
this._handler.onUpdateEvent(um);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
pushDeleteOdd(ds) {
|
|
502
|
+
let records = this.records(this.events(ds.delta().matches()));
|
|
503
|
+
if (records.length > 0) {
|
|
504
|
+
let delo = new DeleteOdd(ds.after(), records);
|
|
505
|
+
this._handler.onDeleteOdd(delo);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
pushReset(out) {
|
|
509
|
+
let partitions = out.delta().getPartitions().toArray();
|
|
510
|
+
let reset = new Reset(out.after(), partitions);
|
|
511
|
+
this._handler.onReset(reset);
|
|
512
|
+
}
|
|
513
|
+
events(matches) {
|
|
514
|
+
let events = [];
|
|
515
|
+
for (let m of matches) {
|
|
516
|
+
for (let e of m.events()) {
|
|
517
|
+
events.push(e);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return events;
|
|
521
|
+
}
|
|
522
|
+
records(events) {
|
|
523
|
+
let records = [];
|
|
524
|
+
for (let e of events) {
|
|
525
|
+
for (let r of e.records()) {
|
|
526
|
+
records.push(r);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return records;
|
|
530
|
+
}
|
|
531
|
+
states(events) {
|
|
532
|
+
let states = [];
|
|
533
|
+
for (let e of events) {
|
|
534
|
+
for (let es of e.eventStates()) {
|
|
535
|
+
states.push(es);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return states;
|
|
539
|
+
}
|
|
540
|
+
isSame(lhs, rhs) {
|
|
541
|
+
return lhs.id() == rhs.id();
|
|
542
|
+
}
|
|
543
|
+
isInitialized() {
|
|
544
|
+
return this._fsRepo.isReady(this.stream());
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
MemoryDispatcher.MEMORY_STREAM = "MEMORY_AGGREGATED_STREAM";
|
|
548
|
+
MemoryDispatcher = MemoryDispatcher_1 = __decorate([
|
|
549
|
+
(0, injection_js_1.Injectable)(),
|
|
550
|
+
__metadata("design:paramtypes", [Object, message_class_1.SportsFeedMessageGroup, Object])
|
|
551
|
+
], MemoryDispatcher);
|
|
552
|
+
exports.MemoryDispatcher = MemoryDispatcher;
|
|
553
|
+
let SportsFeedClient = class SportsFeedClient {
|
|
554
|
+
constructor(grp, fsRepo, epgm, subscriber, eventHandler, inProcessor) {
|
|
555
|
+
this._subscriber = subscriber;
|
|
556
|
+
this._epgm = epgm;
|
|
557
|
+
this._eventHandler = eventHandler;
|
|
558
|
+
this.configureEventHandler(eventHandler);
|
|
559
|
+
this._fsRepo = fsRepo;
|
|
560
|
+
this._grp = grp;
|
|
561
|
+
this._views = new Set();
|
|
562
|
+
this._viewTemplate = this.view();
|
|
563
|
+
this._viewTemplate.register(this);
|
|
564
|
+
let instance = this;
|
|
565
|
+
this.resolverMap = new Collections.Dictionary();
|
|
566
|
+
this.filterRequestCounter = 0;
|
|
567
|
+
inProcessor.startTtlVerification();
|
|
568
|
+
}
|
|
569
|
+
subscriber() {
|
|
570
|
+
return this._subscriber;
|
|
571
|
+
}
|
|
572
|
+
epgm() {
|
|
573
|
+
return this._epgm;
|
|
574
|
+
}
|
|
575
|
+
InEndPointEventHandler() {
|
|
576
|
+
return this._eventHandler;
|
|
577
|
+
}
|
|
578
|
+
fsRepo() {
|
|
579
|
+
return this._fsRepo;
|
|
580
|
+
}
|
|
581
|
+
grp() {
|
|
582
|
+
return this._grp;
|
|
583
|
+
}
|
|
584
|
+
eventHandler() {
|
|
585
|
+
return this._eventHandler;
|
|
586
|
+
}
|
|
587
|
+
eventListener(event) {
|
|
588
|
+
if (event instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionStart) {
|
|
589
|
+
let eve = event;
|
|
590
|
+
for (let streamId of eve.streams) {
|
|
591
|
+
console.log("ConsumptionsStartEvent for streams " + streamId + " from " + event.endPoint);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
else if (event instanceof jayeson_lib_delivery_1.Subscriber.Event.ConsumptionError) {
|
|
595
|
+
let eve = event;
|
|
596
|
+
for (let streamId of eve.streams) {
|
|
597
|
+
console.log("ConsumptionsStartEvent for streams " + streamId);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
console.log("Received event " + event + " from " + event.endPoint);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
configureEventHandler(eventHandler) {
|
|
605
|
+
this._subscriber.attachListener(eventHandler);
|
|
606
|
+
}
|
|
607
|
+
setUpStreamFilter(filterData) {
|
|
608
|
+
if (Object.keys(this._eventHandler.streamSources()).length === 0) {
|
|
609
|
+
let filterRequest = new codec_1.FilterRequest(codec_1.FilterRequest.IGNORED_REQUEST_ID, filterData);
|
|
610
|
+
this._eventHandler.updateFilter(filterRequest);
|
|
611
|
+
let resolver = null;
|
|
612
|
+
let filterResultReceived = new T.Promise((resolve, reject) => {
|
|
613
|
+
resolver = resolve;
|
|
614
|
+
});
|
|
615
|
+
resolver(true);
|
|
616
|
+
return filterResultReceived;
|
|
617
|
+
}
|
|
618
|
+
let requestId = this.filterRequestCounter++;
|
|
619
|
+
let filterRequest = new codec_1.FilterRequest(requestId, filterData);
|
|
620
|
+
let filterResultReceived = new T.Promise((resolve, reject) => {
|
|
621
|
+
this.resolverMap.setValue(requestId, resolve);
|
|
622
|
+
});
|
|
623
|
+
this._eventHandler.updateFilter(filterRequest);
|
|
624
|
+
return filterResultReceived;
|
|
625
|
+
}
|
|
626
|
+
getSubscriber() {
|
|
627
|
+
return this._subscriber;
|
|
628
|
+
}
|
|
629
|
+
start() {
|
|
630
|
+
this.getSubscriber().start();
|
|
631
|
+
}
|
|
632
|
+
view() {
|
|
633
|
+
let newView = new FeedView(this._epgm, this._fsRepo, this._grp);
|
|
634
|
+
this._views.add(newView);
|
|
635
|
+
return newView;
|
|
636
|
+
}
|
|
637
|
+
removeView(view) {
|
|
638
|
+
if (this._views.has(view)) {
|
|
639
|
+
view.cleanUp();
|
|
640
|
+
this._views.delete(view);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
onSwitchFilterFail(requestId) {
|
|
644
|
+
if (requestId != codec_1.FilterRequest.IGNORED_REQUEST_ID) {
|
|
645
|
+
this.resolverMap.remove(requestId)(false);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
onSwitchFilterStart(requestId) {
|
|
649
|
+
if (requestId != codec_1.FilterRequest.IGNORED_REQUEST_ID) {
|
|
650
|
+
this.resolverMap.remove(requestId)(true);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
onInsertMatch(insertMatch) {
|
|
654
|
+
}
|
|
655
|
+
onUpdateMatch(updateMatch) {
|
|
656
|
+
}
|
|
657
|
+
onDeleteMatch(deleteMatch) {
|
|
658
|
+
}
|
|
659
|
+
onInsertEvent(insertEvent) {
|
|
660
|
+
}
|
|
661
|
+
onUpdateEvent(updateEvent) {
|
|
662
|
+
}
|
|
663
|
+
onDeleteEvent(deleteEvent) {
|
|
664
|
+
}
|
|
665
|
+
onInsertOdd(insertOdd) {
|
|
666
|
+
}
|
|
667
|
+
onUpdateOdd(updateOdd) {
|
|
668
|
+
}
|
|
669
|
+
onDeleteOdd(deleteOdd) {
|
|
670
|
+
}
|
|
671
|
+
onReset(resetKeys) {
|
|
672
|
+
}
|
|
673
|
+
onSwitchFilterEnd() {
|
|
674
|
+
}
|
|
675
|
+
onFullSnapshotStart() {
|
|
676
|
+
}
|
|
677
|
+
onFullSnapshotEnd() {
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
SportsFeedClient = __decorate([
|
|
681
|
+
(0, injection_js_1.Injectable)(),
|
|
682
|
+
__param(1, (0, injection_js_1.Inject)(core_1.FSREPO_IMPL)),
|
|
683
|
+
__param(2, (0, injection_js_1.Inject)(dispatch_1.EPGM_IMPL)),
|
|
684
|
+
__metadata("design:paramtypes", [message_class_1.SportsFeedMessageGroup, Object, Object, jayeson_lib_delivery_1.Subscriber, receive_1.InEndPointEventHandler, receive_1.SportsFeedInProcessor])
|
|
685
|
+
], SportsFeedClient);
|
|
686
|
+
exports.SportsFeedClient = SportsFeedClient;
|