@webex/plugin-meetings 3.13.0-next.13 → 3.13.0-next.15

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 (100) hide show
  1. package/.repo-context.json +577 -0
  2. package/.sdd/manifest.json +1320 -428
  3. package/AGENTS.md +528 -72
  4. package/dist/aiEnableRequest/index.js +1 -1
  5. package/dist/breakouts/breakout.js +1 -1
  6. package/dist/breakouts/index.js +1 -1
  7. package/dist/config.js +1 -1
  8. package/dist/interpretation/index.js +1 -1
  9. package/dist/interpretation/siLanguage.js +1 -1
  10. package/dist/webinar/index.js +1 -1
  11. package/docs/adr/0001-migrate-existing-docs-into-sdd.md +141 -0
  12. package/docs/adr/index.md +26 -0
  13. package/docs/architecture.md +816 -0
  14. package/docs/getting-started.md +177 -0
  15. package/docs/index.md +53 -0
  16. package/docs/specs/README.md +126 -0
  17. package/package.json +21 -21
  18. package/schemas/repo-context.schema.json +796 -0
  19. package/src/aiEnableRequest/docs/README.md +376 -0
  20. package/src/annotation/docs/README.md +402 -0
  21. package/src/breakouts/docs/README.md +643 -0
  22. package/src/controls-options-manager/docs/README.md +365 -0
  23. package/src/hashTree/docs/README.md +566 -0
  24. package/src/interceptors/docs/README.md +434 -0
  25. package/src/interpretation/docs/README.md +420 -0
  26. package/src/locus-info/docs/README.md +609 -0
  27. package/src/media/docs/README.md +488 -0
  28. package/src/meeting/docs/README.md +834 -0
  29. package/src/meeting-info/docs/README.md +352 -0
  30. package/src/meetings/docs/README.md +549 -0
  31. package/src/member/docs/README.md +347 -0
  32. package/src/members/docs/README.md +514 -0
  33. package/src/metrics/docs/README.md +287 -0
  34. package/src/multistream/docs/README.md +523 -0
  35. package/src/personal-meeting-room/docs/README.md +322 -0
  36. package/src/reachability/docs/README.md +548 -0
  37. package/src/reactions/docs/README.md +296 -0
  38. package/src/reconnection-manager/docs/README.md +485 -0
  39. package/src/recording-controller/docs/README.md +335 -0
  40. package/src/roap/docs/README.md +444 -0
  41. package/src/webinar/docs/README.md +425 -0
  42. package/.sdd/templates/.source.json +0 -30
  43. package/.sdd/templates/component-repo/module-docs/module-spec-quality.md +0 -111
  44. package/.sdd/templates/component-repo/module-docs/module-spec.template.md +0 -321
  45. package/.sdd/templates/component-repo/reference-docs/adr/_adr-example.md +0 -59
  46. package/.sdd/templates/component-repo/reference-docs/patterns/_pattern-example.md +0 -49
  47. package/.sdd/templates/component-repo/reference-docs/rules/_rule-example.md +0 -42
  48. package/.sdd/templates/component-repo/standing-docs/AGENTS.template.md +0 -120
  49. package/.sdd/templates/component-repo/standing-docs/ARCHITECTURE.template.md +0 -206
  50. package/.sdd/templates/component-repo/standing-docs/CONTRACTS.template.md +0 -90
  51. package/.sdd/templates/component-repo/standing-docs/DATA_MODEL.template.md +0 -68
  52. package/.sdd/templates/component-repo/standing-docs/GETTING_STARTED.template.md +0 -111
  53. package/.sdd/templates/component-repo/standing-docs/GLOSSARY.template.md +0 -57
  54. package/.sdd/templates/component-repo/standing-docs/REVIEW_CHECKLIST.template.md +0 -69
  55. package/.sdd/templates/component-repo/standing-docs/RULES.template.md +0 -96
  56. package/.sdd/templates/component-repo/standing-docs/SECURITY.template.md +0 -84
  57. package/.sdd/templates/component-repo/standing-docs/SERVICE_STATE.template.md +0 -82
  58. package/.sdd/templates/component-repo/standing-docs/SPEC_INDEX.template.md +0 -94
  59. package/.sdd/templates/component-repo/standing-docs/TEST_INDEX.template.md +0 -64
  60. package/.sdd/templates/component-repo/template-map.json +0 -112
  61. package/ai-docs/ARCHITECTURE.md +0 -208
  62. package/ai-docs/CONTRACTS.md +0 -267
  63. package/ai-docs/DATA_MODEL.md +0 -64
  64. package/ai-docs/GETTING_STARTED.md +0 -73
  65. package/ai-docs/GLOSSARY.md +0 -56
  66. package/ai-docs/REVIEW_CHECKLIST.md +0 -45
  67. package/ai-docs/RULES.md +0 -79
  68. package/ai-docs/SECURITY.md +0 -74
  69. package/ai-docs/SERVICE_STATE.md +0 -59
  70. package/ai-docs/SPEC_INDEX.md +0 -85
  71. package/ai-docs/TEST_INDEX.md +0 -45
  72. package/ai-docs/adr/0001-migrate-existing-docs-into-sdd.md +0 -61
  73. package/ai-docs/patterns/defensive-error-propagation.md +0 -55
  74. package/ai-docs/patterns/event-scope-emission.md +0 -46
  75. package/ai-docs/patterns/source-to-test-path-mirroring.md +0 -45
  76. package/ai-docs/patterns/stateless-plugin-request-classes.md +0 -53
  77. package/ai-docs/patterns/typed-constants-and-enum-values.md +0 -47
  78. package/src/aiEnableRequest/ai-docs/ai-enable-request-spec.md +0 -223
  79. package/src/annotation/ai-docs/annotation-spec.md +0 -236
  80. package/src/breakouts/ai-docs/breakouts-spec.md +0 -324
  81. package/src/controls-options-manager/ai-docs/controls-options-manager-spec.md +0 -243
  82. package/src/hashTree/ai-docs/hash-tree-spec.md +0 -267
  83. package/src/interceptors/ai-docs/interceptors-spec.md +0 -247
  84. package/src/interpretation/ai-docs/interpretation-spec.md +0 -256
  85. package/src/locus-info/ai-docs/locus-info-spec.md +0 -293
  86. package/src/media/ai-docs/media-spec.md +0 -267
  87. package/src/meeting/ai-docs/meeting-spec.md +0 -404
  88. package/src/meeting-info/ai-docs/meeting-info-spec.md +0 -261
  89. package/src/meetings/ai-docs/meetings-spec.md +0 -298
  90. package/src/member/ai-docs/member-spec.md +0 -196
  91. package/src/members/ai-docs/members-spec.md +0 -256
  92. package/src/metrics/ai-docs/metrics-spec.md +0 -185
  93. package/src/multistream/ai-docs/multistream-spec.md +0 -295
  94. package/src/personal-meeting-room/ai-docs/personal-meeting-room-spec.md +0 -234
  95. package/src/reachability/ai-docs/reachability-spec.md +0 -261
  96. package/src/reactions/ai-docs/reactions-spec.md +0 -198
  97. package/src/reconnection-manager/ai-docs/reconnection-manager-spec.md +0 -272
  98. package/src/recording-controller/ai-docs/recording-controller-spec.md +0 -223
  99. package/src/roap/ai-docs/roap-spec.md +0 -241
  100. package/src/webinar/ai-docs/webinar-spec.md +0 -243
@@ -0,0 +1,488 @@
1
+ ---
2
+ type: Module Spec
3
+ title: 'Media module specification'
4
+ description: Responsibilities, boundaries, design, invariants, and verification for the plugin-meetings media module.
5
+ tags: [module, specification]
6
+ ---
7
+ <!-- sdd-generated-metadata
8
+ doc_kind: module-spec
9
+ generated_from: module-spec@0.3.0
10
+ generated_by: claude-code
11
+ approved_by: rarajes2@cisco.com
12
+ updated_at: 2026-11-17T03:14:21Z
13
+ validation_status: pass-with-warnings
14
+ -->
15
+
16
+ # Media
17
+
18
+ This source-local document at `src/media/docs/README.md` is the canonical source-local spec for
19
+ `src/media/` and owns the stable specification for **the media module** of `@webex/plugin-meetings`:
20
+ the `Media` facade that creates internal-media-core connections and acquires local browser media,
21
+ the `MediaProperties` holder that a `Meeting` keeps for its streams and connection, and the
22
+ `MediaConnectionAwaiter` that waits for ICE and DTLS connectivity. Ground every claim in package
23
+ evidence and link to the [package architecture](../../../docs/architecture.md) instead of repeating
24
+ broader facts. No service specification exists because this package is a library.
25
+
26
+ Related context: [documentation index](../../../docs/index.md) ·
27
+ [package agent instructions](../../../AGENTS.md) · repo architecture:
28
+ [package architecture](../../../docs/architecture.md) · registry:
29
+ [specification registry](../../../docs/specs/README.md)
30
+
31
+ ## Metadata
32
+
33
+ | Field | Value |
34
+ | ----- | ----- |
35
+ | Owner | @webex/web-client, @webex/web-sdk |
36
+ | Source path | `src/media` |
37
+ | Resource kind | module |
38
+ | Status | Draft |
39
+ | Last verified | 2026-11-16 at `0b8c34db7f` |
40
+ | Module id | `plugin-meetings/media` |
41
+ | Parent spec | — |
42
+ | Doc kind | Module spec |
43
+ | Coverage score | Pending coverage assessment |
44
+ | Validation status | not-run |
45
+
46
+ Coverage state and the contracts baseline are recorded in `.sdd/manifest.json`.
47
+
48
+ ## Applicability
49
+
50
+ | Condition ID | Status | Evidence or reason | Owned section |
51
+ | ------------ | ------ | ------------------ | ------------- |
52
+ | `module.has_tiers` | N/A | No tier policy exists in `package.json` | Tier |
53
+ | `module.has_ui` | N/A | `src/media/index.ts` returns streams and connections; it renders nothing | UI use-case flow |
54
+ | `module.crosses_service_boundaries` | Applicable | `src/media/index.ts` calls navigator.mediaDevices and builds internal-media-core connections; `src/media/properties.ts` and `src/media/MediaConnectionAwaiter.ts` read WebRTC stats and send behavioral metrics | Cross-boundary use-case flow |
55
+ | `module.holds_client_state` | Applicable | `src/media/properties.ts` holds the streams, the connection, the media direction, and the media-issue counters of one Meeting | Client state model |
56
+ | `module.enforces_domain_rules` | Applicable | Settle-once, teardown, and retry rules in `src/media/MediaConnectionAwaiter.ts` | Business rules and invariants |
57
+ | `module.is_concurrent_async` | Applicable | Event listeners, deadlines, and stats promises in `src/media/MediaConnectionAwaiter.ts` and `src/media/properties.ts` | Concurrency and reactive flow |
58
+ | `module.owns_persistence` | N/A | Nothing under `src/media/index.ts`, `src/media/properties.ts`, or `src/media/MediaConnectionAwaiter.ts` writes storage | Data, schema, and migration discipline |
59
+ | `module.stateful_transitions` | Applicable | The State union (idle, ice, dtls, connected, failed) and its transitions in `src/media/MediaConnectionAwaiter.ts` | State machine |
60
+ | `module.exposes_wire_protocol` | Applicable | `src/media/index.ts` sets SDP munging and ICE server options; `src/media/properties.ts` parses the local SDP | Protocol and wire format |
61
+ | `module.ui_multi_screen` | N/A | No UI in `src/media/index.ts` | UI flow |
62
+ | `module.large_data_model` | N/A | The exported shapes in `src/media/properties.ts` and `src/media/MediaConnectionAwaiter.ts` are small | Data model |
63
+ | `module.returns_caller_errors` | Applicable | Readiness rejections in `src/media/MediaConnectionAwaiter.ts`; thrown and rethrown errors in `src/media/index.ts` | Caller-visible failure modes |
64
+ | `module.module_specific_conventions` | N/A | The manifest section profile resolves this to false; repository rules in `AGENTS.md` apply | Module-specific rules |
65
+ | `module.published_package` | N/A | No src/media export is re-exported by `src/index.ts` | Export stability |
66
+ | `module.embedded_in_host` | N/A | No host mount API in `src/media/index.ts` | Host integration and theming |
67
+ | `module.has_design_tradeoff` | Applicable | The Media facade in `src/media/index.ts` isolates Meeting from internal-media-core option shapes | Key design trade-off |
68
+ | `module.has_submodules` | N/A | src/media has no child module in `.sdd/manifest.json` | Sub-modules |
69
+
70
+ ## Evidence register
71
+
72
+ Requirements cite current implementation and mirrored unit-test paths. Current code wins over
73
+ retained prose when they conflict; commit and PR history are excluded by repository-owner decision.
74
+ Missing test evidence is stated as a gap rather than inferred.
75
+
76
+ | Evidence | What it establishes |
77
+ | -------- | ------------------- |
78
+ | `src/media/index.ts` | The `Media` facade: `createMediaConnection`, `getDirection`, `getLocalMedia`, `getUserMedia`, `getDisplayMedia`, `getMedia`, `stopStream`, `toggleStream`; the `BundlePolicy` type |
79
+ | `src/media/properties.ts` | `MediaProperties`: stream, connection, direction, and settings fields; `waitForMediaConnectionConnected`; `getCurrentConnectionInfo`; `sendMediaIssueMetric`; the `MediaDirection` and `IPVersion` types |
80
+ | `src/media/MediaConnectionAwaiter.ts` | The awaiter's `State` union (`idle`, `ice`, `dtls`, `connected`, `failed`), per-phase deadlines, the single ICE gathering retry, teardown, and the `MEDIA_STILL_NOT_CONNECTED` metric |
81
+ | `src/media/util.ts` | `MediaUtil.createMediaStream(tracks)` filters falsy tracks and returns a `MediaStream` |
82
+ | `src/constants.ts` | `ICE_CONNECTION_TIMEOUT` is 20000 ms and `DTLS_CONNECTION_TIMEOUT` is 15000 ms; the `media:*` `EVENT_TRIGGERS` literals |
83
+ | `src/metrics/constants.ts` | `MEDIA_ISSUE_DETECTED` and `MEDIA_STILL_NOT_CONNECTED` behavioral metric names |
84
+ | `src/meeting/index.ts` | The only caller: creates the connection through `Media.createMediaConnection`, holds a `MediaProperties`, waits for readiness, closes the connection, then calls `unsetPeerConnection`; emits the `media:*` events; builds remote streams with `MediaUtil.createMediaStream` |
85
+ | `src/meetings/index.ts` | Exposes `Media.getUserMedia` on the Meetings media helpers |
86
+ | `test/unit/spec/media/index.ts` | `createMediaConnection` cases for both connection classes, directions, ICE servers, bundle and ICE transport policy, DTX, TWCC, AV1 slides, and Firefox relay gathering |
87
+ | `test/unit/spec/media/properties.ts` | Readiness, connection-info fallbacks, IP version, connection type, and media-issue throttling and flush cases |
88
+ | `test/unit/spec/media/MediaConnectionAwaiter.ts` | Phase deadlines, gathering retry, terminal cleanup, late callbacks, and repeated waits |
89
+ | Observation, no stated WHY | `Media.toggleStream` is a no-op kept on the facade (`src/media/index.ts`); `MediaUtil.createMediaStream` logs when `tracks` is missing and then throws a `TypeError` calling `filter` on it (`src/media/util.ts`). Neither is a requirement until a reason is recorded |
90
+
91
+ ## Purpose and boundary
92
+
93
+ - Responsibility: creates/configures media-core connections (`Media.createMediaConnection`),
94
+ derives media properties and connection diagnostics, awaits readiness, and exposes media lifecycle
95
+ helpers to Meeting.
96
+ - In scope: building the `RoapMediaConnection` or `MultistreamRoapMediaConnection` configuration;
97
+ local camera, microphone, and display acquisition through `navigator.mediaDevices`; the
98
+ `MediaProperties` holder; ICE and DTLS readiness waiting; connection-type, IP-version, and
99
+ transport diagnostics; throttled media-issue metrics; `MediaUtil.createMediaStream`.
100
+ - Out of scope: ROAP signaling and TURN discovery (`src/roap`); multistream slots and media
101
+ requests (`src/multistream`); closing the connection and emitting `media:*` events (`Meeting` in
102
+ `src/meeting/index.ts`); the WebRTC implementation (`@webex/internal-media-core`); local stream
103
+ classes (`@webex/media-helpers`).
104
+ - Consumers: `Meeting` (`src/meeting/index.ts`) and the Meetings media helpers
105
+ (`src/meetings/index.ts`).
106
+
107
+ ## Structure and key files
108
+
109
+ `src/media/` contains 4 direct source/reference file(s) and has 3 mirrored unit-test file(s) under
110
+ `test/unit/spec/media/`. The module facade and primary exports are `index.ts`; `properties.ts`,
111
+ `MediaConnectionAwaiter.ts`, and the `util.ts` helper functions sit beside it, and this canonical
112
+ module specification is `src/media/docs/README.md`. The code is TypeScript in the Node 22.14 Yarn
113
+ workspace; Webex core/plugin abstractions and Mocha/Sinon/`@webex/test-helper-chai` tests. Build
114
+ target: `yarn workspace @webex/plugin-meetings build:src`.
115
+
116
+ | File | Holds |
117
+ | ---- | ----- |
118
+ | `src/media/MediaConnectionAwaiter.ts` | MediaConnectionAwaiter: the ICE and DTLS readiness wait for one connection, its deadlines, retry, teardown, and timeout metric |
119
+ | `src/media/index.ts` | module facade (`Media`): connection creation, direction mapping, and local media acquisition, plus the `BundlePolicy` export |
120
+ | `src/media/properties.ts` | `MediaProperties`: per-Meeting streams, connection, media direction and settings, readiness entry point, and connection diagnostics |
121
+ | `src/media/util.ts` | `MediaUtil.createMediaStream`, the helper that builds a `MediaStream` from received tracks |
122
+ | `test/unit/spec/media/MediaConnectionAwaiter.ts` and 2 sibling test file(s) | mirrored characterization/unit coverage (`index.ts`, `properties.ts`) |
123
+
124
+ ## Public surface
125
+
126
+ None of these are re-exported by `src/index.ts`; they are reached through `Meeting`. Contract ID
127
+ `media-connection` is registered in `.sdd/manifest.json` and indexed in the
128
+ [package architecture](../../../docs/architecture.md#public-and-consumer-surfaces).
129
+
130
+ Manifest contracts: provides `media-connection`; requires `internal-media-core` and
131
+ `browser-webrtc`.
132
+
133
+ | Contract ID | Type | Surface | Purpose | Compatibility / deprecation | Schema / detail link | Root index |
134
+ | ----------- | ---- | ------- | ------- | --------------------------- | -------------------- | ---------- |
135
+ | `media-connection` | SDK / in-process | `MediaProperties.setMediaDirection()`, `setMediaSettings()`, `setMediaPeerConnection()`, and `getVideoDeviceId()` / `setVideoDeviceId()` | Hold the media-core configuration and preferred camera identity used by Meeting. | Preserve default directions (all six flags false), null-device behavior (`getVideoDeviceId()` returns `null` when unset), and setter names. | `src/media/properties.ts` | package architecture |
136
+ | `media-connection` | 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` | package architecture |
137
+ | `media-connection` | 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; `remoteQualityLevel` defaults to `HIGH`. | `src/media/properties.ts` | package architecture |
138
+ | `media-connection` | 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; `unsetPeerConnection()` also flushes the throttled media-issue metric. | `src/media/properties.ts` | package architecture |
139
+ | `media-connection` | SDK / async | `MediaProperties.waitForMediaConnectionConnected(correlationId)`, which builds a `MediaConnectionAwaiter`, plus the awaiter's `waitForMediaConnectionConnected()`, `peerConnectionStateHandler()`, `iceConnectionStateHandler()`, `iceGatheringStateHandler()`, and `onTimeout()` | 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` | package architecture |
140
+ | `media-connection` | diagnostic | `MediaProperties.getCurrentConnectionInfo()`, `sendMediaIssueMetric()`, and the awaiter's private timeout metric | Derive connection/IP diagnostics and emit bounded media issue information. | Preserve metric throttling (at most once every 5 minutes) and the existing unknown/fallback values (`unknown`, `-1`, `0`). | `src/media/properties.ts`, `src/media/MediaConnectionAwaiter.ts` | package architecture |
141
+ | `media-connection` | 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` | package architecture |
142
+ | `media-connection` | SDK / factory | `Media.createMediaConnection(isMultistream, debugId, meetingId, options)` and `Media.getDirection(forceSendRecv, receive, send)` | Build a `MultistreamRoapMediaConnection` or a `RoapMediaConnection` from Meeting options and map send/receive flags to `sendrecv`, `sendonly`, `recvonly`, or `inactive`. | Throws for a non-multistream connection without `mediaProperties`; TURN servers are added only when `turnServerInfo.urls` is non-empty. | `src/media/index.ts` | package architecture |
143
+ | `media-connection` | SDK / browser media | `Media.getUserMedia()`, `getLocalMedia()`, `getMedia()`, `getDisplayMedia()`, `stopStream()`, and `toggleStream()`; `MediaUtil.createMediaStream()` | Acquire camera, microphone, and display streams with SDK constraints, stop a local stream, and wrap received tracks. | `getUserMedia()` resolves `[localStream, shareStream]`; `stopStream()` never rejects; `toggleStream()` does nothing. | `src/media/index.ts`, `src/media/util.ts` | package architecture |
144
+
145
+ The `media:*` events below are emitted or forwarded by `Meeting` (`src/meeting/index.ts`) and
146
+ `MeetingsUtil` (`src/meetings/util.ts`), not by files under `src/media/`; they report the outcome of
147
+ the media this module builds. Current source emits or forwards these observable literals for this
148
+ operation boundary. Preserve literal values, scope, payload shape, and emission timing; a constant
149
+ name alone is not a substitute for the consumer-visible value.
150
+
151
+ | Event literal | Constant / expression | Emission evidence |
152
+ |---|---|---|
153
+ | `media:activeSpeakerChanged` | `EVENT_TRIGGERS.ACTIVE_SPEAKER_CHANGED` | `src/meeting/index.ts` |
154
+ | `media:codec:loaded` | `EVENT_TRIGGERS.MEDIA_CODEC_LOADED` | `src/meetings/util.ts` |
155
+ | `media:codec:missing` | `EVENT_TRIGGERS.MEDIA_CODEC_MISSING` | `src/meetings/util.ts` |
156
+ | `media:inboundAudio:issueDetected` | `EVENT_TRIGGERS.MEDIA_INBOUND_AUDIO_ISSUE_DETECTED` | `src/meeting/index.ts` |
157
+ | `media:negotiated` | `EVENT_TRIGGERS.MEDIA_NEGOTIATED` | `src/meeting/index.ts` |
158
+ | `media:ready` | `EVENT_TRIGGERS.MEDIA_READY` | `src/meeting/index.ts` |
159
+ | `media:remoteAudio:created` | `EVENT_TRIGGERS.REMOTE_MEDIA_AUDIO_CREATED` | `src/meeting/index.ts` |
160
+ | `media:remoteInterpretationAudio:created` | `EVENT_TRIGGERS.REMOTE_MEDIA_INTERPRETATION_AUDIO_CREATED` | `src/meeting/index.ts` |
161
+ | `media:remoteScreenShareAudio:created` | `EVENT_TRIGGERS.REMOTE_MEDIA_SCREEN_SHARE_AUDIO_CREATED` | `src/meeting/index.ts` |
162
+ | `media:remoteVideo:layoutChanged` | `EVENT_TRIGGERS.REMOTE_MEDIA_VIDEO_LAYOUT_CHANGED` | `src/meeting/index.ts` |
163
+ | `media:remoteAudioSourceCountChanged` | `EVENT_TRIGGERS.REMOTE_AUDIO_SOURCE_COUNT_CHANGED` | `src/meeting/index.ts` |
164
+ | `media:remoteVideoSourceCountChanged` | `EVENT_TRIGGERS.REMOTE_VIDEO_SOURCE_COUNT_CHANGED` | `src/meeting/index.ts` |
165
+ | `media:stopped` | `EVENT_TRIGGERS.MEDIA_STOPPED` | `src/meeting/index.ts` |
166
+
167
+ Compatibility notes:
168
+
169
+ - Prefer additive options and payload fields. Preserve method/event names, rejection semantics, and cleanup timing; route public changes through `src/index.ts` or the documented owning object.
170
+
171
+ ## Dependencies
172
+
173
+ Browser WebRTC, `@webex/internal-media-core`, `@webex/media-helpers` stream classes, the ROAP
174
+ `TurnServerInfo` type, and logging/metrics; meeting/Locus signaling stays with `Meeting`.
175
+
176
+ | Dependency | Why it is required | Failure behavior |
177
+ | ---------- | ------------------ | ---------------- |
178
+ | `@webex/internal-media-core` (`internal-media-core`) | `RoapMediaConnection`, `MultistreamRoapMediaConnection`, `ConnectionState`, and `MediaConnectionEventNames` | Construction errors propagate to `Meeting`; connection state drives the awaiter |
179
+ | Browser WebRTC and Media Capture (`browser-webrtc`) | `navigator.mediaDevices.getUserMedia` and `getDisplayMedia`, `MediaStream`, `getStats()` | `getMedia` logs and rethrows; stats failures fall back to `unknown` values |
180
+ | `@webex/media-helpers` | `LocalCameraStream`, `LocalMicrophoneStream`, `LocalDisplayStream`, `LocalSystemAudioStream`, `RemoteStream`, `LocalStream` types | — |
181
+ | `@webex/internal-plugin-metrics` | `RtcMetrics` callbacks for multistream connections; the `ClientEvent` type behind `IPVersion` | Callbacks are optional (`rtcMetrics?.`) |
182
+ | `@webex/web-capabilities` and `src/common/browser-detection.ts` | Firefox, Edge, Chrome, and Safari branches | — |
183
+ | `@webex/ts-sdp` | Parses the local SDP to find the IP version when a candidate has no address | A parse error logs a warning and yields `undefined` |
184
+ | `lodash` `throttle` | Media-issue metric throttling | — |
185
+ | `@webex/common` `Defer` | The awaiter's settle-once promise | — |
186
+ | `src/metrics/index.ts`, `src/common/logs/logger-proxy.ts` | Behavioral metrics and logging | Metric failures in the awaiter are logged as warnings |
187
+ | `src/config.ts`, `src/common/config.ts`, `src/constants.ts` | Share constraints, bandwidth limits, phase timeouts | — |
188
+ | `src/roap/types.ts` | `TurnServerInfo` shape for ICE servers | — |
189
+
190
+ ## Requirements
191
+
192
+ | ID | WHAT | WHY | Source evidence | Test / example evidence | Assumptions / gaps | Confidence |
193
+ | --- | ---- | --- | --------------- | ----------------------- | ------------------ | ---------- |
194
+ | `MEDIA-R-001` | create and configure a media connection: `Media.createMediaConnection` returns a `MultistreamRoapMediaConnection` for multistream meetings and a `RoapMediaConnection` otherwise, adds one TURN ICE server entry only when `turnServerInfo.urls` is non-empty, and throws when a non-multistream connection has no `mediaProperties`. | Creates/configures media-core connections, derives media properties, awaits readiness, and exposes media lifecycle helpers to Meeting; the code comment says TURN may be missing when discovery failed, was not done, or a video mesh node was reached. | `src/media/index.ts` | `test/unit/spec/media/index.ts` | none | PRESENT |
195
+ | `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 |
196
+ | `MEDIA-R-003` | Connection failure or timeout rejects with the awaiter result and the awaiter's teardown (`unregisterCallbacks()`) 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 |
197
+ | `MEDIA-R-004` | `Media.createMediaConnection` translates meeting options and the local-stream state of `mediaProperties` (directions through `Media.getDirection`, first output track of each local stream) into media-core connection configuration; `MediaProperties` only stores that state. | Meeting callers should not depend directly on low-level media-core option shapes. | `src/media/index.ts`, `src/media/properties.ts` | `test/unit/spec/media/index.ts` | none | PRESENT |
198
+ | `MEDIA-R-005` | The awaiter transitions through idle, ICE, DTLS, connected, and failed states. ICE has a 20000 ms deadline and DTLS a 15000 ms deadline. Each ICE entry permits one retry if gathering remains incomplete; DTLS rejects at its deadline without retrying. Gathering completing during ICE restarts the ICE deadline. 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`, `src/constants.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts` | none | PRESENT |
199
+ | `MEDIA-R-006` | `MediaProperties.unsetRemoteStreams()` and `unsetPeerConnection()` detach the owned remote streams and connection during replacement/teardown, and `unsetPeerConnection()` flushes any pending throttled media-issue metric; `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 |
200
+ | `MEDIA-R-007` | `getCurrentConnectionInfo()` waits at most 1000 ms for `getStats()` and, on failure or timeout, resolves `{connectionType: 'unknown', ipVersion: undefined, selectedCandidatePairChanges: -1, numTransports: 0}`; otherwise it reports `UDP`, `TCP`, or `TURN-<protocol>` from the first succeeded candidate pair and the IP version of the selected local candidate. | Its JSDoc defines `-1` as "browser doesn't supply this information" and `unknown` as "connection was not established", and the Firefox and Safari branches are commented as browser gaps. | `src/media/properties.ts` | `test/unit/spec/media/properties.ts` | none | PRESENT |
201
+ | `MEDIA-R-008` | `sendMediaIssueMetric(issueType, issueSubType, metadata)` counts each `<type>_<subType>` key and sends `MEDIA_ISSUE_DETECTED` with the counters at most once every 5 minutes, resetting the counters after each send. | Its JSDoc: metrics are throttled so that not too many are sent, but include a count so the number of detected issues is known. | `src/media/properties.ts`, `src/metrics/constants.ts` | `test/unit/spec/media/properties.ts` | none | PRESENT |
202
+
203
+ ## Design overview
204
+
205
+ `index.ts` is the `Media` facade: it creates the internal-media-core connection, maps directions,
206
+ and acquires local camera, microphone, and display media; `util.ts` only creates a `MediaStream`;
207
+ `properties.ts` owns local/remote streams, the peer connection, teardown, and construction of
208
+ `MediaConnectionAwaiter`, which waits on WebRTC/ICE events with phase deadlines. Its `State` union
209
+ owns lifecycle and ICE retry allowance; `waitForMediaConnectionConnected()` registers listeners once
210
+ before evaluation, including for an already terminal connection; `evaluate()` selects transitions,
211
+ `enter()` applies deadlines or settlement, and `teardown()` removes timers and registered callbacks
212
+ idempotently.
213
+
214
+ ## Data flow and sequence coverage
215
+
216
+ Call style: in-process method calls from `Meeting`; event subscriptions on the internal-media-core
217
+ connection; browser `navigator.mediaDevices` promises; behavioral metrics through `src/metrics`.
218
+
219
+ Sequence coverage:
220
+
221
+ | Operation group | Diagram | Failure coverage |
222
+ |---|---|---|
223
+ | UC-1…UC-5 — media properties and readiness operation groups | Media properties and readiness primary sequence | connection failure or closure, immediate terminal state, bounded ICE timeout, incomplete ICE gathering after the bounded retry, listener removal, and explicit owner teardown |
224
+ | UC-6 — connection creation | Connection creation sequence | non-multistream call without `mediaProperties` throws; empty TURN urls give no ICE server |
225
+ | UC-7 — local media acquisition | Local media acquisition sequence | `getUserMedia` rejection is logged and rethrown; `stopStream` swallows stop errors |
226
+ | UC-5 — diagnostics | `src/media/properties.ts`; the awaiter lifecycle is under State machine | `getStats()` failure or 1000 ms timeout resolves fallback values |
227
+
228
+ ```mermaid
229
+ flowchart LR
230
+ Meeting[Meeting media operations] --> Index[index.ts Media.createMediaConnection]
231
+ Index --> Core[internal-media-core connection]
232
+ Meeting --> Props[properties.ts]
233
+ Props --> Core
234
+ Props --> Awaiter[MediaConnectionAwaiter.ts]
235
+ Awaiter --> Core
236
+ Tracks[MediaStreamTrack inputs] --> Util[util.ts createMediaStream]
237
+ Util --> Meeting
238
+ Props --> Output[local/remote streams and connection result]
239
+ ```
240
+
241
+ Media properties and readiness primary sequence:
242
+
243
+ ```mermaid
244
+ sequenceDiagram
245
+ participant M as Meeting
246
+ participant P as MediaProperties
247
+ participant C as WebRTC media connection
248
+ participant A as MediaConnectionAwaiter
249
+ M->>P: set streams / peer connection
250
+ P->>A: waitForMediaConnectionConnected()
251
+ A->>C: subscribe to connection and ICE changes
252
+ alt connection already Connected, Failed, or Closed
253
+ A-->>P: settle at once, before any deadline is armed
254
+ else connected
255
+ C-->>A: connected/completed
256
+ A-->>P: resolve once
257
+ else failed, closed, or timeout
258
+ C--xA: failed/incomplete or timer expiry
259
+ A--xP: failure result
260
+ end
261
+ A->>C: remove the awaiter's registered listeners and clear the timer
262
+ P-->>M: connection outcome
263
+ ```
264
+
265
+ Connection creation sequence:
266
+
267
+ ```mermaid
268
+ sequenceDiagram
269
+ participant M as Meeting
270
+ participant X as Media (index.ts)
271
+ participant C as internal-media-core
272
+ M->>X: createMediaConnection(isMultistream, debugId, meetingId, options)
273
+ X->>X: iceServers = [TURN entry] when turnServerInfo.urls is non-empty
274
+ alt multistream
275
+ X->>C: new MultistreamRoapMediaConnection(config, meetingId, rtcMetrics callbacks)
276
+ else not multistream
277
+ alt mediaProperties missing
278
+ X--xM: throw Error
279
+ else
280
+ X->>C: new RoapMediaConnection(config, localTracks and directions, debugId)
281
+ end
282
+ end
283
+ C-->>M: connection
284
+ ```
285
+
286
+ Local media acquisition sequence:
287
+
288
+ ```mermaid
289
+ sequenceDiagram
290
+ participant Caller as Meetings helper or Meeting
291
+ participant X as Media (index.ts)
292
+ participant B as navigator.mediaDevices
293
+ Caller->>X: getUserMedia(mediaSetting, audioVideo, sharePreferences, config)
294
+ X->>B: getUserMedia(constraints) when audio or video is requested
295
+ alt rejected
296
+ B--xX: error
297
+ X--xCaller: logged and rethrown
298
+ else resolved
299
+ X->>B: getDisplayMedia(constraints) when share is requested and not already sharing
300
+ X-->>Caller: [localStream, shareStream]
301
+ end
302
+ ```
303
+
304
+ ## Class and component relationships
305
+
306
+ ```mermaid
307
+ classDiagram
308
+ class Meeting
309
+ class MediaProperties
310
+ class MediaConnectionAwaiter
311
+ class Media
312
+ class MediaUtil
313
+ class Core
314
+ Meeting --> MediaProperties : Props holder
315
+ Meeting --> Media : creates the Core connection
316
+ Media --> Core : RoapMediaConnection or MultistreamRoapMediaConnection
317
+ MediaProperties --> Core : webrtcMediaConnection
318
+ MediaProperties --> MediaConnectionAwaiter : new Awaiter per wait
319
+ MediaConnectionAwaiter --> Core : listens to connection events
320
+ Meeting --> MediaUtil : Tracks to Util createMediaStream
321
+ MediaProperties --> Meeting : Output streams and connection result
322
+ ```
323
+
324
+ The arrows identify ownership and delegation inside `src/media/`; files that only declare types or constants are not presented as transports.
325
+
326
+ ## Use cases and flows
327
+
328
+ | Use case | Actor or caller | Primary steps and outcome | Failure or boundary behavior | Evidence |
329
+ | -------- | --------------- | ------------------------- | ---------------------------- | -------- |
330
+ | `UC-1` | Meeting | Store media direction, media settings, preferred video device, and the active media-core connection on `MediaProperties` | `getVideoDeviceId()` returns `null` when unset | `src/media/properties.ts` |
331
+ | `UC-2` | Meeting | Assign microphone, camera, share-audio, and share-video streams independently and test local sharing with `hasLocalShareStream()` | Streams are optional; unset streams are `null` | `src/media/properties.ts` |
332
+ | `UC-3` | Meeting | Replace or unset remote audio, video, and share references without treating those assignments as track or peer-connection closure | Meeting closes the connection itself before `unsetPeerConnection()` | `src/media/properties.ts`, `src/meeting/index.ts` |
333
+ | `UC-4` | Meeting | Await connection readiness, retry one incomplete ICE-gathering timeout, and remove only the awaiter's WebRTC listeners when it settles | Rejects with `{iceConnected, iceConnectedAtLeastOnce}` | `src/media/MediaConnectionAwaiter.ts`, `test/unit/spec/media/MediaConnectionAwaiter.ts` |
334
+ | `UC-5` | Meeting | Derive current connection diagnostics and throttle repeated media-issue metric submission | `getStats()` failure gives fallback values | `src/media/properties.ts`, `src/media/MediaConnectionAwaiter.ts` |
335
+ | `UC-6` | Meeting | Build the media connection with `Media.createMediaConnection` from Meeting config, TURN info, and media properties | Throws without `mediaProperties` for a non-multistream connection | `src/media/index.ts`, `test/unit/spec/media/index.ts` |
336
+ | `UC-7` | Meetings media helpers | Acquire local camera, microphone, and display streams with `Media.getUserMedia` | Browser rejections are logged and rethrown | `src/media/index.ts`, `src/meetings/index.ts` |
337
+
338
+ ### Cross-boundary use-case flow
339
+
340
+ | Boundary | Transport and ordering | Compatibility | Timeout, retry, and recovery |
341
+ | -------- | ---------------------- | ------------- | ---------------------------- |
342
+ | internal-media-core connection (`UC-4`, `UC-6`) | In-process construction and `on`/`off` event subscriptions | Constructor options under Protocol and wire format | Awaiter deadlines of 20000 ms (ICE) and 15000 ms (DTLS); one ICE gathering retry |
343
+ | Browser media capture (`UC-7`) | `navigator.mediaDevices` promises, camera/microphone before display | Firefox and Safari constraint branches in `src/media/index.ts` | No retry; rejection is rethrown |
344
+ | WebRTC stats (`UC-5`) | `getStats()` promise | Reads `transport`, `candidate-pair`, and `local-candidate` reports | 1000 ms timeout with fallback values |
345
+ | Behavioral metrics (`UC-4`, `UC-5`) | `Metrics.sendBehavioralMetric` | Metric names in `src/metrics/constants.ts` | Awaiter metric failure is logged, never rethrown |
346
+
347
+ ## Client state model
348
+
349
+ Media connection, transceivers/streams, readiness waiters, and listener cleanup are held for the
350
+ meeting media lifetime.
351
+
352
+ | State or slice | Owner | Initial state | Transition triggers | Reset or persistence boundary |
353
+ | -------------- | ----- | ------------- | ------------------- | ----------------------------- |
354
+ | `webrtcMediaConnection` | `MediaProperties` | `null` | `setMediaPeerConnection` | `unsetPeerConnection` after Meeting closes the connection |
355
+ | Local streams (`audioStream`, `videoStream`, `shareAudioStream`, `shareVideoStream`) | `MediaProperties` | `null` | `setLocal*Stream` | Replaced by the next setter; never stopped here |
356
+ | Remote streams (`remoteAudioStream`, `remoteVideoStream`, `remoteShareStream`) | `MediaProperties` | `undefined` | `setRemote*Stream` | `unsetRemoteMedia`, `unsetRemoteShareStream`, `unsetRemoteStreams` set them to `null` |
357
+ | `mediaDirection`, `mediaSettings`, `videoDeviceId`, `remoteQualityLevel` | `MediaProperties` | All directions false, `{}`, `null`, `HIGH` | Setters | Instance memory |
358
+ | `mediaIssueCounters` | `MediaProperties` | `{}` | `sendMediaIssueMetric` | Zeroed after each throttled send; flushed by `unsetPeerConnection` |
359
+ | Awaiter `state`, `timer`, `iceConnectedAtLeastOnce` | `MediaConnectionAwaiter` | `idle`, none, `false` | Connection events and deadlines | Discarded with the awaiter; one awaiter per `waitForMediaConnectionConnected` call |
360
+
361
+ ## Business rules and invariants
362
+
363
+ | ID | Invariant | WHY | Enforcement source | Test evidence |
364
+ | --- | --------- | --- | ------------------ | ------------- |
365
+ | `INV-001` | 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. | A settled wait must not leave callbacks or deadlines that act on a connection after the wait is over (JSDoc of `teardown`: releases the deadline and registered listeners on either terminal transition). | `src/media/MediaConnectionAwaiter.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts` |
366
+ | `INV-002` | Closed media is not reused: connection state `Closed` is treated like `Failed` and rejects the wait. | A closed connection cannot become ready, so waiting on it would only expire the deadline. | `src/media/MediaConnectionAwaiter.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts` |
367
+ | `INV-003` | Permission/negotiation failures remain visible: `getMedia` logs and rethrows `getUserMedia` errors, and readiness failures reject with the connectivity result. | Meeting reports ICE failures with `iceConnected` (client.ice.end in `src/meeting/index.ts`) and callers must see capture failures. | `src/media/index.ts`, `src/media/MediaConnectionAwaiter.ts` | `test/unit/spec/media/MediaConnectionAwaiter.ts` |
368
+
369
+ ## Concurrency and reactive flow
370
+
371
+ - Execution model: one JavaScript event loop; connection events, deadlines, and `getStats()`
372
+ promises interleave.
373
+ - 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.
374
+ - Ordering guarantees: `waitForMediaConnectionConnected()` registers listeners and evaluates in the
375
+ same synchronous call; repeated calls on one awaiter return the same promise without registering
376
+ again.
377
+ - Idempotency and retry: the ICE gathering retry is the only retry; `sendMetric` captures
378
+ connectivity before awaiting stats so a later state change does not alter the reported values.
379
+ - Shared-state protection: none beyond the settle-once state check; each wait gets its own awaiter.
380
+
381
+ ## State machine
382
+
383
+ `MediaConnectionAwaiter` holds one `State` value. `waitForMediaConnectionConnected()` leaves `idle`
384
+ once, registers the three listeners, and evaluates the connection; every listener and the deadline
385
+ call `evaluate()` again. The phase follows ICE connectivity: ICE state `connected` or `completed`
386
+ selects the DTLS phase, anything else selects the ICE phase, connection state `Connected` resolves,
387
+ and `Failed` or `Closed` rejects. `iceConnectedAtLeastOnce` keeps ICE history across phase changes
388
+ for the failure result and the timeout metric.
389
+
390
+ ```mermaid
391
+ stateDiagram-v2
392
+ [*] --> idle
393
+ idle --> ice: wait starts, ICE not connected
394
+ idle --> dtls: wait starts, ICE connected or completed
395
+ idle --> connected: connection already Connected
396
+ idle --> failed: connection already Failed or Closed
397
+ ice --> dtls: ICE connects (DTLS deadline armed)
398
+ dtls --> ice: ICE lost (fresh gathering retry)
399
+ ice --> ice: deadline with gathering incomplete, retried once
400
+ ice --> failed: deadline after the retry, or with gathering complete
401
+ dtls --> failed: DTLS deadline
402
+ ice --> connected: connection Connected
403
+ dtls --> connected: connection Connected
404
+ ice --> failed: connection Failed or Closed
405
+ dtls --> failed: connection Failed or Closed
406
+ connected --> [*]
407
+ failed --> [*]
408
+ ```
409
+
410
+ - States: `idle` (before the wait), `ice` (with a `gatheringRetried` flag), `dtls`, and the
411
+ terminal `connected` and `failed` (with the `FailureResult`).
412
+ - Timeouts: entering `ice` arms a 20000 ms deadline (`ICE_CONNECTION_TIMEOUT`); entering `dtls`
413
+ arms a 15000 ms deadline (`DTLS_CONNECTION_TIMEOUT`). Each arm replaces the previous timer.
414
+ - Guards: a deadline first re-evaluates the connection, so an unreported change wins over the
415
+ timeout. In `ice`, an expired deadline with gathering not `complete` and `gatheringRetried` false
416
+ re-enters `ice` with the flag set and a new deadline; otherwise it enters `failed`. A `dtls`
417
+ deadline always enters `failed`. Every entry into `ice` from another state resets
418
+ `gatheringRetried` to false; repeated events within the same phase do not.
419
+ - ICE gathering reaching `complete` while the state stays `ice` restarts the ICE deadline without
420
+ consuming the retry.
421
+ - Terminal states: `connected` resolves and `failed` rejects; both run `teardown()`, which clears the
422
+ timer and removes the listeners. Later callbacks and deadlines are ignored, and a repeated
423
+ `waitForMediaConnectionConnected()` returns the same promise.
424
+ - Rejected transitions: a settled awaiter never leaves `connected` or `failed`, and an active wait
425
+ never returns to `idle`.
426
+
427
+ ## Protocol and wire format
428
+
429
+ Wire-relevant values are produced as internal-media-core constructor options and read from browser
430
+ stats and SDP; preserve current field names, enum/raw values, and compatibility behavior, and do not
431
+ treat the normalized client model as the wire schema.
432
+
433
+ | Message or frame | Version | Producer or serializer | Consumer or parser | Compatibility and ordering rule |
434
+ | ---------------- | ------- | ---------------------- | ------------------ | ------------------------------- |
435
+ | ICE server entry `{urls, username, credential}` | — | `Media.createMediaConnection` from `TurnServerInfo` | internal-media-core | Present only when `turnServerInfo.urls` is non-empty; empty username or password become `''` |
436
+ | Multistream config: `iceServers`, `disableAudioTwcc`, `enableAV1SlidesSupport`, optional `bundlePolicy`, `iceTransportPolicy`, `disableAudioMainDtx`; Firefox `doFullIce` and `stopIceGatheringAfterFirstRelayCandidate`; Chromium `enableInboundAudioLevelMonitoring` | — | `Media.createMediaConnection` | `MultistreamRoapMediaConnection` | Optional fields are omitted when undefined |
437
+ | Transcoded config: `requireH264: true`, `skipInactiveTransceivers: false`, `sdpMunging` with bandwidth limits, `startBitrate`, `periodicKeyframes: 20`, `disableExtmap`, `disableRtx` | — | `Media.createMediaConnection` | `RoapMediaConnection` | `periodicKeyframes` is hard-coded; extmap and RTX follow Meeting config |
438
+ | Local SDP candidate lines | SDP | Browser | `MediaProperties.getConnectionIpVersion` through `@webex/ts-sdp` | Used only when the local candidate has no address (Safari) |
439
+ | `js_sdk_media_still_not_connected`, `js_sdk_media_issue_detected` | — | `MediaConnectionAwaiter`, `MediaProperties` | Behavioral metrics | Metric names from `src/metrics/constants.ts` |
440
+
441
+ ## Caller-visible failure modes
442
+
443
+ | Condition | Signal | Caller recovery |
444
+ |---|---|---|
445
+ | 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. |
446
+ | 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. |
447
+ | Media connection reaches the expected connected/completed state | The awaiter resolves once and removes its listeners and timer. | Continue using the established connection. |
448
+ | 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. |
449
+ | A non-multistream connection is requested without `mediaProperties` | `Media.createMediaConnection` throws `mediaProperties have to be provided for non-multistream media connections`. | Pass the Meeting's `mediaProperties`. |
450
+ | The browser rejects camera or microphone capture | `Media.getMedia` logs the error and its `constraint`, then rethrows it. | Handle the capture error; retry with other constraints. |
451
+ | `getStats()` fails or does not settle within 1000 ms | `getCurrentConnectionInfo()` resolves `connectionType: 'unknown'`, `ipVersion: undefined`, `selectedCandidatePairChanges: -1`, `numTransports: 0`. | Treat the values as unknown. |
452
+ | Stopping a local stream throws | `Media.stopStream` logs the error and still resolves. | None. |
453
+
454
+ ## Pitfalls and constraints
455
+
456
+ - 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.
457
+ - Public behavior may be reachable through a parent `Meeting`/`Meetings` object even when the source helper is not exported directly.
458
+ - `unsetPeerConnection()` does not close the connection; `Meeting` calls `webrtcMediaConnection.close()` first, and its `unsetPeerConnections()` JSDoc warns not to call it without closing peer connections (`src/meeting/index.ts`).
459
+ - The awaiter reads the connection passed at construction; `MediaProperties.waitForMediaConnectionConnected` must be called after `setMediaPeerConnection`.
460
+
461
+ ## Key design trade-off
462
+
463
+ - A media-core adapter isolates Meeting from lower-level WebRTC details, adding translation code but keeping public meeting semantics stable.
464
+
465
+ | Chosen trade-off | Preserved invariant or benefit | Cost or limitation | Decision evidence |
466
+ | ---------------- | ------------------------------ | ------------------ | ----------------- |
467
+ | `Media.createMediaConnection` translates Meeting options into internal-media-core configuration | Meeting semantics stay stable while connection option shapes change (`MEDIA-R-004`) | Browser-specific branches and hard-coded munging values live in this module | `src/media/index.ts` |
468
+ | Readiness uses an explicit phase state with per-phase deadlines | ICE recovery and DTLS limits are independent (`MEDIA-R-005`) | More states to test than a single timeout | `src/media/MediaConnectionAwaiter.ts` |
469
+
470
+ ## Verification
471
+
472
+ Use the current mirrored suites: `test/unit/spec/media/MediaConnectionAwaiter.ts`, `test/unit/spec/media/index.ts`, `test/unit/spec/media/properties.ts`. Characterize the media-specific use cases above and each listed failure condition; add cleanup or transition cases only for resources and state this module actually owns.
473
+
474
+ | Behavior / Requirement | Existing test evidence | Gap |
475
+ |---|---|---|
476
+ | `MEDIA-R-001` | `test/unit/spec/media/index.ts` | cover property assignment, readiness waiting, diagnostics, and explicit teardown separately; no case for the missing-`mediaProperties` throw |
477
+ | `MEDIA-R-002` | `test/unit/spec/media/properties.ts`, `test/unit/spec/media/MediaConnectionAwaiter.ts` | awaiter settlement versus Meeting-owned peer closure needs a boundary assertion |
478
+ | `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 |
479
+ | `MEDIA-R-004` | `test/unit/spec/media/index.ts` | none |
480
+ | `MEDIA-R-005` | `test/unit/spec/media/MediaConnectionAwaiter.ts` | none |
481
+ | `MEDIA-R-006` | `test/unit/spec/media/properties.ts` | verify unset during partial setup and replacement; only the metric flush is asserted |
482
+ | `MEDIA-R-007` | `test/unit/spec/media/properties.ts` | none |
483
+ | `MEDIA-R-008` | `test/unit/spec/media/properties.ts` | none |
484
+ | `INV-001` to `INV-003` | `test/unit/spec/media/MediaConnectionAwaiter.ts` | no case for the `getMedia` rethrow, `getDisplayMedia`, or `stopStream` |
485
+
486
+ A module specification is complete only when its public surface, invariants, failure modes, and
487
+ test evidence agree with the implementation. Coverage measurement is pending; semantic validation
488
+ has not run.