Files
archy-demo/web-dist/assets/Mesh-CPUFszgS.js

2 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{d as q,w as J,o as W,O as X,c as o,a as e,J as b,D as l,E as d,G as i,f as u,F as g,P as M,g as Y,H as Q,I as Z,b as ee,r as v,j as w,X as D,m as se,C as te,q as n,t as ae}from"./index-DnbYEqLr.js";import{u as ne}from"./mesh-DgF5cqYW.js";import{u as oe}from"./transport-B_E2RH1i.js";const le={class:"mesh-view"},de={class:"mesh-header"},ce={class:"mesh-header-left"},ie={class:"mesh-subtitle"},re={key:0,class:"mesh-subtitle-badge"},he={key:0,class:"mesh-error"},ue={class:"mesh-columns"},_e={class:"mesh-left"},pe={class:"glass-card mesh-status-card"},ve={class:"mesh-status-header"},me={key:0,class:"mesh-loading"},ye={key:1,class:"mesh-status-grid"},be={class:"mesh-stat"},fe={class:"mesh-stat"},ke={class:"mesh-stat-value"},ge={class:"mesh-stat"},we={class:"mesh-stat-value"},Ce={class:"mesh-stat"},xe={class:"mesh-stat-value"},Me={class:"mesh-stat"},Se={class:"mesh-stat-value"},Ae={class:"mesh-stat"},Ee={class:"mesh-stat-value"},Te={key:2,class:"mesh-detected-devices"},De={class:"mesh-device-path"},Ne={key:0,class:"mesh-offgrid-banner"},Oe={class:"mesh-actions"},Be=["disabled"],Pe=["disabled"],Ie=["disabled"],Le={class:"glass-card mesh-peers-card"},Fe={class:"mesh-section-title"},Ge={class:"mesh-peer-count"},Re={key:0,class:"mesh-empty"},$e={key:1,class:"mesh-peer-list"},Ve=["onClick"],ze={class:"mesh-peer-info"},Ue={class:"mesh-peer-name"},Ke={key:0,class:"mesh-peer-archy-badge"},je={class:"mesh-peer-sub"},He={key:0,class:"mesh-unread-badge"},qe={class:"mesh-peer-signal"},Je={class:"mesh-signal-bars"},We={class:"mesh-right"},Xe={class:"glass-card mesh-chat-card"},Ye={key:0,class:"mesh-chat-empty"},Qe={class:"mesh-chat-header"},Ze={class:"mesh-chat-header-info"},es={class:"mesh-chat-header-name"},ss={key:0,class:"mesh-peer-archy-badge"},ts={key:1,class:"mesh-peer-channel-badge"},as={class:"mesh-chat-header-sub"},ns={class:"mesh-chat-header-status"},os=["title"],ls={key:1,class:"mesh-chat-header-time"},ds={key:0,class:"mesh-chat-no-messages"},cs={key:0,class:"mesh-typed-invoice"},is={class:"mesh-typed-invoice-header"},rs={key:0,class:"mesh-typed-paid"},hs={class:"mesh-typed-invoice-amount"},us={key:0,class:"mesh-typed-invoice-memo"},_s={class:"mesh-typed-invoice-bolt11"},ps={class:"mesh-typed-alert-header"},vs={class:"mesh-typed-icon"},ms={class:"mesh-typed-label"},ys={key:0,class:"mesh-typed-signed"},bs={class:"mesh-typed-alert-message"},fs=["href"],ks={key:2,class:"mesh-typed-coordinate"},gs={class:"mesh-typed-coordinate-value"},ws={key:0,class:"mesh-typed-coordinate-label"},Cs=["href"],xs={key:3,class:"mesh-typed-block"},Ms={class:"mesh-typed-label"},Ss={key:4,class:"mesh-chat-bubble-text"},As={class:"mesh-chat-bubble-meta"},Es={key:0,class:"mesh-chat-e2e"},Ts={key:1,class:"mesh-chat-ack"},Ds={class:"mesh-chat-bubble-time"},Ns={class:"mesh-chat-compose"},Os={key:0,class:"mesh-chat-send-error"},Bs={class:"mesh-chat-compose-row"},Ps=["onKeydown"],Is=["disabled"],Ls={class:"mesh-chat-compose-meta"},Fs=q({__name:"Mesh",setup(Gs){const a=ne(),f=oe(),r=v(null),h=v(null),p=v(""),k=v(""),C=v(!1),S=v(!1),x=v(null);let A=null;const I={index:0,name:"Public"},E=v(!1),m=v(null);J(()=>r.value,async c=>{if(c)try{m.value=await a.getSessionStatus(c.contact_id)}catch{m.value=null}else m.value=null});async function L(){E.value=!0;try{await f.setMeshOnly(!f.meshOnly)}finally{E.value=!1}}W(async()=>{await Promise.all([a.refreshAll(),f.fetchStatus()]),A=setInterval(()=>{a.fetchStatus(),a.fetchPeers(),a.fetchMessages()},5e3)}),X(()=>{A&&clearInterval(A)});const F=w(()=>h.value?h.value.name:r.value?r.value.advert_name:""),G=w(()=>h.value?"Mesh channel":r.value?P(r.value.pubkey_hex):""),R=w(()=>!!r.value||!!h.value),N=w(()=>{if(h.value){const c=-(h.value.index+1);return a.messages.filter(t=>t.peer_contact_id===c)}if(r.value){const c=r.value.contact_id;return a.messages.filter(t=>t.peer_contact_id===c)}return[]});function y(c){return c.advert_name.startsWith("Archy-")}const $=w(()=>[...a.peers].sort((c,t)=>{const s=y(c)?0:1,_=y(t)?0:1;return s!==_?s-_:c.advert_name.localeCompare(t.advert_name)}));function V(c){r.value=c,h.value=null,k.value="",p.value="",a.markChatRead(c.contact_id),D(()=>T())}function z(c){h.value=c,r.value=null,k.value="",p.value="",D(()=>T())}function U(){r.value=null,h.value=null,a.clearViewingChat()}async function O(){if(!(!r.value||!p.value.trim())){k.value="";try{await a.sendMessage(r.value.contact_id,p.value),p.value="",D(()=>T())}catch(c){k.value=c instanceof Error?c.message:"Send failed"}}}function T(){x.value&&(x.value.scrollTop=x.value.scrollHeight)}async function K(){C.value=!0;try{await a.broadcastIdentity()}finally{C.value=!1}}async function j(){S.value=!0;try{const c=!(a.status?.enabled??!1);await a.configure({enabled:c})}finally{S.value=!1}}function H(c){return c===null?0:c>-60?4:c>-75?3:c>-90?2:1}function B(c){const t=Date.now()-new Date(c).getTime(),s=Math.floor(t/1e3);if(s<60)return`${s}s ago`;const _=Math.floor(s/60);return _<60?`${_}m ago`:`${Math.floor(_/60)}h ago`}function P(c){return c?c.slice(0,8)+"..."+c.slice(-6):""}return(c,t)=>(n(),o("div",le,[e("div",de,[e("div",ce,[t[3]||(t[3]=e("h1",{class:"mesh-title"},"Mesh Network",-1)),e("p",ie,[b(l(d(a).status?.peer_count??0)+" peer"+l((d(a).status?.peer_count??0)!==1?"s":"")+" ",1),d(a).status?.device_connected?(n(),o("span",re,"Live")):i("",!0)])]),t[4]||(t[4]=e("a",{href:"https://flasher.meshcore.co.uk/",target:"_blank",rel:"noopener noreferrer",class:"glass-button mesh-flasher-btn"},[b(" Flash Meshcore "),e("span",{class:"mesh-flasher-sep"},"|"),b(" Choose Companion USB ")],-1))]),d(a).error?(n(),o("div",he,l(d(a).error),1)):i("",!0),e("div",ue,[e("div",_e,[e("div",pe,[e("div",ve,[e("div",{class:u(["mesh-status-indicator",d(a).status?.device_connected?"connected":"disconnected"])},null,2),t[5]||(t[5]=e("h2",{class:"mesh-section-title"},"Device",-1))]),d(a).loading&&!d(a).status?(n(),o("div",me,"Loading...")):d(a).status?(n(),o("div",ye,[e("div",be,[t[6]||(t[6]=e("span",{class:"mesh-stat-label"},"Status",-1)),e("span",{class:u(["mesh-stat-value",d(a).status.device_connected?"text-green":d(a).status.enabled?"text-orange":"text-muted"])},l(d(a).status.device_connected?"Broadcasting":d(a).status.enabled?"Connecting...":"Disabled"),3)]),e("div",fe,[t[7]||(t[7]=e("span",{class:"mesh-stat-label"},"Type",-1)),e("span",ke,l(d(a).status.device_type==="unknown"?"—":d(a).status.device_type),1)]),e("div",ge,[t[8]||(t[8]=e("span",{class:"mesh-stat-label"},"Port",-1)),e("span",we,l(d(a).status.device_path??"Auto"),1)]),e("div",Ce,[t[9]||(t[9]=e("span",{class:"mesh-stat-label"},"Sent",-1)),e("span",xe,l(d(a).status.messages_sent),1)]),e("div",Me,[t[10]||(t[10]=e("span",{class:"mesh-stat-label"},"Recv",-1)),e("span",Se,l(d(a).status.messages_received),1)]),e("div",Ae,[t[11]||(t[11]=e("span",{class:"mesh-stat-label"},"Channel",-1)),e("span",Ee,l(d(a).status.channel_name),1)])])):i("",!0),d(a).status?.detected_devices?.length?(n(),o("div",Te,[(n(!0),o(g,null,M(d(a).status.detected_devices,s=>(n(),o("div",{key:s,class:"mesh-device-row"},[t[12]||(t[12]=e("div",{class:"mesh-device-indicator"},null,-1)),e("span",De,l(s),1)]))),128))])):i("",!0)]),d(f).meshOnly?(n(),o("div",Ne,[...t[13]||(t[13]=[e("svg",{class:"w-4 h-4 text-orange-400 shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M18.364 5.636a9 9 0 11-12.728 0M12 9v4m0 4h.01"})],-1),e("span",{class:"text-sm font-medium text-orange-300"},"OFF-GRID",-1),e("span",{class:"text-xs text-white/50"},"Tor disabled — mesh only",-1)])])):i("",!0),e("div",Oe,[e("button",{class:"glass-button mesh-action-btn",disabled:S.value,onClick:j},l(d(a).status?.enabled?"Disable":"Enable"),9,Be),e("button",{class:"glass-button mesh-action-btn",disabled:!d(a).status?.device_connected||C.value,onClick:K},l(C.value?"Sending...":"Broadcast"),9,Pe),e("button",{class:u(["glass-button mesh-action-btn",d(f).meshOnly?"mesh-offgrid-active":""]),disabled:E.value,onClick:L},l(d(f).meshOnly?"Go Online":"Off-Grid"),11,Ie),e("button",{class:"glass-button mesh-action-btn",onClick:t[0]||(t[0]=s=>d(a).refreshAll())},"Refresh")]),e("div",Le,[e("h2",Fe,[t[14]||(t[14]=b("Peers ",-1)),e("span",Ge,l(d(a).peers.length),1)]),d(a).peers.length===0&&!d(a).status?.device_connected?(n(),o("div",Re," No peers discovered yet. ")):(n(),o("div",$e,[e("div",{class:u(["mesh-peer-row is-channel",{active:h.value?.index===0}]),onClick:t[1]||(t[1]=s=>z(I))},[...t[15]||(t[15]=[e("div",{class:"mesh-peer-avatar channel"},"#",-1),e("div",{class:"mesh-peer-info"},[e("div",{class:"mesh-peer-name"},"Public"),e("div",{class:"mesh-peer-sub"},"Mesh channel")],-1)])],2),(n(!0),o(g,null,M($.value,s=>(n(),o("div",{key:s.contact_id,class:u(["mesh-peer-row",{active:r.value?.contact_id===s.contact_id,"is-archy":y(s)}]),onClick:_=>V(s)},[e("div",{class:u(["mesh-peer-avatar",{archy:y(s)}])},[y(s)?(n(),se(te,{key:0,size:"sm"})):(n(),o(g,{key:1},[b(l(s.advert_name.charAt(0).toUpperCase()),1)],64))],2),e("div",ze,[e("div",Ue,[b(l(s.advert_name||`Node #${s.contact_id}`)+" ",1),y(s)?(n(),o("span",Ke,"Archy")):i("",!0)]),e("div",je,l(P(s.pubkey_hex)),1)]),d(a).unreadCounts[s.contact_id]?(n(),o("span",He,l(d(a).unreadCounts[s.contact_id]),1)):i("",!0),e("div",qe,[e("div",Je,[(n(),o(g,null,M(4,_=>e("div",{key:_,class:u(["mesh-signal-bar",{active:_<=H(s.rssi)}])},null,2)),64))])])],10,Ve))),128))]))])]),e("div",We,[e("div",Xe,[R.value?(n(),o(g,{key:1},[e("div",Qe,[e("button",{class:"mesh-chat-back",onClick:U},"←"),e("div",Ze,[e("div",es,[b(l(F.value)+" ",1),r.value&&y(r.value)?(n(),o("span",ss,"Archy")):i("",!0),h.value?(n(),o("span",ts,"Channel")):i("",!0)]),e("div",as,l(G.value),1)]),e("div",ns,[r.value&&m.value?(n(),o("span",{key:0,class:u(["mesh-session-badge",m.value.forward_secrecy?"session-ratchet":m.value.has_session?"session-static":"session-none"]),title:m.value.forward_secrecy?"Double Ratchet (forward secrecy)":m.value.has_session?"Static encryption":"No encryption"},"🛡",10,os)):i("",!0),r.value?(n(),o("span",ls,l(B(r.value.last_heard)),1)):i("",!0)])]),e("div",{ref_key:"chatScrollEl",ref:x,class:"mesh-chat-messages"},[N.value.length===0?(n(),o("div",ds," No messages yet. Say hello! ")):i("",!0),(n(!0),o(g,null,M(N.value,s=>(n(),o("div",{key:s.id,class:u(["mesh-chat-bubble-wrapper",s.direction])},[e("div",{class:u(["mesh-chat-bubble",[s.direction,s.message_type?"typed-"+s.message_type:""]])},[s.message_type==="invoice"&&s.typed_payload?(n(),o("div",cs,[e("div",is,[t[17]||(t[17]=e("span",{class:"mesh-typed-icon"},"⚡",-1)),t[18]||(t[18]=e("span",{class:"mesh-typed-label"},"Lightning Invoice",-1)),s.typed_payload.paid?(n(),o("span",rs,"Paid")):i("",!0)]),e("div",hs,l((s.typed_payload.amount_sats||0).toLocaleString())+" sats",1),s.typed_payload.memo?(n(),o("div",us,l(s.typed_payload.memo),1)):i("",!0),e("div",_s,l((s.typed_payload.bolt11||"").substring(0,40))+"...",1)])):s.message_type==="alert"&&s.typed_payload?(n(),o("div",{key:1,class:u(["mesh-typed-alert","alert-"+(s.typed_payload.alert_type||"status")])},[e("div",ps,[e("span",vs,l(s.typed_payload.alert_type==="emergency"?"🚨":s.typed_payload.alert_type==="dead_man"?"☠":""),1),e("span",ms,l(s.typed_payload.alert_type==="emergency"?"EMERGENCY":s.typed_payload.alert_type==="dead_man"?"DEAD MAN":"Status"),1),s.typed_payload.signed?(n(),o("span",ys,"Signed")):i("",!0)]),e("div",bs,l(s.typed_payload.message),1),s.typed_payload.coordinate?(n(),o("a",{key:0,class:"mesh-typed-alert-location",href:"https://www.openstreetmap.org/?mlat="+s.typed_payload.coordinate.lat/1e6+"&mlon="+s.typed_payload.coordinate.lng/1e6+"&zoom=14",target:"_blank",rel:"noopener"}," 📍 "+l(s.typed_payload.coordinate.label||"View location"),9,fs)):i("",!0)],2)):s.message_type==="coordinate"&&s.typed_payload?(n(),o("div",ks,[t[19]||(t[19]=e("div",{class:"mesh-typed-coordinate-header"},[e("span",{class:"mesh-typed-icon"},"📍"),e("span",{class:"mesh-typed-label"},"Location")],-1)),e("div",gs,l((s.typed_payload.lat/1e6).toFixed(4))+", "+l((s.typed_payload.lng/1e6).toFixed(4)),1),s.typed_payload.label?(n(),o("div",ws,l(s.typed_payload.label),1)):i("",!0),e("a",{class:"mesh-typed-coordinate-link",href:"https://www.openstreetmap.org/?mlat="+s.typed_payload.lat/1e6+"&mlon="+s.typed_payload.lng/1e6+"&zoom=14",target:"_blank",rel:"noopener"},"Open Map",8,Cs)])):s.message_type==="block_header"&&s.typed_payload?(n(),o("div",xs,[t[20]||(t[20]=e("span",{class:"mesh-typed-icon"},"⛓",-1)),e("span",Ms,l(s.typed_payload.message||s.plaintext),1)])):(n(),o("div",Ss,l(s.plaintext),1)),e("div",As,[s.encrypted?(n(),o("span",Es,"E2E")):i("",!0),s.delivered&&s.direction==="sent"?(n(),o("span",Ts,"✓✓")):i("",!0),e("span",Ds,l(B(s.timestamp)),1)])],2)],2))),128))],512),e("div",Ns,[k.value?(n(),o("div",Os,l(k.value),1)):i("",!0),e("div",Bs,[Y(e("input",{"onUpdate:modelValue":t[2]||(t[2]=s=>p.value=s),class:"mesh-chat-input",placeholder:"Type a message...",maxlength:"160",onKeydown:Z(ee(O,["exact","prevent"]),["enter"])},null,40,Ps),[[Q,p.value]]),e("button",{class:"glass-button mesh-chat-send-btn",disabled:!p.value.trim()||d(a).sending,onClick:O},l(d(a).sending?"...":"Send"),9,Is)]),e("div",Ls,[e("span",null,l(p.value.length)+"/160",1)])])],64)):(n(),o("div",Ye,[...t[16]||(t[16]=[e("div",{class:"mesh-chat-empty-icon"},"📡",-1),e("p",null,"Select a peer or channel to chat",-1),e("p",{class:"mesh-chat-empty-sub"},"Messages are sent over LoRa mesh radio",-1)])]))])])])]))}}),Us=ae(Fs,[["__scopeId","data-v-09fc6ab6"]]);export{Us as default};