-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add PromperSettingsService and ViewPortService
- Loading branch information
Showing
46 changed files
with
1,014 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/apps/backend/src/api-server/services/PrompterSettingsService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import EventEmitter from 'eventemitter3' | ||
import { Application, PaginationParams, Params } from '@feathersjs/feathers' | ||
import { | ||
ServiceTypes, | ||
Services, | ||
PrompterSettingsServiceDefinition as Definition, | ||
} from '@sofie-prompter-editor/shared-model' | ||
export { PlaylistServiceDefinition } from '@sofie-prompter-editor/shared-model' | ||
import { PublishChannels } from '../PublishChannels.js' | ||
import { CustomFeathersService } from './lib.js' | ||
import { Store } from '../../data-stores/Store.js' | ||
import { Lambda, observe } from 'mobx' | ||
import { LoggerInstance } from '../../lib/logger.js' | ||
import { BadRequest, NotFound, NotImplemented } from '@feathersjs/errors' | ||
|
||
export type PrompterSettingsFeathersService = CustomFeathersService<Definition.Service, Definition.Events> | ||
|
||
/** The methods exposed by this class are exposed in the API */ | ||
export class PrompterSettingsService extends EventEmitter<Definition.Events> implements Definition.Service { | ||
static setupService( | ||
log: LoggerInstance, | ||
app: Application<ServiceTypes, any>, | ||
store: Store | ||
): PrompterSettingsFeathersService { | ||
app.use( | ||
Services.PrompterSettings, | ||
new PrompterSettingsService(log.category('PrompterSettingsService'), app, store), | ||
{ | ||
methods: Definition.ALL_METHODS, | ||
serviceEvents: Definition.ALL_EVENTS, | ||
} | ||
) | ||
const service = app.service(Services.PrompterSettings) as PrompterSettingsFeathersService | ||
this.setupPublications(app, service) | ||
return service | ||
} | ||
private static setupPublications(app: Application<ServiceTypes, any>, service: PrompterSettingsFeathersService) { | ||
service.publish('created', (_data, _context) => { | ||
return app.channel(PublishChannels.Controller()) | ||
}) | ||
service.publish('updated', (_data, _context) => { | ||
return app.channel(PublishChannels.Controller()) | ||
}) | ||
} | ||
|
||
private observers: Lambda[] = [] | ||
constructor(private log: LoggerInstance, private app: Application<ServiceTypes, any>, private store: Store) { | ||
super() | ||
|
||
this.observers.push( | ||
observe(this.store.prompterSettings.prompterSettings, (change) => { | ||
this.log.debug('observed change', change) | ||
|
||
if (change.type === 'add') { | ||
this.emit('created', change.newValue) | ||
} else if (change.type === 'update') { | ||
this.emit('updated', change.newValue) | ||
} | ||
}) | ||
) | ||
} | ||
destroy() { | ||
// dispose of observers: | ||
for (const obs of this.observers) { | ||
obs() | ||
} | ||
} | ||
|
||
public async find(_params?: Params & { paginate?: PaginationParams }): Promise<Data[]> { | ||
return [this.store.prompterSettings.prompterSettings] | ||
} | ||
public async get(id: Id, _params?: Params): Promise<Data> { | ||
const data = this.store.prompterSettings.prompterSettings | ||
if (!data) throw new NotFound(`PrompterSettings "${id}" not found`) | ||
return data | ||
} | ||
public async create(_data: Data, _params?: Params): Promise<Result> { | ||
throw new NotImplemented(`TODO`) | ||
} | ||
public async update(id: NullId, data: Data, _params?: Params): Promise<Result> { | ||
if (id === null) throw new BadRequest(`id must not be null`) | ||
|
||
this.store.prompterSettings.update(data) | ||
return this.get('') | ||
} | ||
|
||
public async subscribeToController(_: unknown, params: Params): Promise<void> { | ||
if (!params.connection) throw new Error('No connection!') | ||
this.app.channel(PublishChannels.Controller()).join(params.connection) | ||
} | ||
} | ||
type Result = Definition.Result | ||
type Id = Definition.Id | ||
type NullId = Definition.NullId | ||
type Data = Definition.Data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/apps/backend/src/api-server/services/ViewPortService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import EventEmitter from 'eventemitter3' | ||
import { Application, PaginationParams, Params } from '@feathersjs/feathers' | ||
import { ServiceTypes, Services, ViewPortServiceDefinition as Definition } from '@sofie-prompter-editor/shared-model' | ||
import { PublishChannels } from '../PublishChannels.js' | ||
import { CustomFeathersService } from './lib.js' | ||
import { Store } from '../../data-stores/Store.js' | ||
import { Lambda, observe } from 'mobx' | ||
import { LoggerInstance } from '../../lib/logger.js' | ||
import { BadRequest, NotFound } from '@feathersjs/errors' | ||
|
||
export type ViewPortFeathersService = CustomFeathersService<Definition.Service, Definition.Events> | ||
|
||
/** The methods exposed by this class are exposed in the API */ | ||
export class ViewPortService extends EventEmitter<Definition.Events> implements Definition.Service { | ||
static setupService(log: LoggerInstance, app: Application<ServiceTypes, any>, store: Store): ViewPortFeathersService { | ||
app.use(Services.ViewPort, new ViewPortService(log.category('ViewPortService'), app, store), { | ||
methods: Definition.ALL_METHODS, | ||
serviceEvents: Definition.ALL_EVENTS, | ||
}) | ||
const service = app.service(Services.ViewPort) as ViewPortFeathersService | ||
this.setupPublications(app, service) | ||
return service | ||
} | ||
private static setupPublications(app: Application<ServiceTypes, any>, service: ViewPortFeathersService) { | ||
service.publish('created', (_data, _context) => { | ||
return app.channel(PublishChannels.ViewPort()) | ||
}) | ||
service.publish('updated', (_data, _context) => { | ||
return app.channel(PublishChannels.ViewPort()) | ||
}) | ||
service.publish('removed', (_data, _context) => { | ||
return app.channel(PublishChannels.ViewPort()) | ||
}) | ||
} | ||
|
||
private observers: Lambda[] = [] | ||
constructor(private log: LoggerInstance, private app: Application<ServiceTypes, any>, private store: Store) { | ||
super() | ||
|
||
this.observers.push( | ||
observe(this.store.viewPort.viewPort, (change) => { | ||
this.log.debug('observed change', change) | ||
|
||
if (change.type === 'add') { | ||
this.emit('created', change.newValue) | ||
} else if (change.type === 'update') { | ||
this.emit('updated', change.newValue) | ||
} else if (change.type === 'remove') { | ||
this.emit('removed', { | ||
_id: change.oldValue._id, | ||
}) | ||
} | ||
}) | ||
) | ||
} | ||
destroy() { | ||
// dispose of observers: | ||
for (const obs of this.observers) { | ||
obs() | ||
} | ||
} | ||
|
||
public async find(_params?: Params & { paginate?: PaginationParams }): Promise<Data[]> { | ||
return [this.store.viewPort.viewPort] | ||
} | ||
public async get(id: Id, _params?: Params): Promise<Data> { | ||
const data = this.store.viewPort.viewPort | ||
if (!data) throw new NotFound(`ViewPort "${id}" not found`) | ||
return data | ||
} | ||
public async update(id: NullId, data: Data, _params?: Params): Promise<Result> { | ||
if (id === null) throw new BadRequest(`id must not be null`) | ||
if (id !== data._id) throw new BadRequest(`Cannot change id of ViewPort`) | ||
|
||
this.store.viewPort.update(data) | ||
return this.get(data._id) | ||
} | ||
|
||
public async registerInstance(instanceId: string, _params?: Params): Promise<boolean> { | ||
return this.store.viewPort.registerInstance(instanceId) | ||
} | ||
|
||
public async subscribeToViewPort(_: unknown, params: Params): Promise<void> { | ||
if (!params.connection) throw new Error('No connection!') | ||
this.app.channel(PublishChannels.ViewPort()).join(params.connection) | ||
} | ||
} | ||
|
||
type Result = Definition.Result | ||
type Id = Definition.Id | ||
type NullId = Definition.NullId | ||
type Data = Definition.Data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/apps/backend/src/data-stores/PrompterSettingsStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { action, makeAutoObservable, observable } from 'mobx' | ||
import isEqual from 'lodash.isequal' | ||
import { PrompterSettings } from 'packages/shared/model/dist' | ||
|
||
export class PrompterSettingsStore { | ||
public prompterSettings = observable<PrompterSettings>({ | ||
// TODO: load these from persistent store upon startup? | ||
fontSize: 10, | ||
|
||
mirrorHorizontally: false, | ||
mirrorVertically: false, | ||
|
||
focusPosition: 'center', | ||
showFocusPosition: false, | ||
|
||
marginHorizontal: 5, | ||
marginVertical: 5, | ||
}) | ||
|
||
constructor() { | ||
makeAutoObservable(this, { | ||
create: action, | ||
update: action, | ||
}) | ||
} | ||
|
||
create(part: PrompterSettings) { | ||
this._updateIfChanged(part) | ||
} | ||
update(part: PrompterSettings) { | ||
this._updateIfChanged(part) | ||
} | ||
|
||
private _updateIfChanged(prompterSettings: PrompterSettings) { | ||
if (!isEqual(this.prompterSettings, prompterSettings)) { | ||
this.prompterSettings = prompterSettings | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { PartStore } from './PartStore.js' | ||
import { PlaylistStore } from './PlaylistStore.js' | ||
import { PrompterSettingsStore } from './PrompterSettingsStore.js' | ||
import { RundownStore } from './RundownStore.js' | ||
import { SegmentStore } from './SegmentStore.js' | ||
import { ViewPortStore } from './ViewPortStore.js' | ||
|
||
export class Store { | ||
public playlists = new PlaylistStore() | ||
public rundowns = new RundownStore() | ||
public segments = new SegmentStore() | ||
public parts = new PartStore() | ||
public viewPort = new ViewPortStore() | ||
public prompterSettings = new PrompterSettingsStore() | ||
} |
Oops, something went wrong.