|
@@ -1,52 +1,43 @@
|
|
|
-import { defineComponent } from 'vue'
|
|
|
+import { defineComponent, reactive } from 'vue'
|
|
|
import { ElButton, ElDropdown, ElDropdownMenu, ElDropdownItem, ElSlider, ElDialog, ElIcon } from 'element-plus'
|
|
|
import runtime, * as RuntimeUtils from './runtime'
|
|
|
import styles from './action-bar.module.less'
|
|
|
import Share from './share'
|
|
|
+
|
|
|
+export const state = reactive({
|
|
|
+ volume: 30,
|
|
|
+ barStatus: {
|
|
|
+ camera: false, // 摄像头
|
|
|
+ volume: false, // 声音调节
|
|
|
+ microphone: false, // 麦克风
|
|
|
+ screen: false, // 共享屏幕
|
|
|
+ share: false, // 分享
|
|
|
+ },
|
|
|
+ shareVisiable: false
|
|
|
+})
|
|
|
+
|
|
|
export default defineComponent({
|
|
|
name: 'LiveBroadcast-ActionBar',
|
|
|
- data() {
|
|
|
- return {
|
|
|
- volume: 30,
|
|
|
- barStatus: {
|
|
|
- camera: false, // 摄像头
|
|
|
- volume: false, // 声音调节
|
|
|
- microphone: false, // 麦克风
|
|
|
- screen: false, // 共享屏幕
|
|
|
- share: false, // 分享
|
|
|
- },
|
|
|
- shareVisiable: false
|
|
|
- }
|
|
|
- },
|
|
|
computed: {
|
|
|
isCameraDisabled() {
|
|
|
- // @ts-ignore
|
|
|
- return this.barStatus.camera && runtime.deviceStatus.camera !== 'denied' && runtime.cameras.length
|
|
|
+ return state.barStatus.camera && runtime.deviceStatus.camera !== 'denied' && runtime.cameras.length
|
|
|
},
|
|
|
isMicrophoneDisabled() {
|
|
|
- // @ts-ignore
|
|
|
- const isDisabled = this.barStatus.microphone && runtime.deviceStatus.microphone !== 'denied' && runtime.microphones.length
|
|
|
+ const isDisabled = state.barStatus.microphone && runtime.deviceStatus.microphone !== 'denied' && runtime.microphones.length
|
|
|
return isDisabled
|
|
|
},
|
|
|
isVolumeDisabled() {
|
|
|
- // @ts-ignore
|
|
|
- return this.barStatus.volume && this.volume === 0
|
|
|
+ return state.volume === 0
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
startShare() {
|
|
|
console.log('调用')
|
|
|
- this.shareVisiable = true
|
|
|
+ state.shareVisiable = true
|
|
|
},
|
|
|
volumeChange(value: number) {
|
|
|
- this.volume = value
|
|
|
- console.log(runtime.activeTracks)
|
|
|
+ state.volume = value
|
|
|
RuntimeUtils.setVolume(value)
|
|
|
- // @ts-ignore
|
|
|
- if (runtime.activeTracks.microphone && runtime.activeTracks.microphone._element) {
|
|
|
- // @ts-ignore
|
|
|
- runtime.activeTracks.microphone._element.volume = value / 100
|
|
|
- }
|
|
|
}
|
|
|
},
|
|
|
render() {
|
|
@@ -57,7 +48,7 @@ export default defineComponent({
|
|
|
<div class={styles.btnInner}>
|
|
|
<SvgIcon
|
|
|
onClick={() => {
|
|
|
- this.barStatus.camera = !this.barStatus.camera
|
|
|
+ state.barStatus.camera = !state.barStatus.camera
|
|
|
RuntimeUtils.toggleDevice('camera')
|
|
|
}}
|
|
|
name={this.isCameraDisabled ? 'bar-camera-disabled' : 'bar-camera'}
|
|
@@ -96,11 +87,11 @@ export default defineComponent({
|
|
|
<div class={styles.btnInner}>
|
|
|
<SvgIcon
|
|
|
onClick={() => {
|
|
|
- this.barStatus.volume = !this.barStatus.volume;
|
|
|
- if(!this.barStatus.volume) {
|
|
|
+ state.barStatus.volume = !state.barStatus.volume;
|
|
|
+ if(!state.barStatus.volume) {
|
|
|
sessionStorage.getItem('volume') && this.volumeChange(Number(sessionStorage.getItem('volume')))
|
|
|
} else {
|
|
|
- sessionStorage.setItem('volume', this.volume.toString())
|
|
|
+ sessionStorage.setItem('volume', state.volume.toString())
|
|
|
this.volumeChange(0)
|
|
|
}
|
|
|
}}
|
|
@@ -118,7 +109,7 @@ export default defineComponent({
|
|
|
dropdown: () => (
|
|
|
<div class={styles.volumeSlider}>
|
|
|
<SvgIcon class={styles.volumeIcon} name="message-voice" color="#fff" />
|
|
|
- <ElSlider modelValue={this.volume} onInput={this.volumeChange} size="small" />
|
|
|
+ <ElSlider modelValue={state.volume} onInput={this.volumeChange} size="small" />
|
|
|
</div>
|
|
|
)
|
|
|
}}
|
|
@@ -166,8 +157,8 @@ export default defineComponent({
|
|
|
<SvgIcon
|
|
|
onClick={() => {
|
|
|
const needPublish = runtime.videoStatus === 'liveing'
|
|
|
- this.barStatus.microphone = !this.barStatus.microphone
|
|
|
- if (!this.barStatus.microphone) {
|
|
|
+ state.barStatus.microphone = !state.barStatus.microphone
|
|
|
+ if (!state.barStatus.microphone) {
|
|
|
RuntimeUtils.openDevice('microphone', needPublish)
|
|
|
} else {
|
|
|
RuntimeUtils.closeDevice('microphone', needPublish)
|
|
@@ -225,8 +216,8 @@ export default defineComponent({
|
|
|
{/* <ElButton onClick={RuntimeUtils.shareScreenVideo}>屏幕共享</ElButton> */}
|
|
|
<ElDialog width="510px"
|
|
|
destroy-on-close
|
|
|
- append-to-body modelValue={this.shareVisiable} title="分享" before-close={() => { this.shareVisiable = false }}>
|
|
|
- <Share onClose={()=>this.shareVisiable = false}/>
|
|
|
+ append-to-body modelValue={state.shareVisiable} title="分享" before-close={() => { state.shareVisiable = false }}>
|
|
|
+ <Share onClose={()=>state.shareVisiable = false}/>
|
|
|
</ElDialog>
|
|
|
</div>
|
|
|
)
|