-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
99 lines (89 loc) · 2.18 KB
/
types.ts
File metadata and controls
99 lines (89 loc) · 2.18 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
import { EventEmitter } from "events";
export class Session {
os: string
version: string
sessionId: string
beginDate: Date
expiryTime: number
expiryTimeout: NodeJS.Timeout
expiryEvent: EventEmitter = new EventEmitter()
isExpired: boolean = false
expiredDate: Date
/**
*
* @param os Version du système (darwin, win32, linux)
* @param version Version de NoxuNote
* @param sessionId Id de la session (nombre)
* @param expiryTime Nombre de min avant expiration de la session
*/
constructor(os: string, version: string, sessionId: string, expiryTime: number) {
this.os = os
this.version = version
this.sessionId = sessionId
this.expiryTime = expiryTime
this.beginDate = new Date()
this.expiryTimeout = setTimeout(() => this.expire(), this.expiryTime * 1000)
}
/**
* Updates session activity
*/
public update() {
clearTimeout(this.expiryTimeout)
this.expiryTimeout = setTimeout(() => this.expire(), this.expiryTime * 1000)
}
/**
* Set the function as expired
*/
public expire() {
this.expiryEvent.emit("expired")
this.isExpired = true
}
public getDuration(): number {
if (this.isExpired) {
return this.expiredDate.getTime() - this.beginDate.getTime()
} else {
return (new Date()).getTime() - this.beginDate.getTime()
}
}
static findInList(sessionList: Session[], sessionId: string): Session {
return sessionList.find(s => s.sessionId == sessionId)
}
}
export type BodyPacket = {
session: string,
os: string,
version: string,
type: string,
}
export type Rapport = {
stats: {
online: number,
total: number
bySystemActive: {
darwin: number,
win32: number,
linux: number
other: number
},
bySystemAll: {
darwin: number,
win32: number,
linux: number
other: number
},
byVersionActive: {version: string, count: number}[]
byVersionAll: {version: string, count: number}[]
byPeriod: {
today: number,
last24Hours: number
last48Hours: number
lastWeek: number
lastHour: number
}
}
system: {
cpuUsage: number,
memoryUsage: number,
BandwitchUsage: number
}
}