rx-postmessenger
Version:
Minimal RxJS adapter for the window.postMessage API for request-response streams and notification streams across frame windows.
39 lines (38 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageFactory = void 0;
var MessageFactory = /** @class */ (function () {
function MessageFactory(IDGenerator) {
this.IDGenerator = IDGenerator;
}
MessageFactory.prototype.makeNotification = function (channel, payload) {
return {
channel: channel,
id: this.IDGenerator.generateID(),
payload: payload,
type: 'notification',
};
};
MessageFactory.prototype.makeRequest = function (channel, payload) {
return {
channel: channel,
id: this.IDGenerator.generateID(),
payload: payload,
type: 'request',
};
};
MessageFactory.prototype.makeResponse = function (requestId, channel, payload) {
return {
channel: channel,
id: this.IDGenerator.generateID(),
payload: payload,
requestId: requestId,
type: 'response',
};
};
MessageFactory.prototype.invalidateID = function (id) {
this.IDGenerator.invalidateID(id);
};
return MessageFactory;
}());
exports.MessageFactory = MessageFactory;