Roster.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Peer, PeerControls, PeerList } from '@andyet/simplewebrtc';
  2. import VolumeOffIcon from 'material-icons-svg/components/baseline/VolumeOff';
  3. import VolumeUpIcon from 'material-icons-svg/components/baseline/VolumeUp';
  4. import React from 'react';
  5. import styled from 'styled-components';
  6. import { TalkyButton } from '../styles/button';
  7. const Button = styled(TalkyButton)({
  8. marginRight: '5px'
  9. });
  10. const Container = styled.ul({
  11. listStyle: 'none',
  12. '& li': {
  13. marginBottom: '10px'
  14. }
  15. });
  16. interface PeerListItemProps {
  17. peer: Peer;
  18. }
  19. // PeerListItem renders the displayName and mute controls for a peer.
  20. const PeerListItem: React.SFC<PeerListItemProps> = ({ peer }) => (
  21. <li>
  22. <PeerControls
  23. peer={peer}
  24. render={({ isMuted, mute, unmute }) => (
  25. <Button onClick={() => (isMuted ? unmute() : mute())}>
  26. {isMuted ? (
  27. <VolumeOffIcon fill="#505658" />
  28. ) : (
  29. <VolumeUpIcon fill="#505658" />
  30. )}
  31. </Button>
  32. )}
  33. />
  34. {peer.displayName || 'Anonymous'}
  35. </li>
  36. );
  37. interface Props {
  38. roomAddress: string;
  39. }
  40. const Roster: React.SFC<Props> = ({ roomAddress }) => (
  41. <PeerList
  42. room={roomAddress}
  43. render={({ peers }) => {
  44. return peers.length > 0 ? (
  45. <Container>
  46. {peers.map(peer => (
  47. <PeerListItem key={peer.id} peer={peer} />
  48. ))}
  49. </Container>
  50. ) : <span />;
  51. }}
  52. />
  53. );
  54. export default Roster;