Skip to content

Commit

Permalink
wip: smoothify
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Feb 27, 2024
1 parent d6c0bd0 commit 967aa36
Show file tree
Hide file tree
Showing 26 changed files with 541 additions and 161 deletions.
25 changes: 23 additions & 2 deletions packages/apps/backend/src/api-server/services/ControllerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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'
import isEqual from 'lodash.isequal'

export type ControllerFeathersService = CustomFeathersService<Definition.Service, Definition.Events>

Expand Down Expand Up @@ -36,9 +37,10 @@ export class ControllerService extends EventEmitter<Definition.Events> implement
constructor(private log: LoggerInstance, private app: Application<ServiceTypes, any>, private store: Store) {
super()

// console.log('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
this.observers.push(
observe(this.store.controller.message, (change) => {
this.log.debug('observed change', change)
console.log('observed change', change)

if (change.type === 'add') {
this.emit('message', change.newValue)
Expand All @@ -54,12 +56,31 @@ export class ControllerService extends EventEmitter<Definition.Events> implement
obs()
}
}

private _hackyDebouncer: {
timestamp: number
message: Data | null
} = {
timestamp: 0,
message: null,
}
public async sendMessage(message: Data, _params?: Params): Promise<void> {
console.log('sendMessage', message)
const timeSinceLast = Date.now() - this._hackyDebouncer.timestamp

if (timeSinceLast < 100 && isEqual(this._hackyDebouncer.message, message)) {
// The same message was sent twice in rapid succession, ignore
return
}
this._hackyDebouncer = {
timestamp: Date.now(),
message,
}

this.store.controller.updateMessage(message)
}

public async subscribeToMessages(_: unknown, params: Params): Promise<void> {
console.log('subscribeToMessages')
if (!params.connection) throw new Error('No connection!')
this.app.channel(PublishChannels.ControllerMessages()).join(params.connection)
}
Expand Down
7 changes: 6 additions & 1 deletion packages/apps/backend/src/data-stores/ControllerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class ControllerStore {
public message = observable(
{
message: literal<ControllerMessage>({
offset: null,
speed: 0,
}),
},
Expand All @@ -20,6 +19,12 @@ export class ControllerStore {
})
}
updateMessage(message: ControllerMessage) {
// Persist speed if undefined,
// to allow for smooth jump while keeping the speed.
// if (message.speed === undefined) {
// message.speed = this.message.message.speed
// }

this.message.message = message
}
}
3 changes: 2 additions & 1 deletion packages/apps/backend/src/data-stores/ViewPortStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export class ViewPortStore {
_id: '',

lastKnownState: {
controllerMessage: {
state: {
offset: {
offset: 0,
target: null,
},
speed: 0,
animatedOffset: 0,
},
timestamp: getCurrentTime(),
},
Expand Down
7 changes: 4 additions & 3 deletions packages/apps/backend/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ export async function getConfigOptions(): Promise<ConfigOptions> {

return {
logLevel: argv.logLevel,
unsafeSSL: argv.unsafeSSL,
unsafeSSL: true, //argv.unsafeSSL,
certificates: ((argv.certificates || process.env.CERTIFICATES || '').split(';') || []).filter(Boolean),

noCore: argv.noCore,
coreHost: argv.coreHost,
corePort: argv.corePort,
// nocommit hack
coreHost: 'malxsofietest01', // argv.coreHost,
corePort: 443, // argv.corePort,
deviceId: argv.deviceId,
deviceToken: argv.deviceToken,
}
Expand Down
4 changes: 3 additions & 1 deletion packages/apps/client/src/components/RundownOutput/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const Line = observer(function Line({ line }: { line: UILine }): React.Re

return (
<>
<h3 data-obj-id={line.id}>{line.slug}</h3>
<h3 data-obj-id={line.id} data-anchor="line">
{line.slug}
</h3>
{!script ? <p>&nbsp;</p> : isMdIsh ? <MdDisplay source={script} /> : <TextDisplay source={script} />}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { Segment } from './Segment'
export const RundownOutput = observer(function RundownOutput({ rundown }: { rundown: UIRundown }): React.ReactNode {
return (
<div className={classes.RundownOutput}>
<h1 data-obj-id={rundown.id}>{rundown.name}</h1>
<h1 data-obj-id={rundown.id} data-anchor="rundown">
{rundown.name}
</h1>
{rundown.segmentsInOrder.map((segment) => (
<Segment key={segment.id} segment={segment} />
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { Line } from './Line'
export const Segment = observer(function Segment({ segment }: { segment: UISegment }): React.ReactElement {
return (
<>
<h2 data-obj-id={segment.id}>{segment.name}</h2>
<h2 data-obj-id={segment.id} data-anchor="segment">
{segment.name}
</h2>
{segment.linesInOrder.map((line) => (
<Line key={line.id} line={line} />
))}
Expand Down
Loading

0 comments on commit 967aa36

Please sign in to comment.