|
@ -1,7 +1,9 @@ |
|
|
import SubscriptionService from './subscriptionService.js'; |
|
|
import SubscriptionService from './subscriptionService.js'; |
|
|
import { Message, NotificationService } from './notificationService.js'; |
|
|
import { Message, NotificationService } from './notificationService.js'; |
|
|
import { VapidKeys } from './VapidKeys.js'; |
|
|
import { VapidKeys } from './VapidKeys.js'; |
|
|
|
|
|
|
|
|
import VapidService from './vapidService.js'; |
|
|
import VapidService from './vapidService.js'; |
|
|
|
|
|
import DBService from './db.js'; |
|
|
|
|
|
|
|
|
import express, { Express, Request, Response } from 'express'; |
|
|
import express, { Express, Request, Response } from 'express'; |
|
|
|
|
|
|
|
@ -26,7 +28,8 @@ class Server { |
|
|
private worker?: Worker; |
|
|
private worker?: Worker; |
|
|
private subscriptionService: SubscriptionService = SubscriptionService.getInstance(); |
|
|
private subscriptionService: SubscriptionService = SubscriptionService.getInstance(); |
|
|
private notificationService: NotificationService; |
|
|
private notificationService: NotificationService; |
|
|
private vapidService: VapidService = VapidService.getInstance(); |
|
|
dbService: DBService = DBService.getInstance(); |
|
|
|
|
|
vapidService: VapidService = VapidService.getInstance(); |
|
|
private message: Message; |
|
|
private message: Message; |
|
|
|
|
|
|
|
|
constructor(port: number) { |
|
|
constructor(port: number) { |
|
@ -48,9 +51,10 @@ class Server { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.app.get('/vapid', async (_: Request, res: Response) => { |
|
|
this.app.get('/vapid', async (_: Request, res: Response) => { |
|
|
const vapidkeys: VapidKeys = await this.vapidService.getVapidKeys()[0]; |
|
|
const vapidkeys: VapidKeys[] = await this.vapidService.getVapidKeys(); |
|
|
console.log(vapidkeys); |
|
|
const vapidkey = vapidkeys[0]; |
|
|
res.send({}); |
|
|
|
|
|
|
|
|
res.send({"vapidKey": vapidkey['publicKey']}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -61,7 +65,7 @@ class Server { |
|
|
this.worker = new Worker(workerPath, { workerData: 'world' }); |
|
|
this.worker = new Worker(workerPath, { workerData: 'world' }); |
|
|
|
|
|
|
|
|
this.worker.on('message', (message) => { |
|
|
this.worker.on('message', (message) => { |
|
|
console.log(`Received message from worker: ${message} @ ${new Date()}`); |
|
|
console.log(message); |
|
|
this.message = { "title": "Check TimeSafari"} as Message; |
|
|
this.message = { "title": "Check TimeSafari"} as Message; |
|
|
this.notificationService.broadcast(this.message); |
|
|
this.notificationService.broadcast(this.message); |
|
|
}); |
|
|
}); |
|
@ -96,7 +100,25 @@ class Server { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize and start the server
|
|
|
// Initialize and start the server
|
|
|
|
|
|
|
|
|
const server = new Server(3000); |
|
|
const server = new Server(3000); |
|
|
|
|
|
|
|
|
|
|
|
const executeAsyncFunction = async () => { |
|
|
|
|
|
const keys: VapidKeys[] = await server.vapidService.getVapidKeys(); |
|
|
|
|
|
if (keys.length === 0) { |
|
|
|
|
|
await server.vapidService.createVAPIDKeys(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
executeAsyncFunction().catch(error => { |
|
|
|
|
|
// Handle any errors here
|
|
|
|
|
|
console.error('An error occurred:', error); |
|
|
|
|
|
}); |
|
|
|
|
|
}, 5000); // Execute after a delay of 5 seconds
|
|
|
|
|
|
|
|
|
server.start(); |
|
|
server.start(); |
|
|