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
147 lines (127 loc) · 5.5 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { MeetingColors, MeetingColorsHex } from '../../../common/types/meeting-colors.types';
import { Logger, Observer } from '../../../common/utils';
import { DefaultRealtimeService, SlotColor } from './types';
export class RealtimeService implements DefaultRealtimeService {
protected readonly logger: Logger;
public participantObservers: Observer[];
public participants3DObservers: Observer[];
public participantsObserver: Observer;
public participantJoinedObserver: Observer;
public participantLeaveObserver: Observer;
public reconnectObserver: Observer;
public roomInfoUpdatedObserver: Observer;
public roomListUpdatedObserver: Observer;
public realtimeStateObserver: Observer;
public syncPropertiesObserver: Observer;
public kickAllParticipantsObserver: Observer;
public kickParticipantObserver: Observer;
public authenticationObserver: Observer;
public commentsObserver: Observer;
public presenceMouseObserver: Observer;
public privateModeWIOObserver: Observer;
public followWIOObserver: Observer;
public gatherWIOObserver: Observer;
public presenceMouseParticipantLeaveObserver: Observer;
public presenceMouseParticipantJoinedObserver: Observer;
public presenceSlotsInfosObserver: Observer;
public presence3dObserver: Observer;
public presence3dLeaveObserver: Observer;
public presence3dJoinedObserver: Observer;
public sameAccountObserver: Observer;
constructor() {
this.participantObservers = [];
this.participants3DObservers = [];
this.logger = new Logger('@superviz/sdk/realtime-service');
this.participantsObserver = new Observer({ logger: this.logger });
this.participantJoinedObserver = new Observer({ logger: this.logger });
this.participantLeaveObserver = new Observer({ logger: this.logger });
this.syncPropertiesObserver = new Observer({ logger: this.logger });
this.reconnectObserver = new Observer({ logger: this.logger });
this.sameAccountObserver = new Observer({ logger: this.logger });
// Room info observers helpers
this.roomInfoUpdatedObserver = new Observer({ logger: this.logger });
this.roomListUpdatedObserver = new Observer({ logger: this.logger });
this.realtimeStateObserver = new Observer({ logger: this.logger });
this.kickAllParticipantsObserver = new Observer({ logger: this.logger });
this.kickParticipantObserver = new Observer({ logger: this.logger });
this.authenticationObserver = new Observer({ logger: this.logger });
// Comments observer
this.commentsObserver = new Observer({ logger: this.logger });
// presence mouse
this.presenceMouseObserver = new Observer({ logger: this.logger });
// who is online
this.privateModeWIOObserver = new Observer({ logger: this.logger });
this.followWIOObserver = new Observer({ logger: this.logger });
this.gatherWIOObserver = new Observer({ logger: this.logger });
this.presenceMouseParticipantLeaveObserver = new Observer({ logger: this.logger });
this.presenceMouseParticipantJoinedObserver = new Observer({ logger: this.logger });
this.presenceSlotsInfosObserver = new Observer({ logger: this.logger });
// presence 3d
this.presence3dObserver = new Observer({ logger: this.logger });
this.presence3dLeaveObserver = new Observer({ logger: this.logger });
this.presence3dJoinedObserver = new Observer({ logger: this.logger });
}
/**
* @function subscribeToParticipantUpdate
* @description subscribe to a participant's events
* @param {string} participantId
* @param {Function} callback
* @returns {void}
*/
public subscribeToParticipantUpdate(participantId: string, callback: Function): void {
if (!this.participantObservers[participantId]) {
this.participantObservers[participantId] = new Observer({ logger: this.logger });
}
this.participantObservers[participantId].subscribe(callback);
}
/**
* @function unsubscribeFromParticipantUpdate
* @description unsubscribe to a participant's events
* @param {string} participantId
* @param {Function} callback
* @returns {void}
*/
public unsubscribeFromParticipantUpdate(participantId: string, callback: Function): void {
if (this.participantObservers[participantId]) {
this.participantObservers[participantId].unsubscribe(callback);
}
}
/**
* @function subscribeToParticipant3DUpdate
* @description subscribe to a participant's events
* @param {string} participantId
* @param {Function} callback
* @returns {void}
*/
public subscribeToParticipant3DUpdate(participantId: string, callback: Function): void {
if (!this.participants3DObservers[participantId]) {
this.participants3DObservers[participantId] = new Observer({ logger: this.logger });
}
this.participants3DObservers[participantId].subscribe(callback);
}
/**
* @function unsubscribeFromParticipantUpdate
* @description unsubscribe to a participant's events
* @param {string} participantId
* @param {Function} callback
* @returns {void}
*/
public unsubscribeFromParticipant3DUpdate(participantId: string, callback: Function): void {
if (this.participants3DObservers[participantId]) {
this.participants3DObservers[participantId].unsubscribe(callback);
}
}
/**
* @function getSlotColor
* @description get slot color string
* @returns {string}
* @param slotIndex
*/
public getSlotColor(slotIndex: number): SlotColor {
const index = slotIndex ?? MeetingColors.gray;
return {
color: MeetingColorsHex[index],
name: MeetingColors[index],
};
}
}