Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Toolbar.tsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import React, { Component } from 'react';
  2. import AudioMuteButton from './AudioMuteButton';
  3. import HangupButton from './HangupButton';
  4. import VideoMuteButton from './VideoMuteButton';
  5. const { api } = window.alwaysOnTop;
  6. /**
  7. * The type of the React {@code Component} props of {@link Toolbar}.
  8. */
  9. interface IProps {
  10. /**
  11. * Additional CSS class names to add to the root of the toolbar.
  12. */
  13. className: string;
  14. /**
  15. * Callback invoked when no longer moused over the toolbar.
  16. */
  17. onMouseOut: (e?: React.MouseEvent) => void;
  18. /**
  19. * Callback invoked when the mouse has moved over the toolbar.
  20. */
  21. onMouseOver: (e?: React.MouseEvent) => void;
  22. }
  23. /**
  24. * The type of the React {@code Component} state of {@link Toolbar}.
  25. */
  26. interface IState {
  27. /**
  28. * Whether audio button to be shown or not.
  29. */
  30. showAudioButton: boolean;
  31. /**
  32. * Whether video button to be shown or not.
  33. */
  34. showVideoButton: boolean;
  35. }
  36. type Props = Partial<IProps>;
  37. /**
  38. * Represents the toolbar in the Always On Top window.
  39. *
  40. * @augments Component
  41. */
  42. export default class Toolbar extends Component<Props, IState> {
  43. /**
  44. * Initializes a new {@code Toolbar} instance.
  45. *
  46. * @param {IProps} props - The React {@code Component} props to initialize the new {@code Toolbar} instance with.
  47. */
  48. constructor(props: Props) {
  49. super(props);
  50. this.state = {
  51. showAudioButton: true,
  52. showVideoButton: true
  53. };
  54. this._videoConferenceJoinedListener = this._videoConferenceJoinedListener.bind(this);
  55. }
  56. /**
  57. * Sets listens for changing meetings while showing the toolbar.
  58. *
  59. * @inheritdoc
  60. * @returns {void}
  61. */
  62. componentDidMount() {
  63. api.on('videoConferenceJoined', this._videoConferenceJoinedListener);
  64. this._videoConferenceJoinedListener();
  65. }
  66. /**
  67. * Handles is visitor changes.
  68. *
  69. * @returns {void}
  70. */
  71. _videoConferenceJoinedListener() {
  72. // for electron clients that embed the api and are not updated
  73. if (!api.isVisitor) {
  74. console.warn('external API not updated');
  75. return;
  76. }
  77. const isNotVisitor = !api.isVisitor();
  78. this.setState({
  79. showAudioButton: isNotVisitor,
  80. showVideoButton: isNotVisitor
  81. });
  82. }
  83. /**
  84. * Removes all listeners.
  85. *
  86. * @inheritdoc
  87. * @returns {void}
  88. */
  89. componentWillUnmount() {
  90. api.removeListener('videoConferenceJoined', this._videoConferenceJoinedListener);
  91. }
  92. /**
  93. * Implements React's {@link Component#render()}.
  94. *
  95. * @inheritdoc
  96. * @returns {ReactElement}
  97. */
  98. render() {
  99. const {
  100. className = '',
  101. onMouseOut,
  102. onMouseOver
  103. } = this.props;
  104. return (
  105. <div
  106. className = { `toolbox-content-items always-on-top-toolbox ${className}` }
  107. onMouseOut = { onMouseOut }
  108. onMouseOver = { onMouseOver }>
  109. { this.state.showAudioButton && <AudioMuteButton /> }
  110. { this.state.showVideoButton && <VideoMuteButton /> }
  111. <HangupButton customClass = 'hangup-button' />
  112. </div>
  113. );
  114. }
  115. }