@inditextech/weave-store-azure-web-pubsub 0.26.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs +34 -24
- package/dist/client.d.cts +6 -3
- package/dist/client.d.ts +6 -3
- package/dist/client.js +34 -24
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -1455,16 +1455,17 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
1455
1455
|
* @param {number} [options.resyncInterval] Request server state every `resyncInterval` milliseconds.
|
|
1456
1456
|
* @param {number} [options.tokenProvider] token generator for negotiation.
|
|
1457
1457
|
*/
|
|
1458
|
-
constructor(url, topic, doc, options = {
|
|
1458
|
+
constructor(instance, url, topic, doc, options = {
|
|
1459
1459
|
resyncInterval: 15 * 1e3,
|
|
1460
1460
|
tokenProvider: null
|
|
1461
1461
|
}) {
|
|
1462
1462
|
super();
|
|
1463
|
+
this.instance = instance;
|
|
1463
1464
|
this._options = options;
|
|
1464
1465
|
this.doc = doc;
|
|
1465
1466
|
this.topic = topic;
|
|
1467
|
+
this._fetchClient = fetch;
|
|
1466
1468
|
this._url = url;
|
|
1467
|
-
this._connectionUrl = null;
|
|
1468
1469
|
this._uuid = (0, uuid.v4)();
|
|
1469
1470
|
this._status = "disconnected";
|
|
1470
1471
|
this._wsConnected = false;
|
|
@@ -1534,12 +1535,15 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
1534
1535
|
this._ws.close();
|
|
1535
1536
|
}
|
|
1536
1537
|
}
|
|
1537
|
-
|
|
1538
|
+
setFetchClient(fetchClient = window.fetch) {
|
|
1539
|
+
this._fetchClient = fetchClient.bind(window);
|
|
1540
|
+
}
|
|
1541
|
+
async fetchConnectionUrl() {
|
|
1538
1542
|
try {
|
|
1539
|
-
const res = await
|
|
1543
|
+
const res = await this._fetchClient(this._url);
|
|
1540
1544
|
if (res.ok) {
|
|
1541
1545
|
const data = await res.json();
|
|
1542
|
-
|
|
1546
|
+
return data.url;
|
|
1543
1547
|
} else throw new Error(`Failed to fetch connection url from: ${this._url}`);
|
|
1544
1548
|
} catch (err) {
|
|
1545
1549
|
throw new Error(`Failed to fetch connection url from: ${this._url}`);
|
|
@@ -1547,8 +1551,26 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
1547
1551
|
}
|
|
1548
1552
|
async start() {
|
|
1549
1553
|
if (this._wsConnected || this._ws) return;
|
|
1550
|
-
|
|
1551
|
-
|
|
1554
|
+
const websocket = new reconnecting_websocket.default(async () => {
|
|
1555
|
+
let url = "https://error";
|
|
1556
|
+
let error = null;
|
|
1557
|
+
try {
|
|
1558
|
+
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1559
|
+
loading: true,
|
|
1560
|
+
error: null
|
|
1561
|
+
});
|
|
1562
|
+
url = await this.fetchConnectionUrl();
|
|
1563
|
+
} catch (ex) {
|
|
1564
|
+
error = ex;
|
|
1565
|
+
} finally {
|
|
1566
|
+
if (error) this.instance.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.ERROR);
|
|
1567
|
+
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1568
|
+
loading: false,
|
|
1569
|
+
error
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
return url;
|
|
1573
|
+
}, AzureWebPubSubJsonProtocol);
|
|
1552
1574
|
websocket.binaryType = "arraybuffer";
|
|
1553
1575
|
this._ws = websocket;
|
|
1554
1576
|
this._wsConnected = false;
|
|
@@ -1647,7 +1669,7 @@ var WeaveStoreAzureWebPubsub = class extends __inditextech_weave_sdk.WeaveStore
|
|
|
1647
1669
|
}
|
|
1648
1670
|
init() {
|
|
1649
1671
|
const { url } = this.azureWebPubsubOptions;
|
|
1650
|
-
this.provider = new WeaveStoreAzureWebPubSubSyncClient(url, this.roomId, this.getDocument(), {
|
|
1672
|
+
this.provider = new WeaveStoreAzureWebPubSubSyncClient(this, url, this.roomId, this.getDocument(), {
|
|
1651
1673
|
resyncInterval: 1e3,
|
|
1652
1674
|
tokenProvider: null
|
|
1653
1675
|
});
|
|
@@ -1663,27 +1685,15 @@ var WeaveStoreAzureWebPubsub = class extends __inditextech_weave_sdk.WeaveStore
|
|
|
1663
1685
|
this.handleConnectionStatusChange(status);
|
|
1664
1686
|
});
|
|
1665
1687
|
}
|
|
1688
|
+
emitEvent(name, payload) {
|
|
1689
|
+
this.instance.emitEvent(name, payload);
|
|
1690
|
+
}
|
|
1666
1691
|
async connect() {
|
|
1667
1692
|
const { fetchClient } = this.azureWebPubsubOptions;
|
|
1668
1693
|
const awareness = this.provider.awareness;
|
|
1669
1694
|
awareness.on("update", this.handleAwarenessChange.bind(this));
|
|
1670
1695
|
awareness.on("change", this.handleAwarenessChange.bind(this));
|
|
1671
|
-
|
|
1672
|
-
try {
|
|
1673
|
-
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1674
|
-
loading: true,
|
|
1675
|
-
error: null
|
|
1676
|
-
});
|
|
1677
|
-
await this.provider.fetchConnectionUrl(fetchClient ?? fetch);
|
|
1678
|
-
} catch (ex) {
|
|
1679
|
-
error = ex;
|
|
1680
|
-
} finally {
|
|
1681
|
-
if (error) this.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.ERROR);
|
|
1682
|
-
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1683
|
-
loading: false,
|
|
1684
|
-
error
|
|
1685
|
-
});
|
|
1686
|
-
}
|
|
1696
|
+
this.provider.setFetchClient(fetchClient ?? window.fetch);
|
|
1687
1697
|
await this.provider.start();
|
|
1688
1698
|
}
|
|
1689
1699
|
disconnect() {
|
package/dist/client.d.cts
CHANGED
|
@@ -53,9 +53,10 @@ interface ClientOptions {
|
|
|
53
53
|
declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
54
54
|
doc: Doc;
|
|
55
55
|
topic: string;
|
|
56
|
+
private instance;
|
|
56
57
|
private _ws;
|
|
57
58
|
private _url;
|
|
58
|
-
private
|
|
59
|
+
private _fetchClient;
|
|
59
60
|
private _status;
|
|
60
61
|
private _wsConnected;
|
|
61
62
|
private _synced;
|
|
@@ -74,7 +75,7 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
74
75
|
* @param {number} [options.resyncInterval] Request server state every `resyncInterval` milliseconds.
|
|
75
76
|
* @param {number} [options.tokenProvider] token generator for negotiation.
|
|
76
77
|
*/
|
|
77
|
-
constructor(url: string, topic: string, doc: Doc, options?: ClientOptions);
|
|
78
|
+
constructor(instance: WeaveStoreAzureWebPubsub, url: string, topic: string, doc: Doc, options?: ClientOptions);
|
|
78
79
|
get awareness(): awarenessProtocol.Awareness;
|
|
79
80
|
get synced(): boolean;
|
|
80
81
|
set synced(state: boolean);
|
|
@@ -83,7 +84,8 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
83
84
|
setupResyncInterval(): void;
|
|
84
85
|
destroy(): void;
|
|
85
86
|
stop(): void;
|
|
86
|
-
|
|
87
|
+
setFetchClient(fetchClient?: FetchClient): void;
|
|
88
|
+
fetchConnectionUrl(): Promise<string>;
|
|
87
89
|
start(): Promise<void>;
|
|
88
90
|
} //#endregion
|
|
89
91
|
//#region src/store-azure-web-pubsub.d.ts
|
|
@@ -96,6 +98,7 @@ declare class WeaveStoreAzureWebPubsub extends WeaveStore {
|
|
|
96
98
|
protected awarenessCallback: (changes: any) => void;
|
|
97
99
|
constructor(storeOptions: WeaveStoreOptions, azureWebPubsubOptions: WeaveStoreAzureWebPubsubOptions);
|
|
98
100
|
private init;
|
|
101
|
+
emitEvent<T>(name: string, payload?: T): void;
|
|
99
102
|
connect(): Promise<void>;
|
|
100
103
|
disconnect(): void;
|
|
101
104
|
handleAwarenessChange(emit?: boolean): void;
|
package/dist/client.d.ts
CHANGED
|
@@ -53,9 +53,10 @@ interface ClientOptions {
|
|
|
53
53
|
declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
54
54
|
doc: Doc;
|
|
55
55
|
topic: string;
|
|
56
|
+
private instance;
|
|
56
57
|
private _ws;
|
|
57
58
|
private _url;
|
|
58
|
-
private
|
|
59
|
+
private _fetchClient;
|
|
59
60
|
private _status;
|
|
60
61
|
private _wsConnected;
|
|
61
62
|
private _synced;
|
|
@@ -74,7 +75,7 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
74
75
|
* @param {number} [options.resyncInterval] Request server state every `resyncInterval` milliseconds.
|
|
75
76
|
* @param {number} [options.tokenProvider] token generator for negotiation.
|
|
76
77
|
*/
|
|
77
|
-
constructor(url: string, topic: string, doc: Doc, options?: ClientOptions);
|
|
78
|
+
constructor(instance: WeaveStoreAzureWebPubsub, url: string, topic: string, doc: Doc, options?: ClientOptions);
|
|
78
79
|
get awareness(): awarenessProtocol.Awareness;
|
|
79
80
|
get synced(): boolean;
|
|
80
81
|
set synced(state: boolean);
|
|
@@ -83,7 +84,8 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
83
84
|
setupResyncInterval(): void;
|
|
84
85
|
destroy(): void;
|
|
85
86
|
stop(): void;
|
|
86
|
-
|
|
87
|
+
setFetchClient(fetchClient?: FetchClient): void;
|
|
88
|
+
fetchConnectionUrl(): Promise<string>;
|
|
87
89
|
start(): Promise<void>;
|
|
88
90
|
} //#endregion
|
|
89
91
|
//#region src/store-azure-web-pubsub.d.ts
|
|
@@ -96,6 +98,7 @@ declare class WeaveStoreAzureWebPubsub extends WeaveStore {
|
|
|
96
98
|
protected awarenessCallback: (changes: any) => void;
|
|
97
99
|
constructor(storeOptions: WeaveStoreOptions, azureWebPubsubOptions: WeaveStoreAzureWebPubsubOptions);
|
|
98
100
|
private init;
|
|
101
|
+
emitEvent<T>(name: string, payload?: T): void;
|
|
99
102
|
connect(): Promise<void>;
|
|
100
103
|
disconnect(): void;
|
|
101
104
|
handleAwarenessChange(emit?: boolean): void;
|
package/dist/client.js
CHANGED
|
@@ -1432,16 +1432,17 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
1432
1432
|
* @param {number} [options.resyncInterval] Request server state every `resyncInterval` milliseconds.
|
|
1433
1433
|
* @param {number} [options.tokenProvider] token generator for negotiation.
|
|
1434
1434
|
*/
|
|
1435
|
-
constructor(url, topic, doc, options = {
|
|
1435
|
+
constructor(instance, url, topic, doc, options = {
|
|
1436
1436
|
resyncInterval: 15 * 1e3,
|
|
1437
1437
|
tokenProvider: null
|
|
1438
1438
|
}) {
|
|
1439
1439
|
super();
|
|
1440
|
+
this.instance = instance;
|
|
1440
1441
|
this._options = options;
|
|
1441
1442
|
this.doc = doc;
|
|
1442
1443
|
this.topic = topic;
|
|
1444
|
+
this._fetchClient = fetch;
|
|
1443
1445
|
this._url = url;
|
|
1444
|
-
this._connectionUrl = null;
|
|
1445
1446
|
this._uuid = v4();
|
|
1446
1447
|
this._status = "disconnected";
|
|
1447
1448
|
this._wsConnected = false;
|
|
@@ -1511,12 +1512,15 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
1511
1512
|
this._ws.close();
|
|
1512
1513
|
}
|
|
1513
1514
|
}
|
|
1514
|
-
|
|
1515
|
+
setFetchClient(fetchClient = window.fetch) {
|
|
1516
|
+
this._fetchClient = fetchClient.bind(window);
|
|
1517
|
+
}
|
|
1518
|
+
async fetchConnectionUrl() {
|
|
1515
1519
|
try {
|
|
1516
|
-
const res = await
|
|
1520
|
+
const res = await this._fetchClient(this._url);
|
|
1517
1521
|
if (res.ok) {
|
|
1518
1522
|
const data = await res.json();
|
|
1519
|
-
|
|
1523
|
+
return data.url;
|
|
1520
1524
|
} else throw new Error(`Failed to fetch connection url from: ${this._url}`);
|
|
1521
1525
|
} catch (err) {
|
|
1522
1526
|
throw new Error(`Failed to fetch connection url from: ${this._url}`);
|
|
@@ -1524,8 +1528,26 @@ var WeaveStoreAzureWebPubSubSyncClient = class extends Emittery {
|
|
|
1524
1528
|
}
|
|
1525
1529
|
async start() {
|
|
1526
1530
|
if (this._wsConnected || this._ws) return;
|
|
1527
|
-
|
|
1528
|
-
|
|
1531
|
+
const websocket = new ReconnectingWebSocket(async () => {
|
|
1532
|
+
let url = "https://error";
|
|
1533
|
+
let error = null;
|
|
1534
|
+
try {
|
|
1535
|
+
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1536
|
+
loading: true,
|
|
1537
|
+
error: null
|
|
1538
|
+
});
|
|
1539
|
+
url = await this.fetchConnectionUrl();
|
|
1540
|
+
} catch (ex) {
|
|
1541
|
+
error = ex;
|
|
1542
|
+
} finally {
|
|
1543
|
+
if (error) this.instance.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.ERROR);
|
|
1544
|
+
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1545
|
+
loading: false,
|
|
1546
|
+
error
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
return url;
|
|
1550
|
+
}, AzureWebPubSubJsonProtocol);
|
|
1529
1551
|
websocket.binaryType = "arraybuffer";
|
|
1530
1552
|
this._ws = websocket;
|
|
1531
1553
|
this._wsConnected = false;
|
|
@@ -1624,7 +1646,7 @@ var WeaveStoreAzureWebPubsub = class extends WeaveStore {
|
|
|
1624
1646
|
}
|
|
1625
1647
|
init() {
|
|
1626
1648
|
const { url } = this.azureWebPubsubOptions;
|
|
1627
|
-
this.provider = new WeaveStoreAzureWebPubSubSyncClient(url, this.roomId, this.getDocument(), {
|
|
1649
|
+
this.provider = new WeaveStoreAzureWebPubSubSyncClient(this, url, this.roomId, this.getDocument(), {
|
|
1628
1650
|
resyncInterval: 1e3,
|
|
1629
1651
|
tokenProvider: null
|
|
1630
1652
|
});
|
|
@@ -1640,27 +1662,15 @@ var WeaveStoreAzureWebPubsub = class extends WeaveStore {
|
|
|
1640
1662
|
this.handleConnectionStatusChange(status);
|
|
1641
1663
|
});
|
|
1642
1664
|
}
|
|
1665
|
+
emitEvent(name, payload) {
|
|
1666
|
+
this.instance.emitEvent(name, payload);
|
|
1667
|
+
}
|
|
1643
1668
|
async connect() {
|
|
1644
1669
|
const { fetchClient } = this.azureWebPubsubOptions;
|
|
1645
1670
|
const awareness = this.provider.awareness;
|
|
1646
1671
|
awareness.on("update", this.handleAwarenessChange.bind(this));
|
|
1647
1672
|
awareness.on("change", this.handleAwarenessChange.bind(this));
|
|
1648
|
-
|
|
1649
|
-
try {
|
|
1650
|
-
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1651
|
-
loading: true,
|
|
1652
|
-
error: null
|
|
1653
|
-
});
|
|
1654
|
-
await this.provider.fetchConnectionUrl(fetchClient ?? fetch);
|
|
1655
|
-
} catch (ex) {
|
|
1656
|
-
error = ex;
|
|
1657
|
-
} finally {
|
|
1658
|
-
if (error) this.handleConnectionStatusChange(WEAVE_STORE_CONNECTION_STATUS.ERROR);
|
|
1659
|
-
this.instance.emitEvent("onStoreFetchConnectionUrl", {
|
|
1660
|
-
loading: false,
|
|
1661
|
-
error
|
|
1662
|
-
});
|
|
1663
|
-
}
|
|
1673
|
+
this.provider.setFetchClient(fetchClient ?? window.fetch);
|
|
1664
1674
|
await this.provider.start();
|
|
1665
1675
|
}
|
|
1666
1676
|
disconnect() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inditextech/weave-store-azure-web-pubsub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"yjs": "13.6.26"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@inditextech/weave-sdk": "0.
|
|
63
|
+
"@inditextech/weave-sdk": "0.27.0",
|
|
64
64
|
"@koa/cors": "^5.0.0",
|
|
65
65
|
"@types/express": "^5.0.1",
|
|
66
66
|
"@types/ioredis": "^4.28.10",
|