import{_ as s,a3 as e,bj as t,ar as o,aa as n,as as a,at as c,bk as l,G as i,bl as d,bm as r,bn as g,bo as h,b as u,d as m,p,w as f,H as b,i as k,o as w,f as _,k as C,t as y,aw as M,ax as v,R as x}from"./index-2PZN6pGH.js";let I=e().platform;const j=s({data:()=>({connected:!1,connecting:!1,msg:!1,roomId:""}),computed:{showMsg(){return this.connected?this.msg?"收到消息："+this.msg:"等待接收消息":"尚未连接"}},onUnload(){t(),o()},methods:{connect(){if(this.connected||this.connecting)return n({content:"正在连接或者已经连接，请勿重复连接",showCancel:!1}),!1;this.connecting=!0,a({title:"连接中..."}),c({url:"wss://echo.websocket.org",data:()=>({msg:"Hello"}),success(s){},fail(s){}}),l((s=>{this.connecting=!1,this.connected=!0,o(),i({icon:"none",title:"连接成功"}),console.log("onOpen",s)})),d((s=>{this.connecting=!1,this.connected=!1,o(),n({content:"连接失败，可能是websocket服务不可用，请稍后再试",showCancel:!1}),console.log("onError",s)})),r((s=>{this.msg=s.data,console.log("onMessage",s)})),g((s=>{this.connected=!1,this.startRecive=!1,this.msg=!1,console.log("onClose",s)}))},send(){h({data:"from "+I+" : "+parseInt(1e4*Math.random()).toString(),success(s){console.log(s)},fail(s){console.log(s)}})},close(){t()}}},[["render",function(s,e,t,o,n,a){const c=u(m("page-head"),b),l=k,i=x;return w(),p(l,null,{default:f((()=>[_(c,{title:"websocket通讯示例"}),_(l,{class:"uni-padding-wrap"},{default:f((()=>[_(l,{class:"uni-btn-v"},{default:f((()=>[_(l,{class:"websocket-msg"},{default:f((()=>[C(y(a.showMsg),1)])),_:1}),_(i,{type:"primary",onClick:a.connect},{default:f((()=>[C("连接websocket服务")])),_:1},8,["onClick"]),M(_(i,{type:"primary",onClick:a.send},{default:f((()=>[C("发送一条消息")])),_:1},8,["onClick"]),[[v,n.connected]]),_(i,{type:"primary",onClick:a.close},{default:f((()=>[C("断开websocket服务")])),_:1},8,["onClick"]),_(l,{class:"websocket-tips"},{default:f((()=>[C("发送消息后会收到一条服务器返回的消息（与发送的消息内容一致）")])),_:1})])),_:1})])),_:1})])),_:1})}],["__scopeId","data-v-32176b3a"]]);export{j as default};
