Implement client session patch
This commit is contained in:
58
main.js
58
main.js
@@ -161,12 +161,12 @@ class ClientSession {
|
|||||||
let status = this.status;
|
let status = this.status;
|
||||||
this.close();
|
this.close();
|
||||||
if (status === ClientSessionStatus.CONNECTED) {
|
if (status === ClientSessionStatus.CONNECTED) {
|
||||||
this.connect();
|
this.connect().catch(err => this.logger.log1(err));
|
||||||
}
|
}
|
||||||
if (status === ClientSessionStatus.BOUND) {
|
if (status === ClientSessionStatus.BOUND) {
|
||||||
this.connect().then(() => {
|
this.connect().then(() => {
|
||||||
this.bind();
|
this.bind().catch((err => this.logger.log1(err)));
|
||||||
});
|
}).catch((err => this.logger.log1(err)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,6 +703,7 @@ class HTTPServer {
|
|||||||
app.get('/api/client', this.getClientSessions.bind(this));
|
app.get('/api/client', this.getClientSessions.bind(this));
|
||||||
app.post('/api/client', this.createClientSession.bind(this));
|
app.post('/api/client', this.createClientSession.bind(this));
|
||||||
app.get('/api/client/:id', this.getClientSessionById.bind(this));
|
app.get('/api/client/:id', this.getClientSessionById.bind(this));
|
||||||
|
app.patch('/api/client/:id', this.patchClientSession.bind(this));
|
||||||
app.post('/api/client/:id/send', this.send.bind(this));
|
app.post('/api/client/:id/send', this.send.bind(this));
|
||||||
app.post('/api/client/:id/sendMany', this.sendMany.bind(this));
|
app.post('/api/client/:id/sendMany', this.sendMany.bind(this));
|
||||||
app.delete('/api/client/:id/sendMany', this.cancelSendMany.bind(this));
|
app.delete('/api/client/:id/sendMany', this.cancelSendMany.bind(this));
|
||||||
@@ -729,13 +730,13 @@ class HTTPServer {
|
|||||||
|
|
||||||
getClientSessions(req, res) {
|
getClientSessions(req, res) {
|
||||||
this.logger.log1("Getting client sessions");
|
this.logger.log1("Getting client sessions");
|
||||||
res.send(JSON.stringify(clientSessionManager.serialize()));
|
res.send(clientSessionManager.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
createClientSession(req, res) {
|
createClientSession(req, res) {
|
||||||
this.logger.log1("Creating client session");
|
this.logger.log1("Creating client session");
|
||||||
let session = clientSessionManager.createSession(req.body.url, req.body.username, req.body.password);
|
let session = clientSessionManager.createSession(req.body.url, req.body.username, req.body.password);
|
||||||
res.send(JSON.stringify(session.serialize()));
|
res.send(session.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
getClientSessionById(req, res) {
|
getClientSessionById(req, res) {
|
||||||
@@ -743,7 +744,24 @@ class HTTPServer {
|
|||||||
this.logger.log1(`Getting client session by ID ${req.params.id}`);
|
this.logger.log1(`Getting client session by ID ${req.params.id}`);
|
||||||
if (session) {
|
if (session) {
|
||||||
this.logger.log1(`Client session found with ID ${req.params.id}`)
|
this.logger.log1(`Client session found with ID ${req.params.id}`)
|
||||||
res.send(JSON.stringify(session.serialize()));
|
res.send(session.serialize());
|
||||||
|
} else {
|
||||||
|
this.logger.log1(`No client session found with ID ${req.params.id}`);
|
||||||
|
res.status(404).send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patchClientSession(req, res) {
|
||||||
|
let session = clientSessionManager.getSession(req.params.id);
|
||||||
|
if (session) {
|
||||||
|
this.logger.log1(`Client session found with ID ${req.params.id}`)
|
||||||
|
if (!!req.body.username && req.body.username !== session.username) {
|
||||||
|
session.setUsername(req.body.username);
|
||||||
|
}
|
||||||
|
if (!!req.body.password && req.body.password !== session.password) {
|
||||||
|
session.setPassword(req.body.password);
|
||||||
|
}
|
||||||
|
res.send(session.serialize());
|
||||||
} else {
|
} else {
|
||||||
this.logger.log1(`No client session found with ID ${req.params.id}`);
|
this.logger.log1(`No client session found with ID ${req.params.id}`);
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
@@ -758,7 +776,7 @@ class HTTPServer {
|
|||||||
this.logger.log1(`Sending message from ${source} to ${destination} with message ${message} on session with ID ${req.params.id}`)
|
this.logger.log1(`Sending message from ${source} to ${destination} with message ${message} on session with ID ${req.params.id}`)
|
||||||
if (session) {
|
if (session) {
|
||||||
session.send(source, destination, message)
|
session.send(source, destination, message)
|
||||||
.then(pdu => res.send(JSON.stringify(pdu)))
|
.then(pdu => res.send(pdu))
|
||||||
.catch(err => res.status(400).send(JSON.stringify(err)));
|
.catch(err => res.status(400).send(JSON.stringify(err)));
|
||||||
} else {
|
} else {
|
||||||
this.logger.log1(`No session found with ID ${req.params.id}`);
|
this.logger.log1(`No session found with ID ${req.params.id}`);
|
||||||
@@ -781,8 +799,8 @@ class HTTPServer {
|
|||||||
`Sending ${count} messages from ${source} to ${destination} with message ${message} on session with ID ${req.params.id} at a rate of ${perSecond} per second.`);
|
`Sending ${count} messages from ${source} to ${destination} with message ${message} on session with ID ${req.params.id} at a rate of ${perSecond} per second.`);
|
||||||
if (session) {
|
if (session) {
|
||||||
session.sendOnInterval(source, destination, message, interval, count)
|
session.sendOnInterval(source, destination, message, interval, count)
|
||||||
.then(pdu => res.send(JSON.stringify(pdu)))
|
.then(pdu => res.send(pdu))
|
||||||
.catch(err => res.status(400).send(JSON.stringify(err)));
|
.catch(err => res.status(400).send((err)));
|
||||||
} else {
|
} else {
|
||||||
this.logger.log1(`No session found with ID ${req.params.id}`);
|
this.logger.log1(`No session found with ID ${req.params.id}`);
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
@@ -814,7 +832,7 @@ class HTTPServer {
|
|||||||
let session = clientSessionManager.getSession(req.params.id);
|
let session = clientSessionManager.getSession(req.params.id);
|
||||||
if (session) {
|
if (session) {
|
||||||
session.bind()
|
session.bind()
|
||||||
.then(() => res.send(JSON.stringify(session.serialize())))
|
.then(() => res.send(session.serialize()))
|
||||||
.catch(err => res.status(400).send({
|
.catch(err => res.status(400).send({
|
||||||
err: true,
|
err: true,
|
||||||
msg: err
|
msg: err
|
||||||
@@ -830,7 +848,7 @@ class HTTPServer {
|
|||||||
let session = clientSessionManager.getSession(req.params.id);
|
let session = clientSessionManager.getSession(req.params.id);
|
||||||
if (session) {
|
if (session) {
|
||||||
session.connect()
|
session.connect()
|
||||||
.then(() => res.send(JSON.stringify(session.serialize())))
|
.then(() => res.send(session.serialize()))
|
||||||
.catch(err => res.status(400).send({
|
.catch(err => res.status(400).send({
|
||||||
err: true,
|
err: true,
|
||||||
msg: err
|
msg: err
|
||||||
@@ -846,7 +864,7 @@ class HTTPServer {
|
|||||||
let session = clientSessionManager.getSession(req.params.id);
|
let session = clientSessionManager.getSession(req.params.id);
|
||||||
if (session) {
|
if (session) {
|
||||||
session.close()
|
session.close()
|
||||||
.then(() => res.send(JSON.stringify(session.serialize())))
|
.then(() => res.send(session.serialize()))
|
||||||
.catch(err => res.status(400).send({
|
.catch(err => res.status(400).send({
|
||||||
err: true,
|
err: true,
|
||||||
msg: err
|
msg: err
|
||||||
@@ -871,13 +889,13 @@ class HTTPServer {
|
|||||||
|
|
||||||
getCenterSessions(req, res) {
|
getCenterSessions(req, res) {
|
||||||
this.logger.log1("Getting center sessions");
|
this.logger.log1("Getting center sessions");
|
||||||
res.send(JSON.stringify(centerSessionManager.serialize()));
|
res.send(centerSessionManager.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
createCenterSession(req, res) {
|
createCenterSession(req, res) {
|
||||||
this.logger.log1("Creating center session");
|
this.logger.log1("Creating center session");
|
||||||
let session = centerSessionManager.createSession(req.body.port, req.body.username, req.body.password);
|
let session = centerSessionManager.createSession(req.body.port, req.body.username, req.body.password);
|
||||||
res.send(JSON.stringify(session.serialize()));
|
res.send(session.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
getCenterSessionById(req, res) {
|
getCenterSessionById(req, res) {
|
||||||
@@ -885,7 +903,7 @@ class HTTPServer {
|
|||||||
this.logger.log1(`Getting center session by ID ${req.params.id}`);
|
this.logger.log1(`Getting center session by ID ${req.params.id}`);
|
||||||
if (session) {
|
if (session) {
|
||||||
this.logger.log1(`Center session found with ID ${req.params.id}`)
|
this.logger.log1(`Center session found with ID ${req.params.id}`)
|
||||||
res.send(JSON.stringify(session.serialize()));
|
res.send(session.serialize());
|
||||||
} else {
|
} else {
|
||||||
this.logger.log1(`No center session found with ID ${req.params.id}`);
|
this.logger.log1(`No center session found with ID ${req.params.id}`);
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
@@ -900,8 +918,8 @@ class HTTPServer {
|
|||||||
this.logger.log1(`Sending notify message from ${source} to ${destination} with message ${message} on session with ID ${req.params.id}`)
|
this.logger.log1(`Sending notify message from ${source} to ${destination} with message ${message} on session with ID ${req.params.id}`)
|
||||||
if (server) {
|
if (server) {
|
||||||
server.notify(source, destination, message)
|
server.notify(source, destination, message)
|
||||||
.then(pdu => res.send(JSON.stringify(pdu)))
|
.then(pdu => res.send(pdu))
|
||||||
.catch(err => res.status(400).send(JSON.stringify(err)));
|
.catch(err => res.status(400).send(err));
|
||||||
} else {
|
} else {
|
||||||
this.logger.log1(`No session found with ID ${req.params.id}`);
|
this.logger.log1(`No session found with ID ${req.params.id}`);
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
@@ -923,8 +941,8 @@ class HTTPServer {
|
|||||||
`Sending ${count} notify messages from ${source} to ${destination} with message ${message} on session with ID ${req.params.id} at a rate of ${perSecond} per second.`);
|
`Sending ${count} notify messages from ${source} to ${destination} with message ${message} on session with ID ${req.params.id} at a rate of ${perSecond} per second.`);
|
||||||
if (server) {
|
if (server) {
|
||||||
server.notifyOnInterval(source, destination, message, interval, count)
|
server.notifyOnInterval(source, destination, message, interval, count)
|
||||||
.then(pdu => res.send(JSON.stringify(pdu)))
|
.then(pdu => res.send(pdu))
|
||||||
.catch(err => res.status(400).send(JSON.stringify(err)));
|
.catch(err => res.status(400).send(err));
|
||||||
} else {
|
} else {
|
||||||
this.logger.log1(`No session found with ID ${req.params.id}`);
|
this.logger.log1(`No session found with ID ${req.params.id}`);
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
@@ -955,7 +973,7 @@ class HTTPServer {
|
|||||||
let server = centerSessionManager.getSession(req.params.id);
|
let server = centerSessionManager.getSession(req.params.id);
|
||||||
if (server) {
|
if (server) {
|
||||||
server.close()
|
server.close()
|
||||||
.then(() => res.send(JSON.stringify(server.serialize())))
|
.then(() => res.send(server.serialize()))
|
||||||
.catch(err => res.status(400).send({
|
.catch(err => res.status(400).send({
|
||||||
err: true,
|
err: true,
|
||||||
msg: err
|
msg: err
|
||||||
|
Reference in New Issue
Block a user