smartuniverse/dist_ts/smartuniverse.classes.universemessage.js

92 lines
5.7 KiB
JavaScript
Raw Normal View History

2020-09-24 18:13:48 +00:00
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UniverseMessage = void 0;
const plugins = __importStar(require("./smartuniverse.plugins"));
const smarttime_1 = require("@pushrocks/smarttime");
const smartuniverse_logging_1 = require("./smartuniverse.logging");
/**
* represents a message within a universe
* acts as a container to save message states like authentication status
*/
class UniverseMessage {
/**
* the constructor to create a universe message
* @param messageArg
* @param attachedPayloadArg
*/
constructor(messageDescriptor) {
/**
* enables unprotected grouping of messages for efficiency purposes.
*/
this.universeChannelList = new plugins.lik.ObjectMap();
/**
* wether the message is authenticated
*/
this.authenticated = false;
this.smartTimestamp = new smarttime_1.TimeStamp(this.timestamp);
this.messageText = messageDescriptor.messageText;
this.targetChannelName = messageDescriptor.targetChannelName;
this.passphrase = messageDescriptor.passphrase;
this.payload = messageDescriptor.payload;
// prevent memory issues
this.setDestructionTimer();
}
static createMessageFromPayload(socketConnectionArg, dataArg) {
const universeMessageInstance = new UniverseMessage(dataArg);
universeMessageInstance.socketConnection = socketConnectionArg;
return universeMessageInstance;
}
setUniverseCache(universeCacheArg) {
this.universeCache = universeCacheArg;
}
setTargetChannel() { }
setDestructionTimer(selfdestructAfterArg) {
if (selfdestructAfterArg) {
this.destructionTimer = new smarttime_1.Timer(selfdestructAfterArg);
this.destructionTimer.start();
// set up self destruction by removing this from the parent messageCache
this.destructionTimer.completed
.then(async () => {
this.universeCache.messageMap.remove(this);
})
.catch(err => {
console.log(err);
console.log(this);
});
}
else {
plugins.smartdelay.delayFor(1000).then(() => {
if (!this.destructionTimer) {
this.setDestructionTimer(6000);
}
});
}
}
/**
* handles bad messages for further analysis
*/
handleAsBadMessage() {
smartuniverse_logging_1.logger.log('warn', 'received a bad message');
}
}
exports.UniverseMessage = UniverseMessage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlbWVzc2FnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0dW5pdmVyc2UuY2xhc3Nlcy51bml2ZXJzZW1lc3NhZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLGlFQUFtRDtBQUduRCxvREFBd0Q7QUFLeEQsbUVBQWlEO0FBRWpEOzs7R0FHRztBQUNILE1BQWEsZUFBZTtJQXVDMUI7Ozs7T0FJRztJQUNILFlBQVksaUJBQThDO1FBcEIxRDs7V0FFRztRQUNJLHdCQUFtQixHQUFHLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxTQUFTLEVBQW1CLENBQUM7UUFFMUU7O1dBRUc7UUFDSSxrQkFBYSxHQUFZLEtBQUssQ0FBQztRQWFwQyxJQUFJLENBQUMsY0FBYyxHQUFHLElBQUkscUJBQVMsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUM7UUFDcEQsSUFBSSxDQUFDLFdBQVcsR0FBRyxpQkFBaUIsQ0FBQyxXQUFXLENBQUM7UUFDakQsSUFBSSxDQUFDLGlCQUFpQixHQUFHLGlCQ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