UNPKG

@opentiny/fluent-editor

Version:

A rich text editor based on Quill 2.0, which extends rich modules and formats on the basis of Quill. It's powerful and out-of-the-box.

104 lines (103 loc) 3.42 kB
"use strict"; var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); class WebRTCProviderWrapper { constructor({ awareness, doc, options, onConnect, onDisconnect, onError, onSyncChange, deps }) { __publicField(this, "provider"); __publicField(this, "_isConnected", false); __publicField(this, "_isSynced", false); __publicField(this, "onConnect"); __publicField(this, "onDisconnect"); __publicField(this, "onError"); __publicField(this, "onSyncChange"); __publicField(this, "document"); __publicField(this, "awareness"); __publicField(this, "type"); __publicField(this, "connect", () => { try { this.provider.connect(); } catch (error) { console.warn("[yjs] Error connecting WebRTC provider:", error); } }); __publicField(this, "destroy", () => { try { this.provider.destroy(); } catch (error) { console.warn("[yjs] Error destroying WebRTC provider:", error); } }); __publicField(this, "disconnect", () => { try { this.provider.disconnect(); this._isConnected = false; this._isSynced = false; } catch (error) { console.warn("[yjs] Error disconnecting WebRTC provider:", error); } }); this.onConnect = onConnect; this.onDisconnect = onDisconnect; this.onError = onError; this.onSyncChange = onSyncChange; const { Y, Awareness, WebrtcProvider } = deps || window; if (!WebrtcProvider) { throw new Error("WebrtcProvider dependency not provided"); } this.document = doc || new Y.Doc(); this.awareness = awareness ?? new Awareness(this.document); try { this.provider = new WebrtcProvider(options.roomName, this.document, { awareness: this.awareness, ...options }); this.provider.on("status", (status) => { var _a, _b, _c, _d; const wasConnected = this._isConnected; this._isConnected = status.connected; if (status.connected) { if (!wasConnected) { (_a = this.onConnect) == null ? void 0 : _a.call(this); } if (!this._isSynced) { this._isSynced = true; (_b = this.onSyncChange) == null ? void 0 : _b.call(this, true); } } else { if (wasConnected) { (_c = this.onDisconnect) == null ? void 0 : _c.call(this); if (this._isSynced) { this._isSynced = false; (_d = this.onSyncChange) == null ? void 0 : _d.call(this, false); } } } }); } catch (error) { console.warn("[yjs] Error creating WebRTC provider:", error); onError == null ? void 0 : onError(error instanceof Error ? error : new Error(String(error))); } } get isConnected() { return this._isConnected; } get isSynced() { return this._isSynced; } getProvider() { return this.provider; } } exports.WebRTCProviderWrapper = WebRTCProviderWrapper; //# sourceMappingURL=webrtc.cjs.js.map