Skip to content

Commit

Permalink
Merge branch 'prototype/feathers-js' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	yarn.lock
  • Loading branch information
nytamin committed Oct 20, 2023
2 parents 5169d03 + e5e1733 commit 1a8135c
Show file tree
Hide file tree
Showing 35 changed files with 1,831 additions and 565 deletions.
6 changes: 6 additions & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
"@babel/core": "^7.22.1",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@feathersjs/errors": "^5.0.8",
"@feathersjs/feathers": "^5.0.8",
"@feathersjs/koa": "^5.0.8",
"@feathersjs/socketio": "^5.0.8",
"@feathersjs/socketio-client": "^5.0.8",
"@fontsource/barlow": "^4.5.9",
"@fontsource/barlow-condensed": "^4.5.9",
"@fontsource/barlow-semi-condensed": "^4.5.10",
Expand Down Expand Up @@ -110,6 +115,7 @@
"react-visibility-sensor": "^5.1.1",
"semver": "^7.5.0",
"short-uuid": "^4.2.2",
"socket.io-client": "^4.7.2",
"superfly-timeline": "^8.3.1",
"timeline-state-resolver-types": "^8.0.0",
"tiny-warning": "^1.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Project } from '../models/project/Project'
import { MetadataAny, ResourceAny, ResourceId, SerializedProtectedMap, TSRDeviceId } from '@shared/models'
import { Rundown } from '../models/rundown/Rundown'
import { PeripheralStatus } from '../models/project/Peripheral'
import { BrowserWindow } from 'electron'
import { IPCClientMethods, SystemMessageOptions } from '../ipc/IPCAPI'
import { AppData } from '../models/App/AppData'
import { ActiveTriggers } from '../models/rundown/Trigger'
Expand All @@ -12,58 +11,57 @@ import { ActiveAnalog } from '../models/rundown/Analog'
import { AnalogInput } from '../models/project/AnalogInput'
import { BridgeId } from '@shared/api'
import { BridgePeripheralId } from '@shared/lib'
import { EventEmitter } from 'stream'

/** This class is used server-side, to send messages to the client */
export class IPCClient implements IPCClientMethods {
constructor(private mainWindow: BrowserWindow) {}

// --- some of it might be needed, most of it hopefully not
export class ClientEventBus extends EventEmitter implements IPCClientMethods {
close(): void {
// Nothing here
}

systemMessage(message: string, options: SystemMessageOptions): void {
this.mainWindow?.webContents.send('callMethod', 'systemMessage', message, options)
this.emit('callMethod', 'systemMessage', message, options)
}
updateAppData(appData: AppData): void {
this.mainWindow?.webContents.send('callMethod', 'updateAppData', appData)
this.emit('callMethod', 'updateAppData', appData)
}
updateProject(project: Project): void {
this.mainWindow?.webContents.send('callMethod', 'updateProject', project)
this.emit('updateProject', project) // TODO: some type safety, please
}
updateRundown(fileName: string, rundown: Rundown): void {
this.mainWindow?.webContents.send('callMethod', 'updateRundown', fileName, rundown)
updateRundown(_fileName: string, rundown: Rundown): void {
this.emit('updateRundown', rundown) // TODO: some type safety, please
}
updateResourcesAndMetadata(
resources: Array<{ id: ResourceId; resource: ResourceAny | null }>,
metadata: SerializedProtectedMap<TSRDeviceId, MetadataAny | null>
): void {
this.mainWindow?.webContents.send('callMethod', 'updateResourcesAndMetadata', resources, metadata)
this.emit('callMethod', 'updateResourcesAndMetadata', resources, metadata)
}
updateBridgeStatus(id: BridgeId, status: BridgeStatus | null): void {
this.mainWindow?.webContents.send('callMethod', 'updateBridgeStatus', id, status)
this.emit('callMethod', 'updateBridgeStatus', id, status)
}
updatePeripheral(peripheralId: BridgePeripheralId, peripheral: PeripheralStatus | null): void {
this.mainWindow?.webContents.send('callMethod', 'updatePeripheral', peripheralId, peripheral)
this.emit('callMethod', 'updatePeripheral', peripheralId, peripheral)
}
updatePeripheralTriggers(peripheralTriggers: ActiveTriggers): void {
this.mainWindow?.webContents.send('callMethod', 'updatePeripheralTriggers', peripheralTriggers)
this.emit('callMethod', 'updatePeripheralTriggers', peripheralTriggers)
}
updatePeripheralAnalog(fullIdentifier: string, analog: ActiveAnalog | null): void {
this.mainWindow?.webContents.send('callMethod', 'updatePeripheralAnalog', fullIdentifier, analog)
this.emit('callMethod', 'updatePeripheralAnalog', fullIdentifier, analog)
}
updateDeviceRefreshStatus(deviceId: TSRDeviceId, refreshing: boolean): void {
this.mainWindow?.webContents.send('callMethod', 'updateDeviceRefreshStatus', deviceId, refreshing)
this.emit('callMethod', 'updateDeviceRefreshStatus', deviceId, refreshing)
}
displayAboutDialog(): void {
this.mainWindow?.webContents.send('callMethod', 'displayAboutDialog')
this.emit('callMethod', 'displayAboutDialog')
}
updateDefiningArea(definingArea: DefiningArea | null): void {
this.mainWindow?.webContents.send('callMethod', 'updateDefiningArea', definingArea)
this.emit('callMethod', 'updateDefiningArea', definingArea)
}
updateFailedGlobalTriggers(identifiers: string[]): void {
this.mainWindow?.webContents.send('callMethod', 'updateFailedGlobalTriggers', identifiers)
this.emit('callMethod', 'updateFailedGlobalTriggers', identifiers)
}
updateAnalogInput(fullIdentifier: string, analogInput: AnalogInput | null): void {
this.mainWindow?.webContents.send('callMethod', 'updateAnalogInput', fullIdentifier, analogInput)
this.emit('callMethod', 'updateAnalogInput', fullIdentifier, analogInput)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
} from '@shared/models'
import { assertNever, deepClone, getResourceIdFromTimelineObj, omit } from '@shared/lib'
import { TimelineObj } from '../models/rundown/TimelineObj'
import { Project } from '../models/project/Project'
import { Project, ProjectBase } from '../models/project/Project'
import { AppData } from '../models/App/AppData'
import EventEmitter from 'events'
import TypedEmitter from 'typed-emitter'
Expand Down Expand Up @@ -129,8 +129,11 @@ type ConvertToServerSide<T> = {
: T[K]
}

/** This class is used server-side, to handle requests from the client */
export class IPCServer
/**
* This class is used server-side, to handle requests from the client
* The methods in here will later be moved away to other Services
*/
export class EverythingService
extends (EventEmitter as new () => TypedEmitter<IPCServerEvents>)
implements ConvertToServerSide<IPCServerMethods>
{
Expand Down Expand Up @@ -160,7 +163,7 @@ export class IPCServer
}
) {
super()
for (const methodName of Object.getOwnPropertyNames(IPCServer.prototype)) {
for (const methodName of Object.getOwnPropertyNames(EverythingService.prototype)) {
if (methodName[0] !== '_') {
const fcn = (this as any)[methodName].bind(this)
if (fcn) {
Expand Down Expand Up @@ -204,7 +207,7 @@ export class IPCServer
public getProject(): Project {
return this.storage.getProject()
}
public getRundowns(): { rundownIds: string[] } {
private getRundowns(): { rundownIds: string[] } {
const rundowns = this.storage.getAllRundowns()
return { rundownIds: rundowns.map((r) => r.id) }
}
Expand All @@ -214,7 +217,7 @@ export class IPCServer

return { rundown }
}
public getGroup(arg: { rundownId: string; groupId: string }): { rundown: Rundown; group: Group } {
private getGroup(arg: { rundownId: string; groupId: string }): { rundown: Rundown; group: Group } {
const { rundown } = this.getRundown(arg)

return this._getGroupOfRundown(rundown, arg.groupId)
Expand All @@ -240,7 +243,7 @@ export class IPCServer
return { rundown, group }
}

public getPart(arg: { rundownId: string; groupId: string; partId: string }): {
private getPart(arg: { rundownId: string; groupId: string; partId: string }): {
rundown: Rundown
group: Group
part: Part
Expand All @@ -252,7 +255,7 @@ export class IPCServer
return { rundown, group, part }
}

public getPartByExternalId(arg: { rundownId: string; groupId: string; externalId: string }): {
private getPartByExternalId(arg: { rundownId: string; groupId: string; externalId: string }): {
rundown: Rundown
group: Group
part: Part
Expand Down Expand Up @@ -331,9 +334,6 @@ export class IPCServer

this.callbacks.onClientConnected()
}
async triggerSendRundown(arg: { rundownId: string }): Promise<void> {
this.storage.triggerEmitRundown(arg.rundownId)
}
async setKeyboardKeys(arg: { activeKeys: ActiveTrigger[] }): Promise<void> {
this.callbacks.setKeyboardKeys(arg.activeKeys)
}
Expand Down Expand Up @@ -367,6 +367,7 @@ export class IPCServer
}

async exportProject(): Promise<void> {
// TODO: this won't work, needs to return project to the WS client
const result = await dialog.showSaveDialog({
title: 'Export Project',
defaultPath: `${convertToFilename(this.storage.getProject().name) || 'SuperConductor'}.project.json`,
Expand All @@ -387,6 +388,7 @@ export class IPCServer
}
}
async importProject(): Promise<void> {
// TODO: this won't work, needs to return project to the WS client
const result = await dialog.showOpenDialog({
title: 'Import Project',
buttonLabel: 'Import',
Expand All @@ -412,8 +414,8 @@ export class IPCServer
}
}
}
async newProject(): Promise<void> {
await this.storage.newProject('New Project')
async newProject(): Promise<ProjectBase> {
return await this.storage.newProject('New Project')
}
async listProjects(): Promise<{ name: string; id: string }[]> {
return this.storage.listProjects()
Expand All @@ -422,23 +424,26 @@ export class IPCServer
return this.storage.openProject(arg.projectId)
}

async playPart(arg: { rundownId: string; groupId: string; partId: string }): Promise<void> {
async playPart(arg: { rundownId: string; groupId: string; partId: string }): Promise<Rundown> {
const now = Date.now()
const { rundown, group, part } = this.getPart(arg)

RundownActions.playPart(group, part, now)

this._saveUpdates({ rundownId: arg.rundownId, rundown, group })
return rundown // this should return something more granular (group or part)
}

async pausePart(arg: { rundownId: string; groupId: string; partId: string; time?: number }): Promise<void> {
async pausePart(arg: { rundownId: string; groupId: string; partId: string; time?: number }): Promise<Rundown> {
const now = Date.now()
const { rundown, group, part } = this.getPart(arg)
updateGroupPlayingParts(group)
RundownActions.pausePart(group, part, arg.time, now)

this._saveUpdates({ rundownId: arg.rundownId, rundown, group })
return rundown
}

async pauseParts(arg: { rundownId: string; groupId: string; partIds: string[]; time?: number }): Promise<void> {
const now = Date.now()
const { rundown, group } = this.getGroup({
Expand All @@ -458,14 +463,16 @@ export class IPCServer
this._saveUpdates({ rundownId: arg.rundownId, rundown, group })
}

async stopPart(arg: { rundownId: string; groupId: string; partId: string }): Promise<void> {
async stopPart(arg: { rundownId: string; groupId: string; partId: string }): Promise<Rundown> {
const now = Date.now()
const { rundown, group } = this.getGroup(arg)

RundownActions.stopPart(group, arg.partId, now)

this._saveUpdates({ rundownId: arg.rundownId, rundown, group })
return rundown
}

async setPartTrigger(arg: {
rundownId: string
groupId: string
Expand Down Expand Up @@ -2204,11 +2211,14 @@ export class IPCServer

this._saveUpdates({ appData })
}
async updateProject(arg: { id: string; project: Project }): Promise<void> {
async updateProject(arg: { id: string; project: Project }): Promise<Project> {
this._saveUpdates({ project: arg.project })

return this.storage.getProject()
}
async newRundown(arg: { name: string }): Promise<UndoableResult<string>> {
const fileName = this.storage.newRundown(arg.name)
async newRundown(arg: { name: string }): Promise<UndoableResult<Rundown>> {
const rundown = this.storage.newRundown(arg.name)
const fileName = rundown.name
this._saveUpdates({})

return {
Expand All @@ -2217,7 +2227,7 @@ export class IPCServer
this._saveUpdates({})
},
description: ActionDescription.NewRundown,
result: fileName,
result: rundown,
}
}
async deleteRundown(arg: { rundownId: string }): Promise<void> {
Expand Down
Loading

0 comments on commit 1a8135c

Please sign in to comment.