sinch-rtc
Version:
RTC JavaScript/Web SDK
44 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserInstanceStorage = void 0;
const UserInstance_1 = require("../instance/UserInstance");
class UserInstanceStorage {
constructor(storage, appKey, userId) {
this.storage = storage;
this.appKey = appKey;
this.userId = userId;
}
/**
* Makes a prefix to localStorage item in order to distinguish various instances
* @param key - instance identifier that will be
*/
prefix(key) {
return `sinch:${key}:${this.appKey}:${this.userId}`;
}
/**
* Inserts record to localStorage
* @param instance - representation of Ocra instance
*/
set(instance) {
const key = this.prefix(UserInstanceStorage.INSTANCE_PREFIX);
this.storage.setItem(key, instance.toString());
}
/**
* Takes particular instance with given id
* @param instanceId - id of instance to obtain from localStorage
*/
get() {
return this.getUserInstance(this.prefix(UserInstanceStorage.INSTANCE_PREFIX));
}
remove() {
this.storage.removeItem(UserInstanceStorage.INSTANCE_PREFIX);
}
getUserInstance(key) {
const raw = this.storage.getItem(key);
if (raw)
return UserInstance_1.UserInstance.parse(raw);
}
}
exports.UserInstanceStorage = UserInstanceStorage;
UserInstanceStorage.INSTANCE_PREFIX = "instance:";
//# sourceMappingURL=UserInstanceStorage.js.map