Skip to content

Commit

Permalink
Merge pull request #180 from daisy/engine-1.14.17
Browse files Browse the repository at this point in the history
Update engine to 1.14.17 (SNAPSHOT)
  • Loading branch information
marisademeglio authored Jan 19, 2024
2 parents 592f879 + 4e3633e commit b509c12
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 44 deletions.
20 changes: 20 additions & 0 deletions src/shared/data/apis/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import {
Webservice,
NamedResult,
TtsConfig,
EngineProperty,
} from 'shared/types'

import { jobResponseXmlToJson } from 'shared/parser/pipelineXmlConverter/jobResponseToJson'
import { propertiesXmlToJson } from 'shared/parser/pipelineXmlConverter/propertiesXmlToJson'
import { propertyToXml } from 'shared/parser/pipelineXmlConverter/propertyToXml'

//import fetch, { Response, RequestInit } from 'node-fetch'
//import { info, error } from 'electron-log'
Expand Down Expand Up @@ -176,4 +179,21 @@ export class PipelineAPI {
}
)
}
// New /admin/properties endpoint : https://github.com/daisy/pipeline-ui/issues/178
fetchProperties() {
return this.createPipelineFetchFunction(
(ws) => `${baseurl(ws)}/admin/properties`,
(text) => propertiesXmlToJson(text)
)
}
setProperty(prop: EngineProperty) {
return this.createPipelineFetchFunction(
(ws) => prop.href,
(text) => console.log(text),
{
method: 'PUT',
body: propertyToXml(prop),
}
)
}
}
13 changes: 13 additions & 0 deletions src/shared/data/slices/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Alive,
TtsVoice,
TtsEngineProperty,
EngineProperty,
} from 'shared/types'

import { RootState } from 'shared/types/store'
Expand All @@ -30,6 +31,7 @@ const initialState = {
internalJobCounter: 0,
selectedJobId: '',
alive: null,
properties: [],
} as PipelineState

export const pipeline = createSlice({
Expand All @@ -47,6 +49,8 @@ export const pipeline = createSlice({
if (param.payload.scripts) state.scripts = param.payload.scripts
if (param.payload.ttsVoices)
state.ttsVoices = param.payload.ttsVoices
if (param.payload.properties)
state.properties = param.payload.properties
},
/**
* Start the pipeline.
Expand Down Expand Up @@ -118,6 +122,12 @@ export const pipeline = createSlice({
) => {
state.ttsVoices = param.payload
},
setProperties: (
state: PipelineState,
param: PayloadAction<Array<EngineProperty>>
) => {
state.properties = param.payload
},
setJobs: (state: PipelineState, param: PayloadAction<Array<Job>>) => {
state.jobs = param.payload
},
Expand Down Expand Up @@ -301,6 +311,7 @@ export const {
selectPrevJob,
setAlive,
setTtsVoices,
setProperties,
} = pipeline.actions

export const selectors = {
Expand Down Expand Up @@ -341,6 +352,7 @@ export const selectors = {
selectScripts: (state: RootState) => state.pipeline.scripts,
selectDatatypes: (state: RootState) => state.pipeline.datatypes,
selectTtsVoices: (state: RootState) => state.pipeline.ttsVoices,
selectProperties: (state: RootState) => state.pipeline.properties,
newJob: (pipeline: PipelineState) =>
({
internalId: `job-${pipeline.internalJobCounter}`,
Expand Down Expand Up @@ -394,4 +406,5 @@ export const {
newJob,
prepareJobRequest,
selectTtsVoices,
selectProperties,
} = selectors
30 changes: 30 additions & 0 deletions src/shared/parser/pipelineXmlConverter/propertiesXmlToJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { EngineProperty } from 'shared/types'
import { parseXml } from './parser'

function propertyElementToJson(prop: Element): EngineProperty | null {
try {
return {
name: prop.getAttribute('name'),
desc: prop.getAttribute('desc'),
href: prop.getAttribute('href'),
value: prop.getAttribute('value'),
}
} catch (err) {
console.debug('propertyXmlToJson', err)
return null
}
}

function propertiesXmlToJson(xmlString: string): Array<EngineProperty> {
try {
let propertiesElement = parseXml(xmlString, 'properties')
return Array.from(
propertiesElement.getElementsByTagName('property')
).map((propElem: Element) => propertyElementToJson(propElem))
} catch (err) {
console.debug('propertiesXmlToJson', err)
return []
}
}

export { propertyElementToJson, propertiesXmlToJson }
16 changes: 16 additions & 0 deletions src/shared/parser/pipelineXmlConverter/propertyToXml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { EngineProperty } from 'shared/types'

/**
* Convert an EngineProperty to a proper xml string that can be used to update
* a property on the engine.
* @param {EngineProperty} prop the property to update
* @returns {string} an xml string that can be sent to a DP2 1.14.17+ engine for property
* update
*/
function propertyToXml(prop: EngineProperty): string {
return `<property xmlns="http://www.daisy.org/ns/pipeline/data" name="${
prop.name
}" value="${prop.value == null ? '' : prop.value}"/>`
}

export { propertyToXml }
50 changes: 9 additions & 41 deletions src/shared/types/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export type PipelineState = {
selectedJobId: string
datatypes?: Datatype[]
alive: Alive
properties?: Array<EngineProperty>
// messages: Array<string>
// errors: Array<string>
}

/**
* Properties for initializing ipc with the daisy pipeline 2
*
* TODO: rename this to explicit it is properties use on the pipeline js runner
* side (Note the pipeline engine itself)
*/
export type PipelineInstanceProperties = {
/**
Expand Down Expand Up @@ -100,47 +102,13 @@ export type PipelineInstanceProperties = {
}

/**
* Properties for running a DAISY pipeline instance.
* Properties managed by the underlying pipeline engine itself
*/
export interface PipelineInstanceProps {
/**
* optional path of the local installation of the pipeline,
*
* defaults to the application resources/daisy-pipeline
*/
localPipelineHome?: string

appDataFolder?: string

logsFolder?: string
/**
* optional path to the java runtime
*
* defaults to the application resource/jre folder
*/
jrePath?: string

/**
* Webservice configuration to use for embedded pipeline,
*
* defaults to a localhost managed configuration :
* ```js
* {
* host: "localhost"
* port: 0, // will search for an available port on the current host when calling launch() the first time
* path: "/ws"
* }
* ```
*
*/
webservice?: Webservice

/**
*
*/
onError?: (error: string) => void

onMessage?: (message: string) => void
export type EngineProperty = {
name: string
href: string
desc?: string
value?: string
}

export type Alive = {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PipelineInstanceProps, Webservice } from './pipeline'
import { PipelineInstanceProperties, Webservice } from './pipeline'
import { TtsConfig } from './ttsConfig'

export enum ColorScheme {
Expand All @@ -25,7 +25,7 @@ export type ApplicationSettings = {
// - Run or not a local pipeline server
runLocalPipeline?: boolean
// - Local pipeline settings
localPipelineProps?: PipelineInstanceProps
localPipelineProps?: PipelineInstanceProperties
// Remote pipeline settings
// - Use a remote pipeline instead of the local one
useRemotePipeline?: boolean
Expand Down

0 comments on commit b509c12

Please sign in to comment.