diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 540009e..cadb722 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -47,6 +47,45 @@ const connection = new Push({ // 是否正在录音 const recordFalg = ref(0) +/** + * APP端命令目录 + * start 开始录音 + * end 录音完成 + * re 重新录制 + * clear 清空对话 + * pause 暂停播放 + * play 继续播放 + * stop 停止播放 + * re-play 重新播放 + */ +const runOrder = (e)=>{ + switch(e){ + case 'start': startOrder();break; + case 'end':endOrder();break; + } +} + +const startOrder = ()=>{ + if (recordFalg.value == 0) { + RecordXunfei() + recordFalg.value = 1 + nowStatus.value = 'record' + }else { + console.log('无效指令'); + } +} + +const endOrder = ()=>{ + if(recordFalg.value==1){ + RecordXunfei() + recordFalg.value = 0 + nowStatus.value = 'loding' + handleSubmit() + }else { + console.log('无效指令'); + } +} + // 假设用户uid为1 const uid = 1 // 浏览器监听user-1频道的消息,也就是用户uid为1的用户消息 @@ -56,24 +95,7 @@ console.log(user_channel) user_channel.on('message', (data: any) => { // data里是消息内容 console.log('收到命令', data) - return null - if (messageRef.value?.length > 0) - messageRef.value[messageRef.value.length - 1].stopPlay() - if (socket?.readyState < 2) - socket.close() - - // return - if (recordFalg.value == 0) { - RecordXunfei() - recordFalg.value = 1 - nowStatus.value = 'record' - } - else { - RecordXunfei() - recordFalg.value = 0 - nowStatus.value = 'loding' - handleSubmit() - } + runOrder(data.content) }) const changeRecord = () => {