Skip to content

Commit 2e608f3

Browse files
committed
Honor go-live destination subsets per session
1 parent ccd3ffb commit 2e608f3

2 files changed

Lines changed: 48 additions & 6 deletions

File tree

src/actions/legacyCompat.test.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,22 @@ describe('legacyCompatibilityActions', () => {
149149

150150
assert.equal(ok, true);
151151
assert.equal(updateCalls.length, 1);
152-
assert.equal(toggleCalls.length, 1);
152+
assert.ok(
153+
toggleCalls.some(
154+
(call) =>
155+
call.platformId === 'twitch' &&
156+
call.enabled === true &&
157+
call.sessionId === 'session-1',
158+
),
159+
);
160+
assert.ok(
161+
toggleCalls.some(
162+
(call) =>
163+
call.platformId === 'custom' &&
164+
call.enabled === false &&
165+
call.sessionId === 'session-1',
166+
),
167+
);
153168
assert.equal(stopCalls.length, 0);
154169
assert.match(requestedUrls[0] ?? '', /\/stream\/start$/);
155170
assert.match(requestedUrls[1] ?? '', /\/stream\/status$/);
@@ -162,10 +177,18 @@ describe('legacyCompatibilityActions', () => {
162177
assert.equal(lastPayload.content?.success, true);
163178
assert.equal(lastPayload.content?.data?.cloudflareConnected, true);
164179
assert.equal(lastPayload.content?.data?.cfSessionId, 'cf-session-1');
165-
assert.equal(
166-
(lastPayload.content?.data?.destinationSync as { applied?: unknown[] } | undefined)?.applied
167-
?.length,
168-
1,
180+
const destinationSync = lastPayload.content?.data?.destinationSync as
181+
| { applied?: Array<{ platformId?: string; enabled?: boolean }> }
182+
| undefined;
183+
assert.ok(
184+
destinationSync?.applied?.some(
185+
(entry) => entry.platformId === 'twitch' && entry.enabled === true,
186+
),
187+
);
188+
assert.ok(
189+
destinationSync?.applied?.some(
190+
(entry) => entry.platformId === 'custom' && entry.enabled === false,
191+
),
169192
);
170193
},
171194
);

src/actions/legacyCompat.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ async function applyConfiguredDestinations(
492492
platformId,
493493
error: 'unsupported_platform',
494494
}));
495+
const deselectedMappings = requestedPlatformSet.size > 0
496+
? DESTINATION_MAPPINGS.filter((mapping) => !requestedPlatformSet.has(mapping.platformId))
497+
: [];
495498

496499
for (const mapping of mappings) {
497500
const enabled =
@@ -536,8 +539,24 @@ async function applyConfiguredDestinations(
536539
}
537540
}
538541

542+
for (const mapping of deselectedMappings) {
543+
try {
544+
await service.togglePlatform(mapping.platformId, false, sessionId);
545+
applied.push({
546+
platformId: mapping.platformId,
547+
enabled: false,
548+
configured: false,
549+
});
550+
} catch (error) {
551+
failed.push({
552+
platformId: mapping.platformId,
553+
error: `session_disable_failed: ${(error as Error).message}`,
554+
});
555+
}
556+
}
557+
539558
return {
540-
attempted: mappings.length + unsupported.length,
559+
attempted: mappings.length + unsupported.length + deselectedMappings.length,
541560
applied,
542561
skipped,
543562
failed,

0 commit comments

Comments
 (0)