PeerGrid.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. GridLayout,
  3. Peer,
  4. PeerList,
  5. RemoteMediaList
  6. } from '@andyet/simplewebrtc';
  7. import React from 'react';
  8. import styled from 'styled-components';
  9. import mq from '../styles/media-queries';
  10. import isMobile from '../utils/isMobile';
  11. import PeerGridItem from './PeerGridItem';
  12. const StyledGridLayout = styled(GridLayout)({
  13. flex: 1,
  14. [mq.SMALL_DESKTOP]: {
  15. height: '100vh'
  16. },
  17. backgroundColor: '#eaecec',
  18. '& video': {
  19. width: '100%'
  20. },
  21. '& > div': {
  22. position: 'relative'
  23. }
  24. }) as any; // TODO: Fix this!
  25. interface Props {
  26. roomAddress: string;
  27. activeSpeakerView: boolean;
  28. }
  29. // const speakingPeers = peers.filter(p => p.speaking);
  30. // let peersToRender = [];
  31. // if (speakingPeers) {
  32. // peersToRender = [...speakingPeers, peers.filter(p => p.hasSpokenInLast(5))];
  33. // } else {
  34. // peersToRender = peers.filter(p => p.hasSpokenInLast(15));
  35. // }
  36. // if (peersToRender.length === 0) {
  37. // peersToRender = peers;
  38. // }
  39. // PeerGrid is the main video display for Talky. It matches remoteMedia to
  40. // peers and then renders a PeerGridItem for each peer in the room.
  41. const PeerGrid: React.SFC<Props> = ({ roomAddress, activeSpeakerView }) => (
  42. <PeerList
  43. speaking={activeSpeakerView ? activeSpeakerView : undefined}
  44. room={roomAddress}
  45. render={({ peers }) => {
  46. return peers.length > 0 || activeSpeakerView ? (
  47. <StyledGridLayout
  48. items={peers}
  49. renderCell={(peer: Peer) => (
  50. <RemoteMediaList
  51. peer={peer.address}
  52. render={({ media }) => <PeerGridItem media={media} peer={peer} />}
  53. />
  54. )}
  55. />
  56. ) : (
  57. <div style={{ flex: 1 }}>Waiting for peers to join.</div>
  58. );
  59. }}
  60. />
  61. );
  62. export default PeerGrid;