Skip to content

Commit 8f65dac

Browse files
committed
Add ability to set source node volume and mute source node to sceneless project commands.
1 parent b303aab commit 8f65dac

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/core/transforms/GameSource.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export const GameSource = {
142142
source: Sources.GameSource
143143
}) => {
144144
const ref = useRef<HTMLVideoElement>()
145-
const { volume = 1, isHidden = false } = props || {}
145+
const { volume = 1, isMuted = false } = props || {}
146146
const [labelSize, setLabelSize] = useState<0 | 1 | 2 | 3>(0)
147147

148-
const muteAudio = props?.isMuted
148+
const muteAudio = isMuted
149149

150150
const hasVideo = !props?.isHidden && source?.props?.videoEnabled
151151

src/helpers/sceneless-project.ts

+32
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@ export interface Commands {
346346
cb: (nodes: Compositor.SceneNode[]) => void,
347347
type: ExternalSourceType,
348348
): Disposable
349+
/**
350+
* Change a source node's volume.
351+
* This does not affect the underlying MediaStreamTrack.
352+
*/
353+
setSourceNodeVolume(id: string, volume: number): void
354+
/**
355+
* Mute a source node without changing its volume.
356+
* This does not affect the underlying MediaStreamTrack.
357+
*/
358+
setSourceNodeMuted(id: string, isMuted: boolean): void
349359
/**
350360
* Add a participant camera track to the stream canvas.
351361
* Available participants can be gleaned from the WebRTC {@link Room} using
@@ -1838,6 +1848,28 @@ export const commands = (_project: ScenelessProject) => {
18381848
}
18391849
},
18401850

1851+
setSourceNodeVolume(id, volume) {
1852+
const node = commands.getSourceNode(id)
1853+
if (!node) return
1854+
CoreContext.Command.updateNode({
1855+
nodeId: node.id,
1856+
props: {
1857+
volume,
1858+
},
1859+
})
1860+
},
1861+
1862+
setSourceNodeMuted(id, isMuted) {
1863+
const node = commands.getSourceNode(id)
1864+
if (!node) return
1865+
CoreContext.Command.updateNode({
1866+
nodeId: node.id,
1867+
props: {
1868+
isMuted,
1869+
},
1870+
})
1871+
},
1872+
18411873
async addParticipantTrack(
18421874
trackId: string,
18431875
props: Partial<ParticipantProps> = {

0 commit comments

Comments
 (0)