diff --git a/tests/media-lifecycle.spec.ts b/tests/media-lifecycle.spec.ts
index e657a44..07206a2 100644
--- a/tests/media-lifecycle.spec.ts
+++ b/tests/media-lifecycle.spec.ts
@@ -259,4 +259,52 @@ test.describe('device and media lifecycle', () => {
await expect(toggle).toHaveAttribute('data-active', 'true')
await expect(toggle).toBeEnabled()
})
+
+ // https://github.com/binbat/woom/issues/47
+ // A stops sharing while B is still sharing must not lose B's presentation:
+ // the slot is derived from everyone currently sharing, not last-writer-wins.
+ test('stopping the second share keeps the first presentation', async ({
+ browser,
+ }) => {
+ const aliceContext = await browser.newContext()
+ const bobContext = await browser.newContext()
+ const alice = await aliceContext.newPage()
+ const bob = await bobContext.newPage()
+ try {
+ await mockDisplayMedia(alice)
+ await mockDisplayMedia(bob)
+ const roomId = await createMeeting(alice)
+ await joinRoom(alice, 'Alice')
+ await joinMeetingFromWelcome(bob, roomId)
+ await joinRoom(bob, 'Bob')
+
+ const alicePresentation = alice
+ .getByTestId('presentation-player')
+ .getByTestId('video-remote')
+ const bobPresentation = bob
+ .getByTestId('presentation-player')
+ .getByTestId('video-remote')
+
+ const aliceToggle = alice.getByTestId('toggle-screen')
+ await aliceToggle.click()
+ await expect(aliceToggle).toHaveAttribute('data-active', 'true')
+ await expectVideoPlaying(alicePresentation)
+ await expectVideoPlaying(bobPresentation)
+
+ const bobToggle = bob.getByTestId('toggle-screen')
+ await bobToggle.click()
+ await expect(bobToggle).toHaveAttribute('data-active', 'true')
+ await expectVideoPlaying(alicePresentation)
+ await expectVideoPlaying(bobPresentation)
+
+ await bobToggle.click()
+ await expect(bobToggle).toHaveAttribute('data-active', 'false')
+ await expect(aliceToggle).toHaveAttribute('data-active', 'true')
+ await expectVideoPlaying(alicePresentation)
+ await expectVideoPlaying(bobPresentation)
+ } finally {
+ await aliceContext.close()
+ await bobContext.close()
+ }
+ })
})
diff --git a/webapp/components/player/whep-player.vue b/webapp/components/player/whep-player.vue
index a70dbe7..687a237 100644
--- a/webapp/components/player/whep-player.vue
+++ b/webapp/components/player/whep-player.vue
@@ -1,7 +1,7 @@
diff --git a/webapp/store/atoms.ts b/webapp/store/atoms.ts
index fc14e4c..7e94410 100644
--- a/webapp/store/atoms.ts
+++ b/webapp/store/atoms.ts
@@ -27,10 +27,37 @@ const adminMode = ref(false)
/** non-null while the current meeting is being recorded (server snapshot) */
const recordingAt = ref(null)
-const presentationStream = shallowRef({
+// Streams currently sharing their screen register here; the presentation
+// slot is derived from the registry instead of players pushing/clearing a
+// single global stream, so one sharer stopping can never clear another
+// sharer's presentation (https://github.com/binbat/woom/issues/47).
+// Map order is insertion order: the newest registrant takes the stage, and
+// earlier ones resume when it unregisters. Re-registering an existing id
+// keeps its position, so media refreshes never steal the stage.
+const presentationCandidates = shallowRef(new Map())
+
+const registerPresentation = (streamId: string, candidate: UserStream) => {
+ const next = new Map(presentationCandidates.value)
+ next.set(streamId, candidate)
+ presentationCandidates.value = next
+}
+
+const unregisterPresentation = (streamId: string) => {
+ if (!presentationCandidates.value.has(streamId)) return
+ const next = new Map(presentationCandidates.value)
+ next.delete(streamId)
+ presentationCandidates.value = next
+}
+
+const emptyPresentation: UserStream = {
streamId: '',
stream: new MediaStream(),
name: 'Presentation',
+}
+
+const presentationStream = computed(() => {
+ const candidates = [...presentationCandidates.value.values()]
+ return candidates[candidates.length - 1] ?? emptyPresentation
})
const enabledPresentation = computed(
@@ -59,7 +86,9 @@ export {
meetingJoined,
presentationStream,
recordingAt,
+ registerPresentation,
roomInfo,
roomParticipants,
speakerStatus,
+ unregisterPresentation,
}