-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(egress-composite): new configuration system (#689)
Adds `ConfigurationContext` for configuration data provisioning across the whole application. To load the application append this script to the page `head`: ```html <script type="application/javascript"> window.StreamCompositeApp.configureAndRender({ // required call_id: "<your-call-id>", // optional options: { layout: { main: "grid", screenshare: "dominant_speaker", }, }, }); </script> ``` Accepted configuration values (subject to change): https://github.com/GetStream/stream-video-js/blob/7d5d435634a0a4e601cf6b35f289a709f09a2bdb/sample-apps/react/egress-composite/src/ConfigurationContext.tsx#L4-L56 --------- Co-authored-by: Oliver Lazoroski <[email protected]> Co-authored-by: Tommaso Barbugli <[email protected]>
- Loading branch information
1 parent
2e400e7
commit 7f41c71
Showing
30 changed files
with
337 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
VITE_STREAM_API_KEY="<your API key>" | ||
VITE_STREAM_TOKEN="<user token>" | ||
VITE_STREAM_USER_TOKEN="<user token>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
sample-apps/react/egress-composite/src/ConfigurationContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createContext, useContext } from 'react'; | ||
import { decode } from 'js-base64'; | ||
|
||
export type ConfigurationValue = { | ||
base_url?: string; | ||
|
||
api_key: string; | ||
call_type: string; | ||
call_id: string; | ||
token: string; | ||
user_id: string; // pulled from the token payload | ||
|
||
ext_css?: string; | ||
|
||
layout?: 'grid' | 'single_participant' | 'spotlight' | 'mobile'; | ||
screenshare_layout?: 'single_participant' | 'spotlight'; | ||
|
||
options: { | ||
'video.background_color'?: string; | ||
'video.scale_mode'?: 'fill' | 'fit'; | ||
'video.screenshare_scale_mode'?: 'fill' | 'fit'; | ||
|
||
'logo.image_url'?: string; | ||
'logo.horizontal_position'?: 'center' | 'left' | 'right'; | ||
'logo.vertical_position'?: 'center' | 'left' | 'right'; | ||
|
||
'participant.label_display'?: boolean; | ||
'participant.label_text_color'?: string; | ||
'participant.label_background_color'?: string; | ||
'participant.label_display_border'?: boolean; | ||
'participant.label_border_radius'?: string; | ||
'participant.label_border_color'?: string; | ||
'participant.label_horizontal_position'?: 'center' | 'left' | 'right'; | ||
'participant.label_vertical_position'?: 'center' | 'left' | 'right'; | ||
|
||
// participant_border_color: string; | ||
// participant_border_radius: string; | ||
// participant_border_width: string; | ||
'participant.participant_highlight_border_color'?: string; // talking | ||
'participant.placeholder_background_color'?: string; | ||
|
||
// used with any layout | ||
'layout.size_percentage'?: number; | ||
|
||
// grid-specific | ||
'layout.grid.gap'?: string; | ||
'layout.grid.page_size'?: number; | ||
// dominant_speaker-specific (single-participant) | ||
'layout.single_participant.mode'?: 'shuffle' | 'default'; | ||
'layout.single_participant.shuffle_delay'?: number; | ||
// spotlight-specific | ||
'layout.spotlight.bar_position'?: 'top' | 'right' | 'bottom' | 'left'; | ||
'layout.spotlight.bar_limit'?: number; | ||
}; | ||
}; | ||
|
||
export const ConfigurationContext = createContext<ConfigurationValue>( | ||
{} as ConfigurationValue, | ||
); | ||
|
||
export const extractPayloadFromToken = (token: string) => { | ||
const [, payload] = token.split('.'); | ||
|
||
if (!payload) throw new Error('Malformed token, missing payload'); | ||
|
||
try { | ||
return (JSON.parse(decode(payload)) ?? {}) as Record<string, unknown>; | ||
} catch (e) { | ||
console.log('Error parsing token payload', e); | ||
return {}; | ||
} | ||
}; | ||
|
||
export const useConfigurationContext = () => useContext(ConfigurationContext); |
36 changes: 36 additions & 0 deletions
36
sample-apps/react/egress-composite/src/components/LogoAndTitleOverlay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useConfigurationContext } from '../ConfigurationContext'; | ||
|
||
export const LogoAndTitleOverlay = () => { | ||
const { options } = useConfigurationContext(); | ||
|
||
const image_url = options['logo.image_url']; | ||
|
||
return ( | ||
<div | ||
style={{ | ||
top: 0, | ||
left: 0, | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
> | ||
{/* {text?.length && ( | ||
<div | ||
data-test-id="title" | ||
style={{ ...DEFAULT_TITLE_STYLE, ...titleStyle }} | ||
> | ||
{text} | ||
</div> | ||
)} */} | ||
{image_url && ( | ||
<img | ||
data-test-id="logo" | ||
src={image_url} | ||
// style={{ ...DEFAULT_LOGO_STYLE, ...logoStyle }} | ||
alt="logo" | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
23 changes: 23 additions & 0 deletions
23
sample-apps/react/egress-composite/src/components/UIDispatcher.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useCallStateHooks } from '@stream-io/video-react-sdk'; | ||
|
||
import { useConfigurationContext } from '../ConfigurationContext'; | ||
import { LayoutType, layoutMap } from './layouts'; | ||
import { Spotlight } from './layouts/Spotlight'; | ||
|
||
const DEFAULT_LAYOUT: LayoutType = 'spotlight'; | ||
const DEFAULT_SCREENSHARE_LAYOUT: LayoutType = 'spotlight'; | ||
|
||
export const UIDispatcher = () => { | ||
const { | ||
layout = DEFAULT_LAYOUT, | ||
screenshare_layout = DEFAULT_SCREENSHARE_LAYOUT, | ||
} = useConfigurationContext(); | ||
const { useHasOngoingScreenShare } = useCallStateHooks(); | ||
const hasScreenShare = useHasOngoingScreenShare(); | ||
|
||
const DefaultView = layoutMap[layout]?.[0] ?? Spotlight; | ||
|
||
const ScreenShareView = layoutMap[screenshare_layout]?.[1] ?? Spotlight; | ||
|
||
return hasScreenShare ? <ScreenShareView /> : <DefaultView />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './LogoAndTitleOverlay'; | ||
export * from './UIDispatcher'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c/layouts/dominant-speaker/Spotlight.scss → ...outs/DominantSpeaker/DominantSpeaker.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.spotlight-container { | ||
.dominant-speaker__container { | ||
height: 100vh; | ||
|
||
.str-video__participant-view { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...layouts/dominant-speaker/ScreenShare.scss → ...ntSpeaker/DominantSpeakerScreenShare.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
sample-apps/react/egress-composite/src/components/layouts/DominantSpeaker/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { DominantSpeaker } from './DominantSpeaker'; | ||
export { DominantSpeakerScreenShare } from './DominantSpeakerScreenShare'; |
Oops, something went wrong.