UNPKG

@tencentcloud/ai-desk-customer-wechat

Version:

AI Desk customer UIKit for wechat mini program

3 lines (2 loc) 2.4 kB
"use strict";const o=require("../../../../../common/vendor.js"),E=require("../../../../adapter-vue.js"),g=require("../../../../@aidesk/uikit-engine/index.js"),_=require("../../../common/Toast/index-uniapp.js"),d=require("../../../../../common/assets.js"),v=require("../../../../utils/env.js");Math||M();const M=()=>"../../../common/Icon.js",j=o.defineComponent({__name:"message-audio-uniapp",props:{broadcastNewAudioSrc:{},messageItem:{default:()=>({})},content:{default:()=>({})}},emits:["getGlobalAudioContext","setAudioPlayed"],setup(x,{emit:C}){const l=C,n=x,{onUnmounted:h,ref:f,watch:y,computed:k}=E.vue,m=[d.audioIcon1,d.audioIcon2,d.audioIcon3],u=f(2),a=new Map,t=f(!1),p=k(()=>m[u.value]);let s=null;h(()=>{var r;const e=i();t.value&&c(),(r=e==null?void 0:e.destroy)==null||r.call(e),a.delete("audio")}),y(()=>n.broadcastNewAudioSrc,e=>{e!==n.content.url&&t.value&&(c(),t.value=!1)});function T(){if(l("getGlobalAudioContext",a,{newAudioSrc:n.content.url}),n.messageItem.hasRiskContent||!n.content.url&&!n.messageItem.payload.remoteAudioUrl){_.Toast({message:g.jt.t("TUIChat.语音播放失败")});return}i()||(a.set("audio",o.index.createInnerAudioContext()),o.index.setInnerAudioOption({obeyMuteSwitch:!1}),U()),w()}function w(){t.value?c():S()}function U(){const e=i();e&&(e.src=n.content.url||n.messageItem.payload.remoteAudioUrl,t.value=!1,e.onPlay(b),e.onStop(q),e.onEnded(P),e.onError(D))}function S(){const e=i();e&&(e.play(),n.messageItem.flow==="in"&&l("setAudioPlayed",n.messageItem.ID))}function c(){const e=i();if(e)try{e.stop()}catch{}}function I(){A(),u.value=2}function b(){t.value=!0,s||(s=setInterval(()=>{u.value=(u.value+1)%m.length},500))}function q(){t.value=!1,A()}function P(){t.value=!1,I()}function D(){_.Toast({message:g.jt.t("TUIChat.语音播放失败")}),t.value=!1,I()}function i(){return a.get("audio")}function A(){clearInterval(s),s=null}return(e,r)=>o.e$1({a:o.unref(v.isTikTok)},o.unref(v.isTikTok)?{b:o.unref(t)?1:"",c:o.unref(p)}:{d:o.unref(t)?1:"",e:o.p({width:"16px",height:"16px",file:o.unref(p)})},{f:o.t(n.content.second||1),g:`${n.content.second*2+20}px`,h:n.messageItem.flow==="out"?1:"",i:o.o(T)})}}),G=o._export_sfc(j,[["__scopeId","data-v-46d96baa"]]);wx.createComponent(G); //# sourceMappingURL=../../../../../../.sourcemap/mp-weixin/ai-desk-customer-uniapp/components/CustomerServiceChat/message-list/message-elements/message-audio-uniapp.js.map