@observertc/observer-js 0.42.8 → 1.0.1-23e88d8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +0 -104
  3. package/lib/ObservedCall.d.ts +25 -41
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +61 -109
  6. package/lib/ObservedCertificate.d.ts +19 -0
  7. package/lib/ObservedCertificate.d.ts.map +1 -0
  8. package/lib/ObservedCertificate.js +38 -0
  9. package/lib/ObservedClient.d.ts +33 -143
  10. package/lib/ObservedClient.d.ts.map +1 -1
  11. package/lib/ObservedClient.js +156 -757
  12. package/lib/ObservedCodec.d.ts +22 -0
  13. package/lib/ObservedCodec.d.ts.map +1 -0
  14. package/lib/ObservedCodec.js +45 -0
  15. package/lib/ObservedDataChannel.d.ts +20 -70
  16. package/lib/ObservedDataChannel.d.ts.map +1 -1
  17. package/lib/ObservedDataChannel.js +39 -109
  18. package/lib/ObservedIceCandidate.d.ts +29 -0
  19. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  20. package/lib/ObservedIceCandidate.js +59 -0
  21. package/lib/ObservedIceCandidatePair.d.ts +40 -0
  22. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  23. package/lib/ObservedIceCandidatePair.js +83 -0
  24. package/lib/ObservedIceTransport.d.ts +32 -0
  25. package/lib/ObservedIceTransport.d.ts.map +1 -0
  26. package/lib/ObservedIceTransport.js +65 -0
  27. package/lib/ObservedInboundRtp.d.ts +92 -0
  28. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  29. package/lib/ObservedInboundRtp.js +193 -0
  30. package/lib/ObservedInboundTrack.d.ts +29 -0
  31. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  32. package/lib/ObservedInboundTrack.js +57 -0
  33. package/lib/ObservedMediaPlayout.d.ts +22 -0
  34. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  35. package/lib/ObservedMediaPlayout.js +42 -0
  36. package/lib/ObservedMediaSource.d.ts +28 -0
  37. package/lib/ObservedMediaSource.d.ts.map +1 -0
  38. package/lib/ObservedMediaSource.js +55 -0
  39. package/lib/ObservedOutboundRtp.d.ts +62 -0
  40. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  41. package/lib/ObservedOutboundRtp.js +144 -0
  42. package/lib/ObservedOutboundTrack.d.ts +29 -0
  43. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  44. package/lib/ObservedOutboundTrack.js +57 -0
  45. package/lib/ObservedPeerConnection.d.ts +118 -78
  46. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  47. package/lib/ObservedPeerConnection.js +556 -359
  48. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  49. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  50. package/lib/ObservedPeerConnectionTransport.js +34 -0
  51. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  52. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  53. package/lib/ObservedRemoteInboundRtp.js +60 -0
  54. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  55. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  56. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  57. package/lib/Observer.d.ts +30 -53
  58. package/lib/Observer.d.ts.map +1 -1
  59. package/lib/Observer.js +52 -225
  60. package/lib/common/Middleware.d.ts +10 -1
  61. package/lib/common/Middleware.d.ts.map +1 -1
  62. package/lib/common/Middleware.js +55 -36
  63. package/lib/common/logger.d.ts +8 -4
  64. package/lib/common/logger.d.ts.map +1 -1
  65. package/lib/common/logger.js +44 -68
  66. package/lib/common/types.d.ts +0 -21
  67. package/lib/common/types.d.ts.map +1 -1
  68. package/lib/common/types.js +1 -0
  69. package/lib/common/utils.d.ts +1 -0
  70. package/lib/common/utils.d.ts.map +1 -1
  71. package/lib/common/utils.js +13 -1
  72. package/lib/detectors/Detector.d.ts +5 -0
  73. package/lib/detectors/Detector.d.ts.map +1 -0
  74. package/lib/detectors/Detector.js +3 -0
  75. package/lib/detectors/Detectors.d.ts +11 -0
  76. package/lib/detectors/Detectors.d.ts.map +1 -0
  77. package/lib/detectors/Detectors.js +34 -0
  78. package/lib/index.d.ts +23 -24
  79. package/lib/index.d.ts.map +1 -1
  80. package/lib/index.js +41 -41
  81. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  82. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  83. package/lib/monitors/TurnUsageMonitor.js +145 -120
  84. package/lib/schema/ClientEventTypes.d.ts +33 -0
  85. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  86. package/lib/schema/ClientEventTypes.js +38 -0
  87. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  88. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  89. package/lib/schema/ClientMetaTypes.js +16 -0
  90. package/lib/schema/ClientSample.d.ts +1333 -0
  91. package/lib/schema/ClientSample.d.ts.map +1 -0
  92. package/lib/schema/ClientSample.js +4 -0
  93. package/lib/scores/CalculatedScore.d.ts +6 -0
  94. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  95. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  96. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  97. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  98. package/lib/scores/ScoreCalculator.d.ts +4 -0
  99. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  100. package/lib/scores/ScoreCalculator.js +2 -0
  101. package/lib/utils/CallUpdater.d.ts +5 -0
  102. package/lib/utils/CallUpdater.d.ts.map +1 -0
  103. package/lib/utils/CallUpdater.js +2 -0
  104. package/lib/utils/OnAllClientCallUpdater.d.ts +16 -0
  105. package/lib/utils/OnAllClientCallUpdater.d.ts.map +1 -0
  106. package/lib/utils/OnAllClientCallUpdater.js +58 -0
  107. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  108. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  109. package/lib/utils/RemoteTrackResolver.js +2 -0
  110. package/lib/utils/onAnyClientCallUpdater.d.ts +14 -0
  111. package/lib/utils/onAnyClientCallUpdater.d.ts.map +1 -0
  112. package/lib/utils/onAnyClientCallUpdater.js +51 -0
  113. package/package.json +4 -4
  114. package/src/ObservedCall.ts +74 -167
  115. package/src/ObservedCertificate.ts +43 -0
  116. package/src/ObservedClient.ts +173 -1083
  117. package/src/ObservedCodec.ts +49 -0
  118. package/src/ObservedDataChannel.ts +36 -178
  119. package/src/ObservedIceCandidate.ts +64 -0
  120. package/src/ObservedIceCandidatePair.ts +92 -0
  121. package/src/ObservedIceTransport.ts +70 -0
  122. package/src/ObservedInboundRtp.ts +205 -0
  123. package/src/ObservedInboundTrack.ts +70 -0
  124. package/src/ObservedMediaPlayout.ts +49 -0
  125. package/src/ObservedMediaSource.ts +60 -0
  126. package/src/ObservedOutboundRtp.ts +156 -0
  127. package/src/ObservedOutboundTrack.ts +69 -0
  128. package/src/ObservedPeerConnection.ts +743 -401
  129. package/src/ObservedPeerConnectionTransport.ts +38 -0
  130. package/src/ObservedRemoteInboundRtp.ts +64 -0
  131. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  132. package/src/Observer.ts +65 -285
  133. package/src/common/Middleware.ts +70 -42
  134. package/src/common/logger.ts +60 -69
  135. package/src/common/types.ts +0 -42
  136. package/src/common/utils.ts +12 -0
  137. package/src/detectors/Detector.ts +6 -0
  138. package/src/detectors/Detectors.ts +38 -0
  139. package/src/index.ts +23 -87
  140. package/src/monitors/TurnUsageMonitor.ts +164 -164
  141. package/src/schema/ClientEventTypes.ts +36 -0
  142. package/src/schema/ClientMetaTypes.ts +41 -0
  143. package/src/schema/ClientSample.ts +1682 -0
  144. package/src/scores/CalculatedScore.ts +6 -0
  145. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  146. package/src/scores/ScoreCalculator.ts +3 -0
  147. package/src/utils/CallUpdater.ts +5 -0
  148. package/src/utils/OnAllClientCallUpdater.ts +68 -0
  149. package/src/utils/RemoteTrackResolver.ts +12 -0
  150. package/src/utils/onAnyClientCallUpdater.ts +59 -0
  151. package/tsconfig.json +3 -3
  152. package/lib/ObservedICE.d.ts +0 -64
  153. package/lib/ObservedICE.d.ts.map +0 -1
  154. package/lib/ObservedICE.js +0 -141
  155. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  156. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  157. package/lib/ObservedInboundAudioTrack.js +0 -217
  158. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  159. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  160. package/lib/ObservedInboundVideoTrack.js +0 -232
  161. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  162. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  163. package/lib/ObservedOutboundAudioTrack.js +0 -186
  164. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  165. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  166. package/lib/ObservedOutboundVideoTrack.js +0 -193
  167. package/lib/ObservedSfu.d.ts +0 -59
  168. package/lib/ObservedSfu.d.ts.map +0 -1
  169. package/lib/ObservedSfu.js +0 -157
  170. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  171. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  172. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  173. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  174. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  175. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  176. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  177. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  178. package/lib/ObservedSfuSctpChannel.js +0 -57
  179. package/lib/ObservedSfuTransport.d.ts +0 -58
  180. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  181. package/lib/ObservedSfuTransport.js +0 -120
  182. package/lib/RemoteTrackAssigner.d.ts +0 -14
  183. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  184. package/lib/RemoteTrackAssigner.js +0 -52
  185. package/lib/ReportsCollector.d.ts +0 -109
  186. package/lib/ReportsCollector.d.ts.map +0 -1
  187. package/lib/ReportsCollector.js +0 -207
  188. package/lib/common/CalculatedScore.d.ts +0 -80
  189. package/lib/common/CalculatedScore.d.ts.map +0 -1
  190. package/lib/common/CalculatedScore.js +0 -162
  191. package/lib/common/CallEventType.d.ts +0 -63
  192. package/lib/common/CallEventType.d.ts.map +0 -1
  193. package/lib/common/CallEventType.js +0 -39
  194. package/lib/common/CallMetaReports.d.ts +0 -42
  195. package/lib/common/CallMetaReports.d.ts.map +0 -1
  196. package/lib/common/CallMetaReports.js +0 -36
  197. package/lib/common/QualityScoreUtils.d.ts +0 -1
  198. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  199. package/lib/common/QualityScoreUtils.js +0 -1
  200. package/lib/common/TypedEventEmitter.d.ts +0 -22
  201. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  202. package/lib/common/TypedEventEmitter.js +0 -11
  203. package/lib/common/callEventReports.d.ts +0 -10
  204. package/lib/common/callEventReports.d.ts.map +0 -1
  205. package/lib/common/callEventReports.js +0 -112
  206. package/lib/monitors/CallSummary.d.ts +0 -37
  207. package/lib/monitors/CallSummary.d.ts.map +0 -1
  208. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  209. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  210. package/lib/monitors/CallSummaryMonitor.js +0 -152
  211. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  212. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  213. package/lib/monitors/ClientIssueMonitor.js +0 -49
  214. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  215. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  216. package/lib/monitors/SfuServerMonitor.js +0 -198
  217. package/src/ObservedICE.ts +0 -237
  218. package/src/ObservedInboundAudioTrack.ts +0 -344
  219. package/src/ObservedInboundVideoTrack.ts +0 -361
  220. package/src/ObservedOutboundAudioTrack.ts +0 -307
  221. package/src/ObservedOutboundVideoTrack.ts +0 -319
  222. package/src/ObservedSfu.ts +0 -231
  223. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  224. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  225. package/src/ObservedSfuSctpChannel.ts +0 -103
  226. package/src/ObservedSfuTransport.ts +0 -185
  227. package/src/RemoteTrackAssigner.ts +0 -68
  228. package/src/ReportsCollector.ts +0 -336
  229. package/src/common/CalculatedScore.ts +0 -188
  230. package/src/common/CallEventType.ts +0 -69
  231. package/src/common/CallMetaReports.ts +0 -82
  232. package/src/common/QualityScoreUtils.ts +0 -0
  233. package/src/common/TypedEventEmitter.ts +0 -32
  234. package/src/common/callEventReports.ts +0 -178
  235. package/src/monitors/CallSummary.ts +0 -38
  236. package/src/monitors/CallSummaryMonitor.ts +0 -192
  237. package/src/monitors/ClientIssueMonitor.ts +0 -88
  238. package/src/monitors/SfuServerMonitor.ts +0 -285
  239. /package/lib/{monitors/CallSummary.js → scores/CalculatedScore.js} +0 -0
@@ -1,32 +0,0 @@
1
- import EventEmitter from 'events';
2
-
3
- export type EventMap = {
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- [key: string]: [...unknown[]]
6
- }
7
-
8
- export function createTypedEventEmitter<Events extends EventMap>() {
9
- return new EventEmitter() as TypedEventEmitter<Events>;
10
- }
11
-
12
- export interface TypedEventEmitter<Events extends EventMap> {
13
- addListener<E extends keyof Events> (event: E, listener: (...data: Events[E]) => void): this
14
- on<E extends keyof Events> (event: E, listener: (...data: Events[E]) => void): this
15
- once<E extends keyof Events> (event: E, listener: (...data: Events[E]) => void): this
16
- prependListener<E extends keyof Events> (event: E, listener: (...data: Events[E]) => void): this
17
- prependOnceListener<E extends keyof Events> (event: E, listener: (...data: Events[E]) => void): this
18
-
19
- off<E extends keyof Events>(event: E, listener: (...data: Events[E]) => void): this
20
- removeAllListeners<E extends keyof Events> (event?: E): this
21
- removeListener<E extends keyof Events> (event: E, listener: (...data: Events[E]) => void): this
22
-
23
- emit<E extends keyof Events> (event: E, ...args: Events[E]): boolean
24
- // The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5
25
- eventNames(): (keyof Events | string | symbol)[]
26
- rawListeners<E extends keyof Events> (event: E): ((...data: Events[E]) => void)[]
27
- listeners<E extends keyof Events> (event: E): ((...data: Events[E]) => void)[]
28
- listenerCount<E extends keyof Events> (event: E): number
29
-
30
- getMaxListeners (): number
31
- setMaxListeners (maxListeners: number): this
32
- }
@@ -1,178 +0,0 @@
1
- import { CallEventReport } from '@observertc/report-schemas-js';
2
- import { CallEventType } from './CallEventType';
3
-
4
- export function createCallStartedEventReport(
5
- serviceId: string,
6
- roomId: string,
7
- callId: string,
8
- timestamp: number,
9
- marker?: string
10
- ): CallEventReport {
11
- return {
12
- name: CallEventType.CALL_STARTED,
13
- serviceId,
14
- roomId,
15
- callId,
16
- timestamp,
17
- marker,
18
- };
19
- }
20
-
21
- export function createCallEndedEventReport(
22
- serviceId: string,
23
- roomId: string,
24
- callId: string,
25
- timestamp: number,
26
- marker?: string
27
- ): CallEventReport {
28
- return {
29
- name: CallEventType.CALL_ENDED,
30
- serviceId,
31
- roomId,
32
- callId,
33
- timestamp,
34
- marker,
35
- };
36
- }
37
-
38
- export function createClientJoinedEventReport(
39
- serviceId: string,
40
- mediaUnitId: string,
41
- roomId: string,
42
- callId: string,
43
- clientId: string,
44
- timestamp: number,
45
- userId?: string,
46
- marker?: string
47
- ): CallEventReport {
48
- return {
49
- name: CallEventType.CLIENT_JOINED,
50
- serviceId,
51
- mediaUnitId,
52
- roomId,
53
- callId,
54
- clientId,
55
- timestamp,
56
- userId,
57
- marker,
58
- };
59
- }
60
-
61
- export function createClientLeftEventReport(
62
- serviceId: string,
63
- mediaUnitId: string,
64
- roomId: string,
65
- callId: string,
66
- clientId: string,
67
- timestamp: number,
68
- userId?: string,
69
- marker?: string
70
- ): CallEventReport {
71
- return {
72
- name: CallEventType.CLIENT_LEFT,
73
- serviceId,
74
- mediaUnitId,
75
- roomId,
76
- callId,
77
- clientId,
78
- timestamp,
79
- userId,
80
- marker,
81
- };
82
- }
83
-
84
- export function createPeerConnectionOpenedEventReport(
85
- serviceId: string,
86
- mediaUnitId: string,
87
- roomId: string,
88
- callId: string,
89
- clientId: string,
90
- peerConnectionId: string,
91
- timestamp: number,
92
- marker?: string
93
- ): CallEventReport {
94
- return {
95
- name: CallEventType.PEER_CONNECTION_OPENED,
96
- serviceId,
97
- mediaUnitId,
98
- roomId,
99
- callId,
100
- clientId,
101
- peerConnectionId,
102
- timestamp,
103
- marker,
104
- };
105
- }
106
-
107
- export function createPeerConnectionClosedEventReport(
108
- serviceId: string,
109
- mediaUnitId: string,
110
- roomId: string,
111
- callId: string,
112
- clientId: string,
113
- peerConnectionId: string,
114
- timestamp: number,
115
- marker?: string
116
- ): CallEventReport {
117
- return {
118
- name: CallEventType.PEER_CONNECTION_CLOSED,
119
- serviceId,
120
- mediaUnitId,
121
- roomId,
122
- callId,
123
- clientId,
124
- peerConnectionId,
125
- timestamp,
126
- marker,
127
- };
128
- }
129
-
130
- export function createMediaTrackAddedEventReport(
131
- serviceId: string,
132
- mediaUnitId: string,
133
- roomId: string,
134
- callId: string,
135
- clientId: string,
136
- peerConnectionId: string,
137
- mediaTrackId: string,
138
- timestamp: number,
139
- marker?: string
140
- ): CallEventReport {
141
- return {
142
- name: CallEventType.MEDIA_TRACK_ADDED,
143
- serviceId,
144
- mediaUnitId,
145
- roomId,
146
- callId,
147
- clientId,
148
- peerConnectionId,
149
- mediaTrackId,
150
- timestamp,
151
- marker,
152
- };
153
- }
154
-
155
- export function createMediaTrackRemovedEventReport(
156
- serviceId: string,
157
- mediaUnitId: string,
158
- roomId: string,
159
- callId: string,
160
- clientId: string,
161
- peerConnectionId: string,
162
- mediaTrackId: string,
163
- timestamp: number,
164
- marker?: string
165
- ): CallEventReport {
166
- return {
167
- name: CallEventType.MEDIA_TRACK_REMOVED,
168
- serviceId,
169
- mediaUnitId,
170
- roomId,
171
- callId,
172
- clientId,
173
- peerConnectionId,
174
- mediaTrackId,
175
- timestamp,
176
- marker,
177
- };
178
- }
@@ -1,38 +0,0 @@
1
- export interface ClientIssue extends Record<string, unknown> {
2
- severity: 'critical' | 'major' | 'minor';
3
- timestamp: number;
4
- description?: string;
5
- peerConnectionId?: string,
6
- trackId?: string,
7
- attachments?: Record<string, unknown>,
8
- }
9
-
10
- export interface ClientSummary extends Record<string, unknown> {
11
- clientId: string;
12
- mediaUnitId: string;
13
- userId?: string;
14
- joined: number;
15
- left?: number;
16
- durationInMs: number;
17
- totalOutboundAudioBytes: number,
18
- totalOutboundVideoBytes: number,
19
- totalInboundAudioBytes: number,
20
- totalInboundVideoBytes: number,
21
- totalDataChannelBytesSent: number,
22
- totalDataChannelBytesReceived: number,
23
- ewmaRttInMs: number,
24
- usedTurn: boolean;
25
- issues: ClientIssue[];
26
- }
27
-
28
- export interface CallSummary extends Record<string, unknown> {
29
- serviceId: string;
30
- roomId: string;
31
- callId: string;
32
- started: number;
33
- durationInMs: number;
34
- maxNumberOfParticipants: number;
35
- numberOfIssues: number;
36
- highestSeverity?: ClientIssue['severity'],
37
- clients: ClientSummary[];
38
- }
@@ -1,192 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { CallSummary, ClientSummary } from './CallSummary';
3
- import { ObservedCall } from '../ObservedCall';
4
- import { ObservedClient } from '../ObservedClient';
5
- import { ObservedPeerConnection } from '../ObservedPeerConnection';
6
- import { ObservedOutboundVideoTrack } from '../ObservedOutboundVideoTrack';
7
-
8
- export type CallSummaryMonitorEvents = {
9
- close: [],
10
- summary: [CallSummary],
11
- }
12
-
13
- export type CallSummaryMonitorConfig = {
14
- detectUserMediaIssues?: boolean;
15
- detectMediaTrackQualityLimitationIssues?: boolean;
16
- }
17
-
18
- export declare interface CallSummaryMonitor {
19
- on<U extends keyof CallSummaryMonitorEvents>(event: U, listener: (...args: CallSummaryMonitorEvents[U]) => void): this;
20
- off<U extends keyof CallSummaryMonitorEvents>(event: U, listener: (...args: CallSummaryMonitorEvents[U]) => void): this;
21
- once<U extends keyof CallSummaryMonitorEvents>(event: U, listener: (...args: CallSummaryMonitorEvents[U]) => void): this;
22
- emit<U extends keyof CallSummaryMonitorEvents>(event: U, ...args: CallSummaryMonitorEvents[U]): boolean;
23
- }
24
-
25
- export class CallSummaryMonitor extends EventEmitter {
26
- private readonly _summaries = new Map<string, CallSummary>();
27
-
28
- private _closed = false;
29
- public constructor(
30
- public readonly config: CallSummaryMonitorConfig = {},
31
- ) {
32
- super();
33
- this.setMaxListeners(Infinity);
34
- }
35
-
36
- public addCall(call: ObservedCall) {
37
- if (this.closed) return;
38
-
39
- let callSummary: CallSummary | undefined = this._summaries.get(call.callId);
40
-
41
- if (!callSummary) {
42
- callSummary = {
43
- callId: call.callId,
44
- roomId: call.roomId,
45
- serviceId: call.serviceId,
46
- clients: [],
47
- durationInMs: 0,
48
- maxNumberOfParticipants: 0,
49
- numberOfIssues: 0,
50
- started: call.created,
51
- };
52
- this._summaries.set(call.callId, callSummary);
53
- }
54
- const constCallSummary = callSummary;
55
- const onNewClient = (client: ObservedClient) => {
56
- constCallSummary.maxNumberOfParticipants = Math.max(constCallSummary.maxNumberOfParticipants, call.clients.size);
57
- this._addClient(constCallSummary, client);
58
- };
59
-
60
- call.once('close', () => {
61
- call.off('newclient', onNewClient);
62
- });
63
- call.on('newclient', onNewClient);
64
- }
65
-
66
- private _addClient(callSummary: CallSummary, client: ObservedClient) {
67
- if (this.closed) return;
68
- const clientSummary: ClientSummary = {
69
- clientId: client.clientId,
70
- mediaUnitId: client.mediaUnitId,
71
- durationInMs: 0,
72
- totalInboundAudioBytes: 0,
73
- totalInboundVideoBytes: 0,
74
- totalOutboundAudioBytes: 0,
75
- totalOutboundVideoBytes: 0,
76
- totalDataChannelBytesSent: 0,
77
- totalDataChannelBytesReceived: 0,
78
- ewmaRttInMs: 0,
79
- joined: client.created,
80
- userId: client.userId,
81
- usedTurn: false,
82
- issues: [],
83
- };
84
-
85
- callSummary.clients.push(clientSummary);
86
-
87
- const updateClient = () => {
88
- if (client.avgRttInMs) {
89
- clientSummary.ewmaRttInMs = (clientSummary.ewmaRttInMs * 0.9) + (client.avgRttInMs * 0.1);
90
- }
91
- };
92
-
93
- const onUsingTurn = (usingTurn: boolean) => {
94
- clientSummary.usedTurn ||= usingTurn;
95
- };
96
-
97
- const onUserMediaError = (error: string) => {
98
- if (!this.config.detectUserMediaIssues) return;
99
-
100
- client.addIssue({
101
- severity: 'critical',
102
- timestamp: Date.now(),
103
- description: error,
104
- });
105
- };
106
-
107
- const onNewPeerConnection = (peerConnection: ObservedPeerConnection) => this._addPeerConnection(clientSummary, peerConnection);
108
-
109
- client.on('update', updateClient);
110
- client.on('usingturn', onUsingTurn);
111
- client.on('usermediaerror', onUserMediaError);
112
- client.on('newpeerconnection', onNewPeerConnection);
113
- client.once('close', () => {
114
- const now = Date.now();
115
-
116
- clientSummary.totalInboundAudioBytes = client.totalReceivedAudioBytes;
117
- clientSummary.totalInboundVideoBytes = client.totalReceivedVideoBytes;
118
- clientSummary.totalOutboundAudioBytes = client.totalSentAudioBytes;
119
- clientSummary.totalOutboundVideoBytes = client.totalSentVideoBytes;
120
- clientSummary.totalDataChannelBytesSent = client.totalDataChannelBytesSent;
121
- clientSummary.totalDataChannelBytesReceived = client.totalDataChannelBytesReceived;
122
- clientSummary.durationInMs = now - client.created;
123
- clientSummary.left = now;
124
- // client does not store issues after update emitted
125
- // clientSummary.issues.push(...client.issues);
126
-
127
- client.off('update', updateClient);
128
- client.off('usingturn', onUsingTurn);
129
- client.off('usermediaerror', onUserMediaError);
130
- client.off('newpeerconnection', onNewPeerConnection);
131
-
132
- callSummary.durationInMs += clientSummary.durationInMs;
133
- callSummary.numberOfIssues += clientSummary.issues.length;
134
- callSummary.highestSeverity = clientSummary.issues.reduce((highest, issue) => {
135
- if (issue.severity === 'critical') return 'critical';
136
- if (issue.severity === 'major' && highest !== 'critical') return 'major';
137
- if (issue.severity === 'minor' && highest !== 'critical' && highest !== 'major') return 'minor';
138
-
139
- return highest;
140
- }, callSummary.highestSeverity);
141
- });
142
- }
143
-
144
- private _addPeerConnection(clientSummary: ClientSummary, peerConnection: ObservedPeerConnection) {
145
- const onOutboundVideoTrack = (track: ObservedOutboundVideoTrack) => this._addOutboundVideoTrack(clientSummary, track);
146
-
147
- peerConnection.on('newoutboundvideotrack', onOutboundVideoTrack);
148
- peerConnection.once('close', () => {
149
- peerConnection.off('newoutboundvideotrack', onOutboundVideoTrack);
150
- });
151
- }
152
-
153
- private _addOutboundVideoTrack(clientSummary: ClientSummary, track: ObservedOutboundVideoTrack) {
154
- const onQualityLimitationChanged = (reason: string) => {
155
- if (!this.config.detectMediaTrackQualityLimitationIssues) return;
156
-
157
- track.peerConnection.client.addIssue({
158
- severity: 'minor',
159
- timestamp: Date.now(),
160
- description: reason,
161
- peerConnectionId: track.peerConnectionId,
162
- trackId: track.trackId,
163
- });
164
- };
165
-
166
- track.once('close', () => {
167
- track.off('qualitylimitationchanged', onQualityLimitationChanged);
168
- });
169
- track.on('qualitylimitationchanged', onQualityLimitationChanged);
170
- }
171
-
172
- public takeSummary(callId: string): CallSummary | undefined {
173
- if (this.closed) return;
174
-
175
- const summary = this._summaries.get(callId);
176
-
177
- this._summaries.delete(callId);
178
-
179
- return summary;
180
- }
181
-
182
- public get closed() {
183
- return this._closed;
184
- }
185
-
186
- public close() {
187
- if (this._closed) return;
188
- this._closed = true;
189
-
190
- this.emit('close');
191
- }
192
- }
@@ -1,88 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { ObservedCall } from '../ObservedCall';
3
- import { ObservedClient } from '../ObservedClient';
4
- import { ClientIssue } from './CallSummary';
5
-
6
- export type ClientIssueMonitorEmittedIssueEvent = ClientIssue & {
7
- clientId: string,
8
- callId: string,
9
- }
10
-
11
- export type ClientIssueMonitorEvents = {
12
- close: [],
13
- issue: [ClientIssueMonitorEmittedIssueEvent],
14
- major: [ClientIssueMonitorEmittedIssueEvent],
15
- minor: [ClientIssueMonitorEmittedIssueEvent],
16
- critical: [ClientIssueMonitorEmittedIssueEvent],
17
-
18
- }
19
-
20
- export type ClientIssueMonitorConfig = {
21
- // empty
22
- }
23
-
24
- export declare interface ClientIssueMonitor {
25
- on<U extends keyof ClientIssueMonitorEvents>(event: U, listener: (...args: ClientIssueMonitorEvents[U]) => void): this;
26
- off<U extends keyof ClientIssueMonitorEvents>(event: U, listener: (...args: ClientIssueMonitorEvents[U]) => void): this;
27
- once<U extends keyof ClientIssueMonitorEvents>(event: U, listener: (...args: ClientIssueMonitorEvents[U]) => void): this;
28
- emit<U extends keyof ClientIssueMonitorEvents>(event: U, ...args: ClientIssueMonitorEvents[U]): boolean;
29
- }
30
-
31
- export class ClientIssueMonitor extends EventEmitter {
32
- private _closed = false;
33
- public constructor(
34
- public readonly config: ClientIssueMonitorConfig = {},
35
- ) {
36
- super();
37
- this.setMaxListeners(Infinity);
38
- }
39
-
40
- public addCall(call: ObservedCall) {
41
- if (this.closed) return;
42
-
43
- const onNewClient = (client: ObservedClient) => {
44
- this._addClient(call, client);
45
- };
46
-
47
- call.once('close', () => {
48
- call.off('newclient', onNewClient);
49
- });
50
- call.on('newclient', onNewClient);
51
- }
52
-
53
- private _addClient(call: ObservedCall, client: ObservedClient) {
54
- if (this.closed) return;
55
- const {
56
- callId
57
- } = call;
58
- const {
59
- clientId
60
- } = client;
61
- const onIssue = (issue: ClientIssue) => {
62
- const event: ClientIssueMonitorEmittedIssueEvent = {
63
- ...issue,
64
- clientId,
65
- callId,
66
- };
67
-
68
- this.emit(issue.severity, event);
69
- this.emit('issue', event);
70
- };
71
-
72
- client.once('close', () => {
73
- client.off('issue', onIssue);
74
- });
75
- client.on('issue', onIssue);
76
- }
77
-
78
- public get closed() {
79
- return this._closed;
80
- }
81
-
82
- public close() {
83
- if (this._closed) return;
84
- this._closed = true;
85
-
86
- this.emit('close');
87
- }
88
- }