-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathsystem_killboard.js
More file actions
825 lines (725 loc) · 32.8 KB
/
system_killboard.js
File metadata and controls
825 lines (725 loc) · 32.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
/**
* System killboard module
*/
define([
'jquery',
'app/init',
'app/util',
'module/base',
'app/map/util'
], ($, Init, Util, BaseModule, MapUtil) => {
'use strict';
let SystemKillboardModule = class SystemKillboardModule extends BaseModule {
constructor(config = {}) {
super(Object.assign({}, new.target.defaultConfig, config));
}
/**
* module header
* @param text
* @returns {HTMLDivElement}
*/
newHeaderElement(text){
let headEl = super.newHeaderElement(text);
// WebSocket status
let wsStatusEl = Object.assign(document.createElement('h5'), {
className: this._config.wsStatusWrapperClass
});
this._iconWsEl = this.newIconElement([
'fa-circle', 'fa-fw', 'txt-color', this._config.wsStatusClass
]);
wsStatusEl.append(this._iconWsEl);
// toolbar
let toolbarEl = this.newHeadlineToolbarElement();
this._iconFilterEl = this.newIconElement([
'fa-filter', 'fa-fw',
this._config.moduleHeadlineIconClass
]);
let iconKbEl = this.newIconElement([
'fa-external-link-alt', 'fa-fw',
this._config.moduleHeadlineIconClass
]);
iconKbEl.setAttribute('title', 'zkillboard.com');
iconKbEl.onclick = e => this.openKillboardUrl(e);
toolbarEl.append(iconKbEl, this._iconFilterEl);
headEl.append(wsStatusEl, toolbarEl);
return headEl;
}
/**
* HTTP request
* @param url
* @returns {Promise}
*/
request(url){
return new Promise((resolve, reject) => {
let handleResponse = response => {
return response.json()
.then((json) => {
if(!response.ok){
return Promise.reject(Object.assign({}, json, {
status: response.status,
statusText: response.statusText,
}));
}
return json;
});
};
fetch(url)
.then(handleResponse)
.then((result) => {
resolve(result);
}).catch((e) => {
console.error(url, e);
let title = e.status ? e.status : e;
let text = e.error ? e.error : url;
this.showNotify({title: title, text: text, type: 'error'});
reject(e);
}).finally(() => {
$(this.moduleElement).hideLoadingAnimation();
});
});
}
/**
* get zKillboard data
* @returns {Promise}
*/
getSystemKillsData(){
// check for cached responses "short term cache"
let cacheKey = SystemKillboardModule.getCacheKey('systemId', this._systemData.systemId);
let result = SystemKillboardModule.getCache('zkb').get(cacheKey);
if(result){
// could also be an empty array!
return Promise.resolve(result);
}else{
return new Promise(resolve => {
$(this.moduleElement).showLoadingAnimation();
// get kills within the last 24h
let timeFrameInSeconds = 60 * 60 * 24;
// if system is w-space system -> add link modifier
let wSpaceLinkModifier = '';
if(this._systemData.type.id === 1){
wSpaceLinkModifier = 'w-space/';
}
let url = `${Init.url.zKillboard}/no-items/${wSpaceLinkModifier}no-attackers/npc/0/solarSystemID/${this._systemData.systemId}/pastSeconds/${timeFrameInSeconds}/`;
this.request(url).then(result => {
if(result.error){
// successful request with error response
this.showNotify({title: 'Data fetch() from zKillboard failed', text: result.error, type: 'error'});
return Promise.reject(result);
}else{
// zkb result needs to be cached and becomes reduced on "load more"
SystemKillboardModule.getCache('zkb').set(cacheKey, result);
return result;
}
}).then(result => resolve(result)).catch(e => {
console.error(e);
this.showNotify({title: 'Data fetch() from zKillboard failed', text: e, type: 'error'});
});
});
}
}
/**
* render module
* @param mapId
* @param systemData
* @returns {HTMLElement}
*/
render(mapId, systemData){
this._mapId = mapId;
this._systemData = systemData;
// request graph data and store result promise
// -> module is not full rendered jet
this._dataPromise = this.getSystemKillsData();
this._bodyEl = Object.assign(document.createElement('div'), {
className: this._config.bodyClassName
});
this.moduleElement.append(this._bodyEl);
this.setModuleObserver();
// init webSocket connection
SystemKillboardModule.initWebSocket();
return this.moduleElement;
}
/**
* init module
*/
init(){
super.init();
// subscribe this module instance to the zKB WebSocket
SystemKillboardModule.subscribeToWS(this);
this.updateWsStatus();
// show "historic" killmails
if(this._dataPromise instanceof Promise){
this._dataPromise
.then(result => {
this._killboardLabelEl = this.newLabelElement('recent kills within the last hour', [
'label-warning', this._config.labelRecentKillsClass, 'hidden'
]);
if(result.length){
// kills found
this._killboardEl = document.createElement('ul');
this._killboardEl.classList.add(this._config.systemKillboardListClass);
this._bodyEl.append(
this._killboardLabelEl,
this._killboardEl,
this.newControlElement('load more', [this._config.moduleHeadlineIconClass])
);
// set a "local" copy of all indexes from cached response
// -> this "local" array gets reduces when KM gets loaded
// -> manipulation does NOT affect cached data
this._tempZkbKillmailIndexes = Object.keys(result);
this.showKills(this._config.chunkCountKills);
}else{
// no kills found
this._bodyEl.append(
this.newLabelElement('No kills found within the last 24h', ['label-success'])
);
}
})
.catch(e => {
console.error(e);
});
}
}
beforeHide(){
super.beforeHide();
SystemKillboardModule.unsubscribeFromWS(this);
}
/**
* load a chunk of killmails and render them
* @param chunkSize
*/
showKills(chunkSize){
if(chunkSize){
let cacheKey = SystemKillboardModule.getCacheKey('systemId', this._systemData.systemId);
let result = SystemKillboardModule.getCache('zkb').get(cacheKey);
if(
this._killboardEl.children.length < this._config.maxCountKillHistoric &&
(this._tempZkbKillmailIndexes || []).length &&
(result || []).length
){
// next killmail to load -> reduce "local" index array
let nextZkb = result[this._tempZkbKillmailIndexes.shift()];
if(nextZkb){
this.loadKillmailData({
killId: parseInt(nextZkb.killmail_id) || 0,
hash: nextZkb.zkb.hash
}, {
chunkSize: --chunkSize,
zkb: nextZkb.zkb
}, 'renderKillmail');
}else{
console.warn('Killmail not found in local zkb cache');
}
}else{
// no more kills available OR max kills reached
this.moduleElement.querySelector('.' + this._config.controlAreaClass).style.display = 'none';
}
}
}
/**
* get killmail data from ESI
* @param requestData
* @param context
* @param callback
*/
loadKillmailData(requestData, context, callback){
let cacheKey = SystemKillboardModule.getCacheKey('killmail', requestData.killId);
let cacheItem = SystemKillboardModule.getCache('killmail').get(cacheKey);
if(cacheItem){
// ... already cached -> show cache killmail
this[callback](cacheItem.zkb, cacheItem.killmailData, cacheItem.systemData, context.chunkSize)
.then(payload => this.showKills(payload.data.chunkSize))
.catch(e => console.error(e));
}else{
// ...not cached -> request data
let url = 'https://esi.evetech.net/latest/killmails/' + requestData.killId + '/' + requestData.hash + '/';
this.request(url).then(killmailData => {
let systemData = SystemKillboardModule.getSystemDataForCache(this._systemData);
SystemKillboardModule.getCache('killmail').set(cacheKey, {zkb: context.zkb, killmailData: killmailData, systemData: systemData});
this[callback](context.zkb, killmailData, systemData, context.chunkSize)
.then(payload => this.showKills(payload.data.chunkSize))
.catch(e => console.error(e));
}).catch(e => {
// request failed -> skip this and load next
console.warn(e);
this.showKills(context.chunkSize);
});
}
}
/**
* @param zkb
* @param attackersCount
* @returns {{color: string, label: string}}
*/
getAttackerBadgeData(zkb, attackersCount){
let color, label;
if(zkb.solo){
color = '#5cb85c';
label = 'solo';
}else if(zkb.npc){
color = '#d747d6';
label = 'npc';
}else if(attackersCount){
color = '#adadad';
label = attackersCount;
}
return {color, label};
}
/**
* render a single killmail
* @param zkbData
* @param killmailData
* @param systemData
* @param chunkSize
* @param position
* @returns {Promise<any>}
*/
renderKillmail(zkbData, killmailData, systemData, chunkSize, position = 'bottom'){
return new Promise((resolve, reject) => {
if(!this._killboardEl){
// killboard element might not be rendered at this point (e.g. if new kills pushed to WS)
return reject(new ReferenceError('Could not render killmail. KB element not found.'));
}
// calculate time diff in hours
let serverDate = SystemKillboardModule.serverTime;
let serverHours = serverDate.setHours(0,0,0,0);
let killDate = Util.convertDateToUTC(new Date(killmailData.killmail_time));
// get time diff
let timeDiffMin = Math.round((serverDate - killDate) / 1000 / 60);
let timeDiffHour = Math.floor(timeDiffMin / 60);
let attackers = BaseModule.Util.getObjVal(killmailData, 'attackers') || [];
let attackersCount = attackers.length;
let attackerFinal = attackers.find(attacker => attacker.final_blow);
let data = {
zkb: zkbData,
killmail: killmailData,
system: systemData,
isPodKill: BaseModule.Util.getObjVal(killmailData, 'victim.ship_type_id') === 670, // POD shipId
attackersCount: attackersCount,
attackerFinal: attackerFinal,
attackerBadge: this.getAttackerBadgeData(zkbData, attackersCount),
config: this._config,
zKillboardUrl: 'https://zkillboard.com',
ccpImageServerUrl: Init.url.ccpImageServer,
imgUrlType: () => {
return (val, render) => this.getImageUrl('types', parseInt(render(val)) || 0, 64);
},
imgUrlChar: () => {
return (val, render) => this.getImageUrl('characters', parseInt(render(val)) || 0);
},
imgUrlCorp: () => {
return (val, render) => this.getImageUrl('corporations', parseInt(render(val)) || 0);
},
imgUrlAlly: () => {
return (val, render) => this.getImageUrl('alliances', parseInt(render(val)) || 0);
},
dateFormat: () => {
return (val, render) => {
let killDate = Util.convertDateToUTC(new Date(render(val)));
let value = Util.convertDateToString(killDate);
// check whether log is new (today) ->
if(killDate.setHours(0,0,0,0) === serverHours){
// replace dd/mm/YYYY
value = 'today' + value.substring(10);
}
return value;
};
},
iskFormat: () => {
return (val, render) => {
return Util.formatPrice(render(val));
};
},
};
requirejs(['text!templates/modules/killmail.html', 'mustache'], (template, Mustache) => {
// show hint for recent kills
this._killboardLabelEl.classList.toggle('hidden', !(timeDiffHour === 0 && this._killboardLabelEl));
// render killmail entry
let insertPos = ['append', 'beforeend'];
let animationPos = 'lastChild';
if(position === 'top'){
insertPos = ['prepend', 'afterbegin'];
animationPos = 'firstChild';
}
this._killboardEl.insertAdjacentHTML(insertPos[1], Mustache.render(template, data));
// animate kill li-element
$(this._killboardEl[animationPos]).velocity('transition.expandIn', {
display: 'flex',
complete: function(){
$(this).initTooltips();
}
}, {
display: 'flex'
});
resolve({
action: 'renderKillmail',
data: {
chunkSize: chunkSize
}
});
});
});
}
/**
* remove last killmail list entry
*/
removeKillmail(){
if(this._killboardEl){
let lastEl = this._nextToRemove || (this._listStreamHeadline ? this._listStreamHeadline.previousElementSibling : null) || this._killboardEl.lastChild;
if(lastEl){
this._nextToRemove = lastEl.previousElementSibling;
this._killboardEl.removeChild(lastEl);
}
}
}
/**
* get image src URL
* @param resourceType
* @param resourceId
* @param size
* @returns {string}
*/
getImageUrl(resourceType, resourceId, size = 32){
let url = '#';
if(resourceId){
url = BaseModule.Util.eveImageUrl(resourceType, resourceId, size);
}
return url;
}
/**
* Li headline (devider)
* @param text
* @returns {HTMLLIElement}
*/
newListItemHeadElement(text){
let listHeadEl = Object.assign(document.createElement('li'), {
className: ['flex-row', 'flex-between', 'media', this._config.systemKillboardListHeadClass].join(' ')
});
let iconDownEl = this.newIconElement(['fa-angle-double-down']);
let iconUpEl = this.newIconElement(['fa-angle-double-up']);
let headlineIconLeftEl = Object.assign(this.newHeadlineElement(), {
className: 'flex-col'
});
let headlineIconRightEl = Object.assign(this.newHeadlineElement(), {
className: 'flex-col'
});
headlineIconLeftEl.append(iconDownEl);
headlineIconRightEl.append(iconUpEl);
let headlineLeftEl = this.newHeadlineElement(text);
headlineLeftEl.classList.add('flex-col', 'flex-grow', 'media-body');
let headlineRightEl = this.newHeadlineElement('Killstream');
headlineRightEl.classList.add('flex-col', 'flex-grow', 'media-body', 'text-right');
listHeadEl.append(headlineIconLeftEl, headlineLeftEl, headlineRightEl, headlineIconRightEl);
return listHeadEl;
}
/**
* set module observer
*/
setModuleObserver(){
this.setFilterIconObserver();
$(this.moduleElement).initTooltips({
placement: 'top'
});
this.moduleElement.addEventListener('click', e => {
if(e.target.closest('.' + this._config.controlAreaClass)){
e.stopPropagation();
this.showKills(this._config.chunkCountKills);
}
});
}
/**
* init filter icon for WebSocket streams
*/
setFilterIconObserver(){
let cacheKey = `map_${this._mapId}.streams`;
this.getLocalStore().getItem(cacheKey).then(streams => {
if(!streams){
// not saved yet -> default streams
streams = ['system', 'map'];
this.getLocalStore().setItem(cacheKey, streams);
}
this._filterStreams = streams;
let sourceOptions = [{
value: 'system',
text: `System (${this._systemData.name})`
},{
value: 'map',
text: `Map (${BaseModule.Util.getObjVal(BaseModule.Util.getCurrentMapData(this._mapId), 'config.name')})`
},{
value: 'all',
text: `All (New Eden)`
}];
$(this._iconFilterEl).editable({
// toggle: 'manual',
mode: 'popup',
type: 'checklist',
showbuttons: false,
onblur: 'submit',
highlight: false,
title: 'Streams',
placement: 'left',
pk: this._mapId,
value: this._filterStreams,
source: sourceOptions,
emptyclass: '',
emptytext: '',
display: function(value, sourceData){
// update filter badge
if(
value && sourceData &&
value.length < sourceData.length
){
this.dataset.badge = String(value.length);
}else{
delete this.dataset.badge;
}
},
viewport: {
selector: this.moduleElement,
padding: 5
}
});
$(this._iconFilterEl).on('save', (e, params) => {
this.getLocalStore().setItem(cacheKey, params.newValue).then(streams => this._filterStreams = streams);
});
});
}
/**
* open external zKillboard URL
* @param e
*/
openKillboardUrl(e){
e.stopPropagation();
window.open(`//zkillboard.com/system/${this._systemData.systemId}`, '_blank');
}
/**
* check if killmailData matches any killStream
* @param killmailData
* @returns {boolean}
*/
filterKillmailByStreams(killmailData){
let streams = this._filterStreams || [];
return !!(streams.includes('all') ||
(streams.includes('system') && this._systemData.systemId === killmailData.solar_system_id) ||
(streams.includes('map') && MapUtil.getSystemData(this._mapId, killmailData.solar_system_id, 'systemId')));
}
/**
* callback for WebSocket responses
* @param zkbData
* @param killmailData
*/
onWsMessage(zkbData, killmailData){
// check if killmail belongs to current filtered "streams"
if(this.filterKillmailByStreams(killmailData)){
// check max limit for WS kill entries
this._countKillsWS = (this._countKillsWS || 0) + 1;
if(this._countKillsWS > this._config.maxCountKillsWS){
// remove oldest KM
this.removeKillmail();
}
// add headline before first WS killmail gets added to top
if(this._killboardEl && this._countKillsWS === 1){
this._listStreamHeadline = this.newListItemHeadElement(this._systemData.name);
this._killboardEl.prepend(this._listStreamHeadline);
}
// get systemData for killmailData
// -> systemData should exist if KM belongs to any system on any map
let systemData = MapUtil.getSystemData(this._mapId, killmailData.solar_system_id, 'systemId') || null;
this.renderKillmail(zkbData, killmailData, systemData, 0, 'top')
.catch(e => console.warn(e));
}
}
/**
* update module with current WebSocket status
*/
updateWsStatus(){
let isSuccess = false;
let isWarning = false;
let isError = false;
let title = 'unknown';
switch(SystemKillboardModule.wsStatus){
case 1: // connecting
title = 'connecting…';
isWarning = true;
break;
case 2: // connected
title = 'connected';
isSuccess = true;
break;
case 3: // error
title = 'error';
isError = true;
break;
case 4: // close
title = 'closed';
isError = true;
break;
}
this._iconWsEl.classList.toggle('txt-color-green', isSuccess);
this._iconWsEl.classList.toggle('txt-color-orange', isWarning);
this._iconWsEl.classList.toggle('txt-color-red', isError);
this._iconWsEl.setAttribute('title', title);
$(this._iconWsEl).destroyTooltips().initTooltips({
placement: 'top'
});
}
/**
* reduce full systemData to minimal data that should be cached with a KM
* @param systemData
* @returns {*}
*/
static getSystemDataForCache(systemData){
return systemData ? {id: systemData.systemId, name: systemData.name} : null;
}
/**
* get all systems from all maps, that might be relevant for any cache stream
* -> KMs belonging to any of these systems are cached
* @returns {Object}
*/
static getWsRelevantSystemsFromMaps(){
let cacheKey = SystemKillboardModule.getCacheKey('tempSystemsData', 1);
let systemsData = SystemKillboardModule.getCache('zkb').get(cacheKey);
if(!systemsData){
// KB cache ist for all maps (not just the current one)
let mapsData = BaseModule.Util.getCurrentMapData() || [];
systemsData = mapsData.reduce(
(accAll, mapData) => Object.assign(
accAll,
(BaseModule.Util.getObjVal(mapData, 'data.systems') || []).reduce(
(accMap, systemData) => Object.assign(
accMap,
{[systemData.systemId]: this.getSystemDataForCache(systemData)}
), {})
), {});
SystemKillboardModule.getCache('zkb').set(cacheKey, systemsData);
}
return systemsData;
}
/**
* cache WebSocket response if it is relevant for us
* @param response
* @returns {*[]}
*/
static cacheWsResponse(response){
let zkbData = response.zkb;
delete response.zkb;
let killmailData = response;
let systemData = null;
// check if killmailData is relevant (belongs to any system on any map
let systemsData = this.getWsRelevantSystemsFromMaps();
if(Object.keys(systemsData).map(systemId => parseInt(systemId)).includes(killmailData.solar_system_id)){
// system is on map! -> cache
systemData = BaseModule.Util.getObjVal(systemsData, String(killmailData.solar_system_id));
let cacheKey = SystemKillboardModule.getCacheKey('killmail', killmailData.killmail_id);
SystemKillboardModule.getCache('killmail').set(cacheKey, {
zkb: zkbData,
killmailData: killmailData,
systemData: systemData
});
}
return [zkbData, killmailData];
}
/**
* subscribe instance of Killboard module to WebSocket
* @param module
*/
static unsubscribeFromWS(module){
SystemKillboardModule.wsSubscribtions = SystemKillboardModule.wsSubscribtions.filter(subscriber => subscriber !== module);
}
/**
* unsubscribe instance of Killboard module to WebSocket
* @param module
*/
static subscribeToWS(module){
if(
!SystemKillboardModule.wsSubscribtions.includes(module) &&
module instanceof SystemKillboardModule
){
SystemKillboardModule.wsSubscribtions.push(module);
}
}
/**
* init/connect to WebSocket if not already done
*/
static initWebSocket(){
if(!SystemKillboardModule.ws){
SystemKillboardModule.ws = new WebSocket('wss://zkillboard.com/websocket/');
SystemKillboardModule.wsStatus = 1;
}
let sendMessage = req => {
SystemKillboardModule.ws.send(JSON.stringify(req));
};
SystemKillboardModule.ws.onopen = e => {
SystemKillboardModule.wsStatus = 2;
SystemKillboardModule.wsSubscribtions.forEach(subscriber => subscriber.updateWsStatus());
sendMessage({action:'sub', channel:'killstream'});
};
SystemKillboardModule.ws.onmessage = e => {
let response = JSON.parse(e.data);
let [zkbData, killmailData] = this.cacheWsResponse(response);
SystemKillboardModule.wsSubscribtions.forEach(subscriber => subscriber.onWsMessage(zkbData, killmailData));
};
SystemKillboardModule.ws.onerror = e => {
SystemKillboardModule.wsStatus = 3;
SystemKillboardModule.ws = null;
SystemKillboardModule.wsSubscribtions.forEach(subscriber => subscriber.updateWsStatus());
};
SystemKillboardModule.ws.onclose = e => {
SystemKillboardModule.wsStatus = 4;
SystemKillboardModule.ws = null;
SystemKillboardModule.wsSubscribtions.forEach(subscriber => subscriber.updateWsStatus());
};
}
/**
* get cache key
* @param type
* @param objId
* @returns {string}
*/
static getCacheKey(type, objId){
if(
typeof type === 'string' && type.length &&
parseInt(objId)
){
return `${type}_${objId}`;
}
throw new TypeError('Invalid cache key types');
}
};
SystemKillboardModule.isPlugin = false; // module is defined as 'plugin'
SystemKillboardModule.scope = 'system'; // module scope controls how module gets updated and what type of data is injected
SystemKillboardModule.sortArea = 'c'; // default sortable area
SystemKillboardModule.position = 1; // default sort/order position within sortable area
SystemKillboardModule.label = 'Killboard'; // static module label (e.g. description)
SystemKillboardModule.wsStatus = undefined;
SystemKillboardModule.serverTime = BaseModule.Util.getServerTime(); // static Date() with current EVE server time
SystemKillboardModule.wsSubscribtions = []; // static container for all KB module instances (from multiple maps) for WS responses
SystemKillboardModule.cacheConfig = {
zkb: { // cache for "zKillboard" responses -> short term cache
ttl: 60 * 3,
maxSize: 50
},
killmail: { // cache for "Killmail" data -> long term cache
ttl: 60 * 30,
maxSize: 500
}
};
SystemKillboardModule.defaultConfig = {
className: 'pf-system-killboard-module', // class for module
sortTargetAreas: ['a', 'b', 'c'], // sortable areas where module can be dragged into
headline: 'Killboard',
// system killboard list
systemKillboardListClass: 'pf-system-killboard-list', // class for a list with kill entries
systemKillboardListHeadClass: 'pf-system-killboard-list-head', // class for a list entry headline
systemKillboardListImgL: 'pf-system-killboard-img-l', // class for all large centered img (ship images)
systemKillboardListImgM: 'pf-system-killboard-img-m', // class for all medium centered img (character logos)
systemKillboardListImgS: 'pf-system-killboard-img-s', // class for all small top/bottom img (alliance/corp logos)
wsStatusWrapperClass: 'pf-system-killboard-wsStatusWrapper', // class for WebSocket "status" wrapper
wsStatusClass: 'pf-system-killboard-wsStatus', // class for WebSocket "status" headline
labelRecentKillsClass: 'pf-system-killboard-label-recent', // class for "recent kills" label
minCountKills: 5,
chunkCountKills: 5,
maxCountKillHistoric: 43,
maxCountKillsWS: 150
};
return SystemKillboardModule;
});