@observertc/observer-js 0.42.9 → 1.0.0-beta.2

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 (299) hide show
  1. package/.prettierrc +6 -6
  2. package/README.md +493 -63
  3. package/lib/ObservedCall.d.ts +64 -43
  4. package/lib/ObservedCall.d.ts.map +1 -1
  5. package/lib/ObservedCall.js +193 -107
  6. package/lib/ObservedCallEventMonitor.d.ts +104 -0
  7. package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
  8. package/lib/ObservedCallEventMonitor.js +314 -0
  9. package/lib/ObservedCallSummary.d.ts +18 -0
  10. package/lib/ObservedCallSummary.d.ts.map +1 -0
  11. package/lib/ObservedCertificate.d.ts +19 -0
  12. package/lib/ObservedCertificate.d.ts.map +1 -0
  13. package/lib/ObservedCertificate.js +38 -0
  14. package/lib/ObservedClient.d.ts +84 -136
  15. package/lib/ObservedClient.d.ts.map +1 -1
  16. package/lib/ObservedClient.js +594 -743
  17. package/lib/ObservedClientEventMonitor.d.ts +91 -0
  18. package/lib/ObservedClientEventMonitor.d.ts.map +1 -0
  19. package/lib/ObservedClientEventMonitor.js +254 -0
  20. package/lib/ObservedClientSummary.d.ts +23 -0
  21. package/lib/ObservedClientSummary.d.ts.map +1 -0
  22. package/lib/ObservedClientSummary.js +2 -0
  23. package/lib/ObservedCodec.d.ts +22 -0
  24. package/lib/ObservedCodec.d.ts.map +1 -0
  25. package/lib/ObservedCodec.js +45 -0
  26. package/lib/ObservedDataChannel.d.ts +25 -69
  27. package/lib/ObservedDataChannel.d.ts.map +1 -1
  28. package/lib/ObservedDataChannel.js +69 -109
  29. package/lib/ObservedIceCandidate.d.ts +29 -0
  30. package/lib/ObservedIceCandidate.d.ts.map +1 -0
  31. package/lib/ObservedIceCandidate.js +59 -0
  32. package/lib/ObservedIceCandidatePair.d.ts +45 -0
  33. package/lib/ObservedIceCandidatePair.d.ts.map +1 -0
  34. package/lib/ObservedIceCandidatePair.js +127 -0
  35. package/lib/ObservedIceTransport.d.ts +36 -0
  36. package/lib/ObservedIceTransport.d.ts.map +1 -0
  37. package/lib/ObservedIceTransport.js +93 -0
  38. package/lib/ObservedInboundRtp.d.ts +92 -0
  39. package/lib/ObservedInboundRtp.d.ts.map +1 -0
  40. package/lib/ObservedInboundRtp.js +193 -0
  41. package/lib/ObservedInboundTrack.d.ts +32 -0
  42. package/lib/ObservedInboundTrack.d.ts.map +1 -0
  43. package/lib/ObservedInboundTrack.js +60 -0
  44. package/lib/ObservedMediaPlayout.d.ts +22 -0
  45. package/lib/ObservedMediaPlayout.d.ts.map +1 -0
  46. package/lib/ObservedMediaPlayout.js +42 -0
  47. package/lib/ObservedMediaSource.d.ts +28 -0
  48. package/lib/ObservedMediaSource.d.ts.map +1 -0
  49. package/lib/ObservedMediaSource.js +55 -0
  50. package/lib/ObservedOutboundRtp.d.ts +62 -0
  51. package/lib/ObservedOutboundRtp.d.ts.map +1 -0
  52. package/lib/ObservedOutboundRtp.js +144 -0
  53. package/lib/ObservedOutboundTrack.d.ts +32 -0
  54. package/lib/ObservedOutboundTrack.d.ts.map +1 -0
  55. package/lib/ObservedOutboundTrack.js +60 -0
  56. package/lib/ObservedPeerConnection.d.ts +154 -80
  57. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  58. package/lib/ObservedPeerConnection.js +709 -357
  59. package/lib/ObservedPeerConnectionTransport.d.ts +17 -0
  60. package/lib/ObservedPeerConnectionTransport.d.ts.map +1 -0
  61. package/lib/ObservedPeerConnectionTransport.js +34 -0
  62. package/lib/ObservedRemoteInboundRtp.d.ts +30 -0
  63. package/lib/ObservedRemoteInboundRtp.d.ts.map +1 -0
  64. package/lib/ObservedRemoteInboundRtp.js +60 -0
  65. package/lib/ObservedRemoteOutboundRtp.d.ts +30 -0
  66. package/lib/ObservedRemoteOutboundRtp.d.ts.map +1 -0
  67. package/lib/ObservedRemoteOutboundRtp.js +60 -0
  68. package/lib/ObservedTURN.d.ts +31 -0
  69. package/lib/ObservedTURN.d.ts.map +1 -0
  70. package/lib/ObservedTURN.js +58 -0
  71. package/lib/ObservedTurnServer.d.ts +25 -0
  72. package/lib/ObservedTurnServer.d.ts.map +1 -0
  73. package/lib/ObservedTurnServer.js +59 -0
  74. package/lib/Observer.d.ts +49 -54
  75. package/lib/Observer.d.ts.map +1 -1
  76. package/lib/Observer.js +137 -226
  77. package/lib/ObserverEventMonitor.d.ts +138 -0
  78. package/lib/ObserverEventMonitor.d.ts.map +1 -0
  79. package/lib/ObserverEventMonitor.js +433 -0
  80. package/lib/ObserverSummary.d.ts +13 -0
  81. package/lib/ObserverSummary.d.ts.map +1 -0
  82. package/lib/ObserverSummary.js +2 -0
  83. package/lib/common/Middleware.d.ts +10 -1
  84. package/lib/common/Middleware.d.ts.map +1 -1
  85. package/lib/common/Middleware.js +55 -36
  86. package/lib/common/logger.d.ts +8 -4
  87. package/lib/common/logger.d.ts.map +1 -1
  88. package/lib/common/logger.js +44 -68
  89. package/lib/common/types.d.ts +0 -21
  90. package/lib/common/types.d.ts.map +1 -1
  91. package/lib/common/types.js +1 -0
  92. package/lib/common/utils.d.ts +3 -1
  93. package/lib/common/utils.d.ts.map +1 -1
  94. package/lib/common/utils.js +23 -3
  95. package/lib/detectors/Detector.d.ts +5 -0
  96. package/lib/detectors/Detector.d.ts.map +1 -0
  97. package/lib/detectors/Detector.js +3 -0
  98. package/lib/detectors/Detectors.d.ts +11 -0
  99. package/lib/detectors/Detectors.d.ts.map +1 -0
  100. package/lib/detectors/Detectors.js +34 -0
  101. package/lib/index.d.ts +26 -25
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +45 -41
  104. package/lib/mediasoup/ObservedMediaRouter.d.ts +10 -0
  105. package/lib/mediasoup/ObservedMediaRouter.d.ts.map +1 -0
  106. package/lib/mediasoup/ObservedMediaRouter.js +6 -0
  107. package/lib/monitors/TurnUsageMonitor.d.ts +0 -52
  108. package/lib/monitors/TurnUsageMonitor.d.ts.map +1 -1
  109. package/lib/monitors/TurnUsageMonitor.js +145 -120
  110. package/lib/schema/ClientEventTypes.d.ts +228 -0
  111. package/lib/schema/ClientEventTypes.d.ts.map +1 -0
  112. package/lib/schema/ClientEventTypes.js +41 -0
  113. package/lib/schema/ClientMetaTypes.d.ts +34 -0
  114. package/lib/schema/ClientMetaTypes.d.ts.map +1 -0
  115. package/lib/schema/ClientMetaTypes.js +16 -0
  116. package/lib/schema/ClientSample.d.ts +1333 -0
  117. package/lib/schema/ClientSample.d.ts.map +1 -0
  118. package/lib/schema/ClientSample.js +4 -0
  119. package/lib/scores/CalculatedScore.d.ts +6 -0
  120. package/lib/scores/CalculatedScore.d.ts.map +1 -0
  121. package/lib/scores/CalculatedScore.js +2 -0
  122. package/lib/scores/DefaultCallScoreCalculator.d.ts +7 -0
  123. package/lib/scores/DefaultCallScoreCalculator.d.ts.map +1 -0
  124. package/lib/scores/DefaultCallScoreCalculator.js +21 -0
  125. package/lib/scores/ScoreCalculator.d.ts +4 -0
  126. package/lib/scores/ScoreCalculator.d.ts.map +1 -0
  127. package/lib/scores/ScoreCalculator.js +2 -0
  128. package/lib/updaters/CallUpdater.d.ts +5 -0
  129. package/lib/updaters/CallUpdater.d.ts.map +1 -0
  130. package/lib/updaters/CallUpdater.js +2 -0
  131. package/lib/updaters/ObserverUpdater.d.ts +5 -0
  132. package/lib/updaters/ObserverUpdater.d.ts.map +1 -0
  133. package/lib/updaters/ObserverUpdater.js +2 -0
  134. package/lib/updaters/OnAllCallObserverUpdater.d.ts +15 -0
  135. package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
  136. package/lib/updaters/OnAllCallObserverUpdater.js +50 -0
  137. package/lib/updaters/OnAllClientCallUpdater.d.ts +15 -0
  138. package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -0
  139. package/lib/updaters/OnAllClientCallUpdater.js +53 -0
  140. package/lib/updaters/OnAnyCallObserverUpdater.d.ts +12 -0
  141. package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
  142. package/lib/updaters/OnAnyCallObserverUpdater.js +37 -0
  143. package/lib/updaters/OnAnyClientCallUpdater.d.ts +12 -0
  144. package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -0
  145. package/lib/updaters/OnAnyClientCallUpdater.js +36 -0
  146. package/lib/updaters/OnIntervalUpdater.d.ts +10 -0
  147. package/lib/updaters/OnIntervalUpdater.d.ts.map +1 -0
  148. package/lib/updaters/OnIntervalUpdater.js +17 -0
  149. package/lib/updaters/Updater.d.ts +6 -0
  150. package/lib/updaters/Updater.d.ts.map +1 -0
  151. package/lib/updaters/Updater.js +2 -0
  152. package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
  153. package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
  154. package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
  155. package/lib/utils/RemoteTrackResolver.d.ts +7 -0
  156. package/lib/utils/RemoteTrackResolver.d.ts.map +1 -0
  157. package/lib/utils/RemoteTrackResolver.js +2 -0
  158. package/package.json +4 -4
  159. package/src/ObservedCall.ts +281 -165
  160. package/src/ObservedCallEventMonitor.ts +392 -0
  161. package/src/ObservedCallSummary.ts +22 -0
  162. package/src/ObservedCertificate.ts +43 -0
  163. package/src/ObservedClient.ts +640 -1004
  164. package/src/ObservedClientEventMonitor.ts +309 -0
  165. package/src/ObservedClientSummary.ts +24 -0
  166. package/src/ObservedCodec.ts +49 -0
  167. package/src/ObservedDataChannel.ts +71 -181
  168. package/src/ObservedIceCandidate.ts +64 -0
  169. package/src/ObservedIceCandidatePair.ts +134 -0
  170. package/src/ObservedIceTransport.ts +99 -0
  171. package/src/ObservedInboundRtp.ts +205 -0
  172. package/src/ObservedInboundTrack.ts +75 -0
  173. package/src/ObservedMediaPlayout.ts +49 -0
  174. package/src/ObservedMediaSource.ts +60 -0
  175. package/src/ObservedOutboundRtp.ts +156 -0
  176. package/src/ObservedOutboundTrack.ts +74 -0
  177. package/src/ObservedPeerConnection.ts +917 -402
  178. package/src/ObservedPeerConnectionTransport.ts +38 -0
  179. package/src/ObservedRemoteInboundRtp.ts +64 -0
  180. package/src/ObservedRemoteOutboundRtp.ts +65 -0
  181. package/src/ObservedTURN.ts +86 -0
  182. package/src/ObservedTurnServer.ts +72 -0
  183. package/src/Observer.ts +186 -298
  184. package/src/ObserverEventMonitor.ts +551 -0
  185. package/src/ObserverSummary.ts +15 -0
  186. package/src/common/Middleware.ts +70 -42
  187. package/src/common/logger.ts +60 -69
  188. package/src/common/types.ts +0 -42
  189. package/src/common/utils.ts +24 -2
  190. package/src/detectors/Detector.ts +6 -0
  191. package/src/detectors/Detectors.ts +38 -0
  192. package/src/index.ts +26 -91
  193. package/src/mediasoup/ObservedMediaRouter.ts +10 -0
  194. package/src/monitors/TurnUsageMonitor.ts +164 -164
  195. package/src/schema/ClientEventTypes.ts +280 -0
  196. package/src/schema/ClientMetaTypes.ts +41 -0
  197. package/src/schema/ClientSample.ts +1682 -0
  198. package/src/scores/CalculatedScore.ts +6 -0
  199. package/src/scores/DefaultCallScoreCalculator.ts +23 -0
  200. package/src/scores/ScoreCalculator.ts +3 -0
  201. package/src/updaters/CallUpdater.ts +5 -0
  202. package/src/updaters/ObserverUpdater.ts +5 -0
  203. package/src/updaters/OnAllCallObserverUpdater.ts +59 -0
  204. package/src/updaters/OnAllClientCallUpdater.ts +61 -0
  205. package/src/updaters/OnAnyCallObserverUpdater.ts +41 -0
  206. package/src/updaters/OnAnyClientCallUpdater.ts +39 -0
  207. package/src/updaters/OnIntervalUpdater.ts +19 -0
  208. package/src/updaters/Updater.ts +5 -0
  209. package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
  210. package/src/utils/RemoteTrackResolver.ts +12 -0
  211. package/tsconfig.json +3 -3
  212. package/lib/ObservedICE.d.ts +0 -64
  213. package/lib/ObservedICE.d.ts.map +0 -1
  214. package/lib/ObservedICE.js +0 -141
  215. package/lib/ObservedInboundAudioTrack.d.ts +0 -96
  216. package/lib/ObservedInboundAudioTrack.d.ts.map +0 -1
  217. package/lib/ObservedInboundAudioTrack.js +0 -217
  218. package/lib/ObservedInboundVideoTrack.d.ts +0 -101
  219. package/lib/ObservedInboundVideoTrack.d.ts.map +0 -1
  220. package/lib/ObservedInboundVideoTrack.js +0 -232
  221. package/lib/ObservedOutboundAudioTrack.d.ts +0 -87
  222. package/lib/ObservedOutboundAudioTrack.d.ts.map +0 -1
  223. package/lib/ObservedOutboundAudioTrack.js +0 -186
  224. package/lib/ObservedOutboundVideoTrack.d.ts +0 -91
  225. package/lib/ObservedOutboundVideoTrack.d.ts.map +0 -1
  226. package/lib/ObservedOutboundVideoTrack.js +0 -193
  227. package/lib/ObservedSfu.d.ts +0 -59
  228. package/lib/ObservedSfu.d.ts.map +0 -1
  229. package/lib/ObservedSfu.js +0 -157
  230. package/lib/ObservedSfuInboundRtpPad.d.ts +0 -42
  231. package/lib/ObservedSfuInboundRtpPad.d.ts.map +0 -1
  232. package/lib/ObservedSfuInboundRtpPad.js +0 -71
  233. package/lib/ObservedSfuOutboundRtpPad.d.ts +0 -42
  234. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +0 -1
  235. package/lib/ObservedSfuOutboundRtpPad.js +0 -72
  236. package/lib/ObservedSfuSctpChannel.d.ts +0 -42
  237. package/lib/ObservedSfuSctpChannel.d.ts.map +0 -1
  238. package/lib/ObservedSfuSctpChannel.js +0 -57
  239. package/lib/ObservedSfuTransport.d.ts +0 -58
  240. package/lib/ObservedSfuTransport.d.ts.map +0 -1
  241. package/lib/ObservedSfuTransport.js +0 -120
  242. package/lib/RemoteTrackAssigner.d.ts +0 -14
  243. package/lib/RemoteTrackAssigner.d.ts.map +0 -1
  244. package/lib/RemoteTrackAssigner.js +0 -52
  245. package/lib/ReportsCollector.d.ts +0 -109
  246. package/lib/ReportsCollector.d.ts.map +0 -1
  247. package/lib/ReportsCollector.js +0 -207
  248. package/lib/common/CalculatedScore.d.ts +0 -80
  249. package/lib/common/CalculatedScore.d.ts.map +0 -1
  250. package/lib/common/CalculatedScore.js +0 -162
  251. package/lib/common/CallEventType.d.ts +0 -63
  252. package/lib/common/CallEventType.d.ts.map +0 -1
  253. package/lib/common/CallEventType.js +0 -39
  254. package/lib/common/CallMetaReports.d.ts +0 -42
  255. package/lib/common/CallMetaReports.d.ts.map +0 -1
  256. package/lib/common/CallMetaReports.js +0 -36
  257. package/lib/common/QualityScoreUtils.d.ts +0 -1
  258. package/lib/common/QualityScoreUtils.d.ts.map +0 -1
  259. package/lib/common/QualityScoreUtils.js +0 -1
  260. package/lib/common/TypedEventEmitter.d.ts +0 -22
  261. package/lib/common/TypedEventEmitter.d.ts.map +0 -1
  262. package/lib/common/TypedEventEmitter.js +0 -11
  263. package/lib/common/callEventReports.d.ts +0 -10
  264. package/lib/common/callEventReports.d.ts.map +0 -1
  265. package/lib/common/callEventReports.js +0 -112
  266. package/lib/monitors/CallSummary.d.ts +0 -37
  267. package/lib/monitors/CallSummary.d.ts.map +0 -1
  268. package/lib/monitors/CallSummaryMonitor.d.ts +0 -32
  269. package/lib/monitors/CallSummaryMonitor.d.ts.map +0 -1
  270. package/lib/monitors/CallSummaryMonitor.js +0 -152
  271. package/lib/monitors/ClientIssueMonitor.d.ts +0 -32
  272. package/lib/monitors/ClientIssueMonitor.d.ts.map +0 -1
  273. package/lib/monitors/ClientIssueMonitor.js +0 -49
  274. package/lib/monitors/SfuServerMonitor.d.ts +0 -79
  275. package/lib/monitors/SfuServerMonitor.d.ts.map +0 -1
  276. package/lib/monitors/SfuServerMonitor.js +0 -198
  277. package/src/ObservedICE.ts +0 -237
  278. package/src/ObservedInboundAudioTrack.ts +0 -344
  279. package/src/ObservedInboundVideoTrack.ts +0 -361
  280. package/src/ObservedOutboundAudioTrack.ts +0 -307
  281. package/src/ObservedOutboundVideoTrack.ts +0 -319
  282. package/src/ObservedSfu.ts +0 -231
  283. package/src/ObservedSfuInboundRtpPad.ts +0 -106
  284. package/src/ObservedSfuOutboundRtpPad.ts +0 -107
  285. package/src/ObservedSfuSctpChannel.ts +0 -103
  286. package/src/ObservedSfuTransport.ts +0 -185
  287. package/src/RemoteTrackAssigner.ts +0 -68
  288. package/src/ReportsCollector.ts +0 -336
  289. package/src/common/CalculatedScore.ts +0 -188
  290. package/src/common/CallEventType.ts +0 -69
  291. package/src/common/CallMetaReports.ts +0 -82
  292. package/src/common/QualityScoreUtils.ts +0 -0
  293. package/src/common/TypedEventEmitter.ts +0 -32
  294. package/src/common/callEventReports.ts +0 -178
  295. package/src/monitors/CallSummary.ts +0 -38
  296. package/src/monitors/CallSummaryMonitor.ts +0 -192
  297. package/src/monitors/ClientIssueMonitor.ts +0 -88
  298. package/src/monitors/SfuServerMonitor.ts +0 -285
  299. /package/lib/{monitors/CallSummary.js → ObservedCallSummary.js} +0 -0
@@ -1,107 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { SfuOutboundRtpPad } from '@observertc/sample-schemas-js';
3
- import { SfuOutboundRtpPadReport } from '@observertc/report-schemas-js';
4
- import { ObservedSfuTransport } from './ObservedSfuTransport';
5
-
6
- export type ObservedSfuOutboundRtpPadModel= {
7
- sfuOutboundRtpPadId: string;
8
- };
9
-
10
- export type ObservedSfuOutboundRtpPadEvents = {
11
- update: [{
12
- elapsedTimeInMs: number;
13
- }],
14
- close: [],
15
- };
16
-
17
- export declare interface ObservedSfuOutboundRtpPad {
18
- on<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuOutboundRtpPadEvents[U]) => void): this;
19
- off<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuOutboundRtpPadEvents[U]) => void): this;
20
- once<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuOutboundRtpPadEvents[U]) => void): this;
21
- emit<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, ...args: ObservedSfuOutboundRtpPadEvents[U]): boolean;
22
-
23
- update(sample: SfuOutboundRtpPad, timestamp: number): void;
24
- }
25
-
26
- export class ObservedSfuOutboundRtpPad extends EventEmitter {
27
- public readonly created = Date.now();
28
-
29
- public stats?: SfuOutboundRtpPad;
30
- public marker?: string;
31
- private _updated = Date.now();
32
- private _closed = false;
33
-
34
- public constructor(
35
- private readonly _model: ObservedSfuOutboundRtpPadModel,
36
- public readonly transport: ObservedSfuTransport,
37
- ) {
38
- super();
39
- this.setMaxListeners(Infinity);
40
- }
41
-
42
- public get reports() {
43
- return this.transport.reports;
44
- }
45
-
46
- public get serviceId() {
47
- return this.transport.serviceId;
48
- }
49
-
50
- public get mediaUnitId() {
51
- return this.transport.mediaUnitId;
52
- }
53
-
54
- public get sfuId() {
55
- return this.transport.sfuId;
56
- }
57
-
58
- public get sfuTransportId() {
59
- return this.transport.sfuTransportId;
60
- }
61
-
62
- public get sfuRtpPadId() {
63
- return this._model.sfuOutboundRtpPadId;
64
- }
65
-
66
- public get updated() {
67
- return this._updated;
68
- }
69
-
70
- public get closed() {
71
- return this._closed;
72
- }
73
-
74
- public close() {
75
- if (this._closed) return;
76
- this._closed = true;
77
- this.emit('close');
78
- }
79
-
80
- public update(sample: SfuOutboundRtpPad, timestamp: number) {
81
- const now = Date.now();
82
- const elapsedTimeInMs = now - this._updated;
83
-
84
- const { streamId: sfuStreamId, padId: rtpPadId, sinkId: sfuSinkId, ...reportData } = sample;
85
-
86
- const report: SfuOutboundRtpPadReport = {
87
- serviceId: this.serviceId,
88
- mediaUnitId: this.mediaUnitId,
89
- sfuId: this.sfuId,
90
- callId: undefined, // TODO: where to get this from?
91
- sfuStreamId,
92
- sfuSinkId,
93
- rtpPadId,
94
- ...reportData,
95
- timestamp,
96
- marker: this.marker,
97
- };
98
-
99
- this.reports.addSfuOutboundRtpPadReport(report);
100
- this.stats = sample;
101
-
102
- this._updated = now;
103
- this.emit('update', {
104
- elapsedTimeInMs,
105
- });
106
- }
107
- }
@@ -1,103 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { SfuSctpChannel } from '@observertc/sample-schemas-js';
3
- import { ObservedSfuTransport } from './ObservedSfuTransport';
4
- import { SfuSctpStreamReport } from '@observertc/report-schemas-js';
5
-
6
- export type ObservedSfuSctpChannelModel= {
7
- sfuSctpChannelId: string;
8
- };
9
-
10
- export type ObservedSfuSctpChannelEvents = {
11
- update: [{
12
- elapsedTimeInMs: number;
13
- }],
14
- close: [],
15
- };
16
-
17
- export declare interface ObservedSfuSctpChannel {
18
- on<U extends keyof ObservedSfuSctpChannelEvents>(event: U, listener: (...args: ObservedSfuSctpChannelEvents[U]) => void): this;
19
- off<U extends keyof ObservedSfuSctpChannelEvents>(event: U, listener: (...args: ObservedSfuSctpChannelEvents[U]) => void): this;
20
- once<U extends keyof ObservedSfuSctpChannelEvents>(event: U, listener: (...args: ObservedSfuSctpChannelEvents[U]) => void): this;
21
- emit<U extends keyof ObservedSfuSctpChannelEvents>(event: U, ...args: ObservedSfuSctpChannelEvents[U]): boolean;
22
-
23
- update(sample: SfuSctpChannel, timestamp: number): void;
24
- }
25
-
26
- export class ObservedSfuSctpChannel extends EventEmitter {
27
- public readonly created = Date.now();
28
-
29
- public stats?: SfuSctpChannel;
30
- public marker?: string;
31
- private _updated = Date.now();
32
- private _closed = false;
33
-
34
- public constructor(
35
- private readonly _model: ObservedSfuSctpChannelModel,
36
- public readonly transport: ObservedSfuTransport,
37
- ) {
38
- super();
39
- this.setMaxListeners(Infinity);
40
- }
41
-
42
- public get serviceId() {
43
- return this.transport.serviceId;
44
- }
45
-
46
- public get sfuId() {
47
- return this.transport.sfuId;
48
- }
49
-
50
- public get mediaUnitId() {
51
- return this.transport.mediaUnitId;
52
- }
53
-
54
- public get sfuTransportId() {
55
- return this.transport.sfuTransportId;
56
- }
57
-
58
- public get sfuSctpChannelId() {
59
- return this._model.sfuSctpChannelId;
60
- }
61
-
62
- public get reports() {
63
- return this.transport.reports;
64
- }
65
-
66
- public get updated() {
67
- return this._updated;
68
- }
69
-
70
- public get closed() {
71
- return this._closed;
72
- }
73
-
74
- public close() {
75
- if (this._closed) return;
76
- this._closed = true;
77
- this.emit('close');
78
- }
79
-
80
- public update(sample: SfuSctpChannel, timestamp: number) {
81
- const now = Date.now();
82
- const elapsedTimeInMs = now - this._updated;
83
-
84
- const report: SfuSctpStreamReport = {
85
- serviceId: this.serviceId,
86
- mediaUnitId: this.mediaUnitId,
87
- sfuId: this.sfuId,
88
- callId: undefined, // TODO: where to get this from?
89
- roomId: undefined, // TODO: where to get this from?
90
- ...sample,
91
- timestamp,
92
- marker: this.marker,
93
- };
94
-
95
- this.reports.addSfuTransportReport(report);
96
- this.stats = sample;
97
-
98
- this._updated = now;
99
- this.emit('update', {
100
- elapsedTimeInMs,
101
- });
102
- }
103
- }
@@ -1,185 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { SfuTransport } from '@observertc/sample-schemas-js';
3
- import { ObservedSfu } from './ObservedSfu';
4
- import { SFUTransportReport } from '@observertc/report-schemas-js';
5
- import { ObservedSfuInboundRtpPad, ObservedSfuInboundRtpPadModel } from './ObservedSfuInboundRtpPad';
6
- import { ObservedSfuOutboundRtpPad, ObservedSfuOutboundRtpPadModel } from './ObservedSfuOutboundRtpPad';
7
- import { ObservedSfuSctpChannel, ObservedSfuSctpChannelModel } from './ObservedSfuSctpChannel';
8
-
9
- export type ObservedSfuTransportModel= {
10
- sfuTransportId: string;
11
- };
12
-
13
- export type ObservedSfuTransportEvents = {
14
- update: [{
15
- elapsedTimeInMs: number;
16
- }],
17
- close: [],
18
- newsfuoutboundrtppad: [ObservedSfuOutboundRtpPad],
19
- newsfuinboundrtppad: [ObservedSfuInboundRtpPad],
20
- newsfusctpchannel: [ObservedSfuSctpChannel],
21
- };
22
-
23
- export declare interface ObservedSfuTransport {
24
- on<U extends keyof ObservedSfuTransportEvents>(event: U, listener: (...args: ObservedSfuTransportEvents[U]) => void): this;
25
- off<U extends keyof ObservedSfuTransportEvents>(event: U, listener: (...args: ObservedSfuTransportEvents[U]) => void): this;
26
- once<U extends keyof ObservedSfuTransportEvents>(event: U, listener: (...args: ObservedSfuTransportEvents[U]) => void): this;
27
- emit<U extends keyof ObservedSfuTransportEvents>(event: U, ...args: ObservedSfuTransportEvents[U]): boolean;
28
-
29
- update(sample: SfuTransport, timestamp: number): void;
30
- }
31
-
32
- export class ObservedSfuTransport extends EventEmitter {
33
- public readonly created = Date.now();
34
-
35
- public stats?: SfuTransport;
36
- private _updated = Date.now();
37
- private _closed = false;
38
- private _marker?: string;
39
-
40
- private readonly _inboundRtpPads = new Map<string, ObservedSfuInboundRtpPad>();
41
- private readonly _outboundRtpPads = new Map<string, ObservedSfuOutboundRtpPad>();
42
- private readonly _sctpChannels = new Map<string, ObservedSfuSctpChannel>();
43
-
44
- public constructor(
45
- private readonly _model: ObservedSfuTransportModel,
46
- public readonly sfu: ObservedSfu,
47
- ) {
48
- super();
49
- this.setMaxListeners(Infinity);
50
- }
51
-
52
- public get inboundRtpPads(): ReadonlyMap<string, ObservedSfuInboundRtpPad> {
53
- return this._inboundRtpPads;
54
- }
55
-
56
- public get outboundRtpPads(): ReadonlyMap<string, ObservedSfuOutboundRtpPad> {
57
- return this._outboundRtpPads;
58
- }
59
-
60
- public get sctpChannels(): ReadonlyMap<string, ObservedSfuSctpChannel> {
61
- return this._sctpChannels;
62
- }
63
-
64
- public get serviceId() {
65
- return this.sfu.serviceId;
66
- }
67
-
68
- public get mediaUnitId() {
69
- return this.sfu.mediaUnitId;
70
- }
71
-
72
- public get sfuId() {
73
- return this.sfu.sfuId;
74
- }
75
-
76
- public get sfuTransportId() {
77
- return this._model.sfuTransportId;
78
- }
79
-
80
- public get reports() {
81
- return this.sfu.reports;
82
- }
83
-
84
- public get updated() {
85
- return this._updated;
86
- }
87
-
88
- public get marker() {
89
- return this._marker;
90
- }
91
-
92
- public set marker(value: string | undefined) {
93
- this._marker = value;
94
- this._inboundRtpPads.forEach((pad) => (pad.marker = value));
95
- this._outboundRtpPads.forEach((pad) => (pad.marker = value));
96
- this._sctpChannels.forEach((channel) => (channel.marker = value));
97
- }
98
-
99
- public get closed() {
100
- return this._closed;
101
- }
102
-
103
- public close() {
104
- if (this._closed) return;
105
- this._closed = true;
106
-
107
- [ ...this._inboundRtpPads.values() ].forEach((pad) => pad.close());
108
- [ ...this._outboundRtpPads.values() ].forEach((pad) => pad.close());
109
- [ ...this._sctpChannels.values() ].forEach((channel) => channel.close());
110
-
111
- this.emit('close');
112
- }
113
-
114
- public update(sample: SfuTransport, timestamp: number) {
115
- const now = Date.now();
116
- const elapsedTimeInMs = now - this._updated;
117
-
118
- const report: SFUTransportReport = {
119
- serviceId: this.serviceId,
120
- mediaUnitId: this.mediaUnitId,
121
- sfuId: this.sfuId,
122
- callId: undefined, // TODO: where to get this from?
123
- roomId: undefined, // TODO: where to get this from?
124
- ...sample,
125
- timestamp,
126
- marker: this.marker,
127
- };
128
-
129
- this.reports.addSfuTransportReport(report);
130
- this.stats = sample;
131
-
132
- this._updated = now;
133
- this.emit('update', {
134
- elapsedTimeInMs,
135
- });
136
- }
137
-
138
- public createSfuOutboundRtpPad(model: ObservedSfuOutboundRtpPadModel) {
139
- if (this._closed) throw new Error('Cannot create SfuOutboundRtpPad on closed SfuTransport');
140
- if (this._inboundRtpPads.has(model.sfuOutboundRtpPadId)) throw new Error(`SfuOutboundRtpPad with id ${model.sfuOutboundRtpPadId} already exists`);
141
-
142
- const result = new ObservedSfuOutboundRtpPad(model, this);
143
-
144
- result.once('close', () => {
145
- this._outboundRtpPads.delete(model.sfuOutboundRtpPadId);
146
- });
147
- this._outboundRtpPads.set(model.sfuOutboundRtpPadId, result);
148
-
149
- this.emit('newsfuoutboundrtppad', result);
150
-
151
- return result;
152
- }
153
-
154
- public createSfuInboundRtpPad(model: ObservedSfuInboundRtpPadModel) {
155
- if (this._closed) throw new Error('Cannot create SfuInboundRtpPad on closed SfuTransport');
156
- if (this._inboundRtpPads.has(model.sfuInboundRtpPadId)) throw new Error(`SfuInboundRtpPad with id ${model.sfuInboundRtpPadId} already exists`);
157
-
158
- const result = new ObservedSfuInboundRtpPad(model, this);
159
-
160
- result.once('close', () => {
161
- this._inboundRtpPads.delete(model.sfuInboundRtpPadId);
162
- });
163
- this._inboundRtpPads.set(model.sfuInboundRtpPadId, result);
164
-
165
- this.emit('newsfuinboundrtppad', result);
166
-
167
- return result;
168
- }
169
-
170
- public createSfuSctpChannel(model: ObservedSfuSctpChannelModel) {
171
- if (this._closed) throw new Error('Cannot create SfuSctpChannel on closed SfuTransport');
172
- if (this._sctpChannels.has(model.sfuSctpChannelId)) throw new Error(`SfuSctpChannel with id ${model.sfuSctpChannelId} already exists`);
173
-
174
- const result = new ObservedSfuSctpChannel(model, this);
175
-
176
- result.once('close', () => {
177
- this._sctpChannels.delete(model.sfuSctpChannelId);
178
- });
179
- this._sctpChannels.set(model.sfuSctpChannelId, result);
180
-
181
- this.emit('newsfusctpchannel', result);
182
-
183
- return result;
184
- }
185
- }
@@ -1,68 +0,0 @@
1
- import { ObservedInboundAudioTrack } from './ObservedInboundAudioTrack';
2
- import { ObservedInboundVideoTrack } from './ObservedInboundVideoTrack';
3
- import { ObservedOutboundAudioTrack } from './ObservedOutboundAudioTrack';
4
- import { ObservedOutboundVideoTrack } from './ObservedOutboundVideoTrack';
5
-
6
- export class RemoteTrackAssigner {
7
- public readonly sfuStreamIdToOutboundVideoTracks = new Map<string, ObservedOutboundVideoTrack>();
8
- public readonly sfuStreamIdToOutboundAudioTracks = new Map<string, ObservedOutboundAudioTrack>();
9
- public readonly pendingInboundVideoTracks = new Map<string, ObservedInboundVideoTrack[]>();
10
- public readonly pendingInboundAudioTracks = new Map<string, ObservedInboundAudioTrack[]>();
11
-
12
- public addOutboundAudioTrack(track: ObservedOutboundAudioTrack) {
13
- const untilSfuStreamIdListener = () => {
14
- if (!track.sfuStreamId) return;
15
-
16
- this.sfuStreamIdToOutboundAudioTracks.set(track.sfuStreamId, track);
17
- track.off('update', untilSfuStreamIdListener);
18
-
19
- // we need to assign to the pending inbound tracks
20
- };
21
-
22
- track.on('update', untilSfuStreamIdListener);
23
- untilSfuStreamIdListener();
24
- }
25
-
26
- public addOutboundVideoTrack(track: ObservedOutboundVideoTrack) {
27
- const untilSfuStreamIdListener = () => {
28
- if (!track.sfuStreamId) return;
29
-
30
- this.sfuStreamIdToOutboundVideoTracks.set(track.sfuStreamId, track);
31
- track.off('update', untilSfuStreamIdListener);
32
-
33
- // we need to assign to the pending inbound tracks
34
- };
35
-
36
- track.on('update', untilSfuStreamIdListener);
37
- untilSfuStreamIdListener();
38
- }
39
-
40
- public addInboundAudioTrack(track: ObservedInboundAudioTrack) {
41
- const untilSfuStreamIdListener = () => {
42
- if (!track.sfuStreamId) return;
43
- const outboundTrack = this.sfuStreamIdToOutboundAudioTracks.get(track.sfuStreamId);
44
-
45
- if (!outboundTrack) {
46
- this.pendingInboundAudioTracks.set(
47
- track.sfuStreamId,
48
- (this.pendingInboundAudioTracks.get(track.sfuStreamId) || []).concat(track)
49
- );
50
-
51
- return;
52
- }
53
-
54
- if (outboundTrack) {
55
- track.remoteOutboundTrack = outboundTrack;
56
- } else {
57
- this.pendingInboundAudioTracks.set(
58
- track.sfuStreamId,
59
- (this.pendingInboundAudioTracks.get(track.sfuStreamId) || []).concat(track)
60
- );
61
- }
62
-
63
- };
64
-
65
- track.on('update', untilSfuStreamIdListener);
66
- }
67
-
68
- }