UNPKG

@sendbird/uikit-react-native

Version:

Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

59 lines 3.31 kB
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } class VoiceMessageStatusManager { constructor() { _defineProperty(this, "statusMap", new Map()); _defineProperty(this, "generateKey", (channelUrl, messageId) => { return `${channelUrl}-${messageId}`; }); _defineProperty(this, "subscribe", (channelUrl, messageId, subscriber) => { var _subscribers; const key = this.generateKey(channelUrl, messageId); if (!this.statusMap.has(key)) { this.statusMap.set(key, { currentTime: 0, subscribers: new Set() }); } (_subscribers = this.statusMap.get(key).subscribers) === null || _subscribers === void 0 ? void 0 : _subscribers.add(subscriber); }); _defineProperty(this, "unsubscribe", (channelUrl, messageId, subscriber) => { var _this$statusMap$get, _this$statusMap$get$s; const key = this.generateKey(channelUrl, messageId); (_this$statusMap$get = this.statusMap.get(key)) === null || _this$statusMap$get === void 0 ? void 0 : (_this$statusMap$get$s = _this$statusMap$get.subscribers) === null || _this$statusMap$get$s === void 0 ? void 0 : _this$statusMap$get$s.delete(subscriber); }); _defineProperty(this, "publishAll", () => { this.statusMap.forEach(status => { var _status$subscribers; (_status$subscribers = status.subscribers) === null || _status$subscribers === void 0 ? void 0 : _status$subscribers.forEach(subscriber => { subscriber(status.currentTime); }); }); }); _defineProperty(this, "getCurrentTime", (channelUrl, messageId) => { var _this$statusMap$get2; const key = this.generateKey(channelUrl, messageId); return ((_this$statusMap$get2 = this.statusMap.get(key)) === null || _this$statusMap$get2 === void 0 ? void 0 : _this$statusMap$get2.currentTime) || 0; }); _defineProperty(this, "setCurrentTime", (channelUrl, messageId, currentTime) => { const key = this.generateKey(channelUrl, messageId); if (!this.statusMap.has(key)) { this.statusMap.set(key, { currentTime }); } else { this.statusMap.get(key).currentTime = currentTime; } }); _defineProperty(this, "clear", () => { this.statusMap.forEach(status => { var _status$subscribers2; (_status$subscribers2 = status.subscribers) === null || _status$subscribers2 === void 0 ? void 0 : _status$subscribers2.clear(); }); this.statusMap.clear(); }); } } export default VoiceMessageStatusManager; //# sourceMappingURL=VoiceMessageStatusManager.js.map