-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathDefaultHandshakeSupport.ts
More file actions
40 lines (35 loc) · 1.31 KB
/
DefaultHandshakeSupport.ts
File metadata and controls
40 lines (35 loc) · 1.31 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
import { WebConnectionProtocol6Goodbye } from '@kite9/fdc3-schema/generated/api/BrowserTypes';
import { HeartbeatListener } from '../listeners/HeartbeatListener';
import { Messaging } from '../Messaging';
import { HandshakeSupport } from './HandshakeSupport';
import { ImplementationMetadata } from '@kite9/fdc3-standard';
/**
* Handles connection, disconnection and heartbeats for the proxy.
* This will possibly eventually need extending to allow for auth handshaking.
*/
export class DefaultHandshakeSupport implements HandshakeSupport {
readonly messaging: Messaging;
private heartbeatListener: HeartbeatListener | null = null;
constructor(messaging: Messaging) {
this.messaging = messaging;
}
async connect(): Promise<void> {
await this.messaging.connect();
this.heartbeatListener = new HeartbeatListener(this.messaging);
this.heartbeatListener.register();
}
async disconnect(): Promise<void> {
await this.heartbeatListener?.unsubscribe();
const message: WebConnectionProtocol6Goodbye = {
type: 'WCP6Goodbye',
meta: {
timestamp: new Date(),
},
};
await this.messaging.post(message);
return this.messaging.disconnect();
}
async getImplementationMetadata(): Promise<ImplementationMetadata> {
return this.messaging.getImplementationMetadata();
}
}