-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Continued backend implementation. Data flow from Sofie Core to …
…web client
- Loading branch information
Showing
23 changed files
with
1,296 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { action, makeAutoObservable, observable } from 'mobx' | ||
import isEqual from 'lodash.isequal' | ||
import { RundownPlaylist, RundownPlaylistId } from 'packages/shared/model/dist' | ||
|
||
export class PlaylistStore { | ||
ready: boolean = false | ||
public readonly playlists = observable.map<RundownPlaylistId, RundownPlaylist>() | ||
|
||
constructor() { | ||
makeAutoObservable(this, { | ||
create: action, | ||
update: action, | ||
remove: action, | ||
}) | ||
} | ||
|
||
create(playlist: RundownPlaylist) { | ||
this._updateIfChanged(playlist) | ||
} | ||
update(playlist: RundownPlaylist) { | ||
this._updateIfChanged(playlist) | ||
} | ||
remove(playlistId: RundownPlaylistId) { | ||
console.log('a') | ||
this._deleteIfChanged(playlistId) | ||
} | ||
|
||
private _updateIfChanged(playlist: RundownPlaylist) { | ||
if (!isEqual(this.playlists.get(playlist._id), playlist)) { | ||
this.playlists.set(playlist._id, playlist) | ||
} | ||
} | ||
private _deleteIfChanged(playlistId: RundownPlaylistId) { | ||
if (this.playlists.has(playlistId)) { | ||
this.playlists.delete(playlistId) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { PlaylistStore } from './PlaylistStore.js' | ||
|
||
export class Store { | ||
public playlists = new PlaylistStore() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,51 @@ | ||
import { DEFAULT_DEV_API_PORT } from '@sofie-prompter-editor/shared-lib' | ||
import { ApiServer } from './api-server/ApiServer.js' | ||
import { initializeLogger, setupLogger } from './lib/logger.js' | ||
import { LoggerInstance, initializeLogger, isLogLevel, setLogLevel, setupLogger } from './lib/logger.js' | ||
import { SofieCoreConnection } from './sofie-core-connection/SofieCoreConnection.js' | ||
import { Store } from './data-stores/Store.js' | ||
import { getConfigOptions } from './lib/config.js' | ||
import { ProcessHandler } from './lib/ProcessHandler.js' | ||
|
||
const loggerConfig = {} | ||
|
||
initializeLogger(loggerConfig) | ||
const logger = setupLogger(loggerConfig, 'backend') | ||
const log: LoggerInstance = setupLogger(loggerConfig, 'backend') | ||
|
||
async function init() { | ||
logger.info('Initializing backend...') | ||
const options = await getConfigOptions() | ||
if (options.logLevel && isLogLevel(options.logLevel)) setLogLevel(options.logLevel) | ||
|
||
const httpAPI = new ApiServer(logger, DEFAULT_DEV_API_PORT) | ||
log.info('Options:') | ||
log.info(JSON.stringify(options)) | ||
|
||
log.info('Initializing backend...') | ||
|
||
const processHandler = new ProcessHandler(log) | ||
processHandler.init(options) | ||
|
||
const store = new Store() | ||
|
||
const httpAPI = new ApiServer(log, DEFAULT_DEV_API_PORT, store) | ||
|
||
httpAPI.on('connection', () => { | ||
logger.info('new connection!') | ||
log.info('new connection!') | ||
}) | ||
|
||
await httpAPI.initialized | ||
|
||
logger.info('Backend initialized') | ||
if (!options.noCore) { | ||
const coreConnection = new SofieCoreConnection(log, options, processHandler, store) | ||
coreConnection.on('connected', () => { | ||
log.info('Connected to Core') | ||
}) | ||
coreConnection.on('disconnected', () => { | ||
log.warn('Disconnected from Core!') | ||
}) | ||
await coreConnection.initialized | ||
} else { | ||
log.info('NOT connecting to Core (noCore=true)') | ||
} | ||
|
||
log.info('Backend initialized') | ||
} | ||
init().catch(logger.error) | ||
init().catch(log.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import fs from 'fs' | ||
import { LoggerInstance } from './logger' | ||
import { ConfigOptions } from './config' | ||
|
||
// export function setupProcess(config: ProcessConfig): void {} | ||
|
||
export class ProcessHandler { | ||
public certificates: Buffer[] = [] | ||
private log: LoggerInstance | ||
|
||
constructor(log: LoggerInstance) { | ||
this.log = log.category('ProcessHandler') | ||
} | ||
init(processConfig: ConfigOptions): void { | ||
if (processConfig.unsafeSSL) { | ||
this.log.info('Disabling NODE_TLS_REJECT_UNAUTHORIZED, be sure to ONLY DO THIS ON A LOCAL NETWORK!') | ||
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0' | ||
} else { | ||
// var rootCas = SSLRootCAs.create() | ||
} | ||
if (processConfig.certificates.length) { | ||
this.log.info(`Loading certificates...`) | ||
for (const certificate of processConfig.certificates) { | ||
try { | ||
this.certificates.push(fs.readFileSync(certificate)) | ||
this.log.info(`Using certificate "${certificate}"`) | ||
} catch (error) { | ||
this.log.error(`Error loading certificate "${certificate}"`, error) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Options } from 'yargs' | ||
import yargs from 'yargs/yargs' | ||
|
||
/* | ||
* This file contains various CLI argument definitions, used by the various processes that together constitutes the Package Manager | ||
*/ | ||
|
||
/** Generic CLI-argument-definitions for any process */ | ||
const optionsDefinition = defineArguments({ | ||
logLevel: { type: 'string', describe: 'Set default log level. (Might be overwritten by Sofie Core)' }, | ||
|
||
unsafeSSL: { | ||
type: 'boolean', | ||
default: process.env.UNSAFE_SSL === '1', | ||
describe: 'Set to true to allow all SSL certificates (only use this in a safe, local environment)', | ||
}, | ||
certificates: { type: 'string', describe: 'SSL Certificates' }, | ||
|
||
noCore: { | ||
type: 'boolean', | ||
default: process.env.NO_CORE === '1', | ||
describe: 'If true, Package Manager wont try to connect to Sofie Core', | ||
}, | ||
coreHost: { | ||
type: 'string', | ||
default: process.env.CORE_HOST || '127.0.0.1', | ||
describe: 'The IP-address/hostName to Sofie Core', | ||
}, | ||
corePort: { | ||
type: 'number', | ||
default: parseInt(process.env.CORE_PORT || '', 10) || 3000, | ||
describe: 'The port number of Sofie core (usually 80, 443 or 3000)', | ||
}, | ||
|
||
deviceId: { | ||
type: 'string', | ||
default: process.env.DEVICE_ID || '', | ||
describe: '(Optional) Unique device id of this device', | ||
}, | ||
deviceToken: { | ||
type: 'string', | ||
default: process.env.DEVICE_TOKEN || '', | ||
describe: '(Optional) access token of this device.', | ||
}, | ||
}) | ||
|
||
export interface ConfigOptions { | ||
logLevel: string | undefined | ||
/** Will cause the Node app to blindly accept all certificates. Not recommenced unless in local, controlled networks. */ | ||
unsafeSSL: boolean | ||
/** Paths to certificates to load, for SSL-connections */ | ||
certificates: string[] | ||
|
||
noCore: boolean | ||
coreHost: string | ||
corePort: number | ||
deviceId: string | ||
deviceToken: string | ||
} | ||
export async function getConfigOptions(): Promise<ConfigOptions> { | ||
const argv = await Promise.resolve(yargs(process.argv.slice(2)).options(optionsDefinition).argv) | ||
|
||
return { | ||
logLevel: argv.logLevel, | ||
unsafeSSL: argv.unsafeSSL, | ||
certificates: ((argv.certificates || process.env.CERTIFICATES || '').split(';') || []).filter(Boolean), | ||
|
||
noCore: argv.noCore, | ||
coreHost: argv.coreHost, | ||
corePort: argv.corePort, | ||
deviceId: argv.deviceId, | ||
deviceToken: argv.deviceToken, | ||
} | ||
} | ||
|
||
// --------------------------------------------------------------------------------- | ||
|
||
/** Helper function, to get strict typings for the yargs-Options. */ | ||
function defineArguments<O extends { [key: string]: Options }>(opts: O): O { | ||
return opts | ||
} |
Oops, something went wrong.