forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeartbeatPlugin.ts
More file actions
26 lines (20 loc) · 791 Bytes
/
HeartbeatPlugin.ts
File metadata and controls
26 lines (20 loc) · 791 Bytes
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
import { IUserInfo } from '../../models/IUserInfo';
import { EventPluginContext } from '../EventPluginContext';
import { IEventPlugin } from '../IEventPlugin';
export class HeartbeatPlugin implements IEventPlugin {
public priority: number = 100;
public name: string = 'HeartbeatPlugin';
private _interval: number;
private _intervalId: any;
constructor(heartbeatInterval: number = 30000) {
this._interval = heartbeatInterval;
}
public run(context: EventPluginContext, next?: () => void): void {
clearInterval(this._intervalId);
const user: IUserInfo = context.event.data['@user'];
if (user && user.identity) {
this._intervalId = setInterval(() => context.client.submitSessionHeartbeat(user.identity), this._interval);
}
next && next();
}
}