-
Notifications
You must be signed in to change notification settings - Fork 737
Ahoyapps 47 create participant filmstrip #7
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
charliesantos
merged 22 commits into
development
from
AHOYAPPS-47-create-speaker-filmstrip
Oct 30, 2019
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1ff6a0c
Add Participant, publication, and Track components and hooks
11e783c
Apply basic styles to ParticipantStrip
a977ca4
Add AudioTrack component
743ec11
Add Network quality states to ParticipantStrip
f0edb67
Style adjustments for network quality
e4465d9
Clean up network quality appearance and code
0d2bfb4
Fix some bugs in useRoom and useParticipants hooks
4aaf9fa
Fix network quality level
d4db552
Merge in development branch
4893374
Fix useRoom tests
893ec1c
Add more testing dependencies
803dea8
fix networkQuality hook
4e9d100
Add more tests
5f3d56b
Add more tests for hooks
15b4d62
Add tests for Participant and Publication
abd1f51
Add test for participantStrip component
84f25b0
Tidy up tests a little
a41d752
Let Participant component decide if it was passed the localParticipant
00b6164
Adjust import orders
c882901
Restructure participant component
977ca6b
Delete file created on accident
4de91c4
Rename type
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import AudioTrack from './AudioTrack'; | ||
|
|
||
| describe('the AudioTrack component', () => { | ||
| it('should call the attach method when the component mounts', () => { | ||
| const mockTrack = { attach: jest.fn(), detach: jest.fn() } as any; | ||
| render(<AudioTrack track={mockTrack} />); | ||
| expect(mockTrack.attach).toHaveBeenCalledWith( | ||
| expect.any(window.HTMLAudioElement) | ||
| ); | ||
| expect(mockTrack.detach).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('it should call the detach method when the component unmounts', () => { | ||
| const mockTrack = { attach: jest.fn(), detach: jest.fn() } as any; | ||
| const { unmount } = render(<AudioTrack track={mockTrack} />); | ||
| unmount(); | ||
| expect(mockTrack.detach).toHaveBeenCalledWith( | ||
| expect.any(window.HTMLAudioElement) | ||
| ); | ||
| }); | ||
| }); |
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,20 @@ | ||
| import React, { useEffect, useRef } from 'react'; | ||
| import { AudioTrack as IAudioTrack } from 'twilio-video'; | ||
|
|
||
| interface AudioTrackProps { | ||
| track: IAudioTrack; | ||
| } | ||
|
|
||
| export default function AudioTrack({ track }: AudioTrackProps) { | ||
| const ref = useRef<HTMLAudioElement>(null!); | ||
|
|
||
| useEffect(() => { | ||
| const el = ref.current; | ||
| track.attach(el); | ||
| return () => { | ||
| track.detach(el); | ||
| }; | ||
| }, [track]); | ||
|
|
||
| return <audio ref={ref} />; | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/components/NewtorkQualityLevel/NetworkQualityLevel.test.tsx
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,26 @@ | ||
| import React from 'react'; | ||
| import renderer from 'react-test-renderer'; | ||
| import NetworkQualityLevel from './NetworkQualityLevel'; | ||
|
|
||
| describe('the NetworkQualityLevel component', () => { | ||
| it('should render correctly for level 5', () => { | ||
| const tree = renderer | ||
| .create(<NetworkQualityLevel qualityLevel={5} />) | ||
| .toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should render correctly for level 3', () => { | ||
| const tree = renderer | ||
| .create(<NetworkQualityLevel qualityLevel={3} />) | ||
| .toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should render correctly for level 0', () => { | ||
| const tree = renderer | ||
| .create(<NetworkQualityLevel qualityLevel={0} />) | ||
| .toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
| }); |
38 changes: 38 additions & 0 deletions
38
src/components/NewtorkQualityLevel/NetworkQualityLevel.tsx
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,38 @@ | ||
| import React from 'react'; | ||
| import { styled } from '@material-ui/core/styles'; | ||
|
|
||
| const Container = styled('div')({ | ||
| display: 'flex', | ||
| alignItems: 'flex-end', | ||
| '& div': { | ||
| width: '2px', | ||
| border: '1px solid black', | ||
| boxSizing: 'content-box', | ||
| '&:not(:last-child)': { | ||
| borderRight: 'none', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const STEP = 3; | ||
|
|
||
| export default function NetworkQualityLevel({ | ||
| qualityLevel, | ||
| }: { | ||
| qualityLevel: number | null; | ||
| }) { | ||
| if (qualityLevel === null) return null; | ||
| return ( | ||
| <Container> | ||
| {[0, 1, 2, 3, 4].map(level => ( | ||
| <div | ||
| key={level} | ||
| style={{ | ||
| height: `${STEP * (level + 1)}px`, | ||
| background: qualityLevel > level ? '#0c0' : '#040', | ||
| }} | ||
| /> | ||
| ))} | ||
| </Container> | ||
| ); | ||
| } | ||
142 changes: 142 additions & 0 deletions
142
src/components/NewtorkQualityLevel/__snapshots__/NetworkQualityLevel.test.tsx.snap
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,142 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
timmydoza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| exports[`the NetworkQualityLevel component should render correctly for level 0 1`] = ` | ||
| <div | ||
| className="div-root-1" | ||
| > | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "3px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "6px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "9px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "12px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "15px", | ||
| } | ||
| } | ||
| /> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`the NetworkQualityLevel component should render correctly for level 3 1`] = ` | ||
| <div | ||
| className="div-root-1" | ||
| > | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "3px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "6px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "9px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "12px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#040", | ||
| "height": "15px", | ||
| } | ||
| } | ||
| /> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`the NetworkQualityLevel component should render correctly for level 5 1`] = ` | ||
| <div | ||
| className="div-root-1" | ||
| > | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "3px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "6px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "9px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "12px", | ||
| } | ||
| } | ||
| /> | ||
| <div | ||
| style={ | ||
| Object { | ||
| "background": "#0c0", | ||
| "height": "15px", | ||
| } | ||
| } | ||
| /> | ||
| </div> | ||
| `; | ||
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 React from 'react'; | ||
| import ParticipantInfo from '../ParticipantInfo/ParticipantInfo'; | ||
| import ParticipantTracks from '../ParticipantTracks/ParticipantTracks'; | ||
| import { LocalParticipant, RemoteParticipant } from 'twilio-video'; | ||
|
|
||
| interface ParticipantProps { | ||
| participant: LocalParticipant | RemoteParticipant; | ||
| } | ||
|
|
||
| export default function Participant({ participant }: ParticipantProps) { | ||
| return ( | ||
| <ParticipantInfo participant={participant}> | ||
| <ParticipantTracks participant={participant} /> | ||
| </ParticipantInfo> | ||
| ); | ||
| } |
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,19 @@ | ||
| import React from 'react'; | ||
| import ParticipantInfo from './ParticipantInfo'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
| jest.mock( | ||
| '../../hooks/useParticipantNetworkQualityLevel/useParticipantNetworkQualityLevel', | ||
| () => () => 4 | ||
| ); | ||
|
|
||
| describe('the ParticipantInfo component', () => { | ||
| it('should render correctly', () => { | ||
| const wrapper = shallow( | ||
| <ParticipantInfo participant={{ identity: 'mockIdentity' } as any}> | ||
| mock children | ||
| </ParticipantInfo> | ||
| ); | ||
| expect(wrapper).toMatchSnapshot(); | ||
| }); | ||
| }); |
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,46 @@ | ||
| import React from 'react'; | ||
| import { styled } from '@material-ui/core/styles'; | ||
| import { LocalParticipant, RemoteParticipant } from 'twilio-video'; | ||
| import NetworkQualityLevel from '../NewtorkQualityLevel/NetworkQualityLevel'; | ||
| import useParticipantNetworkQualityLevel from '../../hooks/useParticipantNetworkQualityLevel/useParticipantNetworkQualityLevel'; | ||
|
|
||
| const Container = styled('div')({ | ||
| position: 'relative', | ||
| }); | ||
|
|
||
| const InfoContainer = styled('div')({ | ||
| position: 'absolute', | ||
| zIndex: 1, | ||
| display: 'flex', | ||
| justifyContent: 'space-between', | ||
| padding: '0.3em', | ||
| width: '100%', | ||
| }); | ||
|
|
||
| const Identity = styled('h4')({ | ||
| background: 'rgba(0, 0, 0, 0.7)', | ||
| padding: '0.1em 0.3em', | ||
| margin: 0, | ||
| }); | ||
|
|
||
| interface ParticipantInfoProps { | ||
| participant: LocalParticipant | RemoteParticipant; | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export default function ParticipantInfo({ | ||
| participant, | ||
| children, | ||
| }: ParticipantInfoProps) { | ||
| const networkQualityLevel = useParticipantNetworkQualityLevel(participant); | ||
|
|
||
| return ( | ||
| <Container> | ||
| <InfoContainer> | ||
| <Identity>{participant.identity}</Identity> | ||
| <NetworkQualityLevel qualityLevel={networkQualityLevel} /> | ||
| </InfoContainer> | ||
| {children} | ||
| </Container> | ||
| ); | ||
| } |
Oops, something went wrong.
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.
Not part of this PR but just a thought. How would we pass custom styles if I want to reuse this component?