trtc-electron-sdk
Version:
trtc electron sdk
33 lines (32 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
class DevicePixelRatioObserver {
constructor() {
this.mediaQueryString = `(resolution: ${window.devicePixelRatio}dppx)`;
this.mediaQuery = window.matchMedia(this.mediaQueryString);
this.eventEmitter = new events_1.EventEmitter();
this.onPixelRatioChanged = this.onPixelRatioChanged.bind(this);
this.mediaQuery.addEventListener('change', this.onPixelRatioChanged);
}
destroy() {
var _a;
(_a = this.mediaQuery) === null || _a === void 0 ? void 0 : _a.removeEventListener('change', this.onPixelRatioChanged);
this.mediaQuery = null;
this.eventEmitter = null;
}
on(event, func) {
var _a;
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.on(event, func);
}
off(event, func) {
var _a;
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.off(event, func);
}
onPixelRatioChanged() {
var _a;
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.emit('change');
}
}
const devicePixelRationObserver = new DevicePixelRatioObserver();
exports.default = devicePixelRationObserver;