action-bar.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import { defineComponent, reactive } from 'vue'
  2. import { ElButton, ElDropdown, ElDropdownMenu, ElDropdownItem, ElSlider, ElDialog, ElIcon } from 'element-plus'
  3. import runtime, * as RuntimeUtils from './runtime'
  4. import styles from './action-bar.module.less'
  5. import Share from './share'
  6. export const state = reactive({
  7. volume: 30,
  8. barStatus: {
  9. camera: false, // 摄像头
  10. volume: false, // 声音调节
  11. microphone: false, // 麦克风
  12. screen: false, // 共享屏幕
  13. share: false, // 分享
  14. },
  15. shareVisiable: false
  16. })
  17. export default defineComponent({
  18. name: 'LiveBroadcast-ActionBar',
  19. computed: {
  20. isCameraDisabled() {
  21. return state.barStatus.camera && runtime.deviceStatus.camera !== 'denied' && runtime.cameras.length
  22. },
  23. isMicrophoneDisabled() {
  24. const isDisabled = state.barStatus.microphone && runtime.deviceStatus.microphone !== 'denied' && runtime.microphones.length
  25. return isDisabled
  26. },
  27. isVolumeDisabled() {
  28. return state.volume === 0
  29. }
  30. },
  31. methods: {
  32. startShare() {
  33. console.log('调用')
  34. state.shareVisiable = true
  35. },
  36. volumeChange(value: number) {
  37. state.volume = value
  38. RuntimeUtils.setVolume(value)
  39. }
  40. },
  41. render() {
  42. return (
  43. <div class={styles['action-bar']} id="action-bar">
  44. <div style={{ display: 'flex' }}>
  45. <div class={styles['bar-btn']}>
  46. <div class={styles.btnInner}>
  47. <SvgIcon
  48. onClick={() => {
  49. state.barStatus.camera = !state.barStatus.camera
  50. RuntimeUtils.toggleDevice('camera')
  51. }}
  52. name={this.isCameraDisabled ? 'bar-camera-disabled' : 'bar-camera'}
  53. style={{
  54. width: '22px',
  55. cursor: 'pointer'
  56. }}
  57. />
  58. <ElDropdown
  59. placement="top"
  60. // @ts-ignore
  61. disabled={runtime.cameras.length === 0}
  62. onCommand={RuntimeUtils.setSelectCamera}
  63. // @ts-ignore
  64. vSlots={{
  65. dropdown: () => (
  66. <ElDropdownMenu>
  67. {runtime.cameras.map(item => (<ElDropdownItem disabled={item === runtime.selectedCamera} command={item}>{item.label}</ElDropdownItem>))}
  68. </ElDropdownMenu>
  69. )
  70. }}
  71. >
  72. <div class={styles['bar-btn']} style={{ height: '32px' }}>
  73. <SvgIcon
  74. name="bar-arrow-down"
  75. style={{
  76. width: '18px'
  77. }}
  78. />
  79. </div>
  80. </ElDropdown>
  81. </div>
  82. <span class={styles['bar-btn-text']}>摄像头</span>
  83. </div>
  84. <div class={styles['bar-btn']}>
  85. <div class={styles.btnInner}>
  86. <SvgIcon
  87. onClick={() => {
  88. state.barStatus.volume = !state.barStatus.volume;
  89. if(!state.barStatus.volume) {
  90. sessionStorage.getItem('volume') && this.volumeChange(Number(sessionStorage.getItem('volume')))
  91. } else {
  92. sessionStorage.setItem('volume', state.volume.toString())
  93. this.volumeChange(0)
  94. }
  95. }}
  96. name={this.isVolumeDisabled ? 'bar-volume-disabled' : 'bar-volume'}
  97. style={{
  98. width: '22px',
  99. cursor: 'pointer'
  100. }}
  101. />
  102. <ElDropdown
  103. placement="top-start"
  104. popper-options={{ boundariesElement: '#action-bar', gpuAcceleration: false }}
  105. // @ts-ignore
  106. vSlots={{
  107. dropdown: () => (
  108. <div class={styles.volumeSlider}>
  109. <SvgIcon class={styles.volumeIcon} name="message-voice" color="#fff" />
  110. <ElSlider modelValue={state.volume} onInput={this.volumeChange} size="small" />
  111. </div>
  112. )
  113. }}
  114. >
  115. <div class={styles['bar-btn']} style={{ height: '32px' }}>
  116. <SvgIcon
  117. name="bar-arrow-down"
  118. style={{
  119. width: '18px'
  120. }}
  121. />
  122. </div>
  123. </ElDropdown>
  124. </div>
  125. <span class={styles['bar-btn-text']}>音量调节</span>
  126. </div>
  127. <div class={styles['bar-btn']} onClick={RuntimeUtils.shareScreenVideo}>
  128. <div class={styles.btnInner}>
  129. <SvgIcon
  130. name="bar-screen-share"
  131. style={{
  132. width: '22px',
  133. cursor: 'pointer'
  134. }}
  135. />
  136. </div>
  137. <span class={styles['bar-btn-text']}>屏幕共享</span>
  138. </div>
  139. {/* <div class={styles['bar-btn']} >
  140. <div class={styles.btnInner}>
  141. <SvgIcon
  142. name="bar-beauty"
  143. style={{
  144. width: '22px',
  145. cursor: 'pointer'
  146. }}
  147. />
  148. </div>
  149. <span class={styles['bar-btn-text']}>美颜</span>
  150. </div> */}
  151. <div class={styles['bar-btn']}>
  152. <div class={styles.btnInner}>
  153. <SvgIcon
  154. onClick={() => {
  155. const needPublish = runtime.videoStatus === 'liveing'
  156. state.barStatus.microphone = !state.barStatus.microphone
  157. if (!state.barStatus.microphone) {
  158. RuntimeUtils.openDevice('microphone', needPublish)
  159. } else {
  160. RuntimeUtils.closeDevice('microphone', needPublish)
  161. }
  162. }}
  163. name={this.isMicrophoneDisabled ? 'bar-mike-disabled' : 'bar-mike'}
  164. style={{
  165. width: '22px',
  166. cursor: 'pointer'
  167. }}
  168. />
  169. <ElDropdown
  170. placement="top-start"
  171. // @ts-ignore
  172. disabled={runtime.microphones.length === 0}
  173. popper-options={{ boundariesElement: '#action-bar', gpuAcceleration: false }}
  174. onCommand={RuntimeUtils.setSelectMicrophone}
  175. // @ts-ignore
  176. vSlots={{
  177. dropdown: () => (
  178. <ElDropdownMenu>
  179. {runtime.microphones.map(item => (<ElDropdownItem disabled={item === runtime.selectedMicrophone} command={item}>{item.label}</ElDropdownItem>))}
  180. </ElDropdownMenu>
  181. )
  182. }}
  183. >
  184. <div class={styles['bar-btn']} style={{ height: '32px' }}>
  185. <SvgIcon
  186. name="bar-arrow-down"
  187. style={{
  188. width: '18px'
  189. }}
  190. />
  191. </div>
  192. </ElDropdown>
  193. </div>
  194. <span class={styles['bar-btn-text']}>麦克风</span>
  195. </div>
  196. </div>
  197. <div style={{ display: 'flex' }} onClick={this.startShare}>
  198. <div class={styles['bar-btn']} >
  199. <div class={styles.btnInner}>
  200. <SvgIcon
  201. name="bar-share"
  202. style={{
  203. width: '22px',
  204. cursor: 'pointer'
  205. }}
  206. />
  207. </div>
  208. <span class={styles['bar-btn-text']} >分享</span>
  209. </div>
  210. </div>
  211. {/* <ElButton onClick={RuntimeUtils.shareScreenVideo}>屏幕共享</ElButton> */}
  212. <ElDialog width="510px"
  213. destroy-on-close
  214. append-to-body modelValue={state.shareVisiable} title="分享" before-close={() => { state.shareVisiable = false }}>
  215. <Share onClose={()=>state.shareVisiable = false}/>
  216. </ElDialog>
  217. </div>
  218. )
  219. }
  220. })