Skip to content
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
3 changes: 3 additions & 0 deletions src/main/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class Config {
xmdsVersion: number | undefined;
displayName: string | undefined;
settings: any;
displayTags: Record<string, string> = {};

// Device info
macAddress: string = '';
Expand Down Expand Up @@ -198,6 +199,7 @@ export class Config {
this.settings['sizeX'] = registerDisplay.getSetting('sizeX', 0);
this.settings['sizeY'] = registerDisplay.getSetting('sizeY', 0);
this.settings['sendCurrentLayoutAsStatusUpdate'] = registerDisplay.getSetting('sendCurrentLayoutAsStatusUpdate', false);
this.displayTags = registerDisplay.getTags();
this.settings['isRecordGeoLocationOnProofOfPlay'] = registerDisplay.getSetting('isRecordGeoLocationOnProofOfPlay', false) === '1';
this.state.displayStatus = registerDisplay.status || 0;

Expand Down Expand Up @@ -257,6 +259,7 @@ export class Config {
displayName: this.displayName,
settings: this.settings,
isConfigured: this.isConfigured(),
displayTags: this.displayTags,
state: this.state.toJson(),
});
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ const createWindow = () => {
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false,
webSecurity: true,
webSecurity: false,
},
});

Expand Down Expand Up @@ -722,7 +722,7 @@ async function dataWidgetUpdate(file: RequiredFile) {
}

let screenshotIntervalId: NodeJS.Timeout | null = null;
const initXmdsEventHandlers = async function (config: Config, xmr: Xmr) {
const initXmdsEventHandlers = async function (config: Config, xmr: Xmr, win: BrowserWindow) {
// Bind to some events
xmds.on('collecting', () => {
console.debug('[Xmds::on("collecting")] > Collecting Data with collection interval ' +
Expand All @@ -735,9 +735,13 @@ const initXmdsEventHandlers = async function (config: Config, xmr: Xmr) {
registerDisplay: data,
shouldParse: false,
});

const prevDisplayTags = JSON.stringify(config.displayTags);
await config.setConfig(data);

// Only notify the renderer when tags actually change to avoid unnecessary updates.
if (JSON.stringify(config.displayTags) !== prevDisplayTags) {
win.webContents.send('update-display-tags', config.displayTags);
}

// Successfully registered with the CMS, so we are no longer running from a cached schedule.
config.state.usingCachedSchedule = false;

Expand Down Expand Up @@ -1266,7 +1270,7 @@ const mainFunctions = {

// Bind event handlers
await initXmrEventHandlers();
await initXmdsEventHandlers(config, xmr);
await initXmdsEventHandlers(config, xmr, win);
await initSspEventHandlers();

// Delete faults on app start/reboot
Expand Down Expand Up @@ -1430,7 +1434,7 @@ app.whenReady().then(() => {
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': [
"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' http://localhost:9696 https://develop.xibo.co.uk data: https:; connect-src 'self' http://localhost:9696 https://auth.signlicence.co.uk; media-src 'self' http://localhost:9696 https:; frame-src 'self' http://localhost:9696; font-src 'self' http://localhost:9696 http://localhost data:;",
"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:9696; style-src 'self' 'unsafe-inline' http://localhost:9696; img-src 'self' http://localhost:9696 https://develop.xibo.co.uk data: https:; connect-src 'self' http://localhost:9696 https://auth.signlicence.co.uk; media-src 'self' http://localhost:9696 https:; frame-src 'self' http://localhost:9696 https: http:; font-src 'self' http://localhost:9696 http://localhost data:;",
],
// 'Access-Control-Allow-Origin': ['http://localhost:5173'], // Allow any domain to access
'Access-Control-Allow-Methods': ['GET, POST, PUT, DELETE, OPTIONS'], // Allowed methods
Expand Down
29 changes: 29 additions & 0 deletions src/main/xmds/response/registerDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,33 @@ export class RegisterDisplay {

return collection;
}

/**
* Returns display tags from the RegisterDisplay response as a name/value map.
*/
getTags(): Record<string, string> {
const tagsNode = this.settings && this.settings['tags'];
if (!tagsNode || !tagsNode.length) {
return {};
}

const tags: Record<string, string> = {};
// XML parser wraps repeated elements in arrays, hence the [0] indexing.
const tagList = tagsNode[0].tag;

if (!tagList || !tagList.length) {
return {};
}

for (const tagObject of tagList) {
const tagName = tagObject.tagName?.[0] ?? '';
const tagValue = tagObject.tagValue?.[0] ?? '';

if (tagName) {
tags[tagName] = tagValue;
}
}

return tags;
}
}
1 change: 1 addition & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const playerApi: PlayerAPI = {
onXlrExpireWidget: (callback) => ipcRenderer.on('xlr-expire-widget', (_event, widgetId) => callback(widgetId)),
onXlrExtendWidgetDuration: (callback) => ipcRenderer.on('xlr-extend-widget-duration', (_event, widgetId, duration) => callback(widgetId, duration)),
onXlrSetWidgetDuration: (callback) => ipcRenderer.on('xlr-set-widget-duration', (_event, widgetId, duration) => callback(widgetId, duration)),
onUpdateDisplayTags: (callback) => ipcRenderer.on('update-display-tags', (_event, tags) => callback(tags)),
onUpdateDataConnectors: (callback) => ipcRenderer.on('update-data-connectors', (_event, connectors) => callback(connectors)),

// Render to main
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export const startApp = async () => {
splashScreen: logo,
logo: logo,
},
displayTags: config.displayTags ?? {},
};

// Create a splash screen
Expand Down Expand Up @@ -365,6 +366,12 @@ window.playerAPI.onXlrSetWidgetDuration((widgetId, duration) => {
xlr.setWidgetDuration(widgetId, duration);
});

window.playerAPI.onUpdateDisplayTags((tags) => {
if (xlr) {
xlr.config.displayTags = tags;
}
});

window.playerAPI.onUpdateDataConnectors((connectors) => {
console.debug('[Renderer::onUpdateDataConnectors]', { count: connectors.length });
void dataConnectorManager.sync(connectors);
Expand Down
2 changes: 2 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ConfigData {
displayName?: string;
settings: any;
isConfigured: boolean;
displayTags?: Record<string, string>;
state: StateData;
}

Expand Down Expand Up @@ -117,6 +118,7 @@ export interface PlayerAPI {
onXlrExpireWidget: (callback: (widgetId: string) => void) => void;
onXlrExtendWidgetDuration: (callback: (widgetId: string, duration: number) => void) => void;
onXlrSetWidgetDuration: (callback: (widgetId: string, duration: number) => void) => void;
onUpdateDisplayTags: (callback: (tags: Record<string, string>) => void) => void;
onUpdateDataConnectors: (callback: (connectors: DataConnectorPayload[]) => void) => void;

// Render to main
Expand Down
Loading