@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.
65 lines (64 loc) • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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 || _subscribers.add(subscriber);
    });
    _defineProperty(this, "unsubscribe", (channelUrl, messageId, subscriber) => {
      var _this$statusMap$get;
      const key = this.generateKey(channelUrl, messageId);
      (_this$statusMap$get = this.statusMap.get(key)) === null || _this$statusMap$get === void 0 || (_this$statusMap$get = _this$statusMap$get.subscribers) === null || _this$statusMap$get === void 0 || _this$statusMap$get.delete(subscriber);
    });
    _defineProperty(this, "publishAll", () => {
      this.statusMap.forEach(status => {
        var _status$subscribers;
        (_status$subscribers = status.subscribers) === null || _status$subscribers === 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 || _status$subscribers2.clear();
      });
      this.statusMap.clear();
    });
  }
}
var _default = exports.default = VoiceMessageStatusManager;
//# sourceMappingURL=VoiceMessageStatusManager.js.map