Skip to content

Commit

Permalink
feat: added broadcast config (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Mar 27, 2024
1 parent b0267e0 commit 6082120
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 109 deletions.
8 changes: 8 additions & 0 deletions .changeset/healthy-files-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@livepeer/core-web": patch
"@livepeer/core": patch
"@livepeer/core-react": patch
"@livepeer/react": patch
---

**Feature:** added audio and video constraints to the Broadcast Root component.
19 changes: 4 additions & 15 deletions packages/core-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"exports": {
"./package.json": "./package.json",
".": {
Expand All @@ -31,12 +29,8 @@
},
"typesVersions": {
"*": {
"crypto": [
"./dist/crypto/index.d.ts"
],
"*": [
"./dist/index.d.ts"
]
"crypto": ["./dist/crypto/index.d.ts"],
"*": ["./dist/index.d.ts"]
}
},
"scripts": {
Expand All @@ -61,10 +55,5 @@
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"keywords": [
"livepeer",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "video", "streaming", "livestream"]
}
39 changes: 9 additions & 30 deletions packages/core-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"exports": {
"./package.json": "./package.json",
".": {
Expand Down Expand Up @@ -56,27 +54,13 @@
},
"typesVersions": {
"*": {
"broadcast": [
"./dist/broadcast/index.d.ts"
],
"browser": [
"./dist/browser/index.d.ts"
],
"external": [
"./dist/external/index.d.ts"
],
"hls": [
"./dist/hls/index.d.ts"
],
"media": [
"./dist/media/index.d.ts"
],
"webrtc": [
"./dist/webrtc/index.d.ts"
],
"*": [
"./dist/index.d.ts"
]
"broadcast": ["./dist/broadcast/index.d.ts"],
"browser": ["./dist/browser/index.d.ts"],
"external": ["./dist/external/index.d.ts"],
"hls": ["./dist/hls/index.d.ts"],
"media": ["./dist/media/index.d.ts"],
"webrtc": ["./dist/webrtc/index.d.ts"],
"*": ["./dist/index.d.ts"]
}
},
"scripts": {
Expand All @@ -90,10 +74,5 @@
"hls.js": "^1.5.2",
"zustand": "^4.5.0"
},
"keywords": [
"livepeer",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "video", "streaming", "livestream"]
}
33 changes: 27 additions & 6 deletions packages/core-web/src/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export type InitialBroadcastProps = {
*
* Set to false to initialize the broadcast to not request an audio track.
*/
audio: boolean;
audio: boolean | MediaTrackConstraints;

/**
* The creatorId for the current broadcast.
Expand Down Expand Up @@ -138,7 +138,7 @@ export type InitialBroadcastProps = {
*
* Set to false to initialize the broadcast to not request a video track.
*/
video: boolean;
video: boolean | MediaTrackConstraints;
};

export type BroadcastAriaText = {
Expand Down Expand Up @@ -312,7 +312,7 @@ export const createBroadcastStore = ({

__initialProps: {
aspectRatio: initialProps?.aspectRatio ?? null,
audio: initialProps?.video ?? true,
audio: initialProps?.audio ?? true,
creatorId: initialProps.creatorId ?? null,
forceEnabled: initialProps?.forceEnabled ?? false,
hotkeys: initialProps.hotkeys ?? true,
Expand Down Expand Up @@ -806,6 +806,8 @@ const addEffectsToStore = (
audio: state.audio,
requestedAudioDeviceId: state.__controls.requestedAudioInputDeviceId,
requestedVideoDeviceId: state.__controls.requestedVideoInputDeviceId,
initialAudioConfig: state.__initialProps.audio,
initialVideoConfig: state.__initialProps.video,
previousMediaStream: state.mediaStream,
}),
async ({
Expand All @@ -816,6 +818,8 @@ const addEffectsToStore = (
requestedAudioDeviceId,
requestedVideoDeviceId,
previousMediaStream,
initialAudioConfig,
initialVideoConfig,
}) => {
try {
if (!mounted || !hydrated) {
Expand All @@ -832,6 +836,11 @@ const addEffectsToStore = (
video = true;
}

const audioConstraints =
typeof initialAudioConfig !== "boolean" ? initialAudioConfig : null;
const videoConstraints =
typeof initialVideoConfig !== "boolean" ? initialVideoConfig : null;

const stream = await (requestedVideoDeviceId === "screen"
? getDisplayMedia({
// for now, only the microphone audio track is supported - we don't support multiple
Expand All @@ -840,31 +849,43 @@ const addEffectsToStore = (

// we assume that if the user is requested to share screen, they want to enable video,
// and we don't listen to the `video` enabled state
video: true,
//
// we apply the video constraints to the video track
video: videoConstraints ?? true,
})
: getUserMedia({
audio:
audio &&
requestedAudioDeviceId &&
requestedAudioDeviceId !== "default"
? {
...(audioConstraints ? audioConstraints : {}),
deviceId: {
// we pass ideal here, so we don't get overconstrained errors
ideal: requestedAudioDeviceId,
},
}
: Boolean(audio),
: audio
? {
...(audioConstraints ? audioConstraints : {}),
}
: false,
video:
video &&
requestedVideoDeviceId &&
requestedVideoDeviceId !== "default"
? {
...(videoConstraints ? videoConstraints : {}),
deviceId: {
// we pass ideal here, so we don't get overconstrained errors
ideal: requestedVideoDeviceId,
},
}
: Boolean(video),
: video
? {
...(videoConstraints ? videoConstraints : {}),
}
: false,
}));

if (stream) {
Expand Down
39 changes: 9 additions & 30 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"exports": {
"./package.json": "./package.json",
".": {
Expand Down Expand Up @@ -56,27 +54,13 @@
},
"typesVersions": {
"*": {
"crypto": [
"./dist/crypto/index.d.ts"
],
"errors": [
"./dist/errors/index.d.ts"
],
"media": [
"./dist/media/index.d.ts"
],
"storage": [
"./dist/storage/index.d.ts"
],
"utils": [
"./dist/utils/index.d.ts"
],
"version": [
"./dist/version/index.d.ts"
],
"*": [
"./dist/index.d.ts"
]
"crypto": ["./dist/crypto/index.d.ts"],
"errors": ["./dist/errors/index.d.ts"],
"media": ["./dist/media/index.d.ts"],
"storage": ["./dist/storage/index.d.ts"],
"utils": ["./dist/utils/index.d.ts"],
"version": ["./dist/version/index.d.ts"],
"*": ["./dist/index.d.ts"]
}
},
"scripts": {
Expand All @@ -92,10 +76,5 @@
"devDependencies": {
"jose": "^5.2.3"
},
"keywords": [
"livepeer",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "video", "streaming", "livestream"]
}
36 changes: 8 additions & 28 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"exports": {
"./package.json": "./package.json",
".": {
Expand Down Expand Up @@ -51,24 +49,12 @@
},
"typesVersions": {
"*": {
"assets": [
"./dist/assets/index.d.ts"
],
"broadcast": [
"./dist/broadcast/index.d.ts"
],
"crypto": [
"./dist/crypto/index.d.ts"
],
"external": [
"./dist/external/index.d.ts"
],
"player": [
"./dist/player/index.d.ts"
],
"*": [
"./dist/index.d.ts"
]
"assets": ["./dist/assets/index.d.ts"],
"broadcast": ["./dist/broadcast/index.d.ts"],
"crypto": ["./dist/crypto/index.d.ts"],
"external": ["./dist/external/index.d.ts"],
"player": ["./dist/player/index.d.ts"],
"*": ["./dist/index.d.ts"]
}
},
"scripts": {
Expand Down Expand Up @@ -114,11 +100,5 @@
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"keywords": [
"livepeer",
"react",
"video",
"streaming",
"livestream"
]
"keywords": ["livepeer", "react", "video", "streaming", "livestream"]
}

0 comments on commit 6082120

Please sign in to comment.