Skip to content

Commit

Permalink
Register AutopilotProvider on interface start up.
Browse files Browse the repository at this point in the history
Add to plugins interface.
  • Loading branch information
panaaj committed May 17, 2023
1 parent 1e52634 commit f200563
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/server-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export { ResourceProviderRegistry } from './resourcesapi'
import { ResourceProviderRegistry } from './resourcesapi'

export * from './autopilotapi'
import { AutopilotProviderRegistry } from './autopilotapi'

export {
PropertyValue,
Expand All @@ -51,7 +52,8 @@ export interface PropertyValuesEmitter {

export interface PluginServerApp
extends PropertyValuesEmitter,
ResourceProviderRegistry {}
ResourceProviderRegistry,
AutopilotProviderRegistry {}

/**
* This is the API that a [server plugin](https://github.com/SignalK/signalk-server/blob/master/SERVERPLUGINS.md) must implement.
Expand Down
13 changes: 11 additions & 2 deletions src/interfaces/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
PropertyValues,
PropertyValuesCallback,
ResourceProvider,
AutopilotProvider,
ServerAPI
} from '@signalk/server-api'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand All @@ -30,6 +31,7 @@ import fs from 'fs'
import _ from 'lodash'
import path from 'path'
import { ResourcesApi } from '../api/resources'
import { AutopilotApi } from '../api/autopilot'
import { SERVERROUTESPREFIX } from '../constants'
import { createDebug } from '../debug'
import { listAllSerialPorts } from '../serialports'
Expand Down Expand Up @@ -427,9 +429,10 @@ module.exports = (theApp: any) => {
console.error(`${plugin.id}:no configuration data`)
safeConfiguration = {}
}
onStopHandlers[plugin.id].push(() =>
onStopHandlers[plugin.id].push(() => {
app.resourcesApi.unRegister(plugin.id)
)
app.autopilotApi.unRegister(plugin.id)
})
plugin.start(safeConfiguration, restart)
debug('Started plugin ' + plugin.name)
setPluginStartedMessage(plugin)
Expand Down Expand Up @@ -509,6 +512,12 @@ module.exports = (theApp: any) => {
resourcesApi.register(plugin.id, provider)
}

const autopilotApi: AutopilotApi = app.autopilotApi
_.omit(appCopy, 'autopilotApi') // don't expose the actual autopilot api manager
appCopy.registerAutopilotProvider = (provider: AutopilotProvider) => {
autopilotApi.register(plugin.id, provider)
}

try {
const pluginConstructor: (
app: ServerAPI
Expand Down

0 comments on commit f200563

Please sign in to comment.