@webex/plugin-meetings 3.12.0-webex-services-ready.4 → 3.13.0-next.1
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.
- package/.sdd/manifest.json +1312 -0
- package/.sdd/templates/.source.json +30 -0
- package/.sdd/templates/component-repo/module-docs/module-spec-quality.md +111 -0
- package/.sdd/templates/component-repo/module-docs/module-spec.template.md +321 -0
- package/.sdd/templates/component-repo/reference-docs/adr/_adr-example.md +59 -0
- package/.sdd/templates/component-repo/reference-docs/patterns/_pattern-example.md +49 -0
- package/.sdd/templates/component-repo/reference-docs/rules/_rule-example.md +42 -0
- package/.sdd/templates/component-repo/standing-docs/AGENTS.template.md +120 -0
- package/.sdd/templates/component-repo/standing-docs/ARCHITECTURE.template.md +206 -0
- package/.sdd/templates/component-repo/standing-docs/CONTRACTS.template.md +90 -0
- package/.sdd/templates/component-repo/standing-docs/DATA_MODEL.template.md +68 -0
- package/.sdd/templates/component-repo/standing-docs/GETTING_STARTED.template.md +111 -0
- package/.sdd/templates/component-repo/standing-docs/GLOSSARY.template.md +57 -0
- package/.sdd/templates/component-repo/standing-docs/REVIEW_CHECKLIST.template.md +69 -0
- package/.sdd/templates/component-repo/standing-docs/RULES.template.md +96 -0
- package/.sdd/templates/component-repo/standing-docs/SECURITY.template.md +84 -0
- package/.sdd/templates/component-repo/standing-docs/SERVICE_STATE.template.md +82 -0
- package/.sdd/templates/component-repo/standing-docs/SPEC_INDEX.template.md +94 -0
- package/.sdd/templates/component-repo/standing-docs/TEST_INDEX.template.md +64 -0
- package/.sdd/templates/component-repo/template-map.json +112 -0
- package/AGENTS.md +130 -4
- package/ai-docs/ARCHITECTURE.md +208 -0
- package/ai-docs/CONTRACTS.md +267 -0
- package/ai-docs/DATA_MODEL.md +64 -0
- package/ai-docs/GETTING_STARTED.md +73 -0
- package/ai-docs/GLOSSARY.md +56 -0
- package/ai-docs/REVIEW_CHECKLIST.md +45 -0
- package/ai-docs/RULES.md +79 -0
- package/ai-docs/SECURITY.md +74 -0
- package/ai-docs/SERVICE_STATE.md +59 -0
- package/ai-docs/SPEC_INDEX.md +85 -0
- package/ai-docs/TEST_INDEX.md +45 -0
- package/ai-docs/adr/0001-migrate-existing-docs-into-sdd.md +61 -0
- package/ai-docs/patterns/defensive-error-propagation.md +55 -0
- package/ai-docs/patterns/event-scope-emission.md +46 -0
- package/ai-docs/patterns/source-to-test-path-mirroring.md +45 -0
- package/ai-docs/patterns/stateless-plugin-request-classes.md +53 -0
- package/ai-docs/patterns/typed-constants-and-enum-values.md +47 -0
- package/assets/README.md +28 -0
- package/assets/e2ee-0.0.1.js +2 -0
- package/assets/e2ee-0.0.1.wasm +0 -0
- package/dist/aiEnableRequest/index.js +1 -1
- package/dist/annotation/index.js +55 -19
- package/dist/annotation/index.js.map +1 -1
- package/dist/assets/e2ee-0.0.1.js +2 -0
- package/dist/assets/e2ee-0.0.1.wasm +0 -0
- package/dist/breakouts/breakout.js +1 -1
- package/dist/breakouts/index.js +39 -5
- package/dist/breakouts/index.js.map +1 -1
- package/dist/common/errors/webex-errors.js +7 -2
- package/dist/common/errors/webex-errors.js.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.js +6 -5
- package/dist/constants.js.map +1 -1
- package/dist/hashTree/hashTreeParser.js +101 -48
- package/dist/hashTree/hashTreeParser.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interceptors/dataChannelAuthToken.js +41 -59
- package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
- package/dist/interceptors/locusRetry.js +1 -1
- package/dist/interceptors/locusRetry.js.map +1 -1
- package/dist/interpretation/index.js +46 -12
- package/dist/interpretation/index.js.map +1 -1
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/locus-info/index.js +236 -80
- package/dist/locus-info/index.js.map +1 -1
- package/dist/locus-info/types.js +2 -1
- package/dist/locus-info/types.js.map +1 -1
- package/dist/media/MediaConnectionAwaiter.js +225 -175
- package/dist/media/MediaConnectionAwaiter.js.map +1 -1
- package/dist/meeting/index.js +355 -299
- package/dist/meeting/index.js.map +1 -1
- package/dist/meeting/util.js +8 -2
- package/dist/meeting/util.js.map +1 -1
- package/dist/meeting/voicea-meeting.js +2 -1
- package/dist/meeting/voicea-meeting.js.map +1 -1
- package/dist/meeting-info/meeting-info-v2.js +10 -3
- package/dist/meeting-info/meeting-info-v2.js.map +1 -1
- package/dist/meetings/index.js +72 -31
- package/dist/meetings/index.js.map +1 -1
- package/dist/multistream/remoteMediaManager.js +32 -4
- package/dist/multistream/remoteMediaManager.js.map +1 -1
- package/dist/multistream/sendSlotManager.js +11 -1
- package/dist/multistream/sendSlotManager.js.map +1 -1
- package/dist/types/annotation/index.d.ts +19 -0
- package/dist/types/common/errors/webex-errors.d.ts +6 -2
- package/dist/types/config.d.ts +1 -0
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/hashTree/hashTreeParser.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locus-info/index.d.ts +45 -1
- package/dist/types/locus-info/types.d.ts +1 -0
- package/dist/types/media/MediaConnectionAwaiter.d.ts +61 -53
- package/dist/types/meeting/index.d.ts +49 -12
- package/dist/types/meeting/util.d.ts +3 -1
- package/dist/types/meeting-info/meeting-info-v2.d.ts +1 -0
- package/dist/types/meetings/index.d.ts +2 -1
- package/dist/types/multistream/remoteMediaManager.d.ts +18 -0
- package/dist/types/multistream/sendSlotManager.d.ts +5 -1
- package/dist/webinar/index.js +298 -255
- package/dist/webinar/index.js.map +1 -1
- package/package.json +25 -23
- package/src/aiEnableRequest/ai-docs/ai-enable-request-spec.md +223 -0
- package/src/annotation/ai-docs/annotation-spec.md +236 -0
- package/src/annotation/index.ts +61 -29
- package/src/breakouts/ai-docs/breakouts-spec.md +324 -0
- package/src/breakouts/index.ts +35 -2
- package/src/common/errors/webex-errors.ts +8 -2
- package/src/config.ts +5 -1
- package/src/constants.ts +2 -1
- package/src/controls-options-manager/ai-docs/controls-options-manager-spec.md +243 -0
- package/src/hashTree/ai-docs/hash-tree-spec.md +267 -0
- package/src/hashTree/hashTreeParser.ts +67 -3
- package/src/index.ts +1 -0
- package/src/interceptors/ai-docs/interceptors-spec.md +247 -0
- package/src/interceptors/dataChannelAuthToken.ts +48 -77
- package/src/interceptors/locusRetry.ts +1 -1
- package/src/interpretation/ai-docs/interpretation-spec.md +256 -0
- package/src/interpretation/index.ts +38 -1
- package/src/locus-info/ai-docs/locus-info-spec.md +293 -0
- package/src/locus-info/index.ts +156 -35
- package/src/locus-info/types.ts +1 -0
- package/src/media/MediaConnectionAwaiter.ts +223 -207
- package/src/media/ai-docs/media-spec.md +267 -0
- package/src/meeting/ai-docs/meeting-spec.md +404 -0
- package/src/meeting/index.ts +332 -296
- package/src/meeting/util.ts +7 -4
- package/src/meeting/voicea-meeting.ts +1 -1
- package/src/meeting-info/ai-docs/meeting-info-spec.md +261 -0
- package/src/meeting-info/meeting-info-v2.ts +7 -2
- package/src/meetings/ai-docs/meetings-spec.md +296 -0
- package/src/meetings/index.ts +59 -23
- package/src/member/ai-docs/member-spec.md +196 -0
- package/src/members/ai-docs/members-spec.md +256 -0
- package/src/metrics/ai-docs/metrics-spec.md +185 -0
- package/src/multistream/ai-docs/multistream-spec.md +295 -0
- package/src/multistream/remoteMediaManager.ts +23 -1
- package/src/multistream/sendSlotManager.ts +15 -1
- package/src/personal-meeting-room/ai-docs/personal-meeting-room-spec.md +234 -0
- package/src/reachability/ai-docs/reachability-spec.md +261 -0
- package/src/reactions/ai-docs/reactions-spec.md +198 -0
- package/src/reconnection-manager/ai-docs/reconnection-manager-spec.md +272 -0
- package/src/recording-controller/ai-docs/recording-controller-spec.md +223 -0
- package/src/roap/ai-docs/roap-spec.md +241 -0
- package/src/webinar/ai-docs/webinar-spec.md +243 -0
- package/src/webinar/index.ts +168 -188
- package/test/unit/spec/annotation/index.ts +214 -182
- package/test/unit/spec/breakouts/index.ts +145 -13
- package/test/unit/spec/hashTree/hashTreeParser.ts +212 -1
- package/test/unit/spec/interceptors/dataChannelAuthToken.ts +81 -99
- package/test/unit/spec/interceptors/locusRetry.ts +29 -1
- package/test/unit/spec/interpretation/index.ts +93 -0
- package/test/unit/spec/locus-info/index.js +397 -0
- package/test/unit/spec/media/MediaConnectionAwaiter.ts +426 -19
- package/test/unit/spec/media/properties.ts +3 -3
- package/test/unit/spec/meeting/index.js +1219 -723
- package/test/unit/spec/meeting/utils.js +52 -18
- package/test/unit/spec/meeting/voicea-meeting.ts +85 -1
- package/test/unit/spec/meeting-info/meetinginfov2.js +69 -1
- package/test/unit/spec/meetings/index.js +145 -43
- package/test/unit/spec/multistream/remoteMediaManager.ts +46 -0
- package/test/unit/spec/multistream/sendSlotManager.ts +30 -2
- package/test/unit/spec/webinar/index.ts +886 -718
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Defer} from '@webex/common';
|
|
2
2
|
import {ConnectionState, MediaConnectionEventNames} from '@webex/internal-media-core';
|
|
3
3
|
import LoggerProxy from '../common/logs/logger-proxy';
|
|
4
|
-
import {
|
|
4
|
+
import {DTLS_CONNECTION_TIMEOUT, ICE_CONNECTION_TIMEOUT} from '../constants';
|
|
5
5
|
import BEHAVIORAL_METRICS from '../metrics/constants';
|
|
6
6
|
import Metrics from '../metrics';
|
|
7
7
|
|
|
@@ -12,297 +12,313 @@ export interface MediaConnectionAwaiterProps {
|
|
|
12
12
|
|
|
13
13
|
export interface FailureResult {
|
|
14
14
|
iceConnected: boolean;
|
|
15
|
+
iceConnectedAtLeastOnce: boolean;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
type State =
|
|
19
|
+
| {name: 'idle'}
|
|
20
|
+
| {name: 'ice'; gatheringRetried: boolean}
|
|
21
|
+
| {name: 'dtls'}
|
|
22
|
+
| {name: 'connected'}
|
|
23
|
+
| {name: 'failed'; result: FailureResult};
|
|
24
|
+
|
|
25
|
+
type ActiveState = Extract<State, {name: 'ice' | 'dtls'}>;
|
|
26
|
+
type EnteredState = Exclude<State, {name: 'idle'}>;
|
|
27
|
+
|
|
28
|
+
const PHASE_TIMEOUT: Record<ActiveState['name'], number> = {
|
|
29
|
+
ice: ICE_CONNECTION_TIMEOUT,
|
|
30
|
+
dtls: DTLS_CONNECTION_TIMEOUT,
|
|
31
|
+
};
|
|
32
|
+
|
|
17
33
|
/**
|
|
18
|
-
*
|
|
34
|
+
* Waits for ICE and DTLS connectivity using explicit lifecycle states.
|
|
19
35
|
*/
|
|
20
36
|
export default class MediaConnectionAwaiter {
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private correlationId: string;
|
|
27
|
-
private onTimeoutCallback: () => void;
|
|
28
|
-
private peerConnectionStateCallback: () => void;
|
|
29
|
-
private iceConnectionStateCallback: () => void;
|
|
30
|
-
private iceGatheringStateCallback: () => void;
|
|
37
|
+
private props: MediaConnectionAwaiterProps;
|
|
38
|
+
private state: State = {name: 'idle'};
|
|
39
|
+
private timer?: ReturnType<typeof setTimeout>;
|
|
40
|
+
private iceConnectedAtLeastOnce = false;
|
|
41
|
+
private defer = new Defer();
|
|
31
42
|
|
|
32
43
|
/**
|
|
33
|
-
* @param {MediaConnectionAwaiterProps}
|
|
44
|
+
* @param {MediaConnectionAwaiterProps} props
|
|
34
45
|
*/
|
|
35
|
-
constructor(
|
|
36
|
-
this.
|
|
37
|
-
this.defer = new Defer();
|
|
38
|
-
this.retried = false;
|
|
39
|
-
this.iceConnected = false;
|
|
40
|
-
this.correlationId = correlationId;
|
|
41
|
-
this.onTimeoutCallback = this.onTimeout.bind(this);
|
|
42
|
-
this.peerConnectionStateCallback = this.peerConnectionStateHandler.bind(this);
|
|
43
|
-
this.iceConnectionStateCallback = this.iceConnectionStateHandler.bind(this);
|
|
44
|
-
this.iceGatheringStateCallback = this.iceGatheringStateHandler.bind(this);
|
|
46
|
+
constructor(props: MediaConnectionAwaiterProps) {
|
|
47
|
+
this.props = props;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @returns {boolean}
|
|
51
|
+
* Registers listeners and starts the wait once, settling terminal connections immediately.
|
|
52
|
+
* @returns {Promise<void>} Rejects with FailureResult on failure
|
|
51
53
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
waitForMediaConnectionConnected(): Promise<void> {
|
|
55
|
+
if (this.state.name === 'idle') {
|
|
56
|
+
this.registerCallbacks();
|
|
57
|
+
this.evaluate('waitForMediaConnectionConnected');
|
|
58
|
+
}
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
* Returns true if the connection is in an unrecoverable "failed" state
|
|
58
|
-
*
|
|
59
|
-
* @returns {boolean}
|
|
60
|
-
*/
|
|
61
|
-
private isFailed(): boolean {
|
|
62
|
-
return this.webrtcMediaConnection.getConnectionState() === ConnectionState.Failed;
|
|
60
|
+
return this.defer.promise;
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
64
|
+
* Applies a transition to a new state and owns its deadline or terminal settlement.
|
|
65
|
+
* @param {EnteredState} next - State to enter; an active wait cannot return to idle
|
|
66
|
+
* @param {string} reason - Trigger or reason for the transition
|
|
67
|
+
* @returns {void}
|
|
69
68
|
*/
|
|
70
|
-
private
|
|
71
|
-
|
|
69
|
+
private enter(next: EnteredState, reason: string): void {
|
|
70
|
+
if (this.isTerminal()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
LoggerProxy.logger.log(
|
|
75
|
+
`Media:MediaConnectionAwaiter#enter --> ${this.state.name} -> ${next.name}: ${reason}`
|
|
76
|
+
);
|
|
77
|
+
this.state = next;
|
|
78
|
+
|
|
79
|
+
switch (next.name) {
|
|
80
|
+
case 'ice':
|
|
81
|
+
case 'dtls':
|
|
82
|
+
this.armTimer(next, reason);
|
|
83
|
+
break;
|
|
84
|
+
case 'connected':
|
|
85
|
+
this.teardown();
|
|
86
|
+
this.defer.resolve();
|
|
87
|
+
break;
|
|
88
|
+
case 'failed':
|
|
89
|
+
this.teardown();
|
|
90
|
+
this.defer.reject(next.result);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
/**
|
|
77
|
-
* Returns
|
|
78
|
-
*
|
|
96
|
+
* Returns whether the promise has settled.
|
|
79
97
|
* @returns {boolean}
|
|
80
98
|
*/
|
|
81
|
-
private
|
|
82
|
-
return this.
|
|
99
|
+
private isTerminal(): boolean {
|
|
100
|
+
return this.state.name === 'connected' || this.state.name === 'failed';
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @returns {void}
|
|
104
|
+
* Returns the current state only if it owns a connection deadline.
|
|
105
|
+
* @returns {ActiveState | undefined}
|
|
89
106
|
*/
|
|
90
|
-
private
|
|
91
|
-
this
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
95
|
-
this.webrtcMediaConnection.off(
|
|
96
|
-
MediaConnectionEventNames.PEER_CONNECTION_STATE_CHANGED,
|
|
97
|
-
this.peerConnectionStateCallback
|
|
98
|
-
);
|
|
99
|
-
this.webrtcMediaConnection.off(
|
|
100
|
-
MediaConnectionEventNames.ICE_CONNECTION_STATE_CHANGED,
|
|
101
|
-
this.iceConnectionStateCallback
|
|
102
|
-
);
|
|
107
|
+
private getActiveState(): ActiveState | undefined {
|
|
108
|
+
const {state} = this;
|
|
109
|
+
|
|
110
|
+
return state.name === 'ice' || state.name === 'dtls' ? state : undefined;
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @returns {
|
|
114
|
+
* Logs current browser state and transitions when connectivity or phase changes.
|
|
115
|
+
* @param {string} trigger - Callback or operation that triggered evaluation
|
|
116
|
+
* @returns {boolean} Whether a state transition occurred
|
|
109
117
|
*/
|
|
110
|
-
|
|
118
|
+
private evaluate(trigger: string): boolean {
|
|
119
|
+
const connection = this.props.webrtcMediaConnection;
|
|
120
|
+
const connectionState = connection.getConnectionState();
|
|
121
|
+
|
|
111
122
|
LoggerProxy.logger.log(
|
|
112
|
-
`Media:MediaConnectionAwaiter#
|
|
123
|
+
`Media:MediaConnectionAwaiter#evaluate --> triggered by ${trigger}, connection state: ${connectionState}, peer connection state: ${connection.getPeerConnectionState()}, ICE connection state: ${connection.getIceConnectionState()}, ICE gathering state: ${connection.getIceGatheringState()}, awaiter state: ${
|
|
124
|
+
this.state.name
|
|
125
|
+
}`
|
|
113
126
|
);
|
|
114
127
|
|
|
115
|
-
if (this.
|
|
116
|
-
|
|
117
|
-
'Media:MediaConnectionAwaiter#connectionStateChange --> ICE failed, rejecting'
|
|
118
|
-
);
|
|
119
|
-
this.clearCallbacks();
|
|
120
|
-
|
|
121
|
-
this.defer.reject({
|
|
122
|
-
iceConnected: this.iceConnected,
|
|
123
|
-
} satisfies FailureResult);
|
|
128
|
+
if (this.isTerminal()) {
|
|
129
|
+
return false;
|
|
124
130
|
}
|
|
125
131
|
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
const connectivity = this.getConnectivity();
|
|
133
|
+
if (connectionState === ConnectionState.Connected) {
|
|
134
|
+
this.enter({name: 'connected'}, trigger);
|
|
135
|
+
|
|
136
|
+
return true;
|
|
128
137
|
}
|
|
138
|
+
if (connectionState === ConnectionState.Failed || connectionState === ConnectionState.Closed) {
|
|
139
|
+
this.enter({name: 'failed', result: connectivity}, trigger);
|
|
129
140
|
|
|
130
|
-
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
131
143
|
|
|
132
|
-
|
|
144
|
+
const phase = connectivity.iceConnected ? 'dtls' : 'ice';
|
|
145
|
+
if (this.state.name === phase) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
133
148
|
|
|
134
|
-
|
|
149
|
+
this.enter(phase === 'ice' ? {name: 'ice', gatheringRetried: false} : {name: 'dtls'}, trigger);
|
|
135
150
|
|
|
136
|
-
|
|
151
|
+
return true;
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
/**
|
|
140
|
-
* Listener for peer connection state
|
|
141
|
-
*
|
|
155
|
+
* Listener for peer connection state changes.
|
|
142
156
|
* @returns {void}
|
|
143
157
|
*/
|
|
144
|
-
peerConnectionStateHandler(): void {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
LoggerProxy.logger.log(
|
|
148
|
-
`Media:MediaConnectionAwaiter#peerConnectionStateHandler --> Peer connection state change -> ${peerConnectionState}`
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
this.connectionStateChange();
|
|
152
|
-
}
|
|
158
|
+
peerConnectionStateHandler = (): void => {
|
|
159
|
+
this.evaluate('peerConnectionStateHandler');
|
|
160
|
+
};
|
|
153
161
|
|
|
154
162
|
/**
|
|
155
|
-
* Listener for ICE connection state
|
|
156
|
-
*
|
|
163
|
+
* Listener for ICE connection state changes.
|
|
157
164
|
* @returns {void}
|
|
158
165
|
*/
|
|
159
|
-
iceConnectionStateHandler(): void {
|
|
160
|
-
|
|
166
|
+
iceConnectionStateHandler = (): void => {
|
|
167
|
+
this.evaluate('iceConnectionStateHandler');
|
|
168
|
+
};
|
|
161
169
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Restarts only an unchanged ICE phase when gathering completes.
|
|
172
|
+
* @returns {void}
|
|
173
|
+
*/
|
|
174
|
+
iceGatheringStateHandler = (): void => {
|
|
175
|
+
const changed = this.evaluate('iceGatheringStateHandler');
|
|
176
|
+
if (!changed && this.state.name === 'ice' && this.isIceGatheringCompleted()) {
|
|
177
|
+
this.armTimer(this.state, 'iceGatheringStateHandler: ICE gathering completed');
|
|
168
178
|
}
|
|
169
|
-
|
|
170
|
-
this.connectionStateChange();
|
|
171
|
-
}
|
|
179
|
+
};
|
|
172
180
|
|
|
173
181
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
182
|
+
* Rechecks connectivity before applying the deadline or the ICE gathering retry.
|
|
176
183
|
* @returns {void}
|
|
177
184
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
`Media:MediaConnectionAwaiter#iceGatheringStateHandler --> ICE gathering state change -> ${iceGatheringState}`
|
|
183
|
-
);
|
|
185
|
+
onTimeout = (): void => {
|
|
186
|
+
if (this.evaluate('onTimeout')) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
184
189
|
|
|
185
|
-
|
|
190
|
+
const state = this.getActiveState();
|
|
191
|
+
if (!state) {
|
|
186
192
|
return;
|
|
187
193
|
}
|
|
188
194
|
|
|
189
|
-
|
|
195
|
+
this.sendMetric().catch((error) => {
|
|
196
|
+
LoggerProxy.logger.warn('Media:MediaConnectionAwaiter#onTimeout --> metric failed', error);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
if (state.name === 'ice' && !state.gatheringRetried && !this.isIceGatheringCompleted()) {
|
|
200
|
+
this.enter(
|
|
201
|
+
{...state, gatheringRetried: true},
|
|
202
|
+
'onTimeout: ICE gathering incomplete, retrying once'
|
|
203
|
+
);
|
|
204
|
+
|
|
190
205
|
return;
|
|
191
206
|
}
|
|
192
207
|
|
|
193
|
-
|
|
208
|
+
this.enter({name: 'failed', result: this.getConnectivity()}, `${state.name} timeout`);
|
|
209
|
+
};
|
|
194
210
|
|
|
195
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Arms an active phase's deadline and logs every start or restart.
|
|
213
|
+
* @param {ActiveState} state - Active state whose deadline is being started
|
|
214
|
+
* @param {string} reason - Why the deadline is being started or restarted
|
|
215
|
+
* @returns {void}
|
|
216
|
+
*/
|
|
217
|
+
private armTimer(state: ActiveState, reason: string): void {
|
|
218
|
+
if (this.timer !== undefined) {
|
|
219
|
+
clearTimeout(this.timer);
|
|
220
|
+
}
|
|
221
|
+
const timeout = PHASE_TIMEOUT[state.name];
|
|
222
|
+
this.timer = setTimeout(this.onTimeout, timeout);
|
|
223
|
+
LoggerProxy.logger.log(
|
|
224
|
+
`Media:MediaConnectionAwaiter#armTimer --> ${state.name} (${timeout}ms): ${reason}`
|
|
225
|
+
);
|
|
196
226
|
}
|
|
197
227
|
|
|
198
228
|
/**
|
|
199
|
-
*
|
|
200
|
-
* issues where browser doesn't update the RTCPeerConnection's iceConnectionState or connectionState
|
|
201
|
-
*
|
|
229
|
+
* Releases the deadline and registered listeners on either terminal transition.
|
|
202
230
|
* @returns {void}
|
|
203
231
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// but for the purpose of this metric it's fine to just use the first one
|
|
209
|
-
const transportReports = Array.from(
|
|
210
|
-
stats.values().filter((report) => report.type === 'transport')
|
|
211
|
-
) as Record<string, number | string>[];
|
|
212
|
-
|
|
213
|
-
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.MEDIA_STILL_NOT_CONNECTED, {
|
|
214
|
-
correlation_id: this.correlationId,
|
|
215
|
-
numTransports: transportReports.length,
|
|
216
|
-
dtlsState: transportReports[0]?.dtlsState,
|
|
217
|
-
iceState: transportReports[0]?.iceState,
|
|
218
|
-
packetsSent: transportReports[0]?.packetsSent,
|
|
219
|
-
packetsReceived: transportReports[0]?.packetsReceived,
|
|
220
|
-
dataChannelState: this.webrtcMediaConnection.multistreamConnection?.dataChannel?.readyState,
|
|
221
|
-
});
|
|
232
|
+
private teardown(): void {
|
|
233
|
+
clearTimeout(this.timer);
|
|
234
|
+
this.timer = undefined;
|
|
235
|
+
this.unregisterCallbacks();
|
|
222
236
|
}
|
|
223
237
|
|
|
224
238
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
239
|
+
* Registers each callback once with a stable function reference.
|
|
227
240
|
* @returns {void}
|
|
228
241
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
this.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
'Media:MediaConnectionAwaiter#onTimeout --> ICE gathering did not complete within the timeout for the first time, retrying once'
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
// retry once if ICE gathering is not completed
|
|
247
|
-
this.retried = true;
|
|
248
|
-
clearTimeout(this.timer);
|
|
249
|
-
this.timer = setTimeout(this.onTimeoutCallback, ICE_AND_DTLS_CONNECTION_TIMEOUT);
|
|
250
|
-
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
LoggerProxy.logger.warn(
|
|
255
|
-
'Media:MediaConnectionAwaiter#onTimeout --> ICE gathering did not complete within the timeout for the second time, rejecting'
|
|
256
|
-
);
|
|
257
|
-
} else {
|
|
258
|
-
LoggerProxy.logger.warn(
|
|
259
|
-
'Media:MediaConnectionAwaiter#onTimeout --> ICE gathering completed, but connection state is not connected, rejecting'
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
this.clearCallbacks();
|
|
264
|
-
|
|
265
|
-
this.defer.reject({
|
|
266
|
-
iceConnected: this.iceConnected,
|
|
267
|
-
} satisfies FailureResult);
|
|
242
|
+
private registerCallbacks(): void {
|
|
243
|
+
const connection = this.props.webrtcMediaConnection;
|
|
244
|
+
connection.on(
|
|
245
|
+
MediaConnectionEventNames.PEER_CONNECTION_STATE_CHANGED,
|
|
246
|
+
this.peerConnectionStateHandler
|
|
247
|
+
);
|
|
248
|
+
connection.on(
|
|
249
|
+
MediaConnectionEventNames.ICE_CONNECTION_STATE_CHANGED,
|
|
250
|
+
this.iceConnectionStateHandler
|
|
251
|
+
);
|
|
252
|
+
connection.on(
|
|
253
|
+
MediaConnectionEventNames.ICE_GATHERING_STATE_CHANGED,
|
|
254
|
+
this.iceGatheringStateHandler
|
|
255
|
+
);
|
|
268
256
|
}
|
|
269
257
|
|
|
270
258
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* @returns {Promise<void>} In case of failure, the promise is rejected with FailureResult
|
|
259
|
+
* Removes callbacks when the wait reaches a terminal state.
|
|
260
|
+
* @returns {void}
|
|
274
261
|
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return Promise.resolve();
|
|
282
|
-
}
|
|
283
|
-
LoggerProxy.logger.log(
|
|
284
|
-
'Media:MediaConnectionAwaiter#waitForMediaConnectionConnected --> Waiting for media connection to be connected'
|
|
262
|
+
private unregisterCallbacks(): void {
|
|
263
|
+
const connection = this.props.webrtcMediaConnection;
|
|
264
|
+
connection.off(
|
|
265
|
+
MediaConnectionEventNames.ICE_GATHERING_STATE_CHANGED,
|
|
266
|
+
this.iceGatheringStateHandler
|
|
285
267
|
);
|
|
286
|
-
|
|
287
|
-
this.iceConnected = this.isIceConnected();
|
|
288
|
-
|
|
289
|
-
this.webrtcMediaConnection.on(
|
|
268
|
+
connection.off(
|
|
290
269
|
MediaConnectionEventNames.PEER_CONNECTION_STATE_CHANGED,
|
|
291
|
-
this.
|
|
270
|
+
this.peerConnectionStateHandler
|
|
292
271
|
);
|
|
293
|
-
|
|
294
|
-
this.webrtcMediaConnection.on(
|
|
272
|
+
connection.off(
|
|
295
273
|
MediaConnectionEventNames.ICE_CONNECTION_STATE_CHANGED,
|
|
296
|
-
this.
|
|
274
|
+
this.iceConnectionStateHandler
|
|
297
275
|
);
|
|
276
|
+
}
|
|
298
277
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Returns whether ICE gathering has completed.
|
|
280
|
+
* @returns {boolean}
|
|
281
|
+
*/
|
|
282
|
+
private isIceGatheringCompleted(): boolean {
|
|
283
|
+
return this.props.webrtcMediaConnection.getIceGatheringState() === 'complete';
|
|
284
|
+
}
|
|
303
285
|
|
|
304
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Captures current and historical ICE connectivity for failures and metrics.
|
|
288
|
+
* @returns {FailureResult}
|
|
289
|
+
*/
|
|
290
|
+
private getConnectivity(): FailureResult {
|
|
291
|
+
const iceState = this.props.webrtcMediaConnection.getIceConnectionState();
|
|
292
|
+
const iceConnected = iceState === 'connected' || iceState === 'completed';
|
|
293
|
+
this.iceConnectedAtLeastOnce ||= iceConnected;
|
|
305
294
|
|
|
306
|
-
return this.
|
|
295
|
+
return {iceConnected, iceConnectedAtLeastOnce: this.iceConnectedAtLeastOnce};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Sends connectivity diagnostics when a deadline expires.
|
|
300
|
+
* @returns {Promise<void>}
|
|
301
|
+
*/
|
|
302
|
+
private async sendMetric(): Promise<void> {
|
|
303
|
+
// Capture connectivity before awaiting stats, which may finish after another state change.
|
|
304
|
+
const connectivity = this.getConnectivity();
|
|
305
|
+
const connection = this.props.webrtcMediaConnection;
|
|
306
|
+
const stats = await connection.getStats();
|
|
307
|
+
|
|
308
|
+
// There may be multiple transport reports; the first is sufficient for this metric.
|
|
309
|
+
const transportReports = Array.from(
|
|
310
|
+
stats.values().filter((report) => report.type === 'transport')
|
|
311
|
+
) as Record<string, number | string>[];
|
|
312
|
+
|
|
313
|
+
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.MEDIA_STILL_NOT_CONNECTED, {
|
|
314
|
+
correlation_id: this.props.correlationId,
|
|
315
|
+
...connectivity,
|
|
316
|
+
numTransports: transportReports.length,
|
|
317
|
+
dtlsState: transportReports[0]?.dtlsState,
|
|
318
|
+
iceState: transportReports[0]?.iceState,
|
|
319
|
+
packetsSent: transportReports[0]?.packetsSent,
|
|
320
|
+
packetsReceived: transportReports[0]?.packetsReceived,
|
|
321
|
+
dataChannelState: connection.multistreamConnection?.dataChannel?.readyState,
|
|
322
|
+
});
|
|
307
323
|
}
|
|
308
324
|
}
|