1 |
- import{d as ut,k as m,r as X,e as J,w as Y,o as Ft,q as Lt,b as kt,X as x,a6 as U,a9 as r,f as u,Z as n,_ as h,u as a,E as v,aa as Z,F as Q,a2 as D}from"./vue-fae2b924.js";import{aa as tt,aV as V,aI as Rt,aH as et,U as f,a8 as st,bG as ot,bJ as lt,G as d,V as St}from"./radical-e583b742.js";import{u as Tt}from"./global-f6e5c3a3.js";import{p as wt,o as At}from"./index-7a259168.js";const P=wt({requestOptions:{apiUrl:()=>At("stress")}});function It(s,o,c){return P.post({url:`/push/${s}/${o}`,data:c})}function Mt(s,o,c){return P.post({url:`/pull/${s}/${o}`,data:c})}function Vt(){return P.get({url:"/count"})}function qt(){return P.post({url:"/stop/push"})}function Ht(){return P.post({url:"/stop/pull"})}const H="stress_push_urls",W="stress_pull_urls",Wt=10,q=s=>{try{const o=s==="push"?H:W,c=localStorage.getItem(o);return c?JSON.parse(c):[]}catch(o){return console.error("获取缓存地址失败:",o),[]}},k=(s,o)=>{if(!s||!s.trim())return!1;try{const c=o==="push"?H:W,g=q(o).filter(b=>b!==s),C=[s,...g].slice(0,Wt);return localStorage.setItem(c,JSON.stringify(C)),!0}catch(c){return console.error("保存缓存地址失败:",c),!1}},rt=s=>{try{const o=s==="push"?H:W;return localStorage.removeItem(o),!0}catch(o){return console.error("清除缓存地址失败:",o),!1}},R=s=>{if(!s)return"";const o=s.toLowerCase();return o.startsWith("rtmp://")||o.startsWith("rtmps://")?"rtmp":o.startsWith("rtsp://")||o.startsWith("rtsps://")?"rtsp":o.startsWith("srt://")?"srt":o.startsWith("http://")||o.startsWith("https://")?o.includes(".flv")?"http-flv":o.includes(".mp4")?"http-mp4":"http-flv":""},jt=s=>({type:"object",properties:{layout:{type:"void","x-component":"FormLayout","x-component-props":{layout:"horizontal",labelCol:6,wrapperCol:18},properties:{streamPath:{type:"string",title:"流路径","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:"请输入流路径,如: live/test",allowClear:!0},"x-validator":[{required:!0,message:"请输入流路径"}],default:(s==null?void 0:s.streamPath)||""},protocol:{type:"string",title:"推流协议","x-decorator":"FormItem","x-component":"Select","x-component-props":{placeholder:"请选择推流协议",style:{minWidth:"200px"},options:[{label:"RTMP",value:"rtmp"},{label:"RTSP",value:"rtsp"},{label:"SRT",value:"srt"}]},"x-validator":[{required:!0,message:"请选择推流协议"}],default:(s==null?void 0:s.protocol)||"rtmp"},remoteURL:{type:"string",title:"目标地址","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:"请输入推流目标地址,如: rtmp://localhost:1935/live",allowClear:!0},"x-validator":[{required:!0,message:"请输入推流目标地址"},{pattern:/^(rtmp|rtmps|rtsp|rtsps|srt):\/\/.+/,message:"请输入有效的推流地址"}],default:(s==null?void 0:s.remoteURL)||""}}}}}),zt=s=>({type:"object",properties:{layout:{type:"void","x-component":"FormLayout","x-component-props":{layout:"horizontal",labelCol:6,wrapperCol:18},properties:{protocol:{type:"string",title:"拉流协议","x-decorator":"FormItem","x-component":"Select","x-component-props":{placeholder:"请选择拉流协议",style:{minWidth:"200px"},options:[{label:"RTMP",value:"rtmp"},{label:"RTSP",value:"rtsp"},{label:"SRT",value:"srt"},{label:"HTTP-FLV",value:"http-flv"},{label:"HTTP-MP4",value:"http-mp4"}]},"x-validator":[{required:!0,message:"请选择拉流协议"}],default:(s==null?void 0:s.protocol)||"rtmp"},remoteURL:{type:"string",title:"源地址","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:"请输入拉流源地址,如: rtmp://localhost:1935/live/test",allowClear:!0},"x-validator":[{required:!0,message:"请输入拉流源地址"},{pattern:/^(rtmp|rtmps|rtsp|rtsps|srt|http|https):\/\/.+/,message:"请输入有效的拉流地址"}],default:(s==null?void 0:s.remoteURL)||""},testMode:{type:"number",title:"测试模式","x-decorator":"FormItem","x-component":"Radio.Group","x-component-props":{options:[{label:"拉流并发布",value:0},{label:"仅拉流(不发布)",value:1}]},default:(s==null?void 0:s.testMode)||0}}}}}),Et={class:"stress-page"},$t={class:"status-cards"},Nt={class:"status-content"},Bt={class:"status-number"},Kt={class:"status-content"},Gt={class:"status-number"},Ot={key:0,class:"url-suggestions"},Xt={class:"url-suggestions-header"},Jt={class:"slider-container"},Yt={class:"slider-wrapper"},Zt={class:"slider-value"},Qt={class:"quick-buttons"},Dt={class:"action-buttons"},te={key:0,class:"url-suggestions"},ee={class:"url-suggestions-header"},se={class:"slider-container"},oe={class:"slider-wrapper"},le={class:"slider-value"},re={class:"quick-buttons"},ue={class:"action-buttons"},ae=ut({name:"StressDetail"}),ne=ut({...ae,setup(s){const o=m(0),c=m(0),S=m("push"),g=m([]),C=m([]),b=m(!1),T=m(!1),w=m(!1),A=m(!1),i=X({pushCount:1,streamPath:"",protocol:"rtmp",remoteURL:""}),p=X({pullCount:1,protocol:"rtmp",remoteURL:"",testMode:0}),F=1e3,L=1e4,j={0:"0",100:"100",200:"200",500:"500",1e3:"1000"},z=[1,10,100,1e3,5e3],E=[...z.map(e=>-e).reverse(),...z],$=J({get:()=>Math.min(i.pushCount,F),set:e=>{i.pushCount=e}}),N=J({get:()=>Math.min(p.pullCount,F),set:e=>{p.pullCount=e}}),{FormilyForm:at,submit:nt,form:B}=tt({schema:jt(i)}),{FormilyForm:it,submit:pt,form:K}=tt({schema:zt(p)});let I=null;Y(()=>i.remoteURL,e=>{if(e){const t=R(e);t&&t!==i.protocol&&(i.protocol=t),I&&clearTimeout(I),I=setTimeout(()=>{e.trim()&&/^(rtmp|rtmps|rtsp|rtsps|srt):\/\/.+/.test(e)&&(k(e.trim(),"push"),y())},1e3)}});let M=null;Y(()=>p.remoteURL,e=>{if(e){const t=R(e);t&&t!==p.protocol&&(p.protocol=t),M&&clearTimeout(M),M=setTimeout(()=>{e.trim()&&/^(rtmp|rtmps|rtsp|rtsps|srt|http|https):\/\/.+/.test(e)&&(k(e.trim(),"pull"),y())},1e3)}});async function _(){try{const e=await Vt();o.value=e.pushCount||0,c.value=e.pullCount||0}catch(e){console.error("获取推拉流数量失败:",e)}}const{pause:ct,resume:dt}=Tt(_);function y(){g.value=q("push"),C.value=q("pull")}function mt(){g.value.length>0&&!i.remoteURL.trim()&&G(g.value[0]),C.value.length>0&&!p.remoteURL.trim()&&O(C.value[0])}function ht(){rt("push")?(y(),d.success("推流历史记录已清除")):d.error("清除推流历史记录失败")}function vt(){rt("pull")?(y(),d.success("拉流历史记录已清除")):d.error("清除拉流历史记录失败")}function G(e){i.remoteURL=e,B.setValues({remoteURL:e});const t=R(e);t&&t!==i.protocol&&(i.protocol=t,B.setValues({protocol:t}))}function O(e){p.remoteURL=e,K.setValues({remoteURL:e});const t=R(e);t&&t!==p.protocol&&(p.protocol=t,K.setValues({protocol:t}))}function ft(e){const t=i.pushCount+e;t>=0&&t<=L&&(i.pushCount=t)}function gt(e){const t=i.pushCount+e;return t>=0&&t<=L}function Ct(e){const t=p.pullCount+e;t>=0&&t<=L&&(p.pullCount=t)}function yt(e){const t=p.pullCount+e;return t>=0&&t<=L}async function _t(){var e;try{b.value=!0;const t=await nt();if(!t)return;(e=t.remoteURL)!=null&&e.trim()&&(k(t.remoteURL.trim(),"push"),y()),await It(t.protocol,i.pushCount,{streamPath:t.streamPath,remoteURL:t.remoteURL}),d.success("推流测试已开始"),_()}catch(t){d.error("启动推流失败: "+t.message)}finally{b.value=!1}}async function bt(){var e;try{T.value=!0;const t=await pt();if(!t)return;(e=t.remoteURL)!=null&&e.trim()&&(k(t.remoteURL.trim(),"pull"),y()),await Mt(t.protocol,p.pullCount,{remoteURL:t.remoteURL,testMode:t.testMode}),d.success("拉流测试已开始"),_()}catch(t){d.error("启动拉流失败: "+t.message)}finally{T.value=!1}}async function xt(){try{w.value=!0,await qt(),d.success("推流已停止"),_()}catch(e){d.error("停止推流失败: "+e.message)}finally{w.value=!1}}async function Ut(){try{A.value=!0,await Ht(),d.success("拉流已停止"),_()}catch(e){d.error("停止拉流失败: "+e.message)}finally{A.value=!1}}return Ft(async()=>{_(),dt(),y(),await Lt(),mt()}),kt(()=>{ct()}),(e,t)=>(x(),U("div",Et,[r("div",$t,[u(a(V),{title:"推流状态",class:"status-card push-card"},{default:n(()=>[r("div",Nt,[r("div",Bt,h(o.value),1),t[3]||(t[3]=r("div",{class:"status-label"},"正在推流",-1))])]),_:1}),u(a(V),{title:"拉流状态",class:"status-card pull-card"},{default:n(()=>[r("div",Kt,[r("div",Gt,h(c.value),1),t[4]||(t[4]=r("div",{class:"status-label"},"正在拉流",-1))])]),_:1})]),u(a(V),{title:"压力测试控制",class:"control-panel"},{default:n(()=>[u(a(Rt),{activeKey:S.value,"onUpdate:activeKey":t[2]||(t[2]=l=>S.value=l)},{default:n(()=>[u(a(et),{key:"push",tab:"推流测试"},{default:n(()=>[u(a(at),{ref:"pushFormRef"},null,512),g.value.length>0?(x(),U("div",Ot,[r("div",Xt,[t[6]||(t[6]=r("label",null,"历史地址:",-1)),u(a(f),{size:"small",onClick:ht,danger:""},{default:n(()=>t[5]||(t[5]=[v(" 清除历史 ")])),_:1})]),u(a(st),{placeholder:"选择历史地址",style:{width:"100%"},onChange:G,options:g.value.map(l=>({label:l,value:l})),allowClear:""},null,8,["options"])])):Z("",!0),r("div",Jt,[t[7]||(t[7]=r("label",null,"推流数量:",-1)),r("div",Yt,[u(a(ot),{value:$.value,"onUpdate:value":t[0]||(t[0]=l=>$.value=l),min:0,max:F,marks:j,"tooltip-formatter":l=>`${l} 路`},null,8,["value","tooltip-formatter"])]),r("span",Zt,h(i.pushCount)+" 路",1)]),r("div",Qt,[t[8]||(t[8]=r("span",{class:"button-group-label"},"快速调整:",-1)),u(a(lt),null,{default:n(()=>[(x(),U(Q,null,D(E,l=>u(a(f),{key:l,onClick:Pt=>ft(l),disabled:!gt(l)},{default:n(()=>[v(h(l>0?"+":"")+h(l),1)]),_:2},1032,["onClick","disabled"])),64))]),_:1})]),r("div",Dt,[u(a(f),{type:"primary",size:"large",loading:b.value,onClick:_t},{default:n(()=>t[9]||(t[9]=[v(" 开始推流 ")])),_:1},8,["loading"]),u(a(f),{danger:"",size:"large",loading:w.value,onClick:xt},{default:n(()=>t[10]||(t[10]=[v(" 停止推流 ")])),_:1},8,["loading"])])]),_:1}),u(a(et),{key:"pull",tab:"拉流测试"},{default:n(()=>[u(a(it),{ref:"pullFormRef"},null,512),C.value.length>0?(x(),U("div",te,[r("div",ee,[t[12]||(t[12]=r("label",null,"历史地址:",-1)),u(a(f),{size:"small",onClick:vt,danger:""},{default:n(()=>t[11]||(t[11]=[v(" 清除历史 ")])),_:1})]),u(a(st),{placeholder:"选择历史地址",style:{width:"100%"},onChange:O,options:C.value.map(l=>({label:l,value:l})),allowClear:""},null,8,["options"])])):Z("",!0),r("div",se,[t[13]||(t[13]=r("label",null,"拉流数量:",-1)),r("div",oe,[u(a(ot),{value:N.value,"onUpdate:value":t[1]||(t[1]=l=>N.value=l),min:0,max:F,marks:j,"tooltip-formatter":l=>`${l} 路`},null,8,["value","tooltip-formatter"])]),r("span",le,h(p.pullCount)+" 路",1)]),r("div",re,[t[14]||(t[14]=r("span",{class:"button-group-label"},"快速调整:",-1)),u(a(lt),null,{default:n(()=>[(x(),U(Q,null,D(E,l=>u(a(f),{key:l,onClick:Pt=>Ct(l),disabled:!yt(l)},{default:n(()=>[v(h(l>0?"+":"")+h(l),1)]),_:2},1032,["onClick","disabled"])),64))]),_:1})]),r("div",ue,[u(a(f),{type:"primary",size:"large",loading:T.value,onClick:bt},{default:n(()=>t[15]||(t[15]=[v(" 开始拉流 ")])),_:1},8,["loading"]),u(a(f),{danger:"",size:"large",loading:A.value,onClick:Ut},{default:n(()=>t[16]||(t[16]=[v(" 停止拉流 ")])),_:1},8,["loading"])])]),_:1})]),_:1},8,["activeKey"])]),_:1})]))}});const me=St(ne,[["__scopeId","data-v-bd469cff"]]);export{me as default};
|