Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.state.displayStatus = registerDisplay.status || 0;

await this.saveCms();
Expand Down Expand Up @@ -256,6 +258,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 @@ -443,7 +443,7 @@ const createWindow = () => {
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false,
webSecurity: true,
webSecurity: false,
},
});

Expand Down Expand Up @@ -613,7 +613,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 @@ -626,9 +626,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 @@ -1088,7 +1092,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 @@ -1252,7 +1256,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 @@ -82,6 +82,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)),

// Render to main
openChildWindow: (url) => ipcRenderer.send('open-child-window', url),
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 @@ -229,6 +229,7 @@ export const startApp = async () => {
splashScreen: logo,
logo: logo,
},
displayTags: config.displayTags ?? {},
};

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

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

let statusWindowHideTimer: ReturnType<typeof setTimeout> | null = null;

const showStatusWindowFn = (timeout: number) => {
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 @@ -80,6 +81,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;

// Render to main
openChildWindow: (url: string) => void;
Expand Down