Add some debug messages

This commit is contained in:
Jan Oberhauser 2020-06-05 08:23:40 +02:00
parent afe0d16a9a
commit a03d5c6e14
2 changed files with 19 additions and 0 deletions

View file

@ -23,6 +23,7 @@ export class Push {
});
this.channel.on('disconnect', (channel: string, res: express.Response) => {
console.log('>> Push.disconnect');
if (res.req !== undefined) {
delete this.connections[res.req.query.sessionId as string];
}
@ -39,13 +40,17 @@ export class Push {
* @memberof Push
*/
add(sessionId: string, req: express.Request, res: express.Response) {
console.log('>> Push.add 1');
if (this.connections[sessionId] !== undefined) {
console.log('>> Push.add 2');
// Make sure to remove existing connection with the same session
// id if one exists already
this.connections[sessionId].end();
this.channel.removeClient(this.connections[sessionId]);
}
console.log('>> Push.add 3');
this.connections[sessionId] = res;
this.channel.addClient(req, res);
}
@ -63,6 +68,7 @@ export class Push {
send(type: IPushDataType, data: any, sessionId?: string) { // tslint:disable-line:no-any
console.log('>> Push.send 1');
if (sessionId !== undefined && this.connections[sessionId] === undefined) {
// TODO: Log that properly!
console.error(`The session "${sessionId}" is not registred.`);
@ -74,10 +80,13 @@ export class Push {
data,
};
console.log('>> Push.send 2');
if (sessionId === undefined) {
console.log('>> Push.send 3');
// Send to all connected clients
this.channel.send(JSON.stringify(sendData));
} else {
console.log('>> Push.send 4');
// Send only to a specific client
this.channel.send(JSON.stringify(sendData), [this.connections[sessionId]]);
}

View file

@ -230,13 +230,23 @@ class App {
// Get push connections
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log({
headers: req.headers,
method: req.method,
url: req.url,
query: req.query,
});
if (req.url.indexOf('/rest/push') === 0) {
console.log('*** Is Push-Connect-Request');
// TODO: Later also has to add some kind of authentication token
if (req.query.sessionId === undefined) {
next(new Error('The query parameter "sessionId" is missing!'));
return;
}
console.log('*** Push-Connection gets added');
this.push.add(req.query.sessionId as string, req, res);
return;
}