Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jan 11, 2024
1 parent e812222 commit ceede14
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 192 deletions.
17 changes: 15 additions & 2 deletions packages/apps/backend/src/api-server/services/PartService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,21 @@ export class PartService extends EventEmitter<Definition.Events> implements Defi
}
}

public async find(_params?: Params & { paginate?: PaginationParams }): Promise<Data[]> {
return Array.from(this.store.parts.parts.values())
public async find(params?: Params & { paginate?: PaginationParams }): Promise<Data[]> {
let parts = Array.from(this.store.parts.parts.values())
if (params?.query?.playlistId) {
const playlistId = params.query.playlistId
parts = parts.filter((p) => p.playlistId === playlistId)
}
if (params?.query?.rundownId) {
const rundownId = params.query.rundownId
parts = parts.filter((p) => p.rundownId === rundownId)
}
if (params?.query?.segmentId) {
const segmentId = params.query.segmentId
parts = parts.filter((p) => p.segmentId === segmentId)
}
return parts
}
public async get(id: Id, _params?: Params): Promise<Data> {
const data = this.store.parts.parts.get(id)
Expand Down
17 changes: 15 additions & 2 deletions packages/apps/backend/src/api-server/services/RundownService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ export class RundownService extends EventEmitter<Definition.Events> implements D
}
}

public async find(_params?: Params & { paginate?: PaginationParams }): Promise<Data[]> {
return Array.from(this.store.rundowns.rundowns.values())
public async find(params?: Params & { paginate?: PaginationParams }): Promise<Data[]> {
// console.log('FIND', _params)

let rundowns = Array.from(this.store.rundowns.rundowns.values())
if (params?.query?.playlistId) {
const playlistId = params.query.playlistId
rundowns = rundowns.filter((r) => r.playlistId === playlistId)
}
return rundowns
}
public async get(id: Id, _params?: Params): Promise<Data> {
const data = this.store.rundowns.rundowns.get(id)
Expand Down Expand Up @@ -110,6 +117,12 @@ export class RundownService extends EventEmitter<Definition.Events> implements D
this.app.channel(PublishChannels.RundownsInPlaylist(playlistId)).join(params.connection)
this.coreConnection?.subscribeToPlaylist(playlistId)
}
public async unSubscribefromRundownsInPlaylist(playlistId: RundownPlaylistId, params: Params): Promise<void> {
if (!params.connection) throw new Error('No connection!')

this.app.channel(PublishChannels.RundownsInPlaylist(playlistId)).leave(params.connection)
this.coreConnection?.subscribeToPlaylist(playlistId)
}
}
type Result = Definition.Result
type Id = Definition.Id
Expand Down
13 changes: 11 additions & 2 deletions packages/apps/backend/src/api-server/services/SegmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,17 @@ export class SegmentService extends EventEmitter<Definition.Events> implements D
}
}

public async find(_params?: Params & { paginate?: PaginationParams }): Promise<Data[]> {
return Array.from(this.store.segments.segments.values())
public async find(params?: Params & { paginate?: PaginationParams }): Promise<Data[]> {
let segments = Array.from(this.store.segments.segments.values())
if (params?.query?.playlistId) {
const playlistId = params.query.playlistId
segments = segments.filter((s) => s.playlistId === playlistId)
}
if (params?.query?.rundownId) {
const rundownId = params.query.rundownId
segments = segments.filter((s) => s.rundownId === rundownId)
}
return segments
}
public async get(id: Id, _params?: Params): Promise<Data> {
const data = this.store.segments.segments.get(id)
Expand Down
1 change: 1 addition & 0 deletions packages/apps/backend/src/data-stores/SegmentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Segment, SegmentId } from '@sofie-prompter-editor/shared-model'
export class SegmentStore {
public readonly segments = observable.map<SegmentId, Segment>()

public tmp = 0
constructor() {
makeObservable(this, {
create: action,
Expand Down
51 changes: 27 additions & 24 deletions packages/apps/client/src/BackendPlayground/BackendPlayground.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import React, { useContext } from 'react'
import { TestInterface } from '../TestInterface'
import { TestPlaylists } from '../TestPlaylists'
import { APIConnectionContext } from '../api/ApiConnectionContext'
import { TestController } from '../TestController.tsx'
import { TestViewPort } from '../TestViewPort.tsx'
import React from 'react'
// import { TestInterface } from '../TestInterface'
// import { TestPlaylists } from '../TestPlaylists'
// import { APIConnectionContext } from '../api/ApiConnectionContext'
// import { TestController } from '../TestController.tsx'
// import { TestViewPort } from '../TestViewPort.tsx'
// import { api } from '../stores/AppStore.ts'

export function BackendPlayground(): React.JSX.Element {
const api = useContext(APIConnectionContext)
export function BackendPlayground(): React.JSX.Element | null {
// const api = useContext(APIConnectionContext)

return (
<>
<div>
<TestInterface api={api} />
</div>
<div>
<TestController api={api} />
</div>
<div>
<TestViewPort api={api} />
</div>
<div>
<TestPlaylists api={api} />
</div>
</>
)
return null

// return (
// <>
// <div>
// <TestInterface api={api} />
// </div>
// <div>
// <TestController api={api} />
// </div>
// <div>
// <TestViewPort api={api} />
// </div>
// <div>
// <TestPlaylists api={api} />
// </div>
// </>
// )
}
2 changes: 1 addition & 1 deletion packages/apps/client/src/RundownList/RundownEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const RundownEntry = observer(({ rundownId }: { rundownId: UIRundownId })

const onOpen = () => {
if (!rundownEntry) return
navigate(`/rundown/${rundownEntry.playlistId}`)
navigate(`/rundown/${rundownEntry.id}`)
}

return (
Expand Down
6 changes: 3 additions & 3 deletions packages/apps/client/src/TestPlaylists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const TestPlaylists: React.FC<{ api: APIConnection }> = ({ api }) => {
api.playlist.on('updated', (data) => {
updatePlaylists(data._id, () => data)
})
api.playlist.on('removed', (id) => {
updatePlaylists(id, () => null)
})
// api.playlist.on('patched', (data) => {
// updatePlaylists(data._id, (prev) => {
// if (!prev) {
Expand All @@ -69,9 +72,6 @@ export const TestPlaylists: React.FC<{ api: APIConnection }> = ({ api }) => {
// }
// })
// })
api.playlist.on('removed', (id) => {
updatePlaylists(id, () => null)
})

// Also fetch initial list:
api.playlist
Expand Down
68 changes: 34 additions & 34 deletions packages/apps/client/src/api/ApiConnectionContext.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import React from 'react'
import { APIConnection } from './ApiConnection'
import { assertType } from '@sofie-prompter-editor/shared-lib'
import { RundownPlaylist, RundownPlaylistId } from '@sofie-prompter-editor/shared-model'
// import React from 'react'
// import { APIConnection } from './ApiConnection'
// import { assertType } from '@sofie-prompter-editor/shared-lib'
// import { RundownPlaylist, RundownPlaylistId } from '@sofie-prompter-editor/shared-model'

const api = new APIConnection()
api.on('connected', () => console.log('connected'))
api.on('disconnected', () => console.log('disconnected'))
// const api = new APIConnection()
// api.on('connected', () => console.log('connected'))
// api.on('disconnected', () => console.log('disconnected'))

api.playlist.on('tmpPong', (payload) => {
assertType<string>(payload)
console.log(`Got a tmpPong message: "${payload}"`)
})
api.playlist.on('created', (payload) => {
assertType<RundownPlaylist>(payload)
console.log(`playlist created: "${JSON.stringify(payload)}"`)
})
// api.playlist.on('patched', (payload) => {
// assertType<Partial<RundownPlaylist>>(payload)
// console.log(`playlist patched: "${JSON.stringify(payload)}"`)
// api.playlist.on('tmpPong', (payload) => {
// assertType<string>(payload)
// console.log(`Got a tmpPong message: "${payload}"`)
// })
// api.playlist.on('created', (payload) => {
// assertType<RundownPlaylist>(payload)
// console.log(`playlist created: "${JSON.stringify(payload)}"`)
// })
// // api.playlist.on('patched', (payload) => {
// // assertType<Partial<RundownPlaylist>>(payload)
// // console.log(`playlist patched: "${JSON.stringify(payload)}"`)
// // })
// api.playlist.on('updated', (payload) => {
// assertType<RundownPlaylist>(payload)
// console.log(`playlist updated: "${JSON.stringify(payload)}"`)
// })
// api.playlist.on('removed', (id) => {
// assertType<RundownPlaylistId>(id)
// console.log(`playlist removed: "${id}"`)
// })
// api.example.on('pongGeneric', (payload) => {
// assertType<string>(payload)
// console.log(`Got a pongGeneric message: "${payload}"`)
// })
// api.example.on('pongCategory', (message) => {
// console.log(`Got a pongCategory "${message.category}" message: "${message.payload}"`)
// })
api.playlist.on('updated', (payload) => {
assertType<RundownPlaylist>(payload)
console.log(`playlist updated: "${JSON.stringify(payload)}"`)
})
api.playlist.on('removed', (id) => {
assertType<RundownPlaylistId>(id)
console.log(`playlist removed: "${id}"`)
})
api.example.on('pongGeneric', (payload) => {
assertType<string>(payload)
console.log(`Got a pongGeneric message: "${payload}"`)
})
api.example.on('pongCategory', (message) => {
console.log(`Got a pongCategory "${message.category}" message: "${message.payload}"`)
})

export const APIConnectionContext = React.createContext<APIConnection>(api)
// export const APIConnectionContext = React.createContext<APIConnection>(api)
31 changes: 31 additions & 0 deletions packages/apps/client/src/backendConnection/BackendConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import EventEmitter from 'eventemitter3'

export type BackendConnectionEvents = {
connected: []
disconnected: []
}
export class BackendConnection extends EventEmitter<BackendConnectionEvents> {

public readonly playlist: FeathersTypedService<PlaylistServiceDefinition.Service>

constructor() {
super()
}

// playlist = {
// find: async (args?: Query<RundownPlaylist>): Promise<RundownPlaylist[]> => {
// await sleep(500)
// return this._playlists.filter((playlist) => !args || match(playlist, args.query))
// },
// get: async (id: RundownPlaylistId): Promise<RundownPlaylist | undefined> => {
// await sleep(500)
// return this._playlists.find((item) => item._id === id)
// },
// on: (type: EventTypes, fn: Handler) => {
// this.on(`playlist_${type}`, fn)
// },
// off: (type: EventTypes, fn: Handler) => {
// this.off(`playlist_${type}`, fn)
// },
// }
}
11 changes: 6 additions & 5 deletions packages/apps/client/src/mocks/mockConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const START_TIME = Date.now()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Handler<T = any> = (arg: T) => void

type EventTypes = 'created' | 'changed' | 'removed'
type EventTypes = 'created' | 'updated' | 'removed'
type Services = 'playlist' | 'rundown' | 'segment' | 'part'

type Events = `${Services}_${EventTypes}` | 'connected' | 'disconnected'
Expand Down Expand Up @@ -84,6 +84,7 @@ export class MockConnection extends EventEmitter<Events> {
off: (type: EventTypes, fn: Handler) => {
this.off(`playlist_${type}`, fn)
},
subscribeToPlaylists: () => {},
}

private _rundowns = [
Expand Down Expand Up @@ -160,7 +161,7 @@ export class MockConnection extends EventEmitter<Events> {
},
}

private _parts: Part[] = [
private _part: Part[] = [
{
_id: PART_ID_0_0_0,
label: 'Part 0',
Expand Down Expand Up @@ -329,14 +330,14 @@ export class MockConnection extends EventEmitter<Events> {
},
]

parts = {
part = {
find: async (args?: Query<Part>): Promise<Part[]> => {
await sleep(500)
return this._parts.filter((part) => !args || match(part as unknown as { [s: string]: unknown }, args.query))
return this._part.filter((part) => !args || match(part as unknown as { [s: string]: unknown }, args.query))
},
get: async (id: PartId): Promise<Part | undefined> => {
await sleep(500)
return this._parts.find((item) => item._id === id)
return this._part.find((item) => item._id === id)
},
on: (type: EventTypes, fn: Handler<Part>) => {
this.on(`part_${type}`, fn)
Expand Down
17 changes: 5 additions & 12 deletions packages/apps/client/src/model/UILine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,20 @@ export class UILine {

ready: boolean = false

constructor(
private store: RundownStore,
private owner: UISegment,
public partId: PartId,
public id = protectString<UILineId>(randomId())
) {
constructor(private store: RundownStore, private owner: UISegment, public id: PartId) {
makeAutoObservable(this, {
updateFromJson: action,
remove: action,
})

this.store.connection.parts.on('changed', (json: Part) => {
if (this.partId !== json._id) return
this.store.connection.part.on('updated', (json: Part) => {
if (this.id !== json._id) return

this.updateFromJson(json)
})

this.store.connection.parts.on('removed', (json: Part) => {
if (this.partId !== json._id) return
this.store.connection.part.on('removed', (json) => {
if (this.id !== json._id) return

this.remove()
})
Expand Down Expand Up @@ -72,8 +67,6 @@ export class UILine {
dispose() {}
}

export type UILineId = ProtectedString<'UILineId', string>

function partDisplayTypeToLineTypeStyle(type: PartDisplayType): LineType {
switch (type) {
case PartDisplayType.Camera:
Expand Down
Loading

0 comments on commit ceede14

Please sign in to comment.