@matrix-widget-toolkit/api 3.0.0 → 3.0.1

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.
@@ -1043,12 +1043,19 @@ var WidgetApiImpl = /** @class */ (function () {
1043
1043
  /** {@inheritDoc WidgetApi.widgetParameters} */
1044
1044
  widgetParameters, _a) {
1045
1045
  var _b = _a === void 0 ? {} : _a, _c = _b.capabilities, capabilities = _c === void 0 ? [] : _c, _d = _b.supportStandalone, supportStandalone = _d === void 0 ? false : _d;
1046
+ var _this = this;
1046
1047
  this.matrixWidgetApi = matrixWidgetApi$1;
1047
1048
  this.widgetId = widgetId;
1048
1049
  this.widgetParameters = widgetParameters;
1049
1050
  var eventName = "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.SendEvent);
1050
1051
  this.events$ = rxjs.fromEvent(this.matrixWidgetApi, eventName, function (event) {
1051
1052
  event.preventDefault();
1053
+ try {
1054
+ _this.matrixWidgetApi.transport.reply(event.detail, {});
1055
+ }
1056
+ catch (_) {
1057
+ // Ignore errors while replying
1058
+ }
1052
1059
  return event;
1053
1060
  }).pipe(rxjs.share());
1054
1061
  this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [matrixWidgetApi.MatrixCapabilities.RequiresClient]), true);
@@ -1294,7 +1301,6 @@ var WidgetApiImpl = /** @class */ (function () {
1294
1301
  };
1295
1302
  /** {@inheritDoc WidgetApi.observeStateEvents} */
1296
1303
  WidgetApiImpl.prototype.observeStateEvents = function (eventType, _a) {
1297
- var _this = this;
1298
1304
  var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
1299
1305
  var currentRoomId = this.widgetParameters.roomId;
1300
1306
  if (!currentRoomId) {
@@ -1307,7 +1313,6 @@ var WidgetApiImpl = /** @class */ (function () {
1307
1313
  matrixEvent.state_key !== undefined &&
1308
1314
  (stateKey === undefined || matrixEvent.state_key === stateKey) &&
1309
1315
  isInRoom(matrixEvent, currentRoomId, roomIds)) {
1310
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1311
1316
  return event.detail.data;
1312
1317
  }
1313
1318
  return undefined;
@@ -1318,45 +1323,31 @@ var WidgetApiImpl = /** @class */ (function () {
1318
1323
  WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
1319
1324
  var _b = _a === void 0 ? {} : _a, roomId = _b.roomId, _c = _b.stateKey, stateKey = _c === void 0 ? '' : _c;
1320
1325
  return __awaiter(this, void 0, void 0, function () {
1321
- var firstEvent$;
1322
- var _this = this;
1323
- return __generator(this, function (_d) {
1324
- firstEvent$ = this.events$.pipe(rxjs.map(function (event) {
1325
- var matrixEvent = event.detail.data;
1326
- if (matrixEvent.sender === _this.widgetParameters.userId &&
1327
- matrixEvent.state_key !== undefined &&
1328
- matrixEvent.type === eventType &&
1329
- (!roomId || matrixEvent.room_id === roomId)) {
1330
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1331
- return event.detail.data;
1332
- }
1333
- return undefined;
1334
- }), rxjs.filter(isDefined), rxjs.first());
1335
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1336
- var subscription, err_2;
1337
- return __generator(this, function (_a) {
1338
- switch (_a.label) {
1339
- case 0:
1340
- subscription = firstEvent$.subscribe({
1341
- next: function (event) { return resolve(event); },
1342
- error: function (err) { return reject(err); },
1343
- });
1344
- _a.label = 1;
1345
- case 1:
1346
- _a.trys.push([1, 3, , 4]);
1347
- return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
1348
- case 2:
1349
- _a.sent();
1350
- return [3 /*break*/, 4];
1351
- case 3:
1352
- err_2 = _a.sent();
1353
- subscription.unsubscribe();
1354
- reject(err_2);
1355
- return [3 /*break*/, 4];
1356
- case 4: return [2 /*return*/];
1357
- }
1358
- });
1359
- }); })];
1326
+ var subject, subscription, _d, event_id_1, room_id_1, event_1;
1327
+ return __generator(this, function (_e) {
1328
+ switch (_e.label) {
1329
+ case 0:
1330
+ subject = new rxjs.ReplaySubject();
1331
+ subscription = this.events$.subscribe(function (e) { return subject.next(e); });
1332
+ _e.label = 1;
1333
+ case 1:
1334
+ _e.trys.push([1, , 4, 5]);
1335
+ return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
1336
+ case 2:
1337
+ _d = _e.sent(), event_id_1 = _d.event_id, room_id_1 = _d.room_id;
1338
+ return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
1339
+ var matrixEvent = event.detail.data;
1340
+ return (matrixEvent.event_id === event_id_1 &&
1341
+ matrixEvent.room_id === room_id_1);
1342
+ }), rxjs.map(function (event) { return event.detail.data; })))];
1343
+ case 3:
1344
+ event_1 = _e.sent();
1345
+ return [2 /*return*/, event_1];
1346
+ case 4:
1347
+ subscription.unsubscribe();
1348
+ return [7 /*endfinally*/];
1349
+ case 5: return [2 /*return*/];
1350
+ }
1360
1351
  });
1361
1352
  });
1362
1353
  };
@@ -1374,7 +1365,6 @@ var WidgetApiImpl = /** @class */ (function () {
1374
1365
  };
1375
1366
  /** {@inheritDoc WidgetApi.observeRoomEvents} */
1376
1367
  WidgetApiImpl.prototype.observeRoomEvents = function (eventType, _a) {
1377
- var _this = this;
1378
1368
  var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
1379
1369
  var currentRoomId = this.widgetParameters.roomId;
1380
1370
  if (!currentRoomId) {
@@ -1387,7 +1377,6 @@ var WidgetApiImpl = /** @class */ (function () {
1387
1377
  matrixEvent.state_key === undefined &&
1388
1378
  (!messageType || matrixEvent.content.msgtype === messageType) &&
1389
1379
  isInRoom(matrixEvent, currentRoomId, roomIds)) {
1390
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1391
1380
  return event.detail.data;
1392
1381
  }
1393
1382
  return undefined;
@@ -1398,45 +1387,31 @@ var WidgetApiImpl = /** @class */ (function () {
1398
1387
  WidgetApiImpl.prototype.sendRoomEvent = function (eventType, content, _a) {
1399
1388
  var _b = _a === void 0 ? {} : _a, roomId = _b.roomId;
1400
1389
  return __awaiter(this, void 0, void 0, function () {
1401
- var firstEvents$;
1402
- var _this = this;
1403
- return __generator(this, function (_c) {
1404
- firstEvents$ = this.events$.pipe(rxjs.map(function (event) {
1405
- var matrixEvent = event.detail.data;
1406
- if (matrixEvent.sender === _this.widgetParameters.userId &&
1407
- matrixEvent.state_key === undefined &&
1408
- matrixEvent.type === eventType &&
1409
- (!roomId || matrixEvent.room_id === roomId)) {
1410
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1411
- return event.detail.data;
1412
- }
1413
- return undefined;
1414
- }), rxjs.filter(isDefined), rxjs.first());
1415
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1416
- var subscription, err_3;
1417
- return __generator(this, function (_a) {
1418
- switch (_a.label) {
1419
- case 0:
1420
- subscription = firstEvents$.subscribe({
1421
- next: function (event) { return resolve(event); },
1422
- error: function (err) { return reject(err); },
1423
- });
1424
- _a.label = 1;
1425
- case 1:
1426
- _a.trys.push([1, 3, , 4]);
1427
- return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
1428
- case 2:
1429
- _a.sent();
1430
- return [3 /*break*/, 4];
1431
- case 3:
1432
- err_3 = _a.sent();
1433
- subscription.unsubscribe();
1434
- reject(err_3);
1435
- return [3 /*break*/, 4];
1436
- case 4: return [2 /*return*/];
1437
- }
1438
- });
1439
- }); })];
1390
+ var subject, subscription, _c, event_id_2, room_id_2, event_2;
1391
+ return __generator(this, function (_d) {
1392
+ switch (_d.label) {
1393
+ case 0:
1394
+ subject = new rxjs.ReplaySubject();
1395
+ subscription = this.events$.subscribe(function (e) { return subject.next(e); });
1396
+ _d.label = 1;
1397
+ case 1:
1398
+ _d.trys.push([1, , 4, 5]);
1399
+ return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
1400
+ case 2:
1401
+ _c = _d.sent(), event_id_2 = _c.event_id, room_id_2 = _c.room_id;
1402
+ return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
1403
+ var matrixEvent = event.detail.data;
1404
+ return (matrixEvent.event_id === event_id_2 &&
1405
+ matrixEvent.room_id === room_id_2);
1406
+ }), rxjs.map(function (event) { return event.detail.data; })))];
1407
+ case 3:
1408
+ event_2 = _d.sent();
1409
+ return [2 /*return*/, event_2];
1410
+ case 4:
1411
+ subscription.unsubscribe();
1412
+ return [7 /*endfinally*/];
1413
+ case 5: return [2 /*return*/];
1414
+ }
1440
1415
  });
1441
1416
  });
1442
1417
  };
@@ -1588,7 +1563,7 @@ var WidgetApiImpl = /** @class */ (function () {
1588
1563
  WidgetApiImpl.prototype.requestOpenIDConnectTokenInternal = function () {
1589
1564
  var _a;
1590
1565
  return __awaiter(this, void 0, void 0, function () {
1591
- var leywayMilliseconds, openIdToken, err_4;
1566
+ var leywayMilliseconds, openIdToken, err_2;
1592
1567
  return __generator(this, function (_b) {
1593
1568
  switch (_b.label) {
1594
1569
  case 0:
@@ -1609,9 +1584,9 @@ var WidgetApiImpl = /** @class */ (function () {
1609
1584
  };
1610
1585
  return [2 /*return*/, openIdToken];
1611
1586
  case 3:
1612
- err_4 = _b.sent();
1587
+ err_2 = _b.sent();
1613
1588
  this.cachedOpenIdToken = undefined;
1614
- throw err_4;
1589
+ throw err_2;
1615
1590
  case 4: return [2 /*return*/];
1616
1591
  }
1617
1592
  });
@@ -1,6 +1,6 @@
1
1
  import { Symbols, WidgetEventCapability, EventDirection, WidgetApi, WidgetApiToWidgetAction, MatrixCapabilities } from 'matrix-widget-api';
2
2
  import { stringify, parse } from 'qs';
3
- import { filter, fromEvent, firstValueFrom, map, first, throwError, from, mergeAll, concat, share } from 'rxjs';
3
+ import { filter, fromEvent, firstValueFrom, map, first, throwError, from, mergeAll, concat, ReplaySubject, share } from 'rxjs';
4
4
 
5
5
  /*
6
6
  * Copyright 2022 Nordeck IT + Consulting GmbH
@@ -1041,12 +1041,19 @@ var WidgetApiImpl = /** @class */ (function () {
1041
1041
  /** {@inheritDoc WidgetApi.widgetParameters} */
1042
1042
  widgetParameters, _a) {
1043
1043
  var _b = _a === void 0 ? {} : _a, _c = _b.capabilities, capabilities = _c === void 0 ? [] : _c, _d = _b.supportStandalone, supportStandalone = _d === void 0 ? false : _d;
1044
+ var _this = this;
1044
1045
  this.matrixWidgetApi = matrixWidgetApi;
1045
1046
  this.widgetId = widgetId;
1046
1047
  this.widgetParameters = widgetParameters;
1047
1048
  var eventName = "action:".concat(WidgetApiToWidgetAction.SendEvent);
1048
1049
  this.events$ = fromEvent(this.matrixWidgetApi, eventName, function (event) {
1049
1050
  event.preventDefault();
1051
+ try {
1052
+ _this.matrixWidgetApi.transport.reply(event.detail, {});
1053
+ }
1054
+ catch (_) {
1055
+ // Ignore errors while replying
1056
+ }
1050
1057
  return event;
1051
1058
  }).pipe(share());
1052
1059
  this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [MatrixCapabilities.RequiresClient]), true);
@@ -1292,7 +1299,6 @@ var WidgetApiImpl = /** @class */ (function () {
1292
1299
  };
1293
1300
  /** {@inheritDoc WidgetApi.observeStateEvents} */
1294
1301
  WidgetApiImpl.prototype.observeStateEvents = function (eventType, _a) {
1295
- var _this = this;
1296
1302
  var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
1297
1303
  var currentRoomId = this.widgetParameters.roomId;
1298
1304
  if (!currentRoomId) {
@@ -1305,7 +1311,6 @@ var WidgetApiImpl = /** @class */ (function () {
1305
1311
  matrixEvent.state_key !== undefined &&
1306
1312
  (stateKey === undefined || matrixEvent.state_key === stateKey) &&
1307
1313
  isInRoom(matrixEvent, currentRoomId, roomIds)) {
1308
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1309
1314
  return event.detail.data;
1310
1315
  }
1311
1316
  return undefined;
@@ -1316,45 +1321,31 @@ var WidgetApiImpl = /** @class */ (function () {
1316
1321
  WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
1317
1322
  var _b = _a === void 0 ? {} : _a, roomId = _b.roomId, _c = _b.stateKey, stateKey = _c === void 0 ? '' : _c;
1318
1323
  return __awaiter(this, void 0, void 0, function () {
1319
- var firstEvent$;
1320
- var _this = this;
1321
- return __generator(this, function (_d) {
1322
- firstEvent$ = this.events$.pipe(map(function (event) {
1323
- var matrixEvent = event.detail.data;
1324
- if (matrixEvent.sender === _this.widgetParameters.userId &&
1325
- matrixEvent.state_key !== undefined &&
1326
- matrixEvent.type === eventType &&
1327
- (!roomId || matrixEvent.room_id === roomId)) {
1328
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1329
- return event.detail.data;
1330
- }
1331
- return undefined;
1332
- }), filter(isDefined), first());
1333
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1334
- var subscription, err_2;
1335
- return __generator(this, function (_a) {
1336
- switch (_a.label) {
1337
- case 0:
1338
- subscription = firstEvent$.subscribe({
1339
- next: function (event) { return resolve(event); },
1340
- error: function (err) { return reject(err); },
1341
- });
1342
- _a.label = 1;
1343
- case 1:
1344
- _a.trys.push([1, 3, , 4]);
1345
- return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
1346
- case 2:
1347
- _a.sent();
1348
- return [3 /*break*/, 4];
1349
- case 3:
1350
- err_2 = _a.sent();
1351
- subscription.unsubscribe();
1352
- reject(err_2);
1353
- return [3 /*break*/, 4];
1354
- case 4: return [2 /*return*/];
1355
- }
1356
- });
1357
- }); })];
1324
+ var subject, subscription, _d, event_id_1, room_id_1, event_1;
1325
+ return __generator(this, function (_e) {
1326
+ switch (_e.label) {
1327
+ case 0:
1328
+ subject = new ReplaySubject();
1329
+ subscription = this.events$.subscribe(function (e) { return subject.next(e); });
1330
+ _e.label = 1;
1331
+ case 1:
1332
+ _e.trys.push([1, , 4, 5]);
1333
+ return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
1334
+ case 2:
1335
+ _d = _e.sent(), event_id_1 = _d.event_id, room_id_1 = _d.room_id;
1336
+ return [4 /*yield*/, firstValueFrom(subject.pipe(filter(function (event) {
1337
+ var matrixEvent = event.detail.data;
1338
+ return (matrixEvent.event_id === event_id_1 &&
1339
+ matrixEvent.room_id === room_id_1);
1340
+ }), map(function (event) { return event.detail.data; })))];
1341
+ case 3:
1342
+ event_1 = _e.sent();
1343
+ return [2 /*return*/, event_1];
1344
+ case 4:
1345
+ subscription.unsubscribe();
1346
+ return [7 /*endfinally*/];
1347
+ case 5: return [2 /*return*/];
1348
+ }
1358
1349
  });
1359
1350
  });
1360
1351
  };
@@ -1372,7 +1363,6 @@ var WidgetApiImpl = /** @class */ (function () {
1372
1363
  };
1373
1364
  /** {@inheritDoc WidgetApi.observeRoomEvents} */
1374
1365
  WidgetApiImpl.prototype.observeRoomEvents = function (eventType, _a) {
1375
- var _this = this;
1376
1366
  var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
1377
1367
  var currentRoomId = this.widgetParameters.roomId;
1378
1368
  if (!currentRoomId) {
@@ -1385,7 +1375,6 @@ var WidgetApiImpl = /** @class */ (function () {
1385
1375
  matrixEvent.state_key === undefined &&
1386
1376
  (!messageType || matrixEvent.content.msgtype === messageType) &&
1387
1377
  isInRoom(matrixEvent, currentRoomId, roomIds)) {
1388
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1389
1378
  return event.detail.data;
1390
1379
  }
1391
1380
  return undefined;
@@ -1396,45 +1385,31 @@ var WidgetApiImpl = /** @class */ (function () {
1396
1385
  WidgetApiImpl.prototype.sendRoomEvent = function (eventType, content, _a) {
1397
1386
  var _b = _a === void 0 ? {} : _a, roomId = _b.roomId;
1398
1387
  return __awaiter(this, void 0, void 0, function () {
1399
- var firstEvents$;
1400
- var _this = this;
1401
- return __generator(this, function (_c) {
1402
- firstEvents$ = this.events$.pipe(map(function (event) {
1403
- var matrixEvent = event.detail.data;
1404
- if (matrixEvent.sender === _this.widgetParameters.userId &&
1405
- matrixEvent.state_key === undefined &&
1406
- matrixEvent.type === eventType &&
1407
- (!roomId || matrixEvent.room_id === roomId)) {
1408
- _this.matrixWidgetApi.transport.reply(event.detail, {});
1409
- return event.detail.data;
1410
- }
1411
- return undefined;
1412
- }), filter(isDefined), first());
1413
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1414
- var subscription, err_3;
1415
- return __generator(this, function (_a) {
1416
- switch (_a.label) {
1417
- case 0:
1418
- subscription = firstEvents$.subscribe({
1419
- next: function (event) { return resolve(event); },
1420
- error: function (err) { return reject(err); },
1421
- });
1422
- _a.label = 1;
1423
- case 1:
1424
- _a.trys.push([1, 3, , 4]);
1425
- return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
1426
- case 2:
1427
- _a.sent();
1428
- return [3 /*break*/, 4];
1429
- case 3:
1430
- err_3 = _a.sent();
1431
- subscription.unsubscribe();
1432
- reject(err_3);
1433
- return [3 /*break*/, 4];
1434
- case 4: return [2 /*return*/];
1435
- }
1436
- });
1437
- }); })];
1388
+ var subject, subscription, _c, event_id_2, room_id_2, event_2;
1389
+ return __generator(this, function (_d) {
1390
+ switch (_d.label) {
1391
+ case 0:
1392
+ subject = new ReplaySubject();
1393
+ subscription = this.events$.subscribe(function (e) { return subject.next(e); });
1394
+ _d.label = 1;
1395
+ case 1:
1396
+ _d.trys.push([1, , 4, 5]);
1397
+ return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
1398
+ case 2:
1399
+ _c = _d.sent(), event_id_2 = _c.event_id, room_id_2 = _c.room_id;
1400
+ return [4 /*yield*/, firstValueFrom(subject.pipe(filter(function (event) {
1401
+ var matrixEvent = event.detail.data;
1402
+ return (matrixEvent.event_id === event_id_2 &&
1403
+ matrixEvent.room_id === room_id_2);
1404
+ }), map(function (event) { return event.detail.data; })))];
1405
+ case 3:
1406
+ event_2 = _d.sent();
1407
+ return [2 /*return*/, event_2];
1408
+ case 4:
1409
+ subscription.unsubscribe();
1410
+ return [7 /*endfinally*/];
1411
+ case 5: return [2 /*return*/];
1412
+ }
1438
1413
  });
1439
1414
  });
1440
1415
  };
@@ -1586,7 +1561,7 @@ var WidgetApiImpl = /** @class */ (function () {
1586
1561
  WidgetApiImpl.prototype.requestOpenIDConnectTokenInternal = function () {
1587
1562
  var _a;
1588
1563
  return __awaiter(this, void 0, void 0, function () {
1589
- var leywayMilliseconds, openIdToken, err_4;
1564
+ var leywayMilliseconds, openIdToken, err_2;
1590
1565
  return __generator(this, function (_b) {
1591
1566
  switch (_b.label) {
1592
1567
  case 0:
@@ -1607,9 +1582,9 @@ var WidgetApiImpl = /** @class */ (function () {
1607
1582
  };
1608
1583
  return [2 /*return*/, openIdToken];
1609
1584
  case 3:
1610
- err_4 = _b.sent();
1585
+ err_2 = _b.sent();
1611
1586
  this.cachedOpenIdToken = undefined;
1612
- throw err_4;
1587
+ throw err_2;
1613
1588
  case 4: return [2 /*return*/];
1614
1589
  }
1615
1590
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/api",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A simplified layer on top of matrix-widget-api to use build widgets.",
5
5
  "author": "Nordeck IT + Consulting GmbH",
6
6
  "license": "Apache-2.0",