Skip to content

Commit

Permalink
Merge pull request #186 from whereby/nandor/cob-617-make-screenshare-…
Browse files Browse the repository at this point in the history
…captions-work

core: use getTrack().some() to tell if screenshare has audio and use fallback id
  • Loading branch information
nandito authored Apr 11, 2024
2 parents 8a28f79 + 8f6987d commit 78befe1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-steaks-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whereby.com/core": patch
---

Use MediaStream.getTracks() to tell if a screenshare has audio enabled or not. `.getAudioTracks()` is not implemented in some WebRTC implementations.
5 changes: 5 additions & 0 deletions .changeset/small-trains-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whereby.com/core": patch
---

Use `pres-` prefixed clientId as screenshare id for remote participants and "local-screenshare" for local screenshares as a fallback, if the MediaStream has no `id`.
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ describe("remoteParticipantsSlice", () => {
it.each`
localScreenshareStream | remoteParticipants | expected
${null} | ${[]} | ${[]}
${null} | ${[client1, client2]} | ${[{ id: "", hasAudioTrack: false, isLocal: false, participantId: client2.id, stream: client2.presentationStream }]}
${localScreenshareStream} | ${[]} | ${[{ id: "", hasAudioTrack: false, isLocal: true, participantId: "local", stream: localScreenshareStream }]}
${localScreenshareStream} | ${[client3]} | ${[{ id: "", hasAudioTrack: false, isLocal: true, participantId: "local", stream: localScreenshareStream }, { id: "", hasAudioTrack: false, isLocal: false, participantId: client3.id, stream: client3.presentationStream }]}
${null} | ${[client1, client2]} | ${[{ id: `pres-${client2.id}`, hasAudioTrack: false, isLocal: false, participantId: client2.id, stream: client2.presentationStream }]}
${localScreenshareStream} | ${[]} | ${[{ id: "local-screenshare", hasAudioTrack: false, isLocal: true, participantId: "local", stream: localScreenshareStream }]}
${localScreenshareStream} | ${[client3]} | ${[{ id: "local-screenshare", hasAudioTrack: false, isLocal: true, participantId: "local", stream: localScreenshareStream }, { id: `pres-${client3.id}`, hasAudioTrack: false, isLocal: false, participantId: client3.id, stream: client3.presentationStream }]}
`(
"should return $expected when localScreenshareStream=$localScreenshareStream, remoteParticipants=$remoteParticipants",
({ localScreenshareStream, remoteParticipants, expected }) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/redux/slices/remoteParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ export const selectScreenshares = createSelector(

if (localScreenshareStream) {
screenshares.push({
id: localScreenshareStream.id,
id: localScreenshareStream.id || "local-screenshare",
participantId: "local",
hasAudioTrack: localScreenshareStream.getAudioTracks().length > 0,
hasAudioTrack: localScreenshareStream.getTracks().some((track) => track.kind === "audio"),
stream: localScreenshareStream,
isLocal: true,
});
Expand All @@ -308,9 +308,9 @@ export const selectScreenshares = createSelector(
for (const participant of remoteParticipants) {
if (participant.presentationStream) {
screenshares.push({
id: participant.presentationStream.id,
id: participant.presentationStream.id || `pres-${participant.id}`,
participantId: participant.id,
hasAudioTrack: participant.presentationStream.getAudioTracks().length > 0,
hasAudioTrack: participant.presentationStream.getTracks().some((track) => track.kind === "audio"),
stream: participant.presentationStream,
isLocal: false,
});
Expand Down

0 comments on commit 78befe1

Please sign in to comment.