Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jul 5, 2024
1 parent b5e99a8 commit 2964dd4
Show file tree
Hide file tree
Showing 29 changed files with 2,112 additions and 1,253 deletions.
16 changes: 14 additions & 2 deletions packages/connector/src/MosConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,27 @@ export class MosConnection extends EventEmitter<MosConnectionEvents> implements
if (mosDevice) {
mosDevice
.routeData(parsed.mos, client.portDescription)
.catch((err) => {
if (MosModel.ParseError.isParseError(err)) {
// Try to add the main mos message key to the error:
const breadcrumbs = Object.keys(parsed.mos).filter(
(key) =>
!['messageID', 'mosID', 'ncsID'].includes(key) &&
typeof parsed.mos[key] === 'object'
)
throw MosModel.ParseError.handleCaughtError(breadcrumbs.join('/'), err)
} else throw err
})
.then((message: MosModel.MosMessage) => {
sendReply(message)
})
.catch((err: Error | MosModel.MosMessage) => {
.catch((err: Error | MosModel.MosMessage | MosModel.ParseError) => {
// Something went wrong
if (err instanceof MosModel.MosMessage) {
sendReply(err)
} else {
// Unknown / internal error
// Internal/parsing error

// Log error:
this.emit('warning', `Error when handling incoming data: ${err} ${err?.stack}`)
// reply with NACK:
Expand Down
383 changes: 184 additions & 199 deletions packages/connector/src/MosDevice.ts

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions packages/connector/src/__mocks__/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
IMOSScope,
IMOSExternalMetaData,
getMosTypes,
IMOSRequestObjectList,
} from '@mos-connection/model'

const mosTypes = getMosTypes(true)
Expand Down Expand Up @@ -74,7 +75,7 @@ const xmlData = {
reqObj: `<mosReqObj> <objID>M000123</objID> </mosReqObj>`,
mosReqAll: `<mosReqAll> <pause>0</pause> </mosReqAll>`,
mosObj: `<mosObj> <objID>M000123</objID> <objSlug>Hotel Fire</objSlug> <mosAbstract> <b>Hotel Fire</b> <em>vo</em> :30 </mosAbstract> <objGroup>Show 7</objGroup> <objType>VIDEO</objType> <objTB>59.94</objTB> <objRev>1</objRev> <objDur>1800</objDur> <status>NEW</status> <objAir>READY</objAir><objPaths><objPath techDescription="MPEG2 Video">\\server\\media\\clip392028cd2320s0d.mxf</objPath><objProxyPath techDescription="WM9 750Kbps">https://server/proxy/clipe.wmv</objProxyPath><objMetadataPath techDescription="MOS Object">https://server/proxy/clipe.xml</objMetadataPath></objPaths> <createdBy>Chris</createdBy> <created>2009-10-31T23:39:12</created> <changedBy>Chris</changedBy> <changed>2009-10-31T23:39:12</changed> <description> <p> Exterior footage of <em>Baley Park Hotel</em> on fire with natural sound. Trucks are visible for the first portion of the clip. <em>CG locator at 0:04 and duration 0:05, Baley Park Hotel.</em> </p> <p> <tab/> Cuts to view of fire personnel exiting hotel lobby and cleaning up after the fire is out. </p> <p> <em>Clip has been doubled for pad on voice over.</em> </p> </description> <mosExternalMetadata> <mosScope>STORY</mosScope> <mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <ModTime>20010308142001</ModTime> <mediaTime>0</mediaTime> <TextTime>278</TextTime> <ModBy>LJOHNSTON</ModBy> <Approved>0</Approved> <Creator>SHOLMES</Creator> </mosPayload> </mosExternalMetadata></mosObj>`,
mosListAll: `<mosListAll><mosObj><objID>M000123</objID><objSlug>HOTEL FIRE</objSlug><objPaths><objPath techDescription="MPEG2 Video">\\server\\media\\clip392028cd2320s0d.mxf</objPath><objProxyPath techDescription="WM9 750Kbps">https://server/proxy/clipe.wmv</objProxyPath><objMetadataPath techDescription="MOS Object">https://server/proxy/clipe.xml</objMetadataPath></objPaths> <createdBy>Chris</createdBy> <created>2009-10-31T23:39:12</created> <changedBy>Chris</changedBy> <changed>2009-11-01T14:35:55</changed> <description> <p> Exterior footage of <em>Baley Park Hotel</em> on fire with natural sound. Trucks are visible for the first portion of the clip. <em>CG locator at 0:04 and duration 0:05, Baley Park Hotel.</em> </p> <p> <tab/> Cuts to view of fire personnel exiting hotel lobby and cleaning up after the fire is out. </p> <p> <em>Clip has been doubled for pad on voice over.</em> </p> </description> </mosObj> <mosObj> <objID>M000224</objID> <objSlug>COLSTAT MURDER:VO</objSlug> <objType>VIDEO</objType> <objTB>59.94</objTB> <objRev>4</objRev> <objDur>800</objDur> <status>UPDATED</status> <objAir>READY</objAir><objPaths><objPath techDescription="MPEG2 Video">\\server\\media\\clip392028cd2320s0d.mxf</objPath><objProxyPath techDescription="WM9 750Kbps">https://server/proxy/clipe.wmv</objProxyPath><objMetadataPath techDescription="MOS Object">https://server/proxy/clipe.xml</objMetadataPath></objPaths> <createdBy>Phil</createdBy> <created>2009-11-01T15:19:01</created> <changedBy>Chris</changedBy> <changed>2009-11-01T15:21:15</changed> <description>VOICE OVER MATERIAL OF COLSTAT MURDER SITES SHOT ON 1-NOV.</description> <mosExternalMetadata> <mosScope>STORY</mosScope> <mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <ModTime>20010308142001</ModTime> <mediaTime>0</mediaTime> <TextTime>278</TextTime> <ModBy>LJOHNSTON</ModBy> <Approved>0</Approved> <Creator>SHOLMES</Creator> </mosPayload> </mosExternalMetadata> </mosObj> </mosListAll>`,
mosListAll: `<mosListAll><mosObj><objTB>59.94</objTB><objDur>1234</objDur><objID>M000123</objID><objSlug>HOTEL FIRE</objSlug><objPaths><objPath techDescription="MPEG2 Video">\\server\\media\\clip392028cd2320s0d.mxf</objPath><objProxyPath techDescription="WM9 750Kbps">https://server/proxy/clipe.wmv</objProxyPath><objMetadataPath techDescription="MOS Object">https://server/proxy/clipe.xml</objMetadataPath></objPaths> <createdBy>Chris</createdBy> <created>2009-10-31T23:39:12</created> <changedBy>Chris</changedBy> <changed>2009-11-01T14:35:55</changed> <description> <p> Exterior footage of <em>Baley Park Hotel</em> on fire with natural sound. Trucks are visible for the first portion of the clip. <em>CG locator at 0:04 and duration 0:05, Baley Park Hotel.</em> </p> <p> <tab/> Cuts to view of fire personnel exiting hotel lobby and cleaning up after the fire is out. </p> <p> <em>Clip has been doubled for pad on voice over.</em> </p> </description> </mosObj> <mosObj> <objID>M000224</objID> <objSlug>COLSTAT MURDER:VO</objSlug> <objType>VIDEO</objType> <objTB>59.94</objTB> <objRev>4</objRev> <objDur>800</objDur> <status>UPDATED</status> <objAir>READY</objAir><objPaths><objPath techDescription="MPEG2 Video">\\server\\media\\clip392028cd2320s0d.mxf</objPath><objProxyPath techDescription="WM9 750Kbps">https://server/proxy/clipe.wmv</objProxyPath><objMetadataPath techDescription="MOS Object">https://server/proxy/clipe.xml</objMetadataPath></objPaths> <createdBy>Phil</createdBy> <created>2009-11-01T15:19:01</created> <changedBy>Chris</changedBy> <changed>2009-11-01T15:21:15</changed> <description>VOICE OVER MATERIAL OF COLSTAT MURDER SITES SHOT ON 1-NOV.</description> <mosExternalMetadata> <mosScope>STORY</mosScope> <mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <ModTime>20010308142001</ModTime> <mediaTime>0</mediaTime> <TextTime>278</TextTime> <ModBy>LJOHNSTON</ModBy> <Approved>0</Approved> <Creator>SHOLMES</Creator> </mosPayload> </mosExternalMetadata> </mosObj> </mosListAll>`,

roCreate: `<roCreate><roID>96857485</roID> <roSlug>5PM RUNDOWN</roSlug> <roEdStart>2009-04-17T17:02:00</roEdStart> <roEdDur>00:58:25</roEdDur> <story> <storyID>5983A501:0049B924:8390EF2B</storyID> <storySlug>COLSTAT MURDER</storySlug> <storyNum>A5</storyNum> <item> <itemID>0</itemID> <itemSlug>COLSTAT MURDER:VO</itemSlug> <objID>M000224</objID> <mosID>testmos.enps.com</mosID> <objPaths> <objPath techDescription="MPEG2 Video">\\server\\media\\clip392028cd2320s0d.mxf</objPath> <objProxyPath techDescription="WM9 750Kbps">https://server/proxy/clipe.wmv</objProxyPath><objMetadataPath techDescription="MOS Object">https://server/proxy/clipe.xml</objMetadataPath> </objPaths> <itemEdDur>645</itemEdDur> <itemUserTimingDur>310</itemUserTimingDur> <itemTrigger>CHAINED</itemTrigger> <mosExternalMetadata> <mosScope>PLAYLIST</mosScope> <mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <transitionMode>2</transitionMode> <transitionPoint>463</transitionPoint> <source>a</source> <destination>b</destination> </mosPayload> </mosExternalMetadata> </item> </story> <story> <storyID>3854737F:0003A34D:983A0B28</storyID> <storySlug>AIRLINE INSPECTIONS</storySlug> <storyNum>A6</storyNum> <item> <itemID>0</itemID> <objID>M000133</objID> <mosID>testmos.enps.com</mosID> <itemEdStart>55</itemEdStart> <itemEdDur>310</itemEdDur> <itemUserTimingDur>200</itemUserTimingDur> <mosExternalMetadata> <mosScope>PLAYLIST</mosScope> <mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <transitionMode>2</transitionMode> <transitionPoint>463</transitionPoint> <source>a</source> <destination>b</destination> </mosPayload> </mosExternalMetadata> </item> </story> </roCreate>`,
roCreate_simple_story: `<roCreate><roID>96857485</roID><roSlug>5PM RUNDOWN</roSlug><roEdStart>2009-04-17T17:02:00</roEdStart><roEdDur>00:58:25</roEdDur><story><storyID>3854737F:0003A34D:983A0B28</storyID></story></roCreate>`,
Expand Down Expand Up @@ -631,17 +632,17 @@ const xmlApiData = {
}),

mosListAll: [
{
literal<IMOSObject>({
ID: mosTypes.mosString128.create('M000123'),
Slug: mosTypes.mosString128.create('HOTEL FIRE'),
// MosAbstract: ''
// Group?: '
Type: undefined,
TimeBase: undefined,
Revision: undefined,
Duration: undefined,
Status: undefined,
AirStatus: undefined,
Type: IMOSObjectType.OTHER,
TimeBase: 59.94,
// Revision: undefined,
Duration: 1234,
// Status: undefined,
// AirStatus: undefined,
Paths: [
literal<IMOSObjectPath>({
Type: IMOSObjectPathType.PATH,
Expand All @@ -664,7 +665,7 @@ const xmlApiData = {
ChangedBy: mosTypes.mosString128.create('Chris'),
Changed: mosTypes.mosTime.create('2009-11-01T14:35:55'),
Description: {},
},
}),
literal<IMOSObject>({
ID: mosTypes.mosString128.create('M000224'),
Slug: mosTypes.mosString128.create('COLSTAT MURDER:VO'),
Expand Down Expand Up @@ -910,7 +911,7 @@ const xmlApiData = {
}),
],
}),
roDelete: 49478285,
roDelete: mosTypes.mosString128.create('49478285'),
roList: literal<IMOSObject>({
ID: mosTypes.mosString128.create('M000123'),
Slug: mosTypes.mosString128.create('Hotel Fire'),
Expand Down Expand Up @@ -2032,12 +2033,12 @@ const xmlApiData = {
],
}),
mosReqSearchableSchema: 'jbob',
mosReqObjList: {
mosReqObjList: literal<IMOSRequestObjectList>({
username: 'jbob',
queryID: '123439392039393ade0393zdkdls',
queryID: mosTypes.mosString128.create('123439392039393ade0393zdkdls'),
listReturnStart: 1,
listReturnEnd: null,
generalSearch: 'man bites dog',
generalSearch: mosTypes.mosString128.create('man bites dog'),
mosSchema: 'https://MOSA4.com/mos/supported_schemas/MOSAXML2.08',
searchGroups: [
{
Expand Down Expand Up @@ -2081,7 +2082,7 @@ const xmlApiData = {
],
},
],
},
}),
mosObjReqObjActionNew: literal<IMOSObject>({
Slug: mosTypes.mosString128.create('Hotel Fire'),
Group: 'Show 7',
Expand All @@ -2090,7 +2091,7 @@ const xmlApiData = {
Duration: 1800,
CreatedBy: mosTypes.mosString128.create('Chris'),
}),
mosObjReqObjActionUpdateObjId: '1EFA3009233F8329C1',
mosObjReqObjActionUpdateObjId: mosTypes.mosString128.create('1EFA3009233F8329C1'),
mosObjReqObjActionUpdate: literal<IMOSObject>({
Slug: mosTypes.mosString128.create('Hotel Fire'),
Group: 'Show 7',
Expand All @@ -2099,7 +2100,7 @@ const xmlApiData = {
Duration: 1800,
CreatedBy: mosTypes.mosString128.create('Chris'),
}),
mosObjReqObjActionDeleteObjId: '1EFA3009233F8329C1',
mosObjReqObjActionDeleteObjId: mosTypes.mosString128.create('1EFA3009233F8329C1'),
sendRunningOrderStory: literal<IMOSROFullStory>({
ID: mosTypes.mosString128.create('5983A501:0049B924:8390EF1F'),
RunningOrderId: mosTypes.mosString128.create('96857485'),
Expand Down
5 changes: 2 additions & 3 deletions packages/connector/src/__tests__/MosConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ describe('MosDevice: General', () => {
})

expect(errorReported).toHaveBeenCalledTimes(1)
expect(errorReported).nthCalledWith(
1,
expect.stringContaining('primary: Heartbeat error on lower: Error: Sent command timed out after')
expect(`${errorReported.mock.calls[0][0]}`).toMatch(
/primary: Heartbeat error on lower: Sent command timed out after/
)

// Test proper dispose:
Expand Down
6 changes: 3 additions & 3 deletions packages/connector/src/__tests__/Profile0-open-media.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Profile 0 - Open Media (non strict)', () => {

const replyMessage = { ...xmlApiData.machineInfoOpenMediaReply }
replyMessage.time = returnedMachineInfo.time
replyMessage.opTime = returnedMachineInfo.opTime
delete replyMessage.opTime

expect(returnedMachineInfo).toMatchObject(replyMessage)
// expect(returnedMachineInfo.opTime).toBeUndefined()
Expand All @@ -148,7 +148,7 @@ describe('Profile 0 - Open Media (non strict)', () => {

const replyMessage = { ...xmlApiData.machineInfoOpenMediaReply }
replyMessage.time = returnedMachineInfo.time
replyMessage.opTime = returnedMachineInfo.opTime
delete replyMessage.opTime

expect(returnedMachineInfo).toMatchObject(replyMessage)
// expect(returnedMachineInfo.opTime).toBeUndefined()
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('Profile 0 - Open Media (non strict)', () => {
checkMessageSnapshot(msg)

const replyMessage = { ...xmlApiData.machineInfoOpenMediaReply }
replyMessage.opTime = returnedMachineInfo.opTime
delete replyMessage.opTime
replyMessage.time = returnedMachineInfo.time

expect(returnedMachineInfo).toMatchObject(replyMessage)
Expand Down
2 changes: 1 addition & 1 deletion packages/connector/src/__tests__/Profile2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('Profile 2', () => {
const messageId = await fakeIncomingMessage(serverSocketMockUpper, xmlData.roReq)
expect(onRequestRunningOrder).toHaveBeenCalledTimes(1)

expect(onRequestRunningOrder.mock.calls[0][0]).toEqual(96857485)
expect(onRequestRunningOrder.mock.calls[0][0]).toEqual(mosTypes.mosString128.create('96857485'))
expect(fixSnapshot(onRequestRunningOrder.mock.calls)).toMatchSnapshot()
// Check reply to socket server:
await serverSocketMockUpper.mockWaitForSentMessages()
Expand Down
4 changes: 2 additions & 2 deletions packages/connector/src/__tests__/Profile3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ describe('Profile 3', () => {
test('onMosReqObjectActionUpdate', async () => {
const messageId = await fakeIncomingMessage(serverSocketMockQuery, xmlData.mosReqObjActionUpdate)
expect(onRequestObjectActionUpdate).toHaveBeenCalledTimes(1)
expect(onRequestObjectActionUpdate.mock.calls[0][0]).toBe(xmlApiData.mosObjReqObjActionUpdateObjId)
expect(onRequestObjectActionUpdate.mock.calls[0][0]).toMatchObject(xmlApiData.mosObjReqObjActionUpdateObjId)
expect(onRequestObjectActionUpdate.mock.calls[0][1]).toMatchObject(xmlApiData.mosObjReqObjActionUpdate)
expect(fixSnapshot(onRequestObjectActionUpdate.mock.calls)).toMatchSnapshot()
await checkReplyToServer(serverSocketMockQuery, messageId, '<mosAck>')
})
test('onMosReqObjectActionDelete', async () => {
const messageId = await fakeIncomingMessage(serverSocketMockQuery, xmlData.mosReqObjActionDelete)
expect(onRequestObjectActionDelete).toHaveBeenCalledTimes(1)
expect(onRequestObjectActionDelete.mock.calls[0][0]).toBe(xmlApiData.mosObjReqObjActionDeleteObjId)
expect(onRequestObjectActionDelete.mock.calls[0][0]).toMatchObject(xmlApiData.mosObjReqObjActionDeleteObjId)
expect(fixSnapshot(onRequestObjectActionDelete.mock.calls)).toMatchSnapshot()
await checkReplyToServer(serverSocketMockQuery, messageId, '<mosAck>')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Profile 0 - non strict requestMachineInfo - empty <time> 1`] = `
exports[`Profile 0 - Open Media (non strict) requestMachineInfo - empty <time> 1`] = `
"<mos>
<ncsID>their.mos.id</ncsID>
<mosID>our.mos.id</mosID>
Expand All @@ -9,7 +9,7 @@ exports[`Profile 0 - non strict requestMachineInfo - empty <time> 1`] = `
</mos>"
`;
exports[`Profile 0 - non strict requestMachineInfo - missing <opTime> 1`] = `
exports[`Profile 0 - Open Media (non strict) requestMachineInfo - missing <opTime> 1`] = `
"<mos>
<ncsID>their.mos.id</ncsID>
<mosID>our.mos.id</mosID>
Expand All @@ -18,7 +18,7 @@ exports[`Profile 0 - non strict requestMachineInfo - missing <opTime> 1`] = `
</mos>"
`;
exports[`Profile 0 - non strict requestMachineInfo - missing <time> 1`] = `
exports[`Profile 0 - Open Media (non strict) requestMachineInfo - missing <time> 1`] = `
"<mos>
<ncsID>their.mos.id</ncsID>
<mosID>our.mos.id</mosID>
Expand Down
Loading

0 comments on commit 2964dd4

Please sign in to comment.