-
Notifications
You must be signed in to change notification settings - Fork 737
Ahoyapps 46 dominant speaker area #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02f0847
Add new hooks and tests
84b25a1
Add main participant to room component
e4d5bca
Move sidebar position to theme
5647e64
Lint
4536f5c
Disable main participant's audio as it will already be rendered in th…
ac1b772
Typo
8c95bb6
Change import order
4b946c0
Fix circleci
f7e44b9
Add comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,6 +9,6 @@ jobs: | |
|
|
||
| - run: npm ci | ||
|
|
||
| - run: npm test | ||
| - run: npm test -- --runInBand | ||
|
|
||
| - run: npm run build | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,16 +1,35 @@ | ||
| import React from 'react'; | ||
| import Participant from '../Participant/Participant'; | ||
| import ParticipantStrip from '../ParticipantStrip/ParticipantStrip'; | ||
| import { styled } from '@material-ui/core/styles'; | ||
| import useMainSpeaker from '../../hooks/useMainSpeaker/useMainSpeaker'; | ||
|
|
||
| const Container = styled('div')({ | ||
| position: 'relative', | ||
| height: '100%', | ||
| }); | ||
|
|
||
| const MainParticipantContainer = styled('div')(({ theme }) => ({ | ||
| position: 'absolute', | ||
| left: theme.sidebarPosition, | ||
| right: 0, | ||
| top: 0, | ||
| bottom: 0, | ||
| '& > div': { | ||
| height: '100%', | ||
| }, | ||
| })); | ||
|
|
||
| export default function Room() { | ||
| const mainParticipant = useMainSpeaker(); | ||
| return ( | ||
| <Container> | ||
| <ParticipantStrip /> | ||
| <MainParticipantContainer> | ||
| {/* audio is disabled for this participant component because this participant's audio | ||
| is already being rendered in the <ParticipantStrip /> component. */} | ||
| <Participant participant={mainParticipant} disableAudio /> | ||
| </MainParticipantContainer> | ||
| </Container> | ||
| ); | ||
| } | ||
This file contains hidden or 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,32 @@ | ||
| import { act, renderHook } from '@testing-library/react-hooks'; | ||
| import EventEmitter from 'events'; | ||
| import useDominantSpeaker from './useDominantSpeaker'; | ||
| import { useVideoContext } from '../context'; | ||
|
|
||
| jest.mock('../context'); | ||
| const mockUseVideoContext = useVideoContext as jest.Mock<any>; | ||
|
|
||
| describe('the useDominantSpeaker hook', () => { | ||
| const mockRoom: any = new EventEmitter(); | ||
| mockRoom.dominantSpeaker = 'mockDominantSpeaker'; | ||
| mockUseVideoContext.mockImplementation(() => ({ room: mockRoom })); | ||
|
|
||
| it('should return room.dominantSpeaker by default', () => { | ||
| const { result } = renderHook(useDominantSpeaker); | ||
| expect(result.current).toBe('mockDominantSpeaker'); | ||
| }); | ||
|
|
||
| it('should return respond to "dominantSpeakerChanged" events', async () => { | ||
| const { result } = renderHook(useDominantSpeaker); | ||
| act(() => { | ||
| mockRoom.emit('dominantSpeakerChanged', 'newDominantSpeaker'); | ||
| }); | ||
| expect(result.current).toBe('newDominantSpeaker'); | ||
| }); | ||
|
|
||
| it('should clean up listeners on unmount', () => { | ||
| const { unmount } = renderHook(useDominantSpeaker); | ||
| unmount(); | ||
| expect(mockRoom.listenerCount('dominantSpeakerChanged')).toBe(0); | ||
| }); | ||
| }); |
This file contains hidden or 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,16 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { useVideoContext } from '../context'; | ||
|
|
||
| export default function useDominantSpeaker() { | ||
| const { room } = useVideoContext(); | ||
| const [dominantSpeaker, setDominantSpeaker] = useState(room.dominantSpeaker); | ||
|
|
||
| useEffect(() => { | ||
| room.on('dominantSpeakerChanged', setDominantSpeaker); | ||
| return () => { | ||
| room.off('dominantSpeakerChanged', setDominantSpeaker); | ||
| }; | ||
| }, [room]); | ||
|
|
||
| return dominantSpeaker; | ||
| } |
This file contains hidden or 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,42 @@ | ||
| import useMainSpeaker from './useMainSpeaker'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { useVideoContext } from '../context'; | ||
| import { EventEmitter } from 'events'; | ||
|
|
||
| jest.mock('../context'); | ||
| const mockUseVideoContext = useVideoContext as jest.Mock<any>; | ||
|
|
||
| describe('the useMainSpeaker hook', () => { | ||
| it('should return the dominant speaker if it exists', () => { | ||
| const mockRoom: any = new EventEmitter(); | ||
| mockRoom.dominantSpeaker = 'dominantSpeaker'; | ||
| mockRoom.participants = new Map([[0, 'participant']]) as any; | ||
| mockRoom.localParticipant = 'localParticipant'; | ||
| mockUseVideoContext.mockImplementation(() => ({ room: mockRoom })); | ||
| const { result } = renderHook(useMainSpeaker); | ||
| expect(result.current).toBe('dominantSpeaker'); | ||
| }); | ||
|
|
||
| it('should return the first remote participant if it exists', () => { | ||
| const mockRoom: any = new EventEmitter(); | ||
| mockRoom.dominantSpeaker = null; | ||
| mockRoom.participants = new Map([ | ||
| [0, 'participant'], | ||
| [1, 'secondParticipant'], | ||
| ]) as any; | ||
| mockRoom.localParticipant = 'localParticipant'; | ||
| mockUseVideoContext.mockImplementation(() => ({ room: mockRoom })); | ||
| const { result } = renderHook(useMainSpeaker); | ||
| expect(result.current).toBe('participant'); | ||
| }); | ||
|
|
||
| it('should return the local participant if it exists', () => { | ||
| const mockRoom: any = new EventEmitter(); | ||
| mockRoom.dominantSpeaker = null; | ||
| mockRoom.participants = new Map() as any; | ||
| mockRoom.localParticipant = 'localParticipant'; | ||
| mockUseVideoContext.mockImplementation(() => ({ room: mockRoom })); | ||
| const { result } = renderHook(useMainSpeaker); | ||
| expect(result.current).toBe('localParticipant'); | ||
| }); | ||
| }); |
This file contains hidden or 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,11 @@ | ||
| import { useVideoContext } from '../context'; | ||
| import useDominantSpeaker from '../useDominantSpeaker/useDominantSpeaker'; | ||
| import useParticipants from '../useParticipants/useParticipants'; | ||
|
|
||
| export default function useMainSpeaker() { | ||
| const { room } = useVideoContext(); | ||
| const participants = useParticipants(); | ||
| const dominantSpeaker = useDominantSpeaker(); | ||
|
|
||
| return dominantSpeaker || participants[0] || room.localParticipant; | ||
| } |
This file contains hidden or 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,10 +1,22 @@ | ||
| import { createMuiTheme } from '@material-ui/core'; | ||
|
|
||
| declare module '@material-ui/core/styles/createMuiTheme' { | ||
| interface Theme { | ||
| sidebarPosition: string; | ||
| } | ||
|
|
||
| // allow configuration using `createMuiTheme` | ||
| interface ThemeOptions { | ||
| sidebarPosition?: string; | ||
| } | ||
| } | ||
|
|
||
| export default createMuiTheme({ | ||
| palette: { | ||
| type: 'dark', | ||
| primary: { | ||
| main: '#cc2b33', | ||
| }, | ||
| }, | ||
| sidebarPosition: '15%', | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is audio disabled by default in VBT?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disableAudioprevents an<audio>element from being rendered for this participant. I'm doing this here because this participant's<audio>element is already rendered in the<ParticipantStrip />component.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Can you add a comment on this line and put what you just said?