@webex/plugin-meetings 3.12.0-next.174 → 3.12.0-next.175
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/dist/aiEnableRequest/index.js +1 -1
- package/dist/breakouts/breakout.js +1 -1
- package/dist/breakouts/index.js +1 -1
- package/dist/common/errors/webex-errors.js +7 -2
- package/dist/common/errors/webex-errors.js.map +1 -1
- package/dist/constants.js +6 -5
- package/dist/constants.js.map +1 -1
- package/dist/interpretation/index.js +1 -1
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/media/MediaConnectionAwaiter.js +225 -175
- package/dist/media/MediaConnectionAwaiter.js.map +1 -1
- package/dist/meeting/index.js +2 -1
- package/dist/meeting/index.js.map +1 -1
- package/dist/types/common/errors/webex-errors.d.ts +6 -2
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/media/MediaConnectionAwaiter.d.ts +61 -53
- package/dist/webinar/index.js +1 -1
- package/package.json +1 -1
- package/src/common/errors/webex-errors.ts +8 -2
- package/src/constants.ts +2 -1
- package/src/media/MediaConnectionAwaiter.ts +223 -207
- package/src/media/ai-docs/media-spec.md +10 -10
- package/src/meeting/index.ts +2 -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 +17 -6
|
@@ -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
|
}
|
|
@@ -76,7 +76,7 @@ src/media/
|
|
|
76
76
|
| `media.2` | SDK / in-process | local stream setters: `setLocalAudioStream()`, `setLocalVideoStream()`, `setLocalShareAudioStream()`, `setLocalShareVideoStream()`, and `hasLocalShareStream()` | Keep microphone, camera, and share tracks distinct so Meeting can publish and stop them independently. | Preserve optional-stream inputs and the boolean share predicate. | `src/media/properties.ts` | [CONTRACTS](../../../ai-docs/CONTRACTS.md) |
|
|
77
77
|
| `media.3` | SDK / in-process | remote setters: `setRemoteAudioStream()`, `setRemoteVideoStream()`, `setRemoteShareStream()`, `setRemoteQualityLevel()` | Store the remote media projections consumed by Meeting and UI code. | Preserve independent audio, video, share, and quality fields. | `src/media/properties.ts` | [CONTRACTS](../../../ai-docs/CONTRACTS.md) |
|
|
78
78
|
| `media.4` | SDK / lifecycle | `unsetRemoteMedia()`, `unsetRemoteShareStream()`, `unsetRemoteStreams()`, and `unsetPeerConnection()` | Detach stored references when the owning Meeting explicitly replaces or tears down media. | These methods do not close the peer connection or stop tracks themselves. | `src/media/properties.ts` | [CONTRACTS](../../../ai-docs/CONTRACTS.md) |
|
|
79
|
-
| `media.5` | SDK / async | `MediaProperties.waitForMediaConnectionConnected()` plus `
|
|
79
|
+
| `media.5` | SDK / async | `MediaProperties.waitForMediaConnectionConnected()` plus `peerConnectionStateHandler()`, `iceConnectionStateHandler()`, `iceGatheringStateHandler()`, `onTimeout()`, and `waitForMediaConnectionConnected()` | Resolve readiness or reject with `{iceConnected, iceConnectedAtLeastOnce}` after concrete connection/ICE event and timeout evaluation. | Allow one incomplete-gathering retry per ICE phase; DTLS does not retry. Preserve terminal cleanup. | `src/media/properties.ts`, `src/media/MediaConnectionAwaiter.ts` | [CONTRACTS](../../../ai-docs/CONTRACTS.md) |
|
|
80
80
|
| `media.6` | diagnostic | `MediaProperties.getCurrentConnectionInfo()`, `sendMediaIssueMetric()`, and `MediaConnectionAwaiter.sendMetric()` | Derive connection/IP diagnostics and emit bounded media issue information. | Preserve metric throttling and the existing unknown/fallback values. | `src/media/properties.ts`, `src/media/MediaConnectionAwaiter.ts` | [CONTRACTS](../../../ai-docs/CONTRACTS.md) |
|
|
81
81
|
| `media.7` | exported types/constants | `BundlePolicy`, `MediaDirection`, `IPVersion`, `MediaConnectionAwaiterProps`, and `FailureResult` | Provide the concrete configuration and failure shapes used across the meetings package. | Definitions are partitioned precisely: BundlePolicy is in the media index, MediaDirection and IPVersion are in properties, and the awaiter props/result types are in MediaConnectionAwaiter. Add fields compatibly; raw enum/type values are shared package contracts. | `src/media/index.ts`, `src/media/properties.ts`, `src/media/MediaConnectionAwaiter.ts` | [CONTRACTS](../../../ai-docs/CONTRACTS.md) |
|
|
82
82
|
|
|
@@ -112,15 +112,15 @@ Browser WebRTC, @webex/internal-media-core, media helpers, meeting/Locus signali
|
|
|
112
112
|
| ID | WHAT | WHY | Source Evidence | Test / Example Evidence | Assumptions / Gaps | Confidence |
|
|
113
113
|
|---|---|---|---|---|---|---|
|
|
114
114
|
| `MEDIA-R-001` | create and configure a media connection. | Creates/configures media-core connections, derives media properties, awaits readiness, and exposes media lifecycle helpers to Meeting. | `src/media/index.ts` | `test/unit/spec/media/index.ts` | none | PRESENT |
|
|
115
|
-
| `MEDIA-R-002` | `MediaProperties` attaches/replaces local and remote streams and the peer connection; `util.ts` constructs a `MediaStream` from received tracks. `MediaConnectionAwaiter` registers connection-readiness listeners and schedules its timeout,
|
|
115
|
+
| `MEDIA-R-002` | `MediaProperties` attaches/replaces local and remote streams and the peer connection; `util.ts` constructs a `MediaStream` from received tracks. `MediaConnectionAwaiter` registers connection-readiness listeners and schedules its timeout, and clears its timer and listeners on every terminal transition. | Stream ownership must remain separate from readiness waiting, and readiness settlement must release its timer and listeners without closing the owned transport. | `src/media/properties.ts`, `src/media/util.ts`, `src/media/MediaConnectionAwaiter.ts` | `test/unit/spec/media/properties.ts`, `test/unit/spec/media/MediaConnectionAwaiter.ts` | none | PRESENT |
|
|
116
116
|
| `MEDIA-R-003` | Connection failure or timeout rejects with the awaiter result and `MediaConnectionAwaiter.clearCallbacks()` removes only the listeners it registered. It does not close the peer connection or unset streams; explicit `MediaProperties` unset methods detach stored references, while Meeting owns connection closure. | Callers must distinguish readiness-listener cleanup from transport and stream teardown. | `src/media/MediaConnectionAwaiter.ts`, `src/media/properties.ts`, `src/meeting/index.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts`, `test/unit/spec/media/properties.ts` | none | PRESENT |
|
|
117
117
|
| `MEDIA-R-004` | Media properties translate meeting options and local-stream state into media-core connection configuration. | Meeting callers should not depend directly on low-level media-core option shapes. | `src/media/properties.ts`, `src/media/index.ts` | `test/unit/spec/media/properties.ts`, `test/unit/spec/media/index.ts` | none | PRESENT |
|
|
118
|
-
| `MEDIA-R-005` |
|
|
118
|
+
| `MEDIA-R-005` | The awaiter transitions through idle, ICE, DTLS, connected, and failed states. Each ICE entry permits one retry if gathering remains incomplete; DTLS rejects at its deadline without retrying. Terminal transitions clear the timer and listeners exactly once. | Lifecycle state must own its deadline and retry allowance so ICE recovery resets only the ICE retry, and DTLS cannot be extended by incomplete gathering. | `src/media/MediaConnectionAwaiter.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts` | none | PRESENT |
|
|
119
119
|
| `MEDIA-R-006` | `MediaProperties.unsetRemoteStreams()` and `unsetPeerConnection()` detach the owned remote streams and connection during replacement/teardown; `util.ts` only creates a `MediaStream` from tracks. | Teardown ownership must be explicit so browser tracks and media-core callbacks do not outlive their meeting. | `src/media/properties.ts`, `src/media/util.ts` | `test/unit/spec/media/properties.ts` | none | PRESENT |
|
|
120
120
|
|
|
121
121
|
## Design Overview
|
|
122
122
|
|
|
123
|
-
`index.ts` exports media-facing types and helpers; `util.ts` only creates a `MediaStream`; `properties.ts` owns local/remote streams, the peer connection, teardown, and construction of `MediaConnectionAwaiter`, which waits on WebRTC/ICE events with
|
|
123
|
+
`index.ts` exports media-facing types and helpers; `util.ts` only creates a `MediaStream`; `properties.ts` owns local/remote streams, the peer connection, teardown, and construction of `MediaConnectionAwaiter`, which waits on WebRTC/ICE events with phase deadlines. Its `State` union owns lifecycle and ICE retry allowance; `waitForMediaConnectionConnected()` registers listeners once before evaluation, including for an already terminal connection; `evaluate()` selects transitions, `enter()` applies deadlines or settlement, and `teardown()` removes timers and registered callbacks idempotently.
|
|
124
124
|
|
|
125
125
|
## Data Flow
|
|
126
126
|
|
|
@@ -220,11 +220,11 @@ Media connection, transceivers/streams, readiness waiters, and listener cleanup
|
|
|
220
220
|
|
|
221
221
|
## Business Rules & Invariants
|
|
222
222
|
|
|
223
|
-
- Every readiness waiter exposes one defer result and removes registered listeners on its terminal path.
|
|
223
|
+
- Every readiness waiter exposes one defer result and removes registered listeners on its terminal path. Connected and failed transitions both clear the timer through idempotent teardown. Closed media is not reused, and permission/negotiation failures remain visible. Enforced by `src/media/MediaConnectionAwaiter.ts` and supporting code under `src/media/`.
|
|
224
224
|
|
|
225
225
|
## Concurrency & Reactive Flow
|
|
226
226
|
|
|
227
|
-
- Each `MediaConnectionAwaiter` uses one defer for its specific media-core connection and removes its WebRTC listeners on terminal paths.
|
|
227
|
+
- Each `MediaConnectionAwaiter` uses one defer for its specific media-core connection and removes its WebRTC listeners on terminal paths. Both terminal states clear the timer and prevent later callbacks from restarting the wait. Replacing or tearing down media uses `MediaProperties.unsetRemoteStreams()` and `unsetPeerConnection()` so old stream/connection references are detached before reuse.
|
|
228
228
|
|
|
229
229
|
## Protocol / Wire Format
|
|
230
230
|
|
|
@@ -234,14 +234,14 @@ Media connection, transceivers/streams, readiness waiters, and listener cleanup
|
|
|
234
234
|
|
|
235
235
|
| Condition | Signal | Caller recovery |
|
|
236
236
|
|---|---|---|
|
|
237
|
-
| Media connection reports immediate failure | `
|
|
238
|
-
| Media does not become ready before the awaiter's timeout | The timeout callback rejects with its connection result and removes registered listeners; one retry
|
|
237
|
+
| Media connection reports immediate failure | `evaluate()` enters failed with its connectivity result; teardown clears the timer and registered listeners. | Tear down or replace the connection before beginning a new attempt. |
|
|
238
|
+
| Media does not become ready before the awaiter's timeout | The timeout callback rejects with its connection result and removes registered listeners; one retry is allowed on an incomplete-gathering ICE deadline, reset on each new ICE entry. DTLS deadlines reject without retrying. | Tear down or replace that connection before beginning a new media attempt. |
|
|
239
239
|
| Media connection reaches the expected connected/completed state | The awaiter resolves once and removes its listeners and timer. | Continue using the established connection. |
|
|
240
240
|
| Remote streams or peer connection are replaced/removed | `MediaProperties` unsets the owned stream or connection reference; `util.ts` only constructs a `MediaStream` from supplied tracks. | Do not assign transport lifecycle ownership to the utility helper. |
|
|
241
241
|
|
|
242
242
|
## Pitfalls
|
|
243
243
|
|
|
244
|
-
- Event listeners can fire before or after a wait begins. Register and inspect atomically.
|
|
244
|
+
- Event listeners can fire before or after a wait begins. Register and inspect atomically. Terminal transitions clear the timer and listeners. Returning from DTLS to ICE grants a fresh ICE gathering retry; repeated events within the same phase do not reset that allowance.
|
|
245
245
|
- Public behavior may be reachable through a parent `Meeting`/`Meetings` object even when the source helper is not exported directly.
|
|
246
246
|
|
|
247
247
|
## Key Design Trade-off
|
|
@@ -258,7 +258,7 @@ Use the current mirrored suites: `test/unit/spec/media/MediaConnectionAwaiter.ts
|
|
|
258
258
|
| `MEDIA-R-002` | `test/unit/spec/media/index.ts` | awaiter settlement versus Meeting-owned peer closure needs a boundary assertion |
|
|
259
259
|
| `MEDIA-R-003` | `test/unit/spec/media/MediaConnectionAwaiter.ts`, `test/unit/spec/media/properties.ts` | add a boundary assertion that awaiter rejection removes listeners but neither closes the connection nor unsets `MediaProperties` references |
|
|
260
260
|
| `MEDIA-R-004` | `test/unit/spec/media/properties.ts` | none |
|
|
261
|
-
| `MEDIA-R-005` | `test/unit/spec/media/MediaConnectionAwaiter.ts` |
|
|
261
|
+
| `MEDIA-R-005` | The awaiter transitions through idle, ICE, DTLS, connected, and failed states. Each ICE entry permits one retry if gathering remains incomplete; DTLS rejects at its deadline without retrying. Terminal transitions clear the timer and listeners exactly once. | Lifecycle state must own its deadline and retry allowance so ICE recovery resets only the ICE retry, and DTLS cannot be extended by incomplete gathering. | `src/media/MediaConnectionAwaiter.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts` | none | PRESENT |
|
|
262
262
|
| `MEDIA-R-006` | `test/unit/spec/media/properties.ts` | verify unset during partial setup and replacement |
|
|
263
263
|
|
|
264
264
|
## Traceability
|
package/src/meeting/index.ts
CHANGED
|
@@ -8664,6 +8664,8 @@ export default class Meeting extends StatelessWebexPlugin {
|
|
|
8664
8664
|
selectedCandidatePairChanges,
|
|
8665
8665
|
numTransports,
|
|
8666
8666
|
iceConnected,
|
|
8667
|
+
iceConnectedAtLeastOnce:
|
|
8668
|
+
error instanceof MediaConnectionTimedOutError ? error.iceConnectedAtLeastOnce : undefined,
|
|
8667
8669
|
});
|
|
8668
8670
|
}
|
|
8669
8671
|
}
|