openvidu/openvidu-browser/src/OpenViduInternal/KurentoUtils/kurento-jsonrpc/Mapper.js

61 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-03-22 12:14:38 +01:00
function Mapper() {
var sources = {};
2021-03-22 12:14:38 +01:00
this.forEach = function (callback) {
for (var key in sources) {
var source = sources[key];
2021-03-22 12:14:38 +01:00
for (var key2 in source)
callback(source[key2]);
};
};
2021-03-22 12:14:38 +01:00
this.get = function (id, source) {
var ids = sources[source];
2021-03-22 12:14:38 +01:00
if (ids == undefined)
return undefined;
return ids[id];
};
2021-03-22 12:14:38 +01:00
this.remove = function (id, source) {
var ids = sources[source];
2021-03-22 12:14:38 +01:00
if (ids == undefined)
return;
delete ids[id];
// Check it's empty
2021-03-22 12:14:38 +01:00
for (var i in ids) {
return false
}
delete sources[source];
};
2021-03-22 12:14:38 +01:00
this.set = function (value, id, source) {
if (value == undefined)
return this.remove(id, source);
var ids = sources[source];
2021-03-22 12:14:38 +01:00
if (ids == undefined)
sources[source] = ids = {};
ids[id] = value;
};
};
2021-03-22 12:14:38 +01:00
Mapper.prototype.pop = function (id, source) {
var value = this.get(id, source);
2021-03-22 12:14:38 +01:00
if (value == undefined)
return undefined;
this.remove(id, source);
return value;
};
2021-03-22 12:14:38 +01:00
module.exports = Mapper;