@observertc/client-monitor-js 1.0.0-beta.20

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 (248) hide show
  1. package/.eslintrc.js +27 -0
  2. package/.github/workflows/publish.yaml +27 -0
  3. package/.prettierignore +5 -0
  4. package/.prettierrc +5 -0
  5. package/.vscode/launch.json +15 -0
  6. package/CHANGELOG.md +3 -0
  7. package/LICENSE +22 -0
  8. package/README.md +310 -0
  9. package/docs/.nojekyll +1 -0
  10. package/docs/assets/highlight.css +85 -0
  11. package/docs/assets/icons.css +1043 -0
  12. package/docs/assets/icons.png +0 -0
  13. package/docs/assets/icons@2x.png +0 -0
  14. package/docs/assets/main.js +52 -0
  15. package/docs/assets/search.js +1 -0
  16. package/docs/assets/style.css +1413 -0
  17. package/docs/assets/widgets.png +0 -0
  18. package/docs/assets/widgets@2x.png +0 -0
  19. package/docs/classes/MediaDevices.html +1 -0
  20. package/docs/index.html +56 -0
  21. package/docs/interfaces/CertificateEntry.html +4 -0
  22. package/docs/interfaces/ClientObserver.ClientObserver-1.html +76 -0
  23. package/docs/interfaces/CodecEntry.html +6 -0
  24. package/docs/interfaces/ContributingSourceEntry.html +4 -0
  25. package/docs/interfaces/DataChannelEntry.html +4 -0
  26. package/docs/interfaces/IceCandidatePairEntry.html +4 -0
  27. package/docs/interfaces/IceServerEntry.html +4 -0
  28. package/docs/interfaces/InboundRtpEntry.html +14 -0
  29. package/docs/interfaces/LocalCandidateEntry.html +4 -0
  30. package/docs/interfaces/MediaSourceEntry.html +4 -0
  31. package/docs/interfaces/OutboundRtpEntry.html +10 -0
  32. package/docs/interfaces/PcStatsCollector.html +9 -0
  33. package/docs/interfaces/PeerConnectionEntry.html +6 -0
  34. package/docs/interfaces/ReceiverEntry.html +5 -0
  35. package/docs/interfaces/RemoteCandidateEntry.html +4 -0
  36. package/docs/interfaces/RemoteInboundRtpEntry.html +8 -0
  37. package/docs/interfaces/RemoteOutboundRtpEntry.html +8 -0
  38. package/docs/interfaces/SctpTransportEntry.html +4 -0
  39. package/docs/interfaces/SenderEntry.html +5 -0
  40. package/docs/interfaces/StatsReader.html +41 -0
  41. package/docs/interfaces/TransceiverEntry.html +4 -0
  42. package/docs/interfaces/TransportEntry.html +4 -0
  43. package/docs/modules/ClientObserver.html +31 -0
  44. package/docs/modules.html +1 -0
  45. package/jest.config.js +9 -0
  46. package/lib/Accumulator.d.ts +19 -0
  47. package/lib/Accumulator.d.ts.map +1 -0
  48. package/lib/Accumulator.js +64 -0
  49. package/lib/ClientDevices.d.ts +13 -0
  50. package/lib/ClientDevices.d.ts.map +1 -0
  51. package/lib/ClientDevices.js +80 -0
  52. package/lib/ClientMonitor.d.ts +211 -0
  53. package/lib/ClientMonitor.d.ts.map +1 -0
  54. package/lib/ClientMonitor.js +23 -0
  55. package/lib/ClientMonitorImpl.d.ts +58 -0
  56. package/lib/ClientMonitorImpl.d.ts.map +1 -0
  57. package/lib/ClientMonitorImpl.js +282 -0
  58. package/lib/ClientObserver.d.ts +211 -0
  59. package/lib/ClientObserver.d.ts.map +1 -0
  60. package/lib/ClientObserver.js +23 -0
  61. package/lib/ClientObserverImpl.d.ts +54 -0
  62. package/lib/ClientObserverImpl.d.ts.map +1 -0
  63. package/lib/ClientObserverImpl.js +245 -0
  64. package/lib/Collector.d.ts +59 -0
  65. package/lib/Collector.d.ts.map +1 -0
  66. package/lib/Collector.js +123 -0
  67. package/lib/EventsRelayer.d.ts +40 -0
  68. package/lib/EventsRelayer.d.ts.map +1 -0
  69. package/lib/EventsRelayer.js +61 -0
  70. package/lib/Metrics.d.ts +15 -0
  71. package/lib/Metrics.d.ts.map +1 -0
  72. package/lib/Metrics.js +12 -0
  73. package/lib/Sampler.d.ts +100 -0
  74. package/lib/Sampler.d.ts.map +1 -0
  75. package/lib/Sampler.js +523 -0
  76. package/lib/Sender.d.ts +40 -0
  77. package/lib/Sender.d.ts.map +1 -0
  78. package/lib/Sender.js +122 -0
  79. package/lib/adapters/Adapter.d.ts +17 -0
  80. package/lib/adapters/Adapter.d.ts.map +1 -0
  81. package/lib/adapters/Adapter.js +134 -0
  82. package/lib/adapters/Chrome86Adapter.d.ts +6 -0
  83. package/lib/adapters/Chrome86Adapter.d.ts.map +1 -0
  84. package/lib/adapters/Chrome86Adapter.js +71 -0
  85. package/lib/adapters/Chrome86_96Adapter.d.ts +6 -0
  86. package/lib/adapters/Chrome86_96Adapter.d.ts.map +1 -0
  87. package/lib/adapters/Chrome86_96Adapter.js +69 -0
  88. package/lib/adapters/Chrome97Adapter.d.ts +6 -0
  89. package/lib/adapters/Chrome97Adapter.d.ts.map +1 -0
  90. package/lib/adapters/Chrome97Adapter.js +32 -0
  91. package/lib/adapters/Chrome99Adapter.d.ts +6 -0
  92. package/lib/adapters/Chrome99Adapter.d.ts.map +1 -0
  93. package/lib/adapters/Chrome99Adapter.js +73 -0
  94. package/lib/adapters/DefaultAdapter.d.ts +6 -0
  95. package/lib/adapters/DefaultAdapter.d.ts.map +1 -0
  96. package/lib/adapters/DefaultAdapter.js +22 -0
  97. package/lib/adapters/Firefox90_94.d.ts +6 -0
  98. package/lib/adapters/Firefox90_94.d.ts.map +1 -0
  99. package/lib/adapters/Firefox90_94.js +30 -0
  100. package/lib/adapters/Firefox94Adapter.d.ts +6 -0
  101. package/lib/adapters/Firefox94Adapter.d.ts.map +1 -0
  102. package/lib/adapters/Firefox94Adapter.js +33 -0
  103. package/lib/adapters/Safari14Adapter.d.ts +6 -0
  104. package/lib/adapters/Safari14Adapter.d.ts.map +1 -0
  105. package/lib/adapters/Safari14Adapter.js +63 -0
  106. package/lib/codecs/AvroCodec.d.ts +13 -0
  107. package/lib/codecs/AvroCodec.d.ts.map +1 -0
  108. package/lib/codecs/AvroCodec.js +44 -0
  109. package/lib/codecs/Base64Codec.d.ts +12 -0
  110. package/lib/codecs/Base64Codec.d.ts.map +1 -0
  111. package/lib/codecs/Base64Codec.js +25 -0
  112. package/lib/codecs/Codec.d.ts +11 -0
  113. package/lib/codecs/Codec.d.ts.map +1 -0
  114. package/lib/codecs/Codec.js +52 -0
  115. package/lib/codecs/FacadedCodec.d.ts +10 -0
  116. package/lib/codecs/FacadedCodec.d.ts.map +1 -0
  117. package/lib/codecs/FacadedCodec.js +34 -0
  118. package/lib/codecs/JsonCodec.d.ts +12 -0
  119. package/lib/codecs/JsonCodec.d.ts.map +1 -0
  120. package/lib/codecs/JsonCodec.js +30 -0
  121. package/lib/codecs/ProtobufCodec.d.ts +14 -0
  122. package/lib/codecs/ProtobufCodec.d.ts.map +1 -0
  123. package/lib/codecs/ProtobufCodec.js +66 -0
  124. package/lib/codecs/TextCodec.d.ts +14 -0
  125. package/lib/codecs/TextCodec.d.ts.map +1 -0
  126. package/lib/codecs/TextCodec.js +22 -0
  127. package/lib/entries/PeerConnectionEntry.d.ts +91 -0
  128. package/lib/entries/PeerConnectionEntry.d.ts.map +1 -0
  129. package/lib/entries/PeerConnectionEntry.js +899 -0
  130. package/lib/entries/PeerConnectionEntryImpl.d.ts +67 -0
  131. package/lib/entries/PeerConnectionEntryImpl.d.ts.map +1 -0
  132. package/lib/entries/PeerConnectionEntryImpl.js +923 -0
  133. package/lib/entries/StatsEntryInterfaces.d.ts +230 -0
  134. package/lib/entries/StatsEntryInterfaces.d.ts.map +1 -0
  135. package/lib/entries/StatsEntryInterfaces.js +2 -0
  136. package/lib/entries/StatsStorage.d.ts +117 -0
  137. package/lib/entries/StatsStorage.d.ts.map +1 -0
  138. package/lib/entries/StatsStorage.js +173 -0
  139. package/lib/index.d.ts +6 -0
  140. package/lib/index.d.ts.map +1 -0
  141. package/lib/index.js +27 -0
  142. package/lib/schemas/ClientSample.d.ts +1883 -0
  143. package/lib/schemas/ClientSample.d.ts.map +1 -0
  144. package/lib/schemas/ClientSample.js +3 -0
  145. package/lib/schemas/Feedback.d.ts +11 -0
  146. package/lib/schemas/Feedback.d.ts.map +1 -0
  147. package/lib/schemas/Feedback.js +2 -0
  148. package/lib/schemas/Samples.d.ts +35 -0
  149. package/lib/schemas/Samples.d.ts.map +1 -0
  150. package/lib/schemas/Samples.js +3 -0
  151. package/lib/schemas/SfuSample.d.ts +509 -0
  152. package/lib/schemas/SfuSample.d.ts.map +1 -0
  153. package/lib/schemas/SfuSample.js +3 -0
  154. package/lib/schemas/W3CStatsIdentifier.d.ts +344 -0
  155. package/lib/schemas/W3CStatsIdentifier.d.ts.map +1 -0
  156. package/lib/schemas/W3CStatsIdentifier.js +30 -0
  157. package/lib/transports/Transport.d.ts +10 -0
  158. package/lib/transports/Transport.d.ts.map +1 -0
  159. package/lib/transports/Transport.js +2 -0
  160. package/lib/transports/WebsocketTransport.d.ts +49 -0
  161. package/lib/transports/WebsocketTransport.d.ts.map +1 -0
  162. package/lib/transports/WebsocketTransport.js +173 -0
  163. package/lib/utils/MediaDevices.d.ts +10 -0
  164. package/lib/utils/MediaDevices.d.ts.map +1 -0
  165. package/lib/utils/MediaDevices.js +53 -0
  166. package/lib/utils/StatsVisitor.d.ts +26 -0
  167. package/lib/utils/StatsVisitor.d.ts.map +1 -0
  168. package/lib/utils/StatsVisitor.js +79 -0
  169. package/lib/utils/Timer.d.ts +19 -0
  170. package/lib/utils/Timer.d.ts.map +1 -0
  171. package/lib/utils/Timer.js +125 -0
  172. package/lib/utils/common.d.ts +4 -0
  173. package/lib/utils/common.d.ts.map +1 -0
  174. package/lib/utils/common.js +65 -0
  175. package/lib/utils/hash.d.ts +2 -0
  176. package/lib/utils/hash.d.ts.map +1 -0
  177. package/lib/utils/hash.js +50 -0
  178. package/lib/utils/logger.d.ts +5 -0
  179. package/lib/utils/logger.d.ts.map +1 -0
  180. package/lib/utils/logger.js +56 -0
  181. package/lib/utils/reverseEnums.d.ts +6 -0
  182. package/lib/utils/reverseEnums.d.ts.map +1 -0
  183. package/lib/utils/reverseEnums.js +12 -0
  184. package/lib/utils/validators.d.ts +3 -0
  185. package/lib/utils/validators.d.ts.map +1 -0
  186. package/lib/utils/validators.js +14 -0
  187. package/package.json +58 -0
  188. package/src/Accumulator.ts +74 -0
  189. package/src/ClientDevices.ts +62 -0
  190. package/src/ClientMonitor.ts +249 -0
  191. package/src/ClientMonitorImpl.ts +330 -0
  192. package/src/Collector.ts +176 -0
  193. package/src/EventsRelayer.ts +103 -0
  194. package/src/Metrics.ts +22 -0
  195. package/src/Sampler.ts +615 -0
  196. package/src/Sender.ts +156 -0
  197. package/src/adapters/Adapter.ts +159 -0
  198. package/src/adapters/Chrome86Adapter.ts +65 -0
  199. package/src/adapters/DefaultAdapter.ts +20 -0
  200. package/src/adapters/Firefox94Adapter.ts +32 -0
  201. package/src/adapters/Safari14Adapter.ts +58 -0
  202. package/src/codecs/Base64Codec.ts +34 -0
  203. package/src/codecs/Codec.ts +40 -0
  204. package/src/codecs/FacadedCodec.ts +36 -0
  205. package/src/codecs/JsonCodec.ts +41 -0
  206. package/src/codecs/ProtobufCodec.ts +52 -0
  207. package/src/codecs/TextCodec.ts +36 -0
  208. package/src/entries/PeerConnectionEntryImpl.ts +941 -0
  209. package/src/entries/StatsEntryInterfaces.ts +254 -0
  210. package/src/entries/StatsStorage.ts +300 -0
  211. package/src/index.ts +25 -0
  212. package/src/transports/Transport.ts +12 -0
  213. package/src/transports/WebsocketTransport.ts +211 -0
  214. package/src/utils/MediaDevices.ts +47 -0
  215. package/src/utils/StatsVisitor.ts +122 -0
  216. package/src/utils/Timer.ts +142 -0
  217. package/src/utils/common.ts +55 -0
  218. package/src/utils/hash.ts +47 -0
  219. package/src/utils/logger.ts +50 -0
  220. package/src/utils/reverseEnums.ts +21 -0
  221. package/src/utils/validators.ts +12 -0
  222. package/tests/Accumulator.spec.ts +74 -0
  223. package/tests/Collector.spec.ts +371 -0
  224. package/tests/EventsRelayer.spec.ts +100 -0
  225. package/tests/Metrics.spec.ts +13 -0
  226. package/tests/Sampler.spec.ts +247 -0
  227. package/tests/Sender.spec.ts +7 -0
  228. package/tests/adapters/Adapter.spec.ts +39 -0
  229. package/tests/adapters/ChromeAdapter86.spec.ts +62 -0
  230. package/tests/adapters/DefaultAdapter.spec.ts +6 -0
  231. package/tests/adapters/Firefox94Adapter.spec.ts +78 -0
  232. package/tests/adapters/Safari14Adapter.spec.ts +66 -0
  233. package/tests/codecs/Base64Codec.spec.ts +10 -0
  234. package/tests/codecs/FacadedCodec.spec.ts +18 -0
  235. package/tests/codecs/JsonCodec.spec.ts +10 -0
  236. package/tests/codecs/ProtobufCodec.spec.ts +41 -0
  237. package/tests/codecs/TextCodec.spec.ts +12 -0
  238. package/tests/entries/StatsStorage.spec.ts +399 -0
  239. package/tests/helpers/StatsGenerator.ts +310 -0
  240. package/tests/helpers/createBaseAdapterTests.ts +192 -0
  241. package/tests/transports/WebsocketTransport.spec.ts +16 -0
  242. package/tests/utils/MediaDevices.spec.ts +42 -0
  243. package/tests/utils/Timer.spec.ts +90 -0
  244. package/tests/utils/common.spec.ts +113 -0
  245. package/tests/utils/hash.spec.ts +110 -0
  246. package/tests/utils/validators.spec.ts +27 -0
  247. package/tsconfig.json +17 -0
  248. package/tslint.json +6 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:@typescript-eslint/recommended"
9
+ ],
10
+ "parser": "@typescript-eslint/parser",
11
+ "parserOptions": {
12
+ "ecmaVersion": "latest",
13
+ "sourceType": "module"
14
+ },
15
+ "plugins": [
16
+ "@typescript-eslint"
17
+ ],
18
+ "ignorePatterns": ["*.txt"],
19
+ "rules": {
20
+ "prefer-for-of": 0,
21
+ "no-inferrable-types": 0,
22
+ "no-explicit-any": 0,
23
+ "ban-types": 0,
24
+ "no-this-alias": 0,
25
+ "no-non-null-assertion": 0,
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ name: Publish
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - uses: actions/setup-node@v1
13
+ with:
14
+ node-version: 14
15
+ - name: Install
16
+ run: yarn
17
+
18
+ - name: Build
19
+ run: yarn build
20
+
21
+ - name: Test
22
+ run: yarn test
23
+
24
+ - uses: JS-DevTools/npm-publish@v1
25
+ with:
26
+ access: public
27
+ token: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,5 @@
1
+ docs-generator/
2
+ node_modules/
3
+ package.json
4
+ tsconfig.json
5
+ tslint.json
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "tabWidth": 4,
3
+ "trailingComma": "es5",
4
+ "printWidth": 120
5
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "pwa-chrome",
9
+ "request": "launch",
10
+ "name": "Launch Chrome against localhost",
11
+ "url": "http://localhost:8080",
12
+ "webRoot": "${workspaceFolder}"
13
+ }
14
+ ]
15
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 1.0.0
2
+
3
+ Init
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2022 Balazs Kreith
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,310 @@
1
+ ObserveRTC Client Integration Javascript Library
2
+ ---
3
+
4
+ @observertc/client-monitor-js is a client side library to monitor [WebRTCStats](https://www.w3.org/TR/webrtc-stats/) and to integrate you app to observertc components.
5
+
6
+ Table of Contents:
7
+ * [Quick Start](#quick-start)
8
+ - [Collect WebRTC Stats](#collect-webrtc-stats)
9
+ - [Sample and Send](#sample-and-send)
10
+ * [Schema](#schema)
11
+ * [API docs](#api-docs)
12
+ * [NPM package](#npm-package)
13
+ * [Schema](#schema)
14
+ * [Examples](#examples)
15
+ - [Calculate video tracks Fps](#calculate-video-tracks-fps)
16
+ - [Collect RTT measurements for peer connections](#collect-rtt-measurements-for-peer-connections)
17
+ * [Configurations](#configurations)
18
+ * [License](#license)
19
+
20
+ ## Qucik Start
21
+
22
+ Install it from [npm](https://www.npmjs.com/package/@observertc/client-monitor-js) package repository.
23
+
24
+ ```
25
+ npm i @observertc/client-monitor-js
26
+ ```
27
+
28
+ ### Collect WebRTC Stats
29
+
30
+ ```javascript
31
+ import { ClientMonitor } from "@observertc/client-monitor-js";
32
+ // see full config in Configuration section
33
+ const config = {
34
+ collectingPeriodInMs: 5000,
35
+ };
36
+ const monitor = ClientMonitor.create(config);
37
+ monitor.addStatsCollector({
38
+ id: "collectorId",
39
+ getStats: () => peerConnection.getStats(),
40
+ });
41
+ monitor.events.onStatsCollected(() => {
42
+ for (const transport of monitor.stats.transports()) {
43
+ /// use the transport
44
+ console.log(transport.stats.packetsSent);
45
+ }
46
+ })
47
+ ```
48
+ The above example collect stats in every 5s.
49
+ When stats are collected and stored it emits an event to notify the
50
+ application.
51
+
52
+ You can navigate through related stats:
53
+
54
+ ```javascript
55
+ // list outbound RTP stats
56
+ for (const outboundRtp of monitor.stats.outboundRtps()) {
57
+ // get the remote inbound RTP stats belongs to the actual outbound RTP
58
+ const remoteInboundRtp = outboundRtp.getRemoteInboundRtp();
59
+ console.log(outboundRtp.stats, remoteInboundRtp.stats);
60
+ }
61
+ ```
62
+ The example above shows how to get the remote inbound rtp stats related to the outbound rtp stats.
63
+
64
+ With `stats` you accessing to the [StatsStorage](https://observertc.github.io/client-monitor-js/interfaces/StatsReader.html). StatsStorage provided entries can be used to navigate from stats type to another.
65
+
66
+ ![Entry Navigations](docs/navigation.png)
67
+
68
+ ### Sample and Send
69
+
70
+ Sampling means the client-monitor creates a so-called ClientSample. ClientSample is a compound object contains a snapshot from the polled stats, added devices, constrainments, user errors, etc. ClientSample is created by a Sampler component.
71
+ A created ClientSample is added to Samples object. Samples can be sent to the server by a Sender component.
72
+
73
+ The above shown example can be extended to sample and send by adding the following configurations:
74
+
75
+ ```javascript
76
+ import { ClientMontior } from "@observertc/client-monitor-js";
77
+ // see full config in Configuration section
78
+ const config = {
79
+ collectingPeriodInMs: 5000,
80
+ samplingPeriodInMs: 10000,
81
+ sendingPeriodInMs: 10000,
82
+ sampler: {
83
+ roomId: "testRoom",
84
+ },
85
+ sender: {
86
+ websocket: {
87
+ urls: ["ws://localhost:7080/samples/myServiceId/myMediaUnitId"]
88
+ }
89
+ }
90
+ };
91
+ const monitor = ClientMontior.create(config);
92
+ monitor.addStatsCollector({
93
+ id: "collectorId",
94
+ getStats: () => peerConnection.getStats(),
95
+ });
96
+ ```
97
+
98
+ ## API docs
99
+
100
+ https://observertc.github.io/client-monitor-js/modules/ClientMonitor.html
101
+
102
+ ## NPM package
103
+
104
+ https://www.npmjs.com/package/@observertc/client-monitor-js
105
+
106
+ ## Schema
107
+
108
+ The schema used to send samples can be found [here](https://www.npmjs.com/package/@observertc/schemas#Samples).
109
+
110
+ ## Examples
111
+
112
+ ### Calculate video tracks Fps
113
+
114
+ Assuming you have a configured and running monitor and a collector you added to poll the stats from
115
+ peer connection, here is an example to calculate the frame per sec for tracks.
116
+
117
+ ```javascript
118
+ const monitor = //.. defined above
119
+ monitor.onStatsCollected(() => {
120
+ const now = Date.now();
121
+ for (const inboundRtp of monitor.storage.inboundRtps()) {
122
+ const trackId = inboundRtp.getTrackId();
123
+ const SSRC = inboundRtp.getSsrc();
124
+ const traceId = `${trackId}-${SSRC}`;
125
+ // lets extract what we need from the stats for inboundRtp: https://www.w3.org/TR/webrtc-stats/#inboundrtpstats-dict*
126
+ const { framesReceived, kind } = inboundRtp.stats;
127
+ if (kind !== "video") continue;
128
+ const trace = traces.get(traceId);
129
+ if (!trace) {
130
+ traces.set(traceId, {
131
+ framesReceived,
132
+ timestamp: now,
133
+ });
134
+ continue;
135
+ }
136
+ const elapsedTimeInS = (now - trace.timestamp) / 1000;
137
+ const fps = (framesReceived - trace.framesReceived) / elapsedTimeInS;
138
+ const peerConnectionId = inboundRtp.getPeerConnection()?.id;
139
+ trace.framesReceived = framesReceived;
140
+ trace.timestamp = now;
141
+
142
+ console.log(`On peerConnection: ${peerConnectionId}, track ${trackId}, SSRC: ${SSRC} the FPS is ${fps}`);
143
+ }
144
+ });
145
+ ```
146
+
147
+ ### Collect RTT measurements for peer connections
148
+
149
+ ```javascript
150
+ const monitor = //.. defined above
151
+ monitor.onStatsCollected(() => {
152
+ const RTTs = new Map();
153
+ for (const outboundRtp of monitor.storage.outboundRtps()) {
154
+ const remoteInboundRtp = outboundRtp.getRemoteInboundRtp();
155
+ const { roundTripTime } = remoteInboundRtp.stats;
156
+ const peerConnectionId = outboundRtp.getPeerConnection()?.collectorId;
157
+ let measurements = results.get(peerConnectionId);
158
+ if (!measurements) {
159
+ measurements = [];
160
+ RTTs.set(peerConnectionId, measurements);
161
+ }
162
+ measurements.push(roundTripTime);
163
+ }
164
+ // here you have the RTT measurements groupped by peer connections
165
+ console.log(Array.from(RTTs.entries()));
166
+ });
167
+ ```
168
+
169
+ ## Configurations
170
+
171
+ ```javascript
172
+ const config = {
173
+ /**
174
+ * By setting it, the monitor calls the added statsCollectors periodically
175
+ * and pulls the stats.
176
+ *
177
+ * DEFAULT: undefined
178
+ */
179
+ collectingPeriodInMs: 5000,
180
+ /**
181
+ * By setting it, the monitor make samples periodically.
182
+ *
183
+ * DEFAULT: undefined
184
+ */
185
+ samplingPeriodInMs: 10000,
186
+
187
+ /**
188
+ * By setting it, the monitor sends the samples periodically.
189
+ *
190
+ * DEFAULT: undefined
191
+ */
192
+ sendingPeriodInMs: 10000;
193
+
194
+ /**
195
+ * By setting it stats items and entries are deleted if they are not updated.
196
+ *
197
+ * DEFAULT: undefined
198
+ */
199
+ statsExpirationTimeInMs: 60000,
200
+
201
+ /**
202
+ * Collector Component related configurations
203
+ *
204
+ * DEFAULT: configured by the monitor
205
+ */
206
+ collectors: {
207
+ /**
208
+ * Sets the adapter adapt different browser type and version
209
+ * provided stats.
210
+ *
211
+ * DEFAULT: configured by the monitor
212
+ */
213
+ adapter: {
214
+ /**
215
+ * the type of the browser, e.g.: chrome, firefox, safari
216
+ *
217
+ * DEFAULT: configured by the collector
218
+ */
219
+ browserType: "chrome",
220
+ /**
221
+ * the version of the browser, e.g.: 97.xx.xxxxx
222
+ *
223
+ * DEFAULT: configured by the collector
224
+ */
225
+ browserVersion: "97.1111.111",
226
+ },
227
+ },
228
+
229
+ /**
230
+ * Sampling Component Related configurations
231
+ *
232
+ */
233
+ sampler: {
234
+ /**
235
+ * The identifier of the room the clients are in.
236
+ *
237
+ * If server side componet is used to collect the samples, this parameter is the critical to provide to match clients being in the same room.
238
+ *
239
+ * DEFAULT: a generated unique value
240
+ *
241
+ * NOTE: if this value has not been set clients which are in the same room will not be matched at the monitor
242
+ */
243
+ roomId: "testRoom",
244
+
245
+ /**
246
+ * The identifier of the client. If it is not provided, then it a UUID is generated. If it is provided it must be a valid UUID.
247
+ *
248
+ * DEFAULT: a generated unique value
249
+ */
250
+ clientId: "clientId",
251
+
252
+ /**
253
+ * the identifier of the call between clients in the same room. If not given then the server side assigns one. If it is given it must be a valid UUID.
254
+ *
255
+ * DEFAULT: undefined
256
+ */
257
+ callId: "callId",
258
+ /**
259
+ * The userId of the client appeared to other users.
260
+ *
261
+ * DEFAULT: undefined
262
+ */
263
+ userId: "testUser",
264
+
265
+ /**
266
+ * Indicate if the sampler only sample stats updated since the last sampling.
267
+ *
268
+ * DEFAULT: true
269
+ */
270
+ incrementalSampling: true,
271
+ },
272
+ /**
273
+ * Configure the sender component.
274
+ */
275
+ sender: {
276
+ /**
277
+ * Configure the format used to transport samples or receieve
278
+ * feedback from the server.
279
+ *
280
+ * Possible values: json, protobuf
281
+ *
282
+ * DEFAULT: json
283
+ *
284
+ */
285
+ format: "json",
286
+ /**
287
+ * Websocket configuration to transport the samples
288
+ */
289
+ websocket: {
290
+ /**
291
+ * Target urls in a priority order. If the Websocket has not succeeded for the first,
292
+ * it tries with the second. If no more url left the connection is failed
293
+ *
294
+ */
295
+ urls: ["ws://localhost:7080/samples/myServiceId/myMediaUnitId"],
296
+ /**
297
+ * The maximum number of retries to connect to a server before,
298
+ * tha connection failed is stated.
299
+ *
300
+ * DEFAULT: 3
301
+ */
302
+ maxRetries: 1,
303
+ }
304
+ }
305
+ };
306
+ ```
307
+
308
+ ## License
309
+
310
+ Apache-2.0
package/docs/.nojekyll ADDED
@@ -0,0 +1 @@
1
+ TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
@@ -0,0 +1,85 @@
1
+ :root {
2
+ --light-hl-0: #001080;
3
+ --dark-hl-0: #9CDCFE;
4
+ --light-hl-1: #000000;
5
+ --dark-hl-1: #D4D4D4;
6
+ --light-hl-2: #AF00DB;
7
+ --dark-hl-2: #C586C0;
8
+ --light-hl-3: #A31515;
9
+ --dark-hl-3: #CE9178;
10
+ --light-hl-4: #008000;
11
+ --dark-hl-4: #6A9955;
12
+ --light-hl-5: #0000FF;
13
+ --dark-hl-5: #569CD6;
14
+ --light-hl-6: #0070C1;
15
+ --dark-hl-6: #4FC1FF;
16
+ --light-hl-7: #098658;
17
+ --dark-hl-7: #B5CEA8;
18
+ --light-hl-8: #795E26;
19
+ --dark-hl-8: #DCDCAA;
20
+ --light-code-background: #F5F5F5;
21
+ --dark-code-background: #1E1E1E;
22
+ }
23
+
24
+ @media (prefers-color-scheme: light) { :root {
25
+ --hl-0: var(--light-hl-0);
26
+ --hl-1: var(--light-hl-1);
27
+ --hl-2: var(--light-hl-2);
28
+ --hl-3: var(--light-hl-3);
29
+ --hl-4: var(--light-hl-4);
30
+ --hl-5: var(--light-hl-5);
31
+ --hl-6: var(--light-hl-6);
32
+ --hl-7: var(--light-hl-7);
33
+ --hl-8: var(--light-hl-8);
34
+ --code-background: var(--light-code-background);
35
+ } }
36
+
37
+ @media (prefers-color-scheme: dark) { :root {
38
+ --hl-0: var(--dark-hl-0);
39
+ --hl-1: var(--dark-hl-1);
40
+ --hl-2: var(--dark-hl-2);
41
+ --hl-3: var(--dark-hl-3);
42
+ --hl-4: var(--dark-hl-4);
43
+ --hl-5: var(--dark-hl-5);
44
+ --hl-6: var(--dark-hl-6);
45
+ --hl-7: var(--dark-hl-7);
46
+ --hl-8: var(--dark-hl-8);
47
+ --code-background: var(--dark-code-background);
48
+ } }
49
+
50
+ body.light {
51
+ --hl-0: var(--light-hl-0);
52
+ --hl-1: var(--light-hl-1);
53
+ --hl-2: var(--light-hl-2);
54
+ --hl-3: var(--light-hl-3);
55
+ --hl-4: var(--light-hl-4);
56
+ --hl-5: var(--light-hl-5);
57
+ --hl-6: var(--light-hl-6);
58
+ --hl-7: var(--light-hl-7);
59
+ --hl-8: var(--light-hl-8);
60
+ --code-background: var(--light-code-background);
61
+ }
62
+
63
+ body.dark {
64
+ --hl-0: var(--dark-hl-0);
65
+ --hl-1: var(--dark-hl-1);
66
+ --hl-2: var(--dark-hl-2);
67
+ --hl-3: var(--dark-hl-3);
68
+ --hl-4: var(--dark-hl-4);
69
+ --hl-5: var(--dark-hl-5);
70
+ --hl-6: var(--dark-hl-6);
71
+ --hl-7: var(--dark-hl-7);
72
+ --hl-8: var(--dark-hl-8);
73
+ --code-background: var(--dark-code-background);
74
+ }
75
+
76
+ .hl-0 { color: var(--hl-0); }
77
+ .hl-1 { color: var(--hl-1); }
78
+ .hl-2 { color: var(--hl-2); }
79
+ .hl-3 { color: var(--hl-3); }
80
+ .hl-4 { color: var(--hl-4); }
81
+ .hl-5 { color: var(--hl-5); }
82
+ .hl-6 { color: var(--hl-6); }
83
+ .hl-7 { color: var(--hl-7); }
84
+ .hl-8 { color: var(--hl-8); }
85
+ pre, code { background: var(--code-background); }