Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: typed publications in gateways/peripheraldevices SOFIE-1183 #1056

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions meteor/client/lib/ConnectionStatusNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { WithManagedTracker } from './reactiveData/reactiveDataHelper'
import { withTranslation } from 'react-i18next'
import { NotificationCenterPopUps } from './notifications/NotificationCenterPanel'
import { PubSub } from '../../lib/api/pubsub'
import { MeteorPubSub } from '../../lib/api/pubsub'
import { ICoreSystem, ServiceMessage, Criticality } from '../../lib/collections/CoreSystem'
import { TFunction } from 'react-i18next'
import { getRandomId } from '@sofie-automation/corelib/dist/lib'
Expand All @@ -31,7 +31,7 @@ export class ConnectionStatusNotifier extends WithManagedTracker {
constructor(t: TFunction) {
super()

this.subscribe(PubSub.coreSystem)
this.subscribe(MeteorPubSub.coreSystem)

this._translator = t

Expand Down
7 changes: 5 additions & 2 deletions meteor/client/lib/MeteorReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as React from 'react'
import { stringifyObjects } from '../../lib/lib'
import { Meteor } from 'meteor/meteor'
import { PubSubTypes } from '../../lib/api/pubsub'
import { AllPubSubTypes } from '../../lib/api/pubsub'

Check warning on line 5 in meteor/client/lib/MeteorReactComponent.ts

View check run for this annotation

Codecov / codecov/patch

meteor/client/lib/MeteorReactComponent.ts#L5

Added line #L5 was not covered by tests
import { catchError } from './lib'
export class MeteorReactComponent<IProps, IState = {}> extends React.Component<IProps, IState> {
private _subscriptions: { [id: string]: Meteor.SubscriptionHandle } = {}
Expand All @@ -14,7 +14,10 @@
componentWillUnmount(): void {
this._cleanUp()
}
subscribe<K extends keyof PubSubTypes>(name: K, ...args: Parameters<PubSubTypes[K]>): Meteor.SubscriptionHandle {
subscribe<K extends keyof AllPubSubTypes>(
name: K,
...args: Parameters<AllPubSubTypes[K]>
): Meteor.SubscriptionHandle {

Check warning on line 20 in meteor/client/lib/MeteorReactComponent.ts

View check run for this annotation

Codecov / codecov/patch

meteor/client/lib/MeteorReactComponent.ts#L17-L20

Added lines #L17 - L20 were not covered by tests
return Tracker.nonreactive(() => {
// let id = name + '_' + JSON.stringify(args.join())
const id = name + '_' + stringifyObjects(args)
Expand Down
11 changes: 7 additions & 4 deletions meteor/client/lib/ReactMeteorData/ReactMeteorData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Mongo } from 'meteor/mongo'
import { Tracker } from 'meteor/tracker'
import { withTranslation, WithTranslation } from 'react-i18next'
import { MeteorReactComponent } from '../MeteorReactComponent'
import { meteorSubscribe, PubSubTypes } from '../../../lib/api/pubsub'
import { meteorSubscribe, AllPubSubTypes } from '../../../lib/api/pubsub'
import { stringifyObjects } from '../../../lib/lib'

const globalTrackerQueue: Array<Function> = []
Expand Down Expand Up @@ -340,7 +340,10 @@ export function useTracker<T, K extends undefined | T = undefined>(
* @param {...any[]} args A list of arugments for the subscription. This is used for optimizing the subscription across
* renders so that it isn't torn down and created for every render.
*/
export function useSubscription<K extends keyof PubSubTypes>(sub: K, ...args: Parameters<PubSubTypes[K]>): boolean {
export function useSubscription<K extends keyof AllPubSubTypes>(
sub: K,
...args: Parameters<AllPubSubTypes[K]>
): boolean {
const [ready, setReady] = useState<boolean>(false)

useEffect(() => {
Expand All @@ -359,9 +362,9 @@ export function useSubscription<K extends keyof PubSubTypes>(sub: K, ...args: Pa
/**
* Sets up multiple subscriptions of the same type, but with different arguments
*/
export function useSubscriptions<K extends keyof PubSubTypes>(
export function useSubscriptions<K extends keyof AllPubSubTypes>(
sub: K,
argsArray: Parameters<PubSubTypes[K]>[]
argsArray: Parameters<AllPubSubTypes[K]>[]
): boolean {
const [ready, setReady] = useState<boolean>(false)

Expand Down
4 changes: 2 additions & 2 deletions meteor/client/lib/reactiveData/reactiveDataHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tracker } from 'meteor/tracker'
import { meteorSubscribe, PubSubTypes } from '../../../lib/api/pubsub'
import { meteorSubscribe, AllPubSubTypes } from '../../../lib/api/pubsub'
import { Meteor } from 'meteor/meteor'

/**
Expand Down Expand Up @@ -70,7 +70,7 @@
return this._subs.every((e) => e.ready())
}

protected subscribe<K extends keyof PubSubTypes>(sub: K, ...args: Parameters<PubSubTypes[K]>): void {
protected subscribe<K extends keyof AllPubSubTypes>(sub: K, ...args: Parameters<AllPubSubTypes[K]>): void {

Check warning on line 73 in meteor/client/lib/reactiveData/reactiveDataHelper.ts

View check run for this annotation

Codecov / codecov/patch

meteor/client/lib/reactiveData/reactiveDataHelper.ts#L73

Added line #L73 was not covered by tests
this._subs.push(meteorSubscribe(sub, ...args))
}

Expand Down
19 changes: 10 additions & 9 deletions meteor/client/lib/triggers/TriggersHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react'
import { TFunction } from 'i18next'
import { useTranslation } from 'react-i18next'
import Sorensen from '@sofie-automation/sorensen'
import { PubSub } from '../../../lib/api/pubsub'
import { MeteorPubSub } from '../../../lib/api/pubsub'
import { useSubscription, useTracker } from '../ReactMeteorData/ReactMeteorData'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { PlayoutActions, SomeAction, SomeBlueprintTrigger, TriggerType } from '@sofie-automation/blueprints-integration'
Expand Down Expand Up @@ -43,6 +43,7 @@ import { isHotkeyTrigger } from '../../../lib/api/triggers/triggerTypeSelectors'
import { RundownPlaylistCollectionUtil } from '../../../lib/collections/rundownPlaylistUtil'
import { catchError } from '../lib'
import { logger } from '../../../lib/logging'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'

type HotkeyTriggerListener = (e: KeyboardEvent) => void

Expand Down Expand Up @@ -72,32 +73,32 @@ function useSubscriptions(
showStyleBaseId: ShowStyleBaseId
) {
const allReady = [
useSubscription(PubSub.rundownPlaylists, {
useSubscription(CorelibPubSub.rundownPlaylists, {
_id: rundownPlaylistId,
}),
useSubscription(PubSub.rundowns, [rundownPlaylistId], null),
useSubscription(CorelibPubSub.rundowns, [rundownPlaylistId], null),

useSubscription(PubSub.adLibActions, {
useSubscription(CorelibPubSub.adLibActions, {
rundownId: {
$in: rundownIds,
},
}),
useSubscription(PubSub.adLibPieces, {
useSubscription(CorelibPubSub.adLibPieces, {
rundownId: {
$in: rundownIds,
},
}),
useSubscription(PubSub.rundownBaselineAdLibActions, {
useSubscription(CorelibPubSub.rundownBaselineAdLibActions, {
rundownId: {
$in: rundownIds,
},
}),
useSubscription(PubSub.rundownBaselineAdLibPieces, {
useSubscription(CorelibPubSub.rundownBaselineAdLibPieces, {
rundownId: {
$in: rundownIds,
},
}),
useSubscription(PubSub.uiShowStyleBase, showStyleBaseId),
useSubscription(MeteorPubSub.uiShowStyleBase, showStyleBaseId),
]

return !allReady.some((state) => state === false)
Expand Down Expand Up @@ -371,7 +372,7 @@ export const TriggersHandler: React.FC<IProps> = function TriggersHandler(
JSON.stringify(props.nextSegmentPartIds),
])

const triggerSubReady = useSubscription(PubSub.uiTriggeredActions, props.showStyleBaseId)
const triggerSubReady = useSubscription(MeteorPubSub.uiTriggeredActions, props.showStyleBaseId)

const rundownIds =
useTracker(() => {
Expand Down
4 changes: 2 additions & 2 deletions meteor/client/ui/Account/OrganizationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Translated, translateWithTracker } from '../../lib/ReactMeteorData/reac
import { MeteorReactComponent } from '../../lib/MeteorReactComponent'
import { getUser, User, getUserRoles, DBUser } from '../../../lib/collections/Users'
import { Spinner } from '../../lib/Spinner'
import { PubSub } from '../../../lib/api/pubsub'
import { MeteorPubSub } from '../../../lib/api/pubsub'
import { DBOrganization, UserRoles } from '../../../lib/collections/Organization'
import { unprotectString } from '../../../lib/lib'
import { MeteorCall } from '../../../lib/api/methods'
Expand Down Expand Up @@ -53,7 +53,7 @@ export const OrganizationPage = translateWithTracker(() => {
componentDidMount(): void {
this.autorun(() => {
if (this.props.organization) {
this.subscribe(PubSub.usersInOrganization, { organizationId: this.props.organization._id })
this.subscribe(MeteorPubSub.usersInOrganization, { organizationId: this.props.organization._id })
}
})
}
Expand Down
7 changes: 4 additions & 3 deletions meteor/client/ui/ActiveRundownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { useSubscription, useTracker } from '../lib/ReactMeteorData/ReactMeteorD

import { Spinner } from '../lib/Spinner'
import { RundownView } from './RundownView'
import { PubSub } from '../../lib/api/pubsub'
import { MeteorPubSub } from '../../lib/api/pubsub'
import { UIStudios } from './Collections'
import { StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { RundownPlaylists } from '../collections'
import { useTranslation } from 'react-i18next'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'

export function ActiveRundownView({ studioId }: { studioId: StudioId }): JSX.Element | null {
const { t } = useTranslation()

const { path } = useRouteMatch()

const studioReady = useSubscription(PubSub.uiStudio, studioId)
const playlistReady = useSubscription(PubSub.rundownPlaylists, {
const studioReady = useSubscription(MeteorPubSub.uiStudio, studioId)
const playlistReady = useSubscription(CorelibPubSub.rundownPlaylists, {
activationId: { $exists: true },
studioId,
})
Expand Down
6 changes: 3 additions & 3 deletions meteor/client/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { ResetPasswordPage } from './Account/NotLoggedIn/ResetPasswordPage'
import { AccountPage } from './Account/AccountPage'
import { OrganizationPage } from './Account/OrganizationPage'
import { getUser, User } from '../../lib/collections/Users'
import { PubSub } from '../../lib/api/pubsub'
import { MeteorPubSub } from '../../lib/api/pubsub'
import { useTracker, useSubscription } from '../lib/ReactMeteorData/ReactMeteorData'
import { DocumentTitleProvider } from '../lib/DocumentTitleProvider'
import { Spinner } from '../lib/Spinner'
Expand Down Expand Up @@ -82,8 +82,8 @@ export const App: React.FC = function App() {
const [lastStart] = useState(Date.now())
const [requestedRoute, setRequestedRoute] = useState<undefined | string>()

const userReady = useSubscription(PubSub.loggedInUser)
const orgReady = useSubscription(PubSub.organization, user?.organizationId ?? null)
const userReady = useSubscription(MeteorPubSub.loggedInUser)
const orgReady = useSubscription(MeteorPubSub.organization, user?.organizationId ?? null)

const subsReady = userReady && orgReady

Expand Down
4 changes: 2 additions & 2 deletions meteor/client/ui/ClipTrimPanel/ClipTrimPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { UIStudio } from '../../../lib/api/studios'
import { useTranslation } from 'react-i18next'
import { useContentStatusForPiece } from '../SegmentTimeline/withMediaObjectStatus'
import { useSubscription, useTracker } from '../../lib/ReactMeteorData/ReactMeteorData'
import { PubSub } from '../../../lib/api/pubsub'
import { PieceId, RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { Pieces } from '../../collections'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'

export interface IProps {
studio: UIStudio
Expand Down Expand Up @@ -86,7 +86,7 @@ export function ClipTrimPanel({
}: IProps): JSX.Element {
const { t } = useTranslation()

useSubscription(PubSub.pieces, { _id: pieceId, startRundownId: rundownId })
useSubscription(CorelibPubSub.pieces, { _id: pieceId, startRundownId: rundownId })

const piece = useTracker(() => Pieces.findOne(pieceId), [pieceId])

Expand Down
4 changes: 2 additions & 2 deletions meteor/client/ui/ClockView/CameraScreen/Rundown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext } from 'react'
import { useSubscription, useTracker } from '../../../lib/ReactMeteorData/ReactMeteorData'
import { Rundown as RundownObj } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { PubSub } from '../../../../lib/api/pubsub'
import { MeteorPubSub } from '../../../../lib/api/pubsub'
import { Segments } from '../../../collections'
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
import { Segment as SegmentComponent } from './Segment'
Expand All @@ -20,7 +20,7 @@ interface IProps {
export function Rundown({ playlist, rundown, rundownIdsBefore }: IProps): JSX.Element | null {
const rundownId = rundown._id

useSubscription(PubSub.uiShowStyleBase, rundown.showStyleBaseId)
useSubscription(MeteorPubSub.uiShowStyleBase, rundown.showStyleBaseId)

const segments = useTracker(() => Segments.find({ rundownId }).fetch(), [rundownId], [] as DBSegment[])

Expand Down
17 changes: 9 additions & 8 deletions meteor/client/ui/ClockView/CameraScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CameraContent, RemoteContent, SourceLayerType, SplitsContent } from '@s
import { RundownId, ShowStyleBaseId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { Rundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { unprotectString } from '@sofie-automation/corelib/dist/protectedString'
import { PubSub } from '../../../../lib/api/pubsub'
import { MeteorPubSub } from '../../../../lib/api/pubsub'
import { UIStudio } from '../../../../lib/api/studios'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { PieceExtended } from '../../../../lib/Rundown'
Expand All @@ -21,6 +21,7 @@ import { Spinner } from '../../../lib/Spinner'
import { useBlackBrowserTheme } from '../../../lib/useBlackBrowserTheme'
import { useWakeLock } from './useWakeLock'
import { catchError, useDebounce } from '../../../lib/lib'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'

interface IProps {
playlist: DBRundownPlaylist | undefined
Expand Down Expand Up @@ -94,25 +95,25 @@ export function CameraScreen({ playlist, studioId }: IProps): JSX.Element | null
const rundownIds = useMemo(() => rundowns.map((rundown) => rundown._id), [rundowns])
const showStyleBaseIds = useMemo(() => rundowns.map((rundown) => rundown.showStyleBaseId), [rundowns])

const rundownsReady = useSubscription(PubSub.rundowns, playlistIds, null)
useSubscription(PubSub.segments, {
const rundownsReady = useSubscription(CorelibPubSub.rundowns, playlistIds, null)
useSubscription(CorelibPubSub.segments, {
rundownId: {
$in: rundownIds,
},
})

const studioReady = useSubscription(PubSub.uiStudio, studioId)
useSubscription(PubSub.partInstances, rundownIds, playlist?.activationId)
const studioReady = useSubscription(MeteorPubSub.uiStudio, studioId)
useSubscription(CorelibPubSub.partInstances, rundownIds, playlist?.activationId)

useSubscription(PubSub.parts, rundownIds)
useSubscription(CorelibPubSub.parts, rundownIds)

useSubscription(PubSub.pieceInstancesSimple, {
useSubscription(CorelibPubSub.pieceInstancesSimple, {
rundownId: {
$in: rundownIds,
},
})

const piecesReady = useSubscription(PubSub.pieces, {
const piecesReady = useSubscription(CorelibPubSub.pieces, {
startRundownId: {
$in: rundownIds,
},
Expand Down
4 changes: 2 additions & 2 deletions meteor/client/ui/ClockView/ClockView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { useSubscription, useTracker } from '../../lib/ReactMeteorData/react-met

import { RundownTimingProvider } from '../RundownView/RundownTiming/RundownTimingProvider'

import { PubSub } from '../../../lib/api/pubsub'
import { StudioScreenSaver } from '../StudioScreenSaver/StudioScreenSaver'
import { PresenterScreen } from './PresenterScreen'
import { OverlayScreen } from './OverlayScreen'
import { OverlayScreenSaver } from './OverlayScreenSaver'
import { RundownPlaylists } from '../../collections'
import { StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { CameraScreen } from './CameraScreen'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'

export function ClockView({ studioId }: { studioId: StudioId }): JSX.Element {
useSubscription(PubSub.rundownPlaylists, {
useSubscription(CorelibPubSub.rundownPlaylists, {
activationId: { $exists: true },
studioId,
})
Expand Down
7 changes: 4 additions & 3 deletions meteor/client/ui/ClockView/OverlayScreenSaver.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useEffect, useRef } from 'react'
import { Clock } from '../StudioScreenSaver/Clock'
import { useTracker, useSubscription } from '../../lib/ReactMeteorData/ReactMeteorData'
import { PubSub } from '../../../lib/api/pubsub'
import { MeteorPubSub } from '../../../lib/api/pubsub'
import { findNextPlaylist } from '../StudioScreenSaver/StudioScreenSaver'
// @ts-expect-error No types available
import Velocity from 'velocity-animate'
import { StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'

export function OverlayScreenSaver({ studioId }: { studioId: StudioId }): JSX.Element {
const studioNameRef = useRef<HTMLDivElement>(null)
Expand All @@ -17,8 +18,8 @@ export function OverlayScreenSaver({ studioId }: { studioId: StudioId }): JSX.El
}
})

useSubscription(PubSub.uiStudio, studioId)
useSubscription(PubSub.rundownPlaylists, { studioId: studioId, activationId: { $exists: false } })
useSubscription(MeteorPubSub.uiStudio, studioId)
useSubscription(CorelibPubSub.rundownPlaylists, { studioId: studioId, activationId: { $exists: false } })

const data = useTracker(() => findNextPlaylist({ studioId }), [studioId])

Expand Down
Loading
Loading