2022-04-14 14:25:48 +02:00
|
|
|
class Message {
|
|
|
|
|
|
|
|
constructor(id, data) {
|
|
|
|
this.id = id;
|
|
|
|
this.data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
getId() {
|
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
getData() {
|
|
|
|
return this.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
toString() {
|
|
|
|
return JSON.stringify(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
async send(socket) {
|
|
|
|
if (socket === undefined) {
|
|
|
|
socket = connection.socket;
|
|
|
|
}
|
|
|
|
if (socket === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const data = this.toString();
|
2022-05-03 12:26:15 +02:00
|
|
|
// logger.debug('sending data to \'' + socket.remoteAddress + ':' + socket.remotePort + '\': ' + data);
|
2022-04-14 14:25:48 +02:00
|
|
|
await new Promise((resolve, reject) => {
|
2022-04-21 13:40:00 +02:00
|
|
|
socket.write(data + constants.EVENT_DELIMITER, resolve);
|
2022-04-14 14:25:48 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Message;
|