forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback-on.layes.ts
72 lines (69 loc) · 1.67 KB
/
callback-on.layes.ts
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
import { onMode } from '../model/enum';
import { sleep } from '../helpers';
/**
* attribution and behavior change of a given event
*/
export class CallbackOnStatus {
public statusFind: any;
constructor() {
this.statusFind = '';
}
/**
* waiting for event change
* @param event returns event status
*/
async onChange(event: (status: any) => void) {
let change = null;
while (true) {
if (this.statusFind !== change) {
change = this.statusFind;
event && event(change);
}
await sleep(50);
}
}
/**
* here you can monitor user events
* @param type types of monitoring
* @param callback returns of monitoring
*/
public async on(type: onMode, callback: (state: any) => void) {
switch (type) {
case onMode.interfaceChange:
this.onChange((event) => {
if (event.onType === onMode.interfaceChange) {
callback(event);
}
});
break;
case onMode.newOnAck:
this.onChange((event) => {
if (event.onType === onMode.newOnAck) {
callback(event);
}
});
break;
case onMode.newMessage:
this.onChange((event) => {
if (event.onType === onMode.newMessage) {
callback(event);
}
});
break;
case onMode.qrcode:
this.onChange((event) => {
if (event.onType === onMode.qrcode) {
callback(event);
}
});
break;
case onMode.connection:
this.onChange((event) => {
if (event.onType === onMode.connection) {
callback(event);
}
});
break;
}
}
}