Bump version to 1.4.1 and tighten client handling
This commit is contained in:
+37
-2
@@ -5,8 +5,10 @@ const path = require('path');
|
||||
const common = require('./common');
|
||||
const { createPlayerRuntime } = require('./player/runtime');
|
||||
const { createPlayerPlaylistService } = require('./player/playlist');
|
||||
const { normalizeDeviceId, registerPlayerOnboardingRoutes } = require('./player/onboarding');
|
||||
const { normalizeDeviceId, registerPlayerOnboardingRoutes, commitDeviceBinding } = require('./player/onboarding');
|
||||
const { createOnboardingStore } = require('./player/onboarding-store');
|
||||
const { registerPlayerRoutes } = require('./player/routes');
|
||||
const { pruneStaleOnboardingDevices } = require('./db');
|
||||
|
||||
|
||||
// Player runtime, upload API, and websocket wiring.
|
||||
@@ -16,6 +18,9 @@ async function start() {
|
||||
const PORT = Number(process.env.PLAYER_PORT || 3001);
|
||||
const ASSET_DIR = path.join(__dirname, 'player', 'public');
|
||||
const UPLOAD_DIR = path.join(__dirname, '..', 'uploads');
|
||||
const ONBOARDING_QUEUE_FILE = path.join(UPLOAD_DIR, 'player-onboarding-queue.json');
|
||||
const DB_SYNC_INTERVAL_MS = Number(process.env.PLAYER_DB_SYNC_INTERVAL_MS || 15000);
|
||||
const onboardingStore = createOnboardingStore(ONBOARDING_QUEUE_FILE);
|
||||
const playerRuntime = createPlayerRuntime({
|
||||
pool: pool,
|
||||
normalizeDeviceId: normalizeDeviceId
|
||||
@@ -31,6 +36,7 @@ async function start() {
|
||||
pool: pool,
|
||||
common: common,
|
||||
playerRuntime: playerRuntime,
|
||||
onboardingStore: onboardingStore,
|
||||
QRCode: require('qrcode')
|
||||
});
|
||||
registerPlayerRoutes(app, {
|
||||
@@ -47,12 +53,41 @@ async function start() {
|
||||
res.status(error.statusCode || 500).send(error.statusCode ? error.message : 'Internal server error');
|
||||
});
|
||||
|
||||
await common.ensureSchema(pool);
|
||||
fs.mkdirSync(UPLOAD_DIR, { recursive: true });
|
||||
|
||||
server.listen(PORT, function () {
|
||||
console.log(`Pulse Signage app listening on port ${PORT}`);
|
||||
});
|
||||
|
||||
async function syncDatabaseState() {
|
||||
try {
|
||||
await common.ensureSchema(pool);
|
||||
|
||||
if (playerRuntime.snapshotAllConnections().length > 0) {
|
||||
await pruneStaleOnboardingDevices(pool);
|
||||
}
|
||||
|
||||
await onboardingStore.flushBindings(function (entry) {
|
||||
return commitDeviceBinding(
|
||||
pool,
|
||||
entry.deviceId,
|
||||
entry.clientName,
|
||||
entry.screenSlug,
|
||||
playerRuntime.isClientNameAvailableOnScreen,
|
||||
playerRuntime.snapshotAllConnections()
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
await syncDatabaseState();
|
||||
setInterval(function () {
|
||||
syncDatabaseState().catch(function (error) {
|
||||
console.error(error);
|
||||
});
|
||||
}, DB_SYNC_INTERVAL_MS);
|
||||
}
|
||||
|
||||
module.exports = { start };
|
||||
|
||||
Reference in New Issue
Block a user