signalk-multihelm 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -1
- package/package.json +3 -2
- package/plugin/configpanel-entry.js +1 -1
- package/plugin/index.js +681 -159
- package/plugin/index.js.map +1 -1
- package/public/configpanel-entry.js +1 -1
package/README.md
CHANGED
|
@@ -82,6 +82,48 @@ from the transfers, and a master that has not answered for two and a half
|
|
|
82
82
|
minutes no longer counts.
|
|
83
83
|
When several servers are set, the one with the smallest server id is the
|
|
84
84
|
master, and the plugin status says to set one only.
|
|
85
|
+
|
|
86
|
+
### When the master is gone
|
|
87
|
+
|
|
88
|
+
Other servers can take over while the master is gone: give each one a place
|
|
89
|
+
under **Take over as master when the master is gone** (first, second, ...).
|
|
90
|
+
When no server set to be the master has answered for three and a half
|
|
91
|
+
minutes, counted from a server's own start too, the reachable server with
|
|
92
|
+
the lowest place becomes the master,
|
|
93
|
+
with everything that follows the master: the plugins that run on the master
|
|
94
|
+
only, the autopilot, the course, the alarms, the history and the charts it
|
|
95
|
+
shows. When the master set by hand is back, it takes the role back.
|
|
96
|
+
|
|
97
|
+
A server becomes the master only once every server it reaches has stopped
|
|
98
|
+
acting as it; a server acts until its
|
|
99
|
+
plugins that run on the master only have stopped, and keeps trying a stop
|
|
100
|
+
that failed. A server that has not looked at those plugins since its start,
|
|
101
|
+
and has no record of them, counts as acting until it has, so approve its
|
|
102
|
+
own access request. A server taking over also needs the votes of most
|
|
103
|
+
servers: each server votes for one server at a time and keeps that vote for
|
|
104
|
+
a while after it last gave it, so two that share the reachable servers never
|
|
105
|
+
both take over. The server set by hand gets the role back the same way, with most votes, so
|
|
106
|
+
it waits until the servers between it and a standby have stopped voting for
|
|
107
|
+
that one. A server gives no vote while it, or a server it reaches, still
|
|
108
|
+
acts as the master for another, so a master whose plugins will not stop holds
|
|
109
|
+
up the handover even where the new one cannot reach it, as long as the
|
|
110
|
+
servers that still see it can deny the new one most votes. That is as far as
|
|
111
|
+
the guarantee goes: when the network splits so that the new master and most
|
|
112
|
+
servers no longer reach the old one, and the old one cannot stop its plugins
|
|
113
|
+
on its own, both may run them until it can. Its stop is a call to its own
|
|
114
|
+
Signal K, retried every round. A server takes over only once every paired server has heard of its place,
|
|
115
|
+
so a master cut off before it was set does not keep acting beside it, and it
|
|
116
|
+
stops the plugins that run on the master only as soon as it loses those votes,
|
|
117
|
+
as does any server that sees another acting.
|
|
118
|
+
No server takes over while a
|
|
119
|
+
paired server runs a Multihelm too old to say whether it acts. As soon as any server may
|
|
120
|
+
take over, a server is the master only while it reaches most of the boat's
|
|
121
|
+
paired servers, itself included; on a boat of two, the one set by hand
|
|
122
|
+
counts as most. A server cut off from the others, the master included,
|
|
123
|
+
stops the plugins that run on the master only, while the others carry on.
|
|
124
|
+
A boat with only one of three servers switched on therefore has no master;
|
|
125
|
+
leave **Never** on every server to keep the master set by hand alone. Pair
|
|
126
|
+
every server with every other one, so they all count the same servers.
|
|
85
127
|
A server that is set to be the master, or no longer is, says so when it
|
|
86
128
|
next asks its peers, which it does right after the setting changes, so the
|
|
87
129
|
role moves within seconds.
|
|
@@ -100,10 +142,28 @@ while another server is, through its own plugin settings, as the admin UI
|
|
|
100
142
|
does: it shows them as disabled on the other servers, and they stay so
|
|
101
143
|
across a restart. Their own settings are left as they are, so set them up
|
|
102
144
|
on every server that may become the master. While no master is found,
|
|
103
|
-
nothing is switched
|
|
145
|
+
nothing is switched, unless this server reaches too few of the boat's
|
|
146
|
+
servers (see _When the master is gone_): then it stops them. While another server is the master, a plugin on the
|
|
104
147
|
list turned on by hand here is turned off again within a minute. Switching uses the same admin access as
|
|
105
148
|
taking the vessel settings over (see below), on the master too.
|
|
106
149
|
|
|
150
|
+
## Plugins with the same settings on every server
|
|
151
|
+
|
|
152
|
+
Some plugins keep everything in their plugin settings, such as
|
|
153
|
+
signalk-buddylist-plugin with its buddy list. Tick them under **Plugins with
|
|
154
|
+
the same settings on every server**, on the server whose settings you want
|
|
155
|
+
to keep: that server offers them, and the others take them over. After that,
|
|
156
|
+
a change made on any server goes to all of them within a round, with no
|
|
157
|
+
master; two changes made at the same time end on the same one everywhere.
|
|
158
|
+
The list itself is the same on every server.
|
|
159
|
+
|
|
160
|
+
Only the plugin's own settings are shared. Whether it runs, and its logging,
|
|
161
|
+
stay each server's own, and a server where the plugin is not installed takes
|
|
162
|
+
nothing. Taking settings over restarts the plugin there, as saving them in
|
|
163
|
+
the admin UI does, and uses the same admin access as the vessel settings
|
|
164
|
+
(see below). Taking a plugin off the list leaves its settings on every
|
|
165
|
+
server as they are.
|
|
166
|
+
|
|
107
167
|
## Vessel data, metadata and source priorities from the master
|
|
108
168
|
|
|
109
169
|
The vessel is described once, on the master. The other servers take over its
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalk-multihelm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Keeps several Signal K servers on one boat in step, one per nav station, without depending on a single one",
|
|
5
5
|
"author": "Dirk Wahrheit",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
],
|
|
32
32
|
"recommends": [
|
|
33
33
|
"signalk-charts-provider-simple",
|
|
34
|
-
"signalk-questdb"
|
|
34
|
+
"signalk-questdb",
|
|
35
|
+
"signalk-rules"
|
|
35
36
|
]
|
|
36
37
|
},
|
|
37
38
|
"signalk-plugin-enabled-by-default": true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=window.__SK_REACT__;if(!e)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Children:t,Component:n,Fragment:r,Profiler:i,PureComponent:a,StrictMode:o,Suspense:s,cloneElement:c,createContext:l,createElement:u,createRef:d,forwardRef:f,isValidElement:p,lazy:m,memo:h,startTransition:g,use:_,useActionState:v,useCallback:y,useContext:ee,useDebugValue:te,useDeferredValue:ne,useEffect:b,useId:re,useImperativeHandle:ie,useInsertionEffect:ae,useLayoutEffect:oe,useMemo:x,useOptimistic:se,useReducer:S,useRef:ce,useState:C,useSyncExternalStore:w,useTransition:le,version:ue}=e;function T(e){return e===1?`1 server`:`${String(e)} servers`}function E(e,t){if(!e.running)return{tone:`danger`,text:`Multihelm is not running. Enable it above.`};if(e.masterConflict)return{tone:`danger`,text:`More than one server is set to be the boat's master. Set one only.`};if(e.role===`master`){let t=e.pairedBy.length,n=e.pairedBy.filter(e=>e.online).length;return{tone:`info`,text:t===0?`This server is the boat's master. No other server is paired with it yet.`:`This server is the boat's master. ${String(n)} of the ${T(t)} paired with it ${n===1?`is`:`are`} online.`}}if(e.master)return{tone:`success`,text:`The boat's master is ${e.master.name}; it answered ${N(e.master.lastSeen,t)}.`};let n=e.peers.filter(e=>e.state===`paired`),r=n.filter(e=>e.online===!1);return r.length>0?{tone:`danger`,text:`No master found: ${r.map(e=>e.name).join(`, `)} ${r.length===1?`is`:`are`} not reachable.`}:n.length===0?{tone:`warning`,text:`No master found: this server is not paired yet. Pair it with the server set to be the boat's master below.`}:{tone:`warning`,text:`No master found: none of the paired servers is set to be the boat's master.`}}function D(e,t){return e.url===t.url||e.name.toLowerCase()===t.name.toLowerCase()}function O(e){return e.discovered.filter(t=>!e.peers.some(e=>D(t,e)))}function k(e,t){return e.id===``?t.find(t=>t.url===e.url)?.name??e.name:e.name}function A(e){return`/skServer/security/access/requests/${encodeURIComponent(e)}/approved`}function j(e){return[e.signalk&&`Signal K ${e.signalk}`,e.multihelm&&`Multihelm ${e.multihelm}`].filter(Boolean).join(` · `)}function M(e){return`${e}/admin/#/security/access/requests`}function N(e,t){if(e===void 0)return`never`;let n=Math.max(0,Math.round((t-e)/1e3));if(n<10)return`just now`;if(n<90)return`${String(n)} s ago`;let r=Math.round(n/60);if(r<90)return`${String(r)} min ago`;let i=Math.round(r/60);return i<36?`${String(i)} h ago`:`${String(Math.round(i/24))} days ago`}var P=window.__SK_REACT_JSX_RUNTIME__;if(!P)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Fragment:F,jsx:I,jsxs:L}=P,R=`/plugins/signalk-multihelm`,z=3e3,B=`own-access`;async function V(e,t){let n=await fetch(e,{credentials:`same-origin`,...t}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(typeof r.error==`string`?r.error:`HTTP ${String(n.status)}`);return r}function H(e){return e instanceof Error?e.message:String(e)}function U(e){return{master:e?.master===!0,syncResources:e?.syncResources!==!1,followVessel:e?.followVessel!==!1,followMetadata:e?.followMetadata!==!1,followSourcePriorities:e?.followSourcePriorities!==!1,historyFromMaster:e?.historyFromMaster!==!1,autopilotFromMaster:e?.autopilotFromMaster!==!1,courseFromMaster:e?.courseFromMaster!==!1,alarmsFromMaster:e?.alarmsFromMaster!==!1}}function W({configuration:e,save:t}){let[n,r]=C(null),[i,a]=C(null),[o,s]=C(null),[c,l]=C(null),[u,d]=C(``),f=y(async()=>{try{r(await V(`${R}/status`)),a(null)}catch(e){a(H(e))}},[]);b(()=>{f();let e=setInterval(()=>void f(),z);return()=>{clearInterval(e)}},[f]);let p=async(e,t)=>{s(e),l(null);try{return await t(),!0}catch(t){return l({key:e,text:H(t)}),!1}finally{s(null),await f()}},m=e=>p(e,()=>V(`${R}/peers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e})})),h=(e,t)=>{window.confirm(`Stop keeping this server in step with ${t}?`)&&p(e.url,()=>V(`${R}/peers?url=${encodeURIComponent(e.url)}`,{method:`DELETE`}))},g=e=>{window.confirm(`Take ${e.name} off this list? It comes back once it asks this server again.`)&&p(e.id,()=>V(`${R}/paired-by?id=${encodeURIComponent(e.id)}`,{method:`DELETE`}))},_=e=>{p(B,()=>V(A(e),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({permissions:`admin`})}))},v=async e=>{e.preventDefault(),u.trim()!==``&&await m(u.trim())&&d(``)};return L(`div`,{children:[i&&L(`div`,{className:`alert alert-danger`,children:[`Cannot read Multihelm's status: `,i,n&&`. What is shown below may be out of date.`]}),n&&I(G,{status:n,allowing:o===B,allowError:c?.key===B?c.text:null,onAllow:_}),n?.running&&L(F,{children:[n.role===`master`&&I(Y,{status:n,busy:o,onForget:g}),I(K,{status:n,busy:o,onPair:m,onUnpair:h}),n.role!==`master`&&n.pairedBy.length>0&&I(Y,{status:n,busy:o,onForget:g}),I(Q,{status:n,onSaved:f}),L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Pair with another server`}),L(`div`,{className:`card-body`,children:[I(`p`,{className:`small text-body-secondary`,children:n.role===`master`?`The other servers pair with this one in their own Multihelm settings. Pair this one with another only to replicate charts both ways.`:`Each server takes over what the servers it is paired with share. Pair this one with the boat's master; to replicate charts both ways, pair the other server with this one too.`}),I(X,{status:n,busy:o,onPair:m}),L(`form`,{className:`row g-2 mt-1`,onSubmit:e=>void v(e),children:[I(`div`,{className:`col-sm`,children:I(`input`,{className:`form-control`,value:u,onChange:e=>{d(e.target.value)},placeholder:`Or enter its address, e.g. 192.168.1.10 or helm.local:3000`,"aria-label":`Address of the other server`})}),I(`div`,{className:`col-sm-auto`,children:I(`button`,{type:`submit`,className:`btn btn-primary`,disabled:o!==null||u.trim()===``,children:o===u.trim()?`Pairing…`:`Pair`})})]}),c&&c.key!==B&&I(`div`,{className:`alert alert-danger mt-3 mb-0`,children:c.text})]})]})]}),I($,{configuration:e,save:t})]})}function G({status:e,allowing:t,allowError:n,onAllow:r}){let i=E(e,Date.now()),a=e.ownAccess;return L(F,{children:[I(`div`,{className:`alert alert-${i.tone}`,children:i.text}),!e.available&&I(`div`,{className:`alert alert-danger`,children:`This Signal K server is older than 2.31, so the other servers cannot read from it. Update it.`}),a?.state===`waiting-approval`&&L(`div`,{className:`alert alert-warning`,children:[L(`p`,{children:[I(`strong`,{children:`One more step:`}),` Multihelm needs admin access to this server to write the master's vessel data, path metadata and source priorities here, and to start and stop the plugins that run on the master only.`]}),I(`button`,{type:`button`,className:`btn btn-primary`,disabled:t,onClick:()=>{r(a.request)},children:t?`Allowing…`:`Allow`}),L(`div`,{className:`small mt-2`,children:[`This approves Multihelm's own request under`,` `,I(`a`,{href:`#/security/access/requests`,children:`Security → Access Requests`}),`.`]}),n&&I(`div`,{className:`text-danger mt-2`,children:n})]}),e.controlAccess&&L(`div`,{className:`alert alert-warning`,children:[`To operate the autopilot, set the course and acknowledge alarms from this station, approve Multihelm's request `,I(`code`,{children:e.controlAccess.request}),` under Security → Access Requests on the master, `,e.master?.name??`the master`,`.`]}),a?.state===`denied`&&I(`div`,{className:`alert alert-danger`,children:`The access request on this server was denied, so the vessel settings are not taken over from the master and no plugin is switched for the master. Save the settings below to ask again.`})]})}function K({status:e,busy:t,onPair:n,onUnpair:r}){let i=Date.now();return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Paired servers`}),I(`div`,{className:`card-body`,children:e.peers.length===0?I(`p`,{className:`text-body-secondary mb-0`,children:e.role===`master`?`This server takes nothing over from another.`:`This server is not paired with another yet.`}):I(`table`,{className:`table table-sm align-middle mb-0`,children:I(`tbody`,{children:e.peers.map(a=>{let o=k(a,e.discovered);return L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:o}),a.master&&I(`span`,{className:`badge text-bg-primary ms-2`,children:`master`}),I(`div`,{className:`small text-body-secondary`,children:a.url}),j(a)&&I(`div`,{className:`small text-body-secondary`,children:j(a)})]}),I(`td`,{children:I(q,{peer:a,name:o,status:e,now:i})}),L(`td`,{className:`text-end text-nowrap`,children:[a.state===`needs-pairing`&&I(`button`,{type:`button`,className:`btn btn-sm btn-primary me-2`,disabled:t!==null,onClick:()=>void n(a.url),children:`Pair again`}),I(`button`,{type:`button`,className:`btn btn-sm btn-outline-danger`,disabled:t!==null,onClick:()=>{r(a,o)},children:`Remove`})]})]},a.url)})})})})]})}function q({peer:e,name:t,status:n,now:r}){return L(F,{children:[e.state===`paired`&&L(F,{children:[I(J,{online:e.online===!0}),L(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,N(e.lastSeen,r)]})]}),e.state===`waiting-approval`&&L(F,{children:[I(`span`,{className:`badge text-bg-warning`,children:`Waiting for approval`}),L(`div`,{className:`small mt-1`,children:[`On `,t,`, approve “Multihelm on `,n.name,`” under`,` `,I(`a`,{href:M(e.url),target:`_blank`,rel:`noreferrer`,children:`Security → Access Requests`}),`.`]})]}),e.state===`needs-pairing`&&I(`span`,{className:`badge text-bg-danger`,children:`Not paired`}),e.lastError&&I(`div`,{className:`small text-danger mt-1`,children:e.lastError})]})}function J({online:e}){return e?I(`span`,{className:`badge text-bg-success`,children:`Online`}):I(`span`,{className:`badge text-bg-secondary`,children:`Offline`})}function Y({status:e,busy:t,onForget:n}){let r=Date.now();return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Servers paired with this one`}),I(`div`,{className:`card-body`,children:e.pairedBy.length===0?I(`p`,{className:`text-body-secondary mb-0`,children:`No other server is paired with this one yet. Pair the others with it in their Multihelm settings.`}):I(`table`,{className:`table table-sm align-middle mb-0`,children:I(`tbody`,{children:e.pairedBy.map(e=>L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:e.name}),j(e)&&I(`div`,{className:`small text-body-secondary`,children:j(e)})]}),L(`td`,{children:[I(J,{online:e.online}),L(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,N(e.lastSeen,r)]})]}),I(`td`,{className:`text-end`,children:!e.online&&I(`button`,{type:`button`,className:`btn btn-sm btn-outline-secondary`,disabled:t!==null,onClick:()=>{n(e)},children:`Forget`})})]},e.id))})})})]})}function X({status:e,busy:t,onPair:n}){let r=O(e);return r.length===0?I(`p`,{className:`text-body-secondary`,children:`No other Signal K server that is not paired yet was found on the network.`}):I(`table`,{className:`table table-sm align-middle`,children:I(`tbody`,{children:r.map(e=>L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:e.name}),e.vessel&&L(`span`,{className:`text-body-secondary ms-2`,children:[`vessel `,e.vessel]}),I(`div`,{className:`small text-body-secondary`,children:e.url})]}),I(`td`,{className:`text-end`,children:I(`button`,{type:`button`,className:`btn btn-sm btn-primary`,disabled:t!==null,onClick:()=>void n(e.url),children:t===e.url?`Pairing…`:`Pair`})})]},e.url))})})}function Z(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`).filter(e=>e.id!==`signalk-multihelm`).map(e=>({id:e.id,name:typeof e.name==`string`&&e.name!==``?e.name:e.id})).sort((e,t)=>e.name.localeCompare(t.name)):[]}function Q({status:e,onSaved:t}){let[n,r]=C(null),[i,a]=C(null),[o,s]=C([]),[c,l]=C(!1),[u,d]=C(null);b(()=>{V(`/skServer/plugins`).then(e=>{r(Z(e))},e=>{d(`Cannot list the plugins: ${H(e)}`)})},[]);let f=i??e.masterPlugins,p=i===null||[...i].sort().join()===[...e.masterPlugins].sort().join(),m=[...new Set([...e.masterPlugins,...f,...o])].filter(e=>!n?.some(t=>t.id===e)),h=(e,t)=>{a(t?[...f,e]:f.filter(t=>t!==e)),t||s([...o,e])},g=async()=>{l(!0),d(null);try{await V(`${R}/master-plugins`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({plugins:f})}),a(null),s([]),await t()}catch(e){d(H(e))}finally{l(!1)}};return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Plugins that run on the master only`}),L(`div`,{className:`card-body`,children:[I(`p`,{className:`small text-body-secondary`,children:`These plugins run on the boat's master and are stopped on the other servers, for example an autopilot provider, so only one server sends its commands. The list is the same on every server; when another server becomes the master, they move there.`}),n===null&&!u&&I(`p`,{className:`text-body-secondary`,children:`Loading the plugins…`}),n?.map(e=>L(`div`,{className:`form-check`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-master-plugin-${e.id}`,checked:f.includes(e.id),disabled:c,onChange:t=>{h(e.id,t.target.checked)}}),I(`label`,{className:`form-check-label`,htmlFor:`multihelm-master-plugin-${e.id}`,children:e.name})]},e.id)),n!==null&&m.map(e=>L(`div`,{className:`form-check`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-master-plugin-${e}`,checked:f.includes(e),disabled:c,onChange:t=>{h(e,t.target.checked)}}),L(`label`,{className:`form-check-label`,htmlFor:`multihelm-master-plugin-${e}`,children:[e,` `,I(`span`,{className:`text-body-secondary`,children:`(not installed here)`})]})]},e)),I(`button`,{type:`button`,className:`btn btn-primary mt-3`,disabled:c||p,onClick:()=>void g(),children:c?`Saving…`:`Save list`}),u&&I(`div`,{className:`alert alert-danger mt-3 mb-0`,children:u})]})]})}function $({configuration:e,save:t}){let[n,r]=C(()=>U(e)),i=(e,t)=>{r(n=>({...n,[e]:t}))},a=(e,t,r,a=!1)=>L(`div`,{className:`form-check mb-3`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-${e}`,checked:n[e],disabled:a,onChange:t=>{i(e,t.target.checked)}}),I(`label`,{className:`form-check-label`,htmlFor:`multihelm-${e}`,children:t}),I(`div`,{className:`form-text`,children:r})]}),o=n.master;return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Settings`}),L(`div`,{className:`card-body`,children:[a(`master`,`This server is the boat's master`,`Set this on one server only. Plugins that run on the master alone run here, and the other servers use them through this one.`),a(`syncResources`,`Keep routes and waypoints in step`,`Routes, waypoints, regions and notes, kept the same on every server of the boat: a change on one reaches the others, with no master.`),o&&I(`p`,{className:`small text-body-secondary`,children:`The options below apply to the servers that are not the master.`}),a(`followVessel`,`Take the vessel data over from the master`,`Name, MMSI, call sign, dimensions and ship type from Server → Settings. Changes made here are replaced by the master's.`,o),a(`followMetadata`,`Take the path metadata over from the master`,`Display names, units, zones and alarm limits set for paths. Changes made here are replaced by the master's.`,o),a(`followSourcePriorities`,`Take the source priorities over from the master`,`Which source wins for a path, from Data → Source Priorities. They name sources by connection, so give the NMEA 2000 bus the same connection name on every server. Changes made here are replaced by the master's.`,o),a(`historyFromMaster`,`Answer this server's History API from the master`,`While the master has a history provider (signalk-questdb, for example), history graphs on this server show the master's history, so it is kept once on the boat. Needs Signal K 2.32.0 or later.`,o),a(`autopilotFromMaster`,`Operate the master's autopilot from this server`,`A chartplotter here operates the master's autopilot, while only the master sends to it. Put the autopilot provider plugin on the list of plugins that run on the master only.`,o),a(`courseFromMaster`,`Keep the course the same as on the master`,`The active destination or route set at any station is taken over by all the others.`,o),a(`alarmsFromMaster`,`Show the master's alarms here`,`Silencing or acknowledging an alarm at any station does it at all the others. An alarm this server raises itself is not shown twice.`,o),I(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{t({...e,...n})},children:`Save settings`})]})]})}export{W as default};
|
|
1
|
+
var e=window.__SK_REACT__;if(!e)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Children:t,Component:n,Fragment:r,Profiler:i,PureComponent:a,StrictMode:o,Suspense:s,cloneElement:c,createContext:l,createElement:u,createRef:d,forwardRef:f,isValidElement:p,lazy:m,memo:h,startTransition:g,use:_,useActionState:v,useCallback:y,useContext:b,useDebugValue:ee,useDeferredValue:te,useEffect:x,useId:ne,useImperativeHandle:re,useInsertionEffect:ie,useLayoutEffect:ae,useMemo:oe,useOptimistic:se,useReducer:S,useRef:C,useState:w,useSyncExternalStore:ce,useTransition:le,version:ue}=e;function T(e){return e===1?`1 server`:`${String(e)} servers`}function E(e,t){if(!e.running)return{tone:`danger`,text:`Multihelm is not running. Enable it above.`};if(e.masterConflict)return{tone:`danger`,text:`More than one server is set to be the boat's master. Set one only.`};if(e.role===`master`){let t=e.pairedBy.length,n=e.pairedBy.filter(e=>e.online).length;return{tone:`info`,text:t===0?`This server is the boat's master. No other server is paired with it yet.`:`This server is the boat's master. ${String(n)} of the ${T(t)} paired with it ${n===1?`is`:`are`} online.`}}if(e.master)return{tone:`success`,text:`The boat's master is ${e.master.name}; it answered ${N(e.master.lastSeen,t)}.`};let n=e.peers.filter(e=>e.state===`paired`),r=n.filter(e=>e.online===!1);return e.majority===!1?{tone:`danger`,text:`No master: this server reaches too few of the boat's servers (${r.map(e=>e.name).join(`, `)} ${r.length===1?`is`:`are`} not reachable), so the plugins that run on the master only are stopped here.`}:r.length>0?{tone:`danger`,text:`No master found: ${r.map(e=>e.name).join(`, `)} ${r.length===1?`is`:`are`} not reachable.`}:n.length===0?{tone:`warning`,text:`No master found: this server is not paired yet. Pair it with the server set to be the boat's master below.`}:{tone:`warning`,text:`No master found: none of the paired servers is set to be the boat's master.`}}function D(e,t){return e.url===t.url||e.name.toLowerCase()===t.name.toLowerCase()}function O(e){return e.discovered.filter(t=>!e.peers.some(e=>D(t,e)))}function k(e,t){return e.id===``?t.find(t=>t.url===e.url)?.name??e.name:e.name}function A(e){return`/skServer/security/access/requests/${encodeURIComponent(e)}/approved`}function j(e){return[e.signalk&&`Signal K ${e.signalk}`,e.multihelm&&`Multihelm ${e.multihelm}`].filter(Boolean).join(` · `)}function M(e){return`${e}/admin/#/security/access/requests`}function N(e,t){if(e===void 0)return`never`;let n=Math.max(0,Math.round((t-e)/1e3));if(n<10)return`just now`;if(n<90)return`${String(n)} s ago`;let r=Math.round(n/60);if(r<90)return`${String(r)} min ago`;let i=Math.round(r/60);return i<36?`${String(i)} h ago`:`${String(Math.round(i/24))} days ago`}var P=window.__SK_REACT_JSX_RUNTIME__;if(!P)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Fragment:F,jsx:I,jsxs:L}=P,R=`/plugins/signalk-multihelm`,z=3e3,B=`own-access`;async function V(e,t){let n=await fetch(e,{credentials:`same-origin`,...t}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(typeof r.error==`string`?r.error:`HTTP ${String(n.status)}`);return r}function H(e){return e instanceof Error?e.message:String(e)}function U(e){return{master:e?.master===!0,takeOver:typeof e?.takeOver==`number`&&e.takeOver>0?e.takeOver:0,syncResources:e?.syncResources!==!1,followVessel:e?.followVessel!==!1,followMetadata:e?.followMetadata!==!1,followSourcePriorities:e?.followSourcePriorities!==!1,historyFromMaster:e?.historyFromMaster!==!1,autopilotFromMaster:e?.autopilotFromMaster!==!1,courseFromMaster:e?.courseFromMaster!==!1,alarmsFromMaster:e?.alarmsFromMaster!==!1}}function W({configuration:e,save:t}){let[n,r]=w(null),[i,a]=w(null),[o,s]=w(null),[c,l]=w(null),[u,d]=w(``),f=y(async()=>{try{r(await V(`${R}/status`)),a(null)}catch(e){a(H(e))}},[]);x(()=>{f();let e=setInterval(()=>void f(),z);return()=>{clearInterval(e)}},[f]);let p=async(e,t)=>{s(e),l(null);try{return await t(),!0}catch(t){return l({key:e,text:H(t)}),!1}finally{s(null),await f()}},m=e=>p(e,()=>V(`${R}/peers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e})})),h=(e,t)=>{window.confirm(`Stop keeping this server in step with ${t}?`)&&p(e.url,()=>V(`${R}/peers?url=${encodeURIComponent(e.url)}`,{method:`DELETE`}))},g=e=>{window.confirm(`Take ${e.name} off this list? It comes back once it asks this server again.`)&&p(e.id,()=>V(`${R}/paired-by?id=${encodeURIComponent(e.id)}`,{method:`DELETE`}))},_=e=>{p(B,()=>V(A(e),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({permissions:`admin`})}))},v=async e=>{e.preventDefault(),u.trim()!==``&&await m(u.trim())&&d(``)};return L(`div`,{children:[i&&L(`div`,{className:`alert alert-danger`,children:[`Cannot read Multihelm's status: `,i,n&&`. What is shown below may be out of date.`]}),n&&I(G,{status:n,allowing:o===B,allowError:c?.key===B?c.text:null,onAllow:_}),n?.running&&L(F,{children:[n.role===`master`&&I(Y,{status:n,busy:o,onForget:g}),I(K,{status:n,busy:o,onPair:m,onUnpair:h}),n.role!==`master`&&n.pairedBy.length>0&&I(Y,{status:n,busy:o,onForget:g}),I(Q,{title:`Plugins that run on the master only`,description:`These plugins run on the boat's master and are stopped on the other servers, for example an autopilot provider, so only one server sends its commands. The list is the same on every server; when another server becomes the master, they move there.`,name:`master-plugins`,current:n.masterPlugins,onSaved:f}),I(Q,{title:`Plugins with the same settings on every server`,description:`The settings of these plugins, such as a buddy list, are kept the same on every server; whether a plugin runs stays each server's own. Add a plugin on the server that has the settings you want: the others take them over. After that, a change on any server goes to all.`,name:`shared-plugins`,current:n.sharedPlugins,onSaved:f}),L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Pair with another server`}),L(`div`,{className:`card-body`,children:[I(`p`,{className:`small text-body-secondary`,children:n.role===`master`?`The other servers pair with this one in their own Multihelm settings. Pair this one with another only to replicate charts both ways.`:`Each server takes over what the servers it is paired with share. Pair this one with the boat's master; to replicate charts both ways, pair the other server with this one too.`}),I(X,{status:n,busy:o,onPair:m}),L(`form`,{className:`row g-2 mt-1`,onSubmit:e=>void v(e),children:[I(`div`,{className:`col-sm`,children:I(`input`,{className:`form-control`,value:u,onChange:e=>{d(e.target.value)},placeholder:`Or enter its address, e.g. 192.168.1.10 or helm.local:3000`,"aria-label":`Address of the other server`})}),I(`div`,{className:`col-sm-auto`,children:I(`button`,{type:`submit`,className:`btn btn-primary`,disabled:o!==null||u.trim()===``,children:o===u.trim()?`Pairing…`:`Pair`})})]}),c&&c.key!==B&&I(`div`,{className:`alert alert-danger mt-3 mb-0`,children:c.text})]})]})]}),I($,{configuration:e,save:t})]})}function G({status:e,allowing:t,allowError:n,onAllow:r}){let i=E(e,Date.now()),a=e.ownAccess;return L(F,{children:[I(`div`,{className:`alert alert-${i.tone}`,children:i.text}),!e.available&&I(`div`,{className:`alert alert-danger`,children:`This Signal K server is older than 2.31, so the other servers cannot read from it. Update it.`}),a?.state===`waiting-approval`&&L(`div`,{className:`alert alert-warning`,children:[L(`p`,{children:[I(`strong`,{children:`One more step:`}),` Multihelm needs admin access to this server to write the master's vessel data, path metadata and source priorities here, and to start and stop the plugins that run on the master only.`]}),I(`button`,{type:`button`,className:`btn btn-primary`,disabled:t,onClick:()=>{r(a.request)},children:t?`Allowing…`:`Allow`}),L(`div`,{className:`small mt-2`,children:[`This approves Multihelm's own request under`,` `,I(`a`,{href:`#/security/access/requests`,children:`Security → Access Requests`}),`.`]}),n&&I(`div`,{className:`text-danger mt-2`,children:n})]}),e.controlAccess&&L(`div`,{className:`alert alert-warning`,children:[`To operate the autopilot, set the course and acknowledge alarms from this station, approve Multihelm's request `,I(`code`,{children:e.controlAccess.request}),` under Security → Access Requests on the master, `,e.master?.name??`the master`,`.`]}),a?.state===`denied`&&I(`div`,{className:`alert alert-danger`,children:`The access request on this server was denied, so the vessel settings are not taken over from the master and no plugin is switched for the master. Save the settings below to ask again.`})]})}function K({status:e,busy:t,onPair:n,onUnpair:r}){let i=Date.now();return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Paired servers`}),I(`div`,{className:`card-body`,children:e.peers.length===0?I(`p`,{className:`text-body-secondary mb-0`,children:e.role===`master`?`This server takes nothing over from another.`:`This server is not paired with another yet.`}):I(`table`,{className:`table table-sm align-middle mb-0`,children:I(`tbody`,{children:e.peers.map(a=>{let o=k(a,e.discovered);return L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:o}),a.master&&I(`span`,{className:`badge text-bg-primary ms-2`,children:`master`}),I(`div`,{className:`small text-body-secondary`,children:a.url}),j(a)&&I(`div`,{className:`small text-body-secondary`,children:j(a)})]}),I(`td`,{children:I(q,{peer:a,name:o,status:e,now:i})}),L(`td`,{className:`text-end text-nowrap`,children:[a.state===`needs-pairing`&&I(`button`,{type:`button`,className:`btn btn-sm btn-primary me-2`,disabled:t!==null,onClick:()=>void n(a.url),children:`Pair again`}),I(`button`,{type:`button`,className:`btn btn-sm btn-outline-danger`,disabled:t!==null,onClick:()=>{r(a,o)},children:`Remove`})]})]},a.url)})})})})]})}function q({peer:e,name:t,status:n,now:r}){return L(F,{children:[e.state===`paired`&&L(F,{children:[I(J,{online:e.online===!0}),L(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,N(e.lastSeen,r)]})]}),e.state===`waiting-approval`&&L(F,{children:[I(`span`,{className:`badge text-bg-warning`,children:`Waiting for approval`}),L(`div`,{className:`small mt-1`,children:[`On `,t,`, approve “Multihelm on `,n.name,`” under`,` `,I(`a`,{href:M(e.url),target:`_blank`,rel:`noreferrer`,children:`Security → Access Requests`}),`.`]})]}),e.state===`needs-pairing`&&I(`span`,{className:`badge text-bg-danger`,children:`Not paired`}),e.lastError&&I(`div`,{className:`small text-danger mt-1`,children:e.lastError})]})}function J({online:e}){return e?I(`span`,{className:`badge text-bg-success`,children:`Online`}):I(`span`,{className:`badge text-bg-secondary`,children:`Offline`})}function Y({status:e,busy:t,onForget:n}){let r=Date.now();return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Servers paired with this one`}),I(`div`,{className:`card-body`,children:e.pairedBy.length===0?I(`p`,{className:`text-body-secondary mb-0`,children:`No other server is paired with this one yet. Pair the others with it in their Multihelm settings.`}):I(`table`,{className:`table table-sm align-middle mb-0`,children:I(`tbody`,{children:e.pairedBy.map(e=>L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:e.name}),j(e)&&I(`div`,{className:`small text-body-secondary`,children:j(e)})]}),L(`td`,{children:[I(J,{online:e.online}),L(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,N(e.lastSeen,r)]})]}),I(`td`,{className:`text-end`,children:!e.online&&I(`button`,{type:`button`,className:`btn btn-sm btn-outline-secondary`,disabled:t!==null,onClick:()=>{n(e)},children:`Forget`})})]},e.id))})})})]})}function X({status:e,busy:t,onPair:n}){let r=O(e);return r.length===0?I(`p`,{className:`text-body-secondary`,children:`No other Signal K server that is not paired yet was found on the network.`}):I(`table`,{className:`table table-sm align-middle`,children:I(`tbody`,{children:r.map(e=>L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:e.name}),e.vessel&&L(`span`,{className:`text-body-secondary ms-2`,children:[`vessel `,e.vessel]}),I(`div`,{className:`small text-body-secondary`,children:e.url})]}),I(`td`,{className:`text-end`,children:I(`button`,{type:`button`,className:`btn btn-sm btn-primary`,disabled:t!==null,onClick:()=>void n(e.url),children:t===e.url?`Pairing…`:`Pair`})})]},e.url))})})}function Z(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`).filter(e=>e.id!==`signalk-multihelm`).map(e=>({id:e.id,name:typeof e.name==`string`&&e.name!==``?e.name:e.id})).sort((e,t)=>e.name.localeCompare(t.name)):[]}function Q({title:e,description:t,name:n,current:r,onSaved:i}){let[a,o]=w(null),[s,c]=w(null),[l,u]=w([]),[d,f]=w(!1),[p,m]=w(null);x(()=>{V(`/skServer/plugins`).then(e=>{o(Z(e))},e=>{m(`Cannot list the plugins: ${H(e)}`)})},[]);let h=s??r,g=s===null||[...s].sort().join()===[...r].sort().join(),_=[...new Set([...r,...h,...l])].filter(e=>!a?.some(t=>t.id===e)),v=(e,t)=>{c(t?[...h,e]:h.filter(t=>t!==e)),t||u([...l,e])},y=async()=>{f(!0),m(null);try{await V(`${R}/${n}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({plugins:h})}),c(null),u([]),await i()}catch(e){m(H(e))}finally{f(!1)}};return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:e}),L(`div`,{className:`card-body`,children:[I(`p`,{className:`small text-body-secondary`,children:t}),a===null&&!p&&I(`p`,{className:`text-body-secondary`,children:`Loading the plugins…`}),a?.map(e=>L(`div`,{className:`form-check`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-${n}-${e.id}`,checked:h.includes(e.id),disabled:d,onChange:t=>{v(e.id,t.target.checked)}}),I(`label`,{className:`form-check-label`,htmlFor:`multihelm-${n}-${e.id}`,children:e.name})]},e.id)),a!==null&&_.map(e=>L(`div`,{className:`form-check`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-${n}-${e}`,checked:h.includes(e),disabled:d,onChange:t=>{v(e,t.target.checked)}}),L(`label`,{className:`form-check-label`,htmlFor:`multihelm-${n}-${e}`,children:[e,` `,I(`span`,{className:`text-body-secondary`,children:`(not installed here)`})]})]},e)),I(`button`,{type:`button`,className:`btn btn-primary mt-3`,disabled:d||g,onClick:()=>void y(),children:d?`Saving…`:`Save list`}),p&&I(`div`,{className:`alert alert-danger mt-3 mb-0`,children:p})]})]})}function $({configuration:e,save:t}){let[n,r]=w(()=>U(e)),i=(e,t)=>{r(n=>({...n,[e]:t}))},a=(e,t,r,a=!1)=>L(`div`,{className:`form-check mb-3`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-${e}`,checked:n[e],disabled:a,onChange:t=>{i(e,t.target.checked)}}),I(`label`,{className:`form-check-label`,htmlFor:`multihelm-${e}`,children:t}),I(`div`,{className:`form-text`,children:r})]}),o=n.master;return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Settings`}),L(`div`,{className:`card-body`,children:[a(`master`,`This server is the boat's master`,`Set this on one server only. Plugins that run on the master alone run here, and the other servers use them through this one.`),L(`div`,{className:`mb-3`,children:[I(`label`,{className:`form-label`,htmlFor:`multihelm-takeOver`,children:`Take over as master when the master is gone`}),L(`select`,{className:`form-select w-auto`,id:`multihelm-takeOver`,value:n.takeOver,disabled:o,onChange:e=>{r(t=>({...t,takeOver:Number(e.target.value)}))},children:[I(`option`,{value:0,children:`Never`}),[1,2,3,4,5,6,7,8,9].map(e=>I(`option`,{value:e,children:e===1?`First`:`${String(e)}.`},e))]}),I(`div`,{className:`form-text`,children:`When the server set to be the master has been gone for three and a half minutes, the server with the lowest place here takes over, while it reaches most of the boat's servers. Give each server that may take over a place of its own.`})]}),a(`syncResources`,`Keep routes and waypoints in step`,`Routes, waypoints, regions and notes, kept the same on every server of the boat: a change on one reaches the others, with no master.`),o&&I(`p`,{className:`small text-body-secondary`,children:`The options below apply to the servers that are not the master.`}),a(`followVessel`,`Take the vessel data over from the master`,`Name, MMSI, call sign, dimensions and ship type from Server → Settings. Changes made here are replaced by the master's.`,o),a(`followMetadata`,`Take the path metadata over from the master`,`Display names, units, zones and alarm limits set for paths. Changes made here are replaced by the master's.`,o),a(`followSourcePriorities`,`Take the source priorities over from the master`,`Which source wins for a path, from Data → Source Priorities. They name sources by connection, so give the NMEA 2000 bus the same connection name on every server. Changes made here are replaced by the master's.`,o),a(`historyFromMaster`,`Answer this server's History API from the master`,`While the master has a history provider (signalk-questdb, for example), history graphs on this server show the master's history, so it is kept once on the boat. Needs Signal K 2.32.0 or later.`,o),a(`autopilotFromMaster`,`Operate the master's autopilot from this server`,`A chartplotter here operates the master's autopilot, while only the master sends to it. Put the autopilot provider plugin on the list of plugins that run on the master only.`,o),a(`courseFromMaster`,`Keep the course the same as on the master`,`The active destination or route set at any station is taken over by all the others.`,o),a(`alarmsFromMaster`,`Show the master's alarms here`,`Silencing or acknowledging an alarm at any station does it at all the others. An alarm this server raises itself is not shown twice.`,o),I(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{t({...e,...n})},children:`Save settings`})]})]})}export{W as default};
|