signalk-multihelm 0.6.0 → 0.7.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 +22 -0
- package/package.json +1 -1
- package/plugin/configpanel-entry.js +1 -1
- package/plugin/index.js +256 -0
- package/plugin/index.js.map +1 -1
- package/public/configpanel-entry.js +1 -1
package/README.md
CHANGED
|
@@ -189,6 +189,28 @@ the autopilot (see above), and taking it over the same admin access on this
|
|
|
189
189
|
server as the vessel settings. Turn it off per server with **Keep the course
|
|
190
190
|
the same as on the master**.
|
|
191
191
|
|
|
192
|
+
## Alarms from every station
|
|
193
|
+
|
|
194
|
+
Every active alarm on the master sounds on every station, and silencing or
|
|
195
|
+
acknowledging it at any station does it at all of them. A server that is not
|
|
196
|
+
the master reads the master's alarms each second and raises each one through
|
|
197
|
+
its own Notifications API, marked as the master's, so its chartplotters show
|
|
198
|
+
and sound it like any other. Silencing or acknowledging one here is sent to
|
|
199
|
+
the master, and whatever the master has silenced or acknowledged is done
|
|
200
|
+
here too. When the master clears an alarm, or another server becomes the
|
|
201
|
+
master, the alarm goes from this server as well.
|
|
202
|
+
|
|
203
|
+
Stations on the same NMEA 2000 bus see the same alarm themselves. A server
|
|
204
|
+
that already has an alarm of its own on a path does not show the master's
|
|
205
|
+
on top of it: it keeps its own and only keeps it in step, so silencing it
|
|
206
|
+
here silences it on the master and the other way round. Alarms are matched
|
|
207
|
+
by path, as each server gives its alarms ids of its own. An alarm the master
|
|
208
|
+
does not have stays this server's own.
|
|
209
|
+
|
|
210
|
+
This uses the same write access on the master as the autopilot (see above).
|
|
211
|
+
It needs the server's Notifications API with notification management on,
|
|
212
|
+
and does nothing otherwise. Turn it off per server with **Show the master's alarms here**.
|
|
213
|
+
|
|
192
214
|
## History from the master
|
|
193
215
|
|
|
194
216
|
While the master has a History API provider (signalk-questdb, for example),
|
package/package.json
CHANGED
|
@@ -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}}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 and set the course 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),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: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};
|
package/plugin/index.js
CHANGED
|
@@ -344,6 +344,239 @@ function interpretReply(raw) {
|
|
|
344
344
|
message: "unexpected access request reply"
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
|
+
// src/alarms-from-master.ts
|
|
348
|
+
/**
|
|
349
|
+
* Alarms are matched by path: each server gives its alarms ids of its own,
|
|
350
|
+
* and stations on one NMEA 2000 bus raise the same alarm themselves.
|
|
351
|
+
*/
|
|
352
|
+
var NOTIFICATIONS_PATH = "/signalk/v2/api/notifications";
|
|
353
|
+
var ALARMS_POLL_MS = 1e3;
|
|
354
|
+
/** In the data of an alarm shown for the master: the master's server id, and its id for the alarm. */
|
|
355
|
+
var FROM_MASTER = "multihelmMaster";
|
|
356
|
+
var MASTER_ALARM = "multihelmMasterAlarm";
|
|
357
|
+
/**
|
|
358
|
+
* The server's Notifications API, while the server manages notifications:
|
|
359
|
+
* older servers lack it, and with management off it still raises alarms but
|
|
360
|
+
* can no longer clear, silence or acknowledge them.
|
|
361
|
+
*/
|
|
362
|
+
function managedNotifications(api) {
|
|
363
|
+
const notifications = api;
|
|
364
|
+
if (typeof notifications?.list !== "function" || typeof notifications.getId !== "function") return null;
|
|
365
|
+
try {
|
|
366
|
+
notifications.getId("signalk-multihelm-probe");
|
|
367
|
+
} catch {
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
return notifications;
|
|
371
|
+
}
|
|
372
|
+
var ACTIVE = /* @__PURE__ */ new Set([
|
|
373
|
+
"alert",
|
|
374
|
+
"warn",
|
|
375
|
+
"alarm",
|
|
376
|
+
"emergency"
|
|
377
|
+
]);
|
|
378
|
+
function isActive(state) {
|
|
379
|
+
return typeof state === "string" && ACTIVE.has(state);
|
|
380
|
+
}
|
|
381
|
+
function isRecord$5(value) {
|
|
382
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
383
|
+
}
|
|
384
|
+
function errorText$7(error) {
|
|
385
|
+
return error instanceof Error ? error.message : String(error);
|
|
386
|
+
}
|
|
387
|
+
function activeAlarms(listing) {
|
|
388
|
+
if (!isRecord$5(listing)) return [];
|
|
389
|
+
const alarms = [];
|
|
390
|
+
for (const [id, entry] of Object.entries(listing)) {
|
|
391
|
+
if (!isRecord$5(entry) || typeof entry.path !== "string" || !isRecord$5(entry.value)) continue;
|
|
392
|
+
const value = entry.value;
|
|
393
|
+
const status = isRecord$5(value.status) ? value.status : {};
|
|
394
|
+
if (!isActive(value.state)) continue;
|
|
395
|
+
alarms.push({
|
|
396
|
+
id,
|
|
397
|
+
path: entry.path,
|
|
398
|
+
state: value.state,
|
|
399
|
+
message: typeof value.message === "string" ? value.message : "",
|
|
400
|
+
data: isRecord$5(value.data) ? value.data : {},
|
|
401
|
+
silenced: status.silenced === true,
|
|
402
|
+
acknowledged: status.acknowledged === true
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
return alarms;
|
|
406
|
+
}
|
|
407
|
+
function isMirror(alarm) {
|
|
408
|
+
return typeof alarm.data[FROM_MASTER] === "string";
|
|
409
|
+
}
|
|
410
|
+
function byPath(alarms) {
|
|
411
|
+
const paths = /* @__PURE__ */ new Map();
|
|
412
|
+
for (const alarm of alarms) if (!paths.has(alarm.path)) paths.set(alarm.path, alarm);
|
|
413
|
+
return paths;
|
|
414
|
+
}
|
|
415
|
+
var MasterAlarms = class {
|
|
416
|
+
host;
|
|
417
|
+
timer = null;
|
|
418
|
+
running = false;
|
|
419
|
+
stopped = false;
|
|
420
|
+
seen = /* @__PURE__ */ new Map();
|
|
421
|
+
constructor(host) {
|
|
422
|
+
this.host = host;
|
|
423
|
+
}
|
|
424
|
+
start() {
|
|
425
|
+
this.timer = setInterval(() => {
|
|
426
|
+
this.sync();
|
|
427
|
+
}, ALARMS_POLL_MS);
|
|
428
|
+
}
|
|
429
|
+
stop() {
|
|
430
|
+
this.stopped = true;
|
|
431
|
+
if (this.timer) clearInterval(this.timer);
|
|
432
|
+
this.timer = null;
|
|
433
|
+
this.clearMirrors(() => false);
|
|
434
|
+
}
|
|
435
|
+
/** One pass; never rejects. */
|
|
436
|
+
async sync() {
|
|
437
|
+
if (this.running || this.stopped) return;
|
|
438
|
+
this.running = true;
|
|
439
|
+
try {
|
|
440
|
+
await this.syncOnce();
|
|
441
|
+
} catch (error) {
|
|
442
|
+
this.host.debug(`Multihelm: the alarms from the master: ${errorText$7(error)}`);
|
|
443
|
+
} finally {
|
|
444
|
+
this.running = false;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async syncOnce() {
|
|
448
|
+
const master = this.host.master();
|
|
449
|
+
if (!master) {
|
|
450
|
+
this.clearMirrors(() => false);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
this.clearMirrors((mirror) => mirror.data[FROM_MASTER] === master.id);
|
|
454
|
+
const listing = await callPeer("GET", master.access, NOTIFICATIONS_PATH, master.access.token);
|
|
455
|
+
if (!this.stillFor(master)) return;
|
|
456
|
+
const theirs = byPath(activeAlarms(listing).filter((alarm) => !isMirror(alarm)));
|
|
457
|
+
this.clearMirrors((mirror) => mirror.data["multihelmMaster"] === master.id && mirror.data["multihelmMasterAlarm"] === theirs.get(mirror.path)?.id);
|
|
458
|
+
const seen = /* @__PURE__ */ new Map();
|
|
459
|
+
for (const [path, alarm] of theirs) {
|
|
460
|
+
if (!this.stillFor(master)) return;
|
|
461
|
+
try {
|
|
462
|
+
const here = this.alarmHere(path, alarm, master.id);
|
|
463
|
+
seen.set(here.id, await this.keepInStep(master, here, alarm));
|
|
464
|
+
} catch (error) {
|
|
465
|
+
this.host.debug(`Multihelm: the master's alarm ${path}: ${errorText$7(error)}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
this.seen = seen;
|
|
469
|
+
}
|
|
470
|
+
stillFor(master) {
|
|
471
|
+
return !this.stopped && this.host.master()?.id === master.id;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* This server's own alarm on the path, or the one shown for the master's.
|
|
475
|
+
* Read again for each alarm, since the server may have raised one of its own while a send waited.
|
|
476
|
+
*/
|
|
477
|
+
alarmHere(path, theirs, masterId) {
|
|
478
|
+
const here = activeAlarms(this.host.notifications.list()).filter((a) => a.path === path);
|
|
479
|
+
const own = here.find((alarm) => !isMirror(alarm));
|
|
480
|
+
const mirror = here.find(isMirror);
|
|
481
|
+
if (!own) return this.mirrored(mirror, theirs, masterId);
|
|
482
|
+
if (mirror) this.host.notifications.clear(mirror.id);
|
|
483
|
+
return own;
|
|
484
|
+
}
|
|
485
|
+
mirrored(mirror, theirs, masterId) {
|
|
486
|
+
const notifications = this.host.notifications;
|
|
487
|
+
const data = {
|
|
488
|
+
...theirs.data,
|
|
489
|
+
[FROM_MASTER]: masterId,
|
|
490
|
+
[MASTER_ALARM]: theirs.id
|
|
491
|
+
};
|
|
492
|
+
const shown = {
|
|
493
|
+
...theirs,
|
|
494
|
+
data,
|
|
495
|
+
silenced: false,
|
|
496
|
+
acknowledged: false
|
|
497
|
+
};
|
|
498
|
+
if (!mirror) {
|
|
499
|
+
const id = notifications.raise({
|
|
500
|
+
state: theirs.state,
|
|
501
|
+
message: theirs.message,
|
|
502
|
+
path: theirs.path,
|
|
503
|
+
data
|
|
504
|
+
});
|
|
505
|
+
return {
|
|
506
|
+
...shown,
|
|
507
|
+
id
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
if (mirror.state === theirs.state && mirror.message === theirs.message && isDeepStrictEqual(mirror.data, data)) return mirror;
|
|
511
|
+
notifications.update(mirror.id, {
|
|
512
|
+
state: theirs.state,
|
|
513
|
+
message: theirs.message,
|
|
514
|
+
data
|
|
515
|
+
});
|
|
516
|
+
return mirror.state === theirs.state ? {
|
|
517
|
+
...mirror,
|
|
518
|
+
message: theirs.message,
|
|
519
|
+
data
|
|
520
|
+
} : {
|
|
521
|
+
...shown,
|
|
522
|
+
id: mirror.id
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
async keepInStep(master, here, theirs) {
|
|
526
|
+
const last = this.seen.get(here.id);
|
|
527
|
+
const before = last?.masterId === master.id && last.theirId === theirs.id ? last : null;
|
|
528
|
+
const now = {
|
|
529
|
+
masterId: master.id,
|
|
530
|
+
theirId: theirs.id,
|
|
531
|
+
silenced: here.silenced,
|
|
532
|
+
acknowledged: here.acknowledged,
|
|
533
|
+
unsent: null
|
|
534
|
+
};
|
|
535
|
+
const id = here.id;
|
|
536
|
+
if (theirs.acknowledged && !here.acknowledged) {
|
|
537
|
+
this.host.notifications.acknowledge(id);
|
|
538
|
+
return {
|
|
539
|
+
...now,
|
|
540
|
+
acknowledged: true
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
if (theirs.silenced && !here.silenced && !here.acknowledged) {
|
|
544
|
+
this.host.notifications.silence(id);
|
|
545
|
+
return {
|
|
546
|
+
...now,
|
|
547
|
+
silenced: true
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
if (!before) return now;
|
|
551
|
+
const unsent = here.acknowledged && !theirs.acknowledged && (!before.acknowledged || before.unsent === "acknowledge") ? "acknowledge" : here.silenced && !theirs.silenced && !theirs.acknowledged && (!before.silenced || before.unsent === "silence") ? "silence" : null;
|
|
552
|
+
if (unsent && !await this.sendToMaster(master, theirs, unsent)) return {
|
|
553
|
+
...now,
|
|
554
|
+
unsent
|
|
555
|
+
};
|
|
556
|
+
return now;
|
|
557
|
+
}
|
|
558
|
+
async sendToMaster(master, alarm, action) {
|
|
559
|
+
const token = await this.host.control.token(master);
|
|
560
|
+
if (token === null || !this.stillFor(master)) return false;
|
|
561
|
+
try {
|
|
562
|
+
await callPeer("POST", master.access, `${NOTIFICATIONS_PATH}/${encodeURIComponent(alarm.id)}/${action}`, token);
|
|
563
|
+
} catch (error) {
|
|
564
|
+
if (error instanceof PeerHttpError && (error.status === 401 || error.status === 403)) this.host.control.revoked(master.id, token);
|
|
565
|
+
this.host.debug(`Multihelm: sending the ${action} of ${alarm.path} to the master: ${errorText$7(error)}`);
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
this.host.debug(`Multihelm: sent the ${action} of ${alarm.path} to the master`);
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
clearMirrors(keep) {
|
|
572
|
+
const notifications = this.host.notifications;
|
|
573
|
+
for (const alarm of activeAlarms(notifications.list())) if (isMirror(alarm) && !keep(alarm)) try {
|
|
574
|
+
notifications.clear(alarm.id);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
this.host.debug(`Multihelm: clearing ${alarm.path}: ${errorText$7(error)}`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
347
580
|
// src/autopilot-from-master.ts
|
|
348
581
|
/**
|
|
349
582
|
* On a server that is not the master: the master's autopilot, served by this
|
|
@@ -1000,6 +1233,11 @@ var ConfigSchema = Type.Object({
|
|
|
1000
1233
|
title: "Keep the course the same as on the master",
|
|
1001
1234
|
description: "This server takes the master's active destination or route over, and a destination or route set here is sent to the master, so every station follows the same course. Does nothing on the master.",
|
|
1002
1235
|
default: true
|
|
1236
|
+
}),
|
|
1237
|
+
alarmsFromMaster: Type.Boolean({
|
|
1238
|
+
title: "Show the master's alarms here",
|
|
1239
|
+
description: "Every active alarm on the master also sounds here, and silencing or acknowledging an alarm here does it on the master and every other station. An alarm this server raises itself on the same path is not shown twice. Does nothing on the master, or on a server without the Notifications API or with notification management off.",
|
|
1240
|
+
default: true
|
|
1003
1241
|
})
|
|
1004
1242
|
});
|
|
1005
1243
|
// src/source-priorities.ts
|
|
@@ -3632,6 +3870,23 @@ function src_default(app) {
|
|
|
3632
3870
|
}
|
|
3633
3871
|
}) : null;
|
|
3634
3872
|
course?.start();
|
|
3873
|
+
const notifications = managedNotifications(app.notifications);
|
|
3874
|
+
const alarms = settings.alarmsFromMaster !== false && notifications ? new MasterAlarms({
|
|
3875
|
+
master: () => {
|
|
3876
|
+
const masterAccess = mh.masterAccess();
|
|
3877
|
+
const master = mh.role() === "master" ? null : mh.master();
|
|
3878
|
+
return masterAccess && master ? {
|
|
3879
|
+
id: master.id,
|
|
3880
|
+
access: masterAccess
|
|
3881
|
+
} : null;
|
|
3882
|
+
},
|
|
3883
|
+
control,
|
|
3884
|
+
notifications,
|
|
3885
|
+
debug: (msg) => {
|
|
3886
|
+
app.debug(msg);
|
|
3887
|
+
}
|
|
3888
|
+
}) : null;
|
|
3889
|
+
alarms?.start();
|
|
3635
3890
|
const stopRoleAutopilot = mh.onRoleChanged(() => {
|
|
3636
3891
|
autopilot?.roleChanged();
|
|
3637
3892
|
});
|
|
@@ -3645,6 +3900,7 @@ function src_default(app) {
|
|
|
3645
3900
|
stopRoleAutopilot();
|
|
3646
3901
|
autopilot?.stop();
|
|
3647
3902
|
course?.stop();
|
|
3903
|
+
alarms?.stop();
|
|
3648
3904
|
clearInterval(followTimer);
|
|
3649
3905
|
stopRoleFollow();
|
|
3650
3906
|
clearInterval(historyTimer);
|