@webex/plugin-meetings 3.13.0-next.6 → 3.13.0-next.8

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.
@@ -0,0 +1,215 @@
1
+ /*!
2
+ * Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import type LLMChannel from '@webex/internal-plugin-llm';
6
+
7
+ /** Source labels passed to the MLS engine for incoming signaling messages. */
8
+ type E2eeSignalingSource = 'llm' | 'mercury';
9
+
10
+ /** LLM event carrying the channel's connection state. */
11
+ export const LLM_ONLINE_EVENT = 'online';
12
+
13
+ /** Mercury events carrying MLS protocol messages. */
14
+ export const MEDIA_ENCRYPTION_MERCURY_EVENTS = [
15
+ 'event:media_encryption.leader_nominated',
16
+ 'event:media_encryption.welcome',
17
+ 'event:media_encryption.annotated_welcome',
18
+ 'event:media_encryption.multi_welcome',
19
+ 'event:media_encryption.group_update',
20
+ 'event:media_encryption.annotated_commit',
21
+ 'event:media_encryption.large_group_update',
22
+ 'event:media_encryption.use_key',
23
+ 'event:media_encryption.join_request',
24
+ 'event:media_encryption.leave_request',
25
+ 'event:media_encryption.join_failure',
26
+ 'event:media_encryption.leader_changed',
27
+ 'event:media_encryption.message_segment',
28
+ ];
29
+
30
+ /** The subset of the MLS engine the signaling adapter drives. */
31
+ export interface IMlsSignalingTarget {
32
+ handleEvent(bytes: Uint8Array, source: E2eeSignalingSource): void;
33
+ setLlmConnectedBeforeJoin(connected: boolean): void;
34
+ llmConnected(): void;
35
+ }
36
+
37
+ /** The subset of a mercury channel the adapter subscribes to for MLS protocol events. */
38
+ export interface IMercuryChannel {
39
+ on(event: string, handler: (envelope: any) => void): void;
40
+ off(event: string, handler: (envelope: any) => void): void;
41
+ }
42
+
43
+ /**
44
+ * Mercury (and LLM) adapter for the MLS engine. Subscribes to this meeting's
45
+ * media_encryption.* events on both the LLM and mercury channels and forwards them to the engine,
46
+ * and tracks whether the signaling channel is connected so the engine knows when it can proceed
47
+ * with its join.
48
+ */
49
+ export default class E2eeSignaling {
50
+ private llm?: LLMChannel;
51
+
52
+ private readonly mercury: IMercuryChannel;
53
+
54
+ private readonly getLocusUrl: () => string | undefined;
55
+
56
+ private readonly session: IMlsSignalingTarget;
57
+
58
+ private started = false;
59
+
60
+ /**
61
+ * @param {Object} deps
62
+ * @param {LLMChannel} [deps.llm] - This meeting's LLM channel, when one is available.
63
+ * @param {IMercuryChannel} deps.mercury - The mercury channel (webex.internal.mercury).
64
+ * @param {Function} deps.getLocusUrl - Returns the meeting's current locus url (read live, as it
65
+ * can change, e.g. when moving between breakout sessions).
66
+ * @param {IMlsSignalingTarget} deps.session - The MLS engine to drive.
67
+ */
68
+ constructor({
69
+ llm,
70
+ mercury,
71
+ getLocusUrl,
72
+ session,
73
+ }: {
74
+ llm?: LLMChannel;
75
+ mercury: IMercuryChannel;
76
+ getLocusUrl: () => string | undefined;
77
+ session: IMlsSignalingTarget;
78
+ }) {
79
+ this.llm = llm;
80
+ this.mercury = mercury;
81
+ this.getLocusUrl = getLocusUrl;
82
+ this.session = session;
83
+ }
84
+
85
+ /**
86
+ * Subscribes to MLS mercury events and wires up connection tracking. Idempotent.
87
+ * @returns {void}
88
+ */
89
+ start(): void {
90
+ if (this.started) {
91
+ return;
92
+ }
93
+ this.started = true;
94
+
95
+ MEDIA_ENCRYPTION_MERCURY_EVENTS.forEach((event) => {
96
+ this.mercury.on(event, this.onMercuryEvent);
97
+ });
98
+
99
+ if (this.llm && this.isLlmOnlineForThisSession()) {
100
+ this.session.setLlmConnectedBeforeJoin(true);
101
+ }
102
+ this.subscribeToLlmEvents();
103
+ }
104
+
105
+ /**
106
+ * Removes all subscriptions. Idempotent.
107
+ * @returns {void}
108
+ */
109
+ stop(): void {
110
+ if (!this.started) {
111
+ return;
112
+ }
113
+ this.started = false;
114
+
115
+ MEDIA_ENCRYPTION_MERCURY_EVENTS.forEach((event) => {
116
+ this.mercury.off(event, this.onMercuryEvent);
117
+ });
118
+ this.unsubscribeFromLlmEvents();
119
+ }
120
+
121
+ /**
122
+ * Replaces the meeting-owned LLM channel after the meeting reconnects its data channel.
123
+ * @param {LLMChannel} [llm]
124
+ * @returns {void}
125
+ */
126
+ setLlmChannel(llm?: LLMChannel): void {
127
+ if (this.llm === llm) {
128
+ return;
129
+ }
130
+
131
+ this.unsubscribeFromLlmEvents();
132
+ this.llm = llm;
133
+
134
+ if (!this.started || !this.llm) {
135
+ return;
136
+ }
137
+
138
+ this.subscribeToLlmEvents();
139
+
140
+ if (this.isLlmOnlineForThisSession()) {
141
+ this.session.llmConnected();
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Forwards a signaling envelope to the engine, tagging which channel it came from.
147
+ * @param {Object} envelope - The mercury event envelope.
148
+ * @param {E2eeSignalingSource} source - The channel the envelope arrived on.
149
+ * @returns {void}
150
+ */
151
+ private forwardEvent(envelope: any, source: E2eeSignalingSource): void {
152
+ const eventData = envelope?.data ?? envelope;
153
+ const bytes = new TextEncoder().encode(JSON.stringify(eventData));
154
+
155
+ this.session.handleEvent(new Uint8Array(bytes), source);
156
+ }
157
+
158
+ /**
159
+ * @param {Object} envelope - The mercury event envelope from the LLM channel.
160
+ * @returns {void}
161
+ */
162
+ private onLlmEvent = (envelope: any): void => {
163
+ this.forwardEvent(envelope, 'llm');
164
+ };
165
+
166
+ /**
167
+ * @param {Object} envelope - The mercury event envelope from the mercury channel.
168
+ * @returns {void}
169
+ */
170
+ private onMercuryEvent = (envelope: any): void => {
171
+ this.forwardEvent(envelope, 'mercury');
172
+ };
173
+
174
+ /**
175
+ * @returns {void}
176
+ */
177
+ private onLlmOnline = (): void => {
178
+ if (this.isLlmOnlineForThisSession()) {
179
+ this.session.llmConnected();
180
+ }
181
+ };
182
+
183
+ /** @returns {void} */
184
+ private subscribeToLlmEvents(): void {
185
+ if (!this.started || !this.llm) {
186
+ return;
187
+ }
188
+
189
+ MEDIA_ENCRYPTION_MERCURY_EVENTS.forEach((event) => {
190
+ this.llm?.on(event, this.onLlmEvent);
191
+ });
192
+ if (!this.isLlmOnlineForThisSession()) {
193
+ this.llm.on(LLM_ONLINE_EVENT, this.onLlmOnline);
194
+ }
195
+ }
196
+
197
+ /** @returns {void} */
198
+ private unsubscribeFromLlmEvents(): void {
199
+ this.llm?.off(LLM_ONLINE_EVENT, this.onLlmOnline);
200
+ MEDIA_ENCRYPTION_MERCURY_EVENTS.forEach((event) => {
201
+ this.llm?.off(event, this.onLlmEvent);
202
+ });
203
+ }
204
+
205
+ /**
206
+ * @returns {boolean} whether the LLM is connected for this specific session (locus-url matched).
207
+ */
208
+ private isLlmOnlineForThisSession(): boolean {
209
+ const sessionLocusUrl = this.getLocusUrl();
210
+
211
+ return (
212
+ !!sessionLocusUrl && !!this.llm?.isConnected() && sessionLocusUrl === this.llm.getLocusUrl()
213
+ );
214
+ }
215
+ }
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ const MEDIA_ENCRYPTION_SERVICE = 'media-encryption';
6
+
7
+ /** The bound webex.request function shape consumed by this adapter. */
8
+ type WebexRequestMethod = (options: Record<string, any>) => Promise<any>;
9
+
10
+ /**
11
+ * Routes the MLS engine's protocol HTTP requests to the media-encryption service via
12
+ * webex.request. Bodies are plain JS objects; MLS owns the conversion to/from the engine's bytes.
13
+ * Requests use standard webex auth (Authorization bearer token) — no custom header is needed.
14
+ */
15
+ export default class MediaEncryptionService {
16
+ private readonly webexRequest: WebexRequestMethod;
17
+
18
+ /**
19
+ * @param {Object} deps
20
+ * @param {WebexRequestMethod} deps.webexRequest - The (bound) webex.request method.
21
+ */
22
+ constructor({webexRequest}: {webexRequest: WebexRequestMethod}) {
23
+ this.webexRequest = webexRequest;
24
+ }
25
+
26
+ /**
27
+ * @param {string} url - The absolute request URL provided by the engine.
28
+ * @param {unknown} body - Request payload, sent as JSON.
29
+ * @returns {Promise<unknown>} The JSON-parsed response body.
30
+ */
31
+ async request(url: string, body: unknown): Promise<unknown> {
32
+ const {body: responseBody} = await this.webexRequest({
33
+ method: 'POST',
34
+ service: MEDIA_ENCRYPTION_SERVICE,
35
+ url,
36
+ body,
37
+ });
38
+
39
+ return responseBody;
40
+ }
41
+ }