🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@ixo/matrix-crdt

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ixo/matrix-crdt - npm Package Compare versions

Comparing version
1.0.3
to
1.0.4
+23
-21
dist/ixo-matrix-crdt12.js

@@ -1,13 +0,15 @@

import * as r from "lodash";
import { lifecycle as o, event as i } from "vscode-lib";
import * as a from "yjs";
const d = {
import * as n from "lodash";
import { lifecycle as r, event as s } from "vscode-lib";
import * as o from "yjs";
const a = {
// throttle flushing write events to matrix by 500ms
flushInterval: process.env.NODE_ENV === "test" ? 100 : 500,
// if writing to the room fails, wait 30 seconds before retrying
retryIfForbiddenInterval: 1e3 * 30
retryIfForbiddenInterval: 1e3 * 30,
// maximum number of retry attempts after M_FORBIDDEN (0 = unlimited retries)
maxForbiddenRetries: 3
};
class p extends o.Disposable {
constructor(t, s, e = {}) {
super(), this.matrixClient = t, this.translator = s, this.opts = { ...d, ...e }, this.throttledFlushUpdatesToMatrix = r.throttle(
class l extends r.Disposable {
constructor(t, e, i = {}) {
super(), this.matrixClient = t, this.translator = e, this.opts = { ...a, ...i }, this.throttledFlushUpdatesToMatrix = n.throttle(
this.flushUpdatesToMatrix,

@@ -22,8 +24,9 @@ this.canWrite ? this.opts.flushInterval : this.opts.retryIfForbiddenInterval

roomId;
forbiddenRetryCount = 0;
_onCanWriteChanged = this._register(
new i.Emitter()
new s.Emitter()
);
onCanWriteChanged = this._onCanWriteChanged.event;
_onSentAllEvents = this._register(
new i.Emitter()
new s.Emitter()
);

@@ -40,14 +43,13 @@ onSentAllEvents = this._onSentAllEvents.event;

this.isSendingUpdates = !0;
const t = a.mergeUpdates(this.pendingUpdates);
const t = o.mergeUpdates(this.pendingUpdates);
this.pendingUpdates = [];
let s = !1;
try {
console.log("Sending updates"), await this.translator.sendUpdate(this.matrixClient, this.roomId, t), this.setCanWrite(!0), console.log("sent updates");
console.log("Sending updates"), await this.translator.sendUpdate(this.matrixClient, this.roomId, t), this.setCanWrite(!0), this.forbiddenRetryCount = 0, console.log("sent updates");
} catch (e) {
if (e.errcode === "M_FORBIDDEN") {
console.warn("not allowed to edit document", e), this.setCanWrite(!1);
try {
await this.matrixClient.joinRoom(this.roomId), console.log("joined room", this.roomId), s = !0;
} catch (n) {
console.warn("failed to join room", n);
if (console.warn("not allowed to edit document", e), this.setCanWrite(!1), this.forbiddenRetryCount++, this.opts.maxForbiddenRetries > 0 && this.forbiddenRetryCount >= this.opts.maxForbiddenRetries) {
console.warn(
`Maximum forbidden retry attempts (${this.opts.maxForbiddenRetries}) reached. Stopping retries.`
), this.pendingUpdates = [], this._onSentAllEvents.fire();
return;
}

@@ -64,3 +66,3 @@ } else

},
s ? 0 : this.canWrite ? this.opts.flushInterval : this.opts.retryIfForbiddenInterval
this.canWrite ? this.opts.flushInterval : this.opts.retryIfForbiddenInterval
) : (console.log("_onSentAllEvents"), this._onSentAllEvents.fire());

@@ -79,3 +81,3 @@ };

async waitForFlush() {
!this.pendingUpdates.length && !this.isSendingUpdates || await i.Event.toPromise(this.onSentAllEvents);
!this.pendingUpdates.length && !this.isSendingUpdates || await s.Event.toPromise(this.onSentAllEvents);
}

@@ -87,3 +89,3 @@ dispose() {

export {
p as ThrottledMatrixWriter
l as ThrottledMatrixWriter
};
{
"name": "@ixo/matrix-crdt",
"version": "1.0.3",
"version": "1.0.4",
"private": false,

@@ -5,0 +5,0 @@ "license": "MPL-2.0",

@@ -22,3 +22,5 @@ import { MatrixClient } from "matrix-js-sdk";

* // if writing to the room fails, wait 30 seconds before retrying
* retryIfForbiddenInterval: number = 30000
* retryIfForbiddenInterval: number = 30000,
* // maximum number of retry attempts after M_FORBIDDEN (0 = unlimited retries)
* maxForbiddenRetries: number = 3
* },

@@ -25,0 +27,0 @@ * // Options for `MatrixCRDTEventTranslator`

@@ -7,2 +7,3 @@ import { MatrixClient } from "matrix-js-sdk";

retryIfForbiddenInterval: number;
maxForbiddenRetries: number;
};

@@ -21,2 +22,3 @@ export type ThrottledMatrixWriterOptions = Partial<typeof DEFAULT_OPTIONS>;

private roomId;
private forbiddenRetryCount;
private readonly _onCanWriteChanged;

@@ -23,0 +25,0 @@ readonly onCanWriteChanged: event.Event<void>;