Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
feat: implemented Mos-connection (it works now)
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Apr 11, 2018
1 parent 7f2774e commit 27bf4c0
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 58 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"scripts": {
"info": "npm-scripts-info",
"build": "trash dist && yarn build:main",
"buildstart": "yarn build && yarn start",
"build:main": "tsc -p tsconfig.json",
"lint": "tslint --project tsconfig.jest.json --config tslint.json",
"unit": "jest",
Expand Down
19 changes: 14 additions & 5 deletions src/connector.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@

import {MosHandler} from './mosHandler'
import {CoreHandler} from './coreHandler'
import {MosHandler, MosConfig} from './mosHandler'
import {CoreHandler, CoreConfig} from './coreHandler'

export interface Config {
core: CoreConfig
mos: MosConfig
}
export class Connector {

private mosHandler: MosHandler
private coreHandler: CoreHandler
private _config: Config

init (): Promise<number> {
init (config: Config): Promise<number> {
this._config = config

return Promise.resolve()
.then(() => {
console.log('Initializing Core...')
return this.initCore()
})
.then(() => {
console.log('Initializing Mos...')
return this.initMos()
})
.then(() => {
console.log('Initialization done')
return 0
})
}
initCore () {
this.coreHandler = new CoreHandler()
return this.coreHandler.init()
return this.coreHandler.init(this._config.core)
}
initMos (): Promise<void> {
// TODO: maybe get some config data from core here?
this.mosHandler = new MosHandler()
return this.mosHandler.init(this.coreHandler)
return this.mosHandler.init(this._config.mos, this.coreHandler)

}
}
43 changes: 24 additions & 19 deletions src/coreHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import {CoreConnection,
import { CoreConnection,
CoreOptions,
DeviceType,
PeripheralDeviceAPI as P
Expand Down Expand Up @@ -29,20 +29,22 @@ import * as _ from 'underscore'
import { MosHandler } from './mosHandler'
// import { STATUS_CODES } from 'http'

export interface CoreConfig {
host: string,
port: number
}
/**
* Represents a connection between mos-integration and Core
*/
export class CoreHandler {
core: CoreConnection

init (): Promise<void> {

this.core = new CoreConnection(this.getCoreConnectionOptions('parent process'))
init (config: CoreConfig): Promise<void> {
console.log('========')
this.core = new CoreConnection(this.getCoreConnectionOptions('MOS: Parent process', 'MosCoreParent'))

return this.core.init({
host: '127.0.0.1',
port: 3000
}).then((id: string) => {
return this.core.init(config).then((id: string) => {
id = id // tsignore

this.core.setStatus({
statusCode: P.StatusCode.GOOD
Expand All @@ -62,14 +64,15 @@ export class CoreHandler {
// nothing
})
}
getCoreConnectionOptions (name: string): CoreOptions {
let credentials = CoreConnection.getCredentials('mosDevice')
getCoreConnectionOptions (name: string, deviceId: string): CoreOptions {
let credentials = CoreConnection.getCredentials(deviceId)
return _.extend(credentials, {
deviceType: DeviceType.MOSDEVICE,
deviceName: name
})
}
registerMosDevice (mosDevice: IMOSDevice, mosHandler: MosHandler): Promise<CoreMosDeviceHandler> {
console.log('registerMosDevice -------------')
let coreMos = new CoreMosDeviceHandler(this, mosDevice, mosHandler)

return coreMos.init()
Expand All @@ -93,13 +96,15 @@ export class CoreMosDeviceHandler {
this._mosDevice = mosDevice
this._mosHandler = mosHandler

this.core = new CoreConnection(parent.getCoreConnectionOptions('MOS device'))
console.log('new CoreMosDeviceHandler ' + mosDevice.id)
this.core = new CoreConnection(parent.getCoreConnectionOptions('MOS: ' + mosDevice.id, mosDevice.id))

}
init (): Promise<void> {
return this.core.init(this._coreParentHandler.core)
.then((id: string) => {
// nothing
id = id // tsignore
})
}
onMosConnectionChanged (connectionStatus: IMOSConnectionStatus) {
Expand Down Expand Up @@ -147,14 +152,14 @@ export class CoreMosDeviceHandler {
mosRev: new MosString128('0'),
supportedProfiles: {
deviceType: 'MOS', // MOS, NCS
profile0: this._mosHandler.mosOptions.profiles['0'],
profile1: this._mosHandler.mosOptions.profiles['1'],
profile2: this._mosHandler.mosOptions.profiles['2'],
profile3: this._mosHandler.mosOptions.profiles['3'],
profile4: this._mosHandler.mosOptions.profiles['4'],
profile5: this._mosHandler.mosOptions.profiles['5'],
profile6: this._mosHandler.mosOptions.profiles['6'],
profile7: this._mosHandler.mosOptions.profiles['7']
profile0: this._mosHandler.mosOptions.self.profiles['0'],
profile1: this._mosHandler.mosOptions.self.profiles['1'],
profile2: this._mosHandler.mosOptions.self.profiles['2'],
profile3: this._mosHandler.mosOptions.self.profiles['3'],
profile4: this._mosHandler.mosOptions.self.profiles['4'],
profile5: this._mosHandler.mosOptions.self.profiles['5'],
profile6: this._mosHandler.mosOptions.self.profiles['6'],
profile7: this._mosHandler.mosOptions.self.profiles['7']
}
}
return Promise.resolve(info)
Expand Down
39 changes: 37 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@

import {Connector} from './connector'
import {Connector, Config} from './connector'

console.log('Running MOS-integration...')
let c = new Connector()

c.init()
let config: Config = {
core: {
host: '127.0.0.1',
port: 3010
},
mos: {
self: {

mosID: 'seff.tv.automation',
acceptsConnections: true, // default:true
// accepsConnectionsFrom: ['127.0.0.1'],
profiles: {
'0': true,
'1': true,
'2': true,
'3': false,
'4': false,
'5': false,
'6': false,
'7': false
}
},
devices: [{
primary: {
id: 'WINSERVERSOMETHINGENPS',
host: '10.0.1.248'
}
/*secondary?: {
ncsID: string;
host: string;
},*/
}]
}
}
c.init(config)
83 changes: 51 additions & 32 deletions src/mosHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,44 @@ import {
IMOSItemAction,
IMOSItem,
IMOSROReadyToAir,
IMOSROFullStory
IMOSROFullStory,
IConnectionConfig,
IMOSDeviceConnectionOptions
} from 'mos-connection'
import * as _ from 'underscore'
import { CoreHandler } from './coreHandler'

export interface IMOSOptions {
mosID: string,
acceptsConnections: boolean,
profiles: {
'0': boolean,
'1': boolean,
'2': boolean,
'3': boolean,
'4': boolean,
'5': boolean,
'6': boolean,
'7': boolean
}
// export interface MosOptions {
// mosID: string,
// acceptsConnections: boolean,
// profiles: {
// '0': boolean,
// '1': boolean,
// '2': boolean,
// '3': boolean,
// '4': boolean,
// '5': boolean,
// '6': boolean,
// '7': boolean
// }
// }
export interface MosConfig {
self: IConnectionConfig
devices: Array<IMOSDeviceConnectionOptions>
}

export class MosHandler {

public mos: MosConnection

public mosOptions: IMOSOptions
public mosOptions: MosConfig

private mosDevices: {[id: string]: IMOSDevice}
private mosDevices: {[id: string]: IMOSDevice} = {}

init (coreHandler: CoreHandler): Promise<void> {
init (config: MosConfig, coreHandler: CoreHandler): Promise<void> {

this.mosOptions = {
this.mosOptions = config
/*{
mosID: 'seff-tv-automation',
acceptsConnections: true, // default:true
// accepsConnectionsFrom: ['127.0.0.1'],
Expand All @@ -60,22 +67,26 @@ export class MosHandler {
'7': false
}
}
*/

this.mos = new MosConnection(this.mosOptions)
this.mos = new MosConnection(this.mosOptions.self)

this.mos.onConnection((mosDevice: IMOSDevice) => {
// a new connection to a device has been made
console.log('---------------------------------')

console.log('onConnection')
this.mosDevices[mosDevice.id] = mosDevice

return coreHandler.registerMosDevice(mosDevice, this)
.then((coreMosHandler) => {

console.log('mosDevice registered -------------')
// Setup message flow between the devices:
// Profile 0: -------------------------------------------------
mosDevice.onConnectionChange((connectionStatus: IMOSConnectionStatus) => { // MOSDevice >>>> Core
coreMosHandler.onMosConnectionChanged(connectionStatus)
})
coreMosHandler.onMosConnectionChanged(mosDevice.getConnectionStatus()) // initial check
mosDevice.onGetMachineInfo(() => { // MOSDevice >>>> Core
return coreMosHandler.getMachineInfo()
})
Expand Down Expand Up @@ -155,26 +166,34 @@ export class MosHandler {
// Profile 3: -------------------------------------------------
// Profile 4: -------------------------------------------------
// onStory: (cb: (story: IMOSROFullStory) => Promise<any>) => void
mosDevice.onStory((story: IMOSROFullStory) => { // MOSDevice >>>> Core
mosDevice.onROStory((story: IMOSROFullStory) => { // MOSDevice >>>> Core
return this._getROAck(story.RunningOrderId, coreMosHandler.mosRoFullStory(story))
})

/*
setTimeout(() => {
console.log('.......................')
console.log('DISPOSE!')
mosDevice.di
}, 3000)
*/

})
.catch((e) => {
console.log('Error:',e)
})

})

// Connect to ENPS:
return this.mos.connect({
primary: {
id: 'WINSERVERSOMETHINGENPS',
host: '192.168.0.1'
}
/*secondary?: {
ncsID: string;
host: string;
},*/
}).then(() => {
// called when a connection has been made
return Promise.all(
_.map(this.mosOptions.devices, (device) => {
return this.mos.connect(device).then(() => {
// called when a connection has been made
})
})
).then(() => {
// Called when all connection has been made
})
}
private _getROAck (roId: MosString128, p: Promise<any>) {
Expand Down

0 comments on commit 27bf4c0

Please sign in to comment.