This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
71 lines (59 loc) · 2.38 KB
/
index.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
import { MeetingConnectionStatus } from '../../common/types/events.types';
import { Logger, Observer } from '../../common/utils';
import { DefaultConnectionService, WindowConnectionStatus } from './types';
export class ConnectionService implements DefaultConnectionService {
private readonly logger: Logger;
public connectionStatus: MeetingConnectionStatus;
public oldConnectionStatus: MeetingConnectionStatus;
public connectionStatusObserver: Observer;
constructor() {
this.logger = new Logger('@superviz/sdk/connection-service');
this.connectionStatus = MeetingConnectionStatus.NOT_AVAILABLE;
this.connectionStatusObserver = new Observer({ logger: this.logger });
}
/**
* @function addListeners
* @description add browser listeners to connection status
* @returns {void}
*/
public addListeners(): void {
window.addEventListener('online', this.onUpdateBrowserOnlineStatus);
window.addEventListener('offline', this.onUpdateBrowserOnlineStatus);
}
/**
* @function removeListeners
* @description remove browser listeners to connection status
* @returns {void}
*/
public removeListeners(): void {
window.removeEventListener('online', this.onUpdateBrowserOnlineStatus);
window.removeEventListener('offline', this.onUpdateBrowserOnlineStatus);
}
/**
* @function updateMeetingConnectionStatus
* @description update connection status of audio/video services in ConnectionService
* @param {MeetingConnectionStatus} newStatus - new connection status
* @returns {void}
*/
public updateMeetingConnectionStatus = (newStatus: MeetingConnectionStatus): void => {
this.oldConnectionStatus = this.connectionStatus;
this.connectionStatus = newStatus;
this.connectionStatusObserver.publish(newStatus);
this.logger.log('CONNECTION STATUS CHANGE', newStatus);
};
/**
* @function onUpdateBrowserOnlineStatus
* @description updates connection status based on browser connection status
* @param {Event} event - DOM Event
* @returns {void}
*/
private onUpdateBrowserOnlineStatus = (event: Event): void => {
const { type } = event;
const status: WindowConnectionStatus = type as WindowConnectionStatus;
if (status === 'online') {
this.updateMeetingConnectionStatus(MeetingConnectionStatus.GOOD);
return;
}
this.updateMeetingConnectionStatus(MeetingConnectionStatus.DISCONNECTED);
};
}