@webex/internal-plugin-device 3.0.0-beta.3 → 3.0.0-beta.300

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 (44) hide show
  1. package/README.md +10 -6
  2. package/dist/config.js +0 -8
  3. package/dist/config.js.map +1 -1
  4. package/dist/constants.js +2 -3
  5. package/dist/constants.js.map +1 -1
  6. package/dist/device.js +102 -172
  7. package/dist/device.js.map +1 -1
  8. package/dist/features/feature-collection.js +1 -8
  9. package/dist/features/feature-collection.js.map +1 -1
  10. package/dist/features/feature-model.js +15 -42
  11. package/dist/features/feature-model.js.map +1 -1
  12. package/dist/features/features-model.js +9 -21
  13. package/dist/features/features-model.js.map +1 -1
  14. package/dist/features/index.js +0 -8
  15. package/dist/features/index.js.map +1 -1
  16. package/dist/index.js +2 -24
  17. package/dist/index.js.map +1 -1
  18. package/dist/interceptors/device-url.js +12 -33
  19. package/dist/interceptors/device-url.js.map +1 -1
  20. package/dist/ipNetworkDetector.js +200 -0
  21. package/dist/ipNetworkDetector.js.map +1 -0
  22. package/dist/metrics.js +0 -2
  23. package/dist/metrics.js.map +1 -1
  24. package/package.json +10 -10
  25. package/src/config.js +8 -9
  26. package/src/constants.js +3 -5
  27. package/src/device.js +149 -146
  28. package/src/features/feature-collection.js +1 -1
  29. package/src/features/feature-model.js +5 -11
  30. package/src/features/features-model.js +3 -9
  31. package/src/features/index.js +1 -5
  32. package/src/index.js +3 -11
  33. package/src/interceptors/device-url.js +5 -7
  34. package/src/ipNetworkDetector.ts +176 -0
  35. package/src/metrics.js +1 -2
  36. package/test/integration/spec/device.js +210 -239
  37. package/test/integration/spec/webex.js +9 -9
  38. package/test/unit/spec/device.js +44 -53
  39. package/test/unit/spec/features/feature-collection.js +2 -2
  40. package/test/unit/spec/features/feature-model.js +23 -39
  41. package/test/unit/spec/features/features-model.js +4 -12
  42. package/test/unit/spec/interceptors/device-url.js +69 -109
  43. package/test/unit/spec/ipNetworkDetector.js +410 -0
  44. package/test/unit/spec/wdm-dto.json +5 -13
@@ -0,0 +1,176 @@
1
+ /*!
2
+ * Copyright (c) 2015-2023 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {WebexPlugin} from '@webex/webex-core';
6
+
7
+ /**
8
+ * @class
9
+ */
10
+ const IpNetworkDetector = WebexPlugin.extend({
11
+ idAttribute: 'IpNetworkDetectorId',
12
+
13
+ namespace: 'Device',
14
+
15
+ props: {
16
+ firstIpV4: ['number', true, -1], // time [ms] it took to receive first IPv4 candidate
17
+ firstIpV6: ['number', true, -1], // time [ms] it took to receive first IPv6 candidate
18
+ firstMdns: ['number', true, -1], // time [ms] it took to receive first mDNS candidate
19
+ totalTime: ['number', true, -1], // total time [ms] it took to do the last IP network detection
20
+ },
21
+
22
+ derived: {
23
+ /**
24
+ * True if we know we're on an IPv4 network,
25
+ * False if we know that we are not on an IPv4 network,
26
+ * undefined if we are not sure
27
+ */
28
+ supportsIpV4: {
29
+ deps: ['firstIpV4', 'firstIpV6', 'firstMdns', 'totalTime'],
30
+ /**
31
+ * Function for calculating the value of supportsIpV4 prop
32
+ * @returns {boolean | undefined}
33
+ */
34
+ fn() {
35
+ if (this.firstIpV4 >= 0) {
36
+ return true;
37
+ }
38
+ if (this.totalTime < 0) {
39
+ // we haven't completed the detection, yet
40
+ return undefined;
41
+ }
42
+ if (this.receivedOnlyMDnsCandidates()) {
43
+ return undefined;
44
+ }
45
+
46
+ return false;
47
+ },
48
+ },
49
+ /**
50
+ * True if we know we're on an IPv6 network,
51
+ * False if we know that we are not on an IPv6 network,
52
+ * undefined if we are not sure
53
+ */
54
+ supportsIpV6: {
55
+ deps: ['firstIpV4', 'firstIpV6', 'firstMdns', 'totalTime'],
56
+ /**
57
+ * Function for calculating the value of supportsIpV6 prop
58
+ * @returns {boolean | undefined}
59
+ */ fn() {
60
+ if (this.firstIpV6 >= 0) {
61
+ return true;
62
+ }
63
+ if (this.totalTime < 0) {
64
+ // we haven't completed the detection, yet
65
+ return undefined;
66
+ }
67
+ if (this.receivedOnlyMDnsCandidates()) {
68
+ return undefined;
69
+ }
70
+
71
+ return false;
72
+ },
73
+ },
74
+ },
75
+
76
+ /**
77
+ * Returns true if we have received only mDNS candidates - browsers usually do that if we don't have any user media permissions
78
+ *
79
+ * @private
80
+ * @returns {boolean}
81
+ */
82
+ receivedOnlyMDnsCandidates() {
83
+ return this.totalTime >= 0 && this.firstMdns >= 0 && this.firstIpV4 < 0 && this.firstIpV6 < 0;
84
+ },
85
+
86
+ /**
87
+ *
88
+ * @param {RTCPeerConnection} pc Peer connection to use
89
+ * @private
90
+ * @returns {Promise<void>}
91
+ */
92
+ async gatherLocalCandidates(pc: RTCPeerConnection): Promise<void> {
93
+ return new Promise((resolve, reject) => {
94
+ let done = false;
95
+
96
+ this.firstIpV4 = -1;
97
+ this.firstIpV6 = -1;
98
+ this.firstMdns = -1;
99
+ this.totalTime = -1;
100
+ const startTime = performance.now();
101
+
102
+ const doneGatheringIceCandidates = () => {
103
+ if (done) {
104
+ return;
105
+ }
106
+ done = true;
107
+
108
+ this.totalTime = performance.now() - startTime;
109
+
110
+ resolve();
111
+ };
112
+
113
+ pc.onicecandidate = (event) => {
114
+ if (event.candidate?.address) {
115
+ if (event.candidate.address.endsWith('.local')) {
116
+ // if we don't have camera/mic permissions, browser just gives us mDNS candidates
117
+ if (this.firstMdns === -1) {
118
+ this.firstMdns = performance.now() - startTime;
119
+ }
120
+ } else if (event.candidate.address.includes(':')) {
121
+ if (this.firstIpV6 === -1) {
122
+ this.firstIpV6 = performance.now() - startTime;
123
+ }
124
+ } else if (this.firstIpV4 === -1) {
125
+ this.firstIpV4 = performance.now() - startTime;
126
+ }
127
+
128
+ if (this.firstIpV4 >= 0 && this.firstIpV6 >= 0) {
129
+ // if we've got both ipv4 and ipv6 candidates, there is no need to wait for any more candidates, we can resolve now
130
+ resolve();
131
+ }
132
+ } else if (event.candidate === null) {
133
+ doneGatheringIceCandidates();
134
+ }
135
+ };
136
+
137
+ pc.onicegatheringstatechange = () => {
138
+ if (pc.iceGatheringState === 'complete') {
139
+ doneGatheringIceCandidates();
140
+ }
141
+ };
142
+
143
+ pc.createDataChannel('data');
144
+
145
+ pc.createOffer()
146
+ .then((offer) => pc.setLocalDescription(offer))
147
+ .catch((e) => {
148
+ this.webex.logger.error('Failed to detect ip network version:', e);
149
+ reject(e);
150
+ });
151
+ });
152
+ },
153
+
154
+ /**
155
+ * Detects if we are on IPv4 and/or IPv6 network. Once it resolves, read the
156
+ * supportsIpV4 and supportsIpV6 props to find out the result.
157
+ *
158
+ * @returns {Promise<Object>}
159
+ */
160
+ async detect() {
161
+ let results;
162
+ let pc;
163
+
164
+ try {
165
+ pc = new RTCPeerConnection();
166
+
167
+ results = await this.gatherLocalCandidates(pc);
168
+ } finally {
169
+ pc.close();
170
+ }
171
+
172
+ return results;
173
+ },
174
+ });
175
+
176
+ export default IpNetworkDetector;
package/src/metrics.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // Metric to do with WDM registration
2
2
  export default {
3
3
  JS_SDK_WDM_REGISTRATION_SUCCESSFUL: 'JS_SDK_WDM_REGISTRATION_SUCCESSFUL',
4
- JS_SDK_WDM_REGISTRATION_FAILED: 'JS_SDK_WDM_REGISTRATION_FAILED'
4
+ JS_SDK_WDM_REGISTRATION_FAILED: 'JS_SDK_WDM_REGISTRATION_FAILED',
5
5
  };
6
-