@matrix-widget-toolkit/api 3.0.1 → 3.2.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/build/cjs/index.js +65 -2
- package/build/esm/index.js +65 -2
- package/build/index.d.ts +91 -4
- package/package.json +3 -3
package/build/cjs/index.js
CHANGED
|
@@ -1047,8 +1047,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1047
1047
|
this.matrixWidgetApi = matrixWidgetApi$1;
|
|
1048
1048
|
this.widgetId = widgetId;
|
|
1049
1049
|
this.widgetParameters = widgetParameters;
|
|
1050
|
-
|
|
1051
|
-
this.events$ = rxjs.fromEvent(this.matrixWidgetApi, eventName, function (event) {
|
|
1050
|
+
this.events$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.SendEvent), function (event) {
|
|
1052
1051
|
event.preventDefault();
|
|
1053
1052
|
try {
|
|
1054
1053
|
_this.matrixWidgetApi.transport.reply(event.detail, {});
|
|
@@ -1058,6 +1057,16 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1058
1057
|
}
|
|
1059
1058
|
return event;
|
|
1060
1059
|
}).pipe(rxjs.share());
|
|
1060
|
+
this.toDeviceMessages$ = rxjs.fromEvent(this.matrixWidgetApi, 'action:send_to_device', function (event) {
|
|
1061
|
+
event.preventDefault();
|
|
1062
|
+
try {
|
|
1063
|
+
matrixWidgetApi$1.transport.reply(event.detail, {});
|
|
1064
|
+
}
|
|
1065
|
+
catch (_) {
|
|
1066
|
+
// Ignore errors while replying
|
|
1067
|
+
}
|
|
1068
|
+
return event;
|
|
1069
|
+
}).pipe(rxjs.share());
|
|
1061
1070
|
this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [matrixWidgetApi.MatrixCapabilities.RequiresClient]), true);
|
|
1062
1071
|
}
|
|
1063
1072
|
/**
|
|
@@ -1432,6 +1441,23 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1432
1441
|
});
|
|
1433
1442
|
});
|
|
1434
1443
|
};
|
|
1444
|
+
/** {@inheritDoc WidgetApi.sendToDeviceMessage} */
|
|
1445
|
+
WidgetApiImpl.prototype.sendToDeviceMessage = function (eventType, encrypted, content) {
|
|
1446
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1447
|
+
return __generator(this, function (_a) {
|
|
1448
|
+
switch (_a.label) {
|
|
1449
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.sendToDevice(eventType, encrypted, content)];
|
|
1450
|
+
case 1:
|
|
1451
|
+
_a.sent();
|
|
1452
|
+
return [2 /*return*/];
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
1456
|
+
};
|
|
1457
|
+
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
1458
|
+
WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
|
|
1459
|
+
return this.toDeviceMessages$.pipe(rxjs.map(function (e) { return e.detail.data; }), rxjs.filter(function (e) { return e.type === eventType; }));
|
|
1460
|
+
};
|
|
1435
1461
|
/** {@inheritDoc WidgetApi.openModal} */
|
|
1436
1462
|
WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
|
|
1437
1463
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1592,6 +1618,43 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1592
1618
|
});
|
|
1593
1619
|
});
|
|
1594
1620
|
};
|
|
1621
|
+
/** {@inheritdoc WidgetApi.observeTurnServers} */
|
|
1622
|
+
WidgetApiImpl.prototype.observeTurnServers = function () {
|
|
1623
|
+
return rxjs.from(this.matrixWidgetApi.getTurnServers()).pipe(
|
|
1624
|
+
// For some reason a different naming was chosen for the API, but
|
|
1625
|
+
// we already convert them to the right type for WebRTC consumers.
|
|
1626
|
+
rxjs.map(function (_a) {
|
|
1627
|
+
var uris = _a.uris, username = _a.username, password = _a.password;
|
|
1628
|
+
return ({
|
|
1629
|
+
urls: uris,
|
|
1630
|
+
username: username,
|
|
1631
|
+
credential: password,
|
|
1632
|
+
});
|
|
1633
|
+
}));
|
|
1634
|
+
};
|
|
1635
|
+
/** {@inheritdoc WidgetApi.searchUserDirectory} */
|
|
1636
|
+
WidgetApiImpl.prototype.searchUserDirectory = function (searchTerm, options) {
|
|
1637
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1638
|
+
var results;
|
|
1639
|
+
return __generator(this, function (_a) {
|
|
1640
|
+
switch (_a.label) {
|
|
1641
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.searchUserDirectory(searchTerm, options === null || options === void 0 ? void 0 : options.limit)];
|
|
1642
|
+
case 1:
|
|
1643
|
+
results = (_a.sent()).results;
|
|
1644
|
+
return [2 /*return*/, {
|
|
1645
|
+
results: results.map(function (_a) {
|
|
1646
|
+
var user_id = _a.user_id, display_name = _a.display_name, avatar_url = _a.avatar_url;
|
|
1647
|
+
return ({
|
|
1648
|
+
userId: user_id,
|
|
1649
|
+
displayName: display_name,
|
|
1650
|
+
avatarUrl: avatar_url,
|
|
1651
|
+
});
|
|
1652
|
+
}),
|
|
1653
|
+
}];
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
};
|
|
1595
1658
|
return WidgetApiImpl;
|
|
1596
1659
|
}());
|
|
1597
1660
|
|
package/build/esm/index.js
CHANGED
|
@@ -1045,8 +1045,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1045
1045
|
this.matrixWidgetApi = matrixWidgetApi;
|
|
1046
1046
|
this.widgetId = widgetId;
|
|
1047
1047
|
this.widgetParameters = widgetParameters;
|
|
1048
|
-
|
|
1049
|
-
this.events$ = fromEvent(this.matrixWidgetApi, eventName, function (event) {
|
|
1048
|
+
this.events$ = fromEvent(this.matrixWidgetApi, "action:".concat(WidgetApiToWidgetAction.SendEvent), function (event) {
|
|
1050
1049
|
event.preventDefault();
|
|
1051
1050
|
try {
|
|
1052
1051
|
_this.matrixWidgetApi.transport.reply(event.detail, {});
|
|
@@ -1056,6 +1055,16 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1056
1055
|
}
|
|
1057
1056
|
return event;
|
|
1058
1057
|
}).pipe(share());
|
|
1058
|
+
this.toDeviceMessages$ = fromEvent(this.matrixWidgetApi, 'action:send_to_device', function (event) {
|
|
1059
|
+
event.preventDefault();
|
|
1060
|
+
try {
|
|
1061
|
+
matrixWidgetApi.transport.reply(event.detail, {});
|
|
1062
|
+
}
|
|
1063
|
+
catch (_) {
|
|
1064
|
+
// Ignore errors while replying
|
|
1065
|
+
}
|
|
1066
|
+
return event;
|
|
1067
|
+
}).pipe(share());
|
|
1059
1068
|
this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [MatrixCapabilities.RequiresClient]), true);
|
|
1060
1069
|
}
|
|
1061
1070
|
/**
|
|
@@ -1430,6 +1439,23 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1430
1439
|
});
|
|
1431
1440
|
});
|
|
1432
1441
|
};
|
|
1442
|
+
/** {@inheritDoc WidgetApi.sendToDeviceMessage} */
|
|
1443
|
+
WidgetApiImpl.prototype.sendToDeviceMessage = function (eventType, encrypted, content) {
|
|
1444
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1445
|
+
return __generator(this, function (_a) {
|
|
1446
|
+
switch (_a.label) {
|
|
1447
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.sendToDevice(eventType, encrypted, content)];
|
|
1448
|
+
case 1:
|
|
1449
|
+
_a.sent();
|
|
1450
|
+
return [2 /*return*/];
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
1456
|
+
WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
|
|
1457
|
+
return this.toDeviceMessages$.pipe(map(function (e) { return e.detail.data; }), filter(function (e) { return e.type === eventType; }));
|
|
1458
|
+
};
|
|
1433
1459
|
/** {@inheritDoc WidgetApi.openModal} */
|
|
1434
1460
|
WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
|
|
1435
1461
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1590,6 +1616,43 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1590
1616
|
});
|
|
1591
1617
|
});
|
|
1592
1618
|
};
|
|
1619
|
+
/** {@inheritdoc WidgetApi.observeTurnServers} */
|
|
1620
|
+
WidgetApiImpl.prototype.observeTurnServers = function () {
|
|
1621
|
+
return from(this.matrixWidgetApi.getTurnServers()).pipe(
|
|
1622
|
+
// For some reason a different naming was chosen for the API, but
|
|
1623
|
+
// we already convert them to the right type for WebRTC consumers.
|
|
1624
|
+
map(function (_a) {
|
|
1625
|
+
var uris = _a.uris, username = _a.username, password = _a.password;
|
|
1626
|
+
return ({
|
|
1627
|
+
urls: uris,
|
|
1628
|
+
username: username,
|
|
1629
|
+
credential: password,
|
|
1630
|
+
});
|
|
1631
|
+
}));
|
|
1632
|
+
};
|
|
1633
|
+
/** {@inheritdoc WidgetApi.searchUserDirectory} */
|
|
1634
|
+
WidgetApiImpl.prototype.searchUserDirectory = function (searchTerm, options) {
|
|
1635
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1636
|
+
var results;
|
|
1637
|
+
return __generator(this, function (_a) {
|
|
1638
|
+
switch (_a.label) {
|
|
1639
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.searchUserDirectory(searchTerm, options === null || options === void 0 ? void 0 : options.limit)];
|
|
1640
|
+
case 1:
|
|
1641
|
+
results = (_a.sent()).results;
|
|
1642
|
+
return [2 /*return*/, {
|
|
1643
|
+
results: results.map(function (_a) {
|
|
1644
|
+
var user_id = _a.user_id, display_name = _a.display_name, avatar_url = _a.avatar_url;
|
|
1645
|
+
return ({
|
|
1646
|
+
userId: user_id,
|
|
1647
|
+
displayName: display_name,
|
|
1648
|
+
avatarUrl: avatar_url,
|
|
1649
|
+
});
|
|
1650
|
+
}),
|
|
1651
|
+
}];
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
});
|
|
1655
|
+
};
|
|
1593
1656
|
return WidgetApiImpl;
|
|
1594
1657
|
}());
|
|
1595
1658
|
|
package/build/index.d.ts
CHANGED
|
@@ -395,6 +395,29 @@ export declare type StateEvent<T = unknown> = Omit<IRoomEvent, 'content' | 'unsi
|
|
|
395
395
|
content: T;
|
|
396
396
|
};
|
|
397
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Generic type for to device message events.
|
|
400
|
+
*/
|
|
401
|
+
export declare type ToDeviceMessageEvent<T = unknown> = {
|
|
402
|
+
type: string;
|
|
403
|
+
sender: string;
|
|
404
|
+
encrypted: boolean;
|
|
405
|
+
content: T;
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* WebRTC Ice server credentials like turn servers, type is compatible to
|
|
410
|
+
* `RTCIceServer` from WebRTC.
|
|
411
|
+
*/
|
|
412
|
+
export declare type TurnServer = {
|
|
413
|
+
/** One or more URLs for this turn server. */
|
|
414
|
+
urls: string[];
|
|
415
|
+
/** Username for this turn server. */
|
|
416
|
+
username: string;
|
|
417
|
+
/** Credentials for this turn server. */
|
|
418
|
+
credential: string;
|
|
419
|
+
};
|
|
420
|
+
|
|
398
421
|
/**
|
|
399
422
|
* The capability that needs to be requested in order to navigate to another room.
|
|
400
423
|
*/
|
|
@@ -420,13 +443,13 @@ export declare type WidgetApi = {
|
|
|
420
443
|
*/
|
|
421
444
|
getWidgetConfig<T extends IWidgetApiRequestData>(): Readonly<WidgetConfig<T> | undefined>;
|
|
422
445
|
/**
|
|
423
|
-
* Rerequests
|
|
446
|
+
* Rerequests capabilities initially passed in the constructor.
|
|
424
447
|
*
|
|
425
448
|
* This is useful in case the user denied one or all of them.
|
|
426
449
|
*/
|
|
427
450
|
rerequestInitialCapabilities(): Promise<void>;
|
|
428
451
|
/**
|
|
429
|
-
* True, if the initial
|
|
452
|
+
* True, if the initial capabilities passed via the constructor were granted.
|
|
430
453
|
*/
|
|
431
454
|
hasInitialCapabilities(): boolean;
|
|
432
455
|
/**
|
|
@@ -526,7 +549,7 @@ export declare type WidgetApi = {
|
|
|
526
549
|
*
|
|
527
550
|
* @param eventType - The type of the event to receive.
|
|
528
551
|
* @param options - Options for receiving the room event.
|
|
529
|
-
* Use `messageType` to receive events with a
|
|
552
|
+
* Use `messageType` to receive events with a specific
|
|
530
553
|
* message type.
|
|
531
554
|
* Use `roomIds` to receive the state events from other
|
|
532
555
|
* rooms.
|
|
@@ -548,7 +571,7 @@ export declare type WidgetApi = {
|
|
|
548
571
|
*
|
|
549
572
|
* @param eventType - The type of the event to receive.
|
|
550
573
|
* @param options - Options for receiving the room event.
|
|
551
|
-
* Use `messageType` to receive events with a
|
|
574
|
+
* Use `messageType` to receive events with a specific
|
|
552
575
|
* message type.
|
|
553
576
|
* Use `roomIds` to receive the state events from other
|
|
554
577
|
* rooms.
|
|
@@ -605,6 +628,27 @@ export declare type WidgetApi = {
|
|
|
605
628
|
chunk: Array<RoomEvent | StateEvent>;
|
|
606
629
|
nextToken?: string;
|
|
607
630
|
}>;
|
|
631
|
+
/**
|
|
632
|
+
* Send a message to a device of a user (or multiple users / devices).
|
|
633
|
+
*
|
|
634
|
+
* @param eventType - The type of the event.
|
|
635
|
+
* @param encrypted - Whether the event should be encrypted.
|
|
636
|
+
* @param content - The content to send. This is a map of user ids, to device
|
|
637
|
+
* ids, to the content that should be send. It is possible to
|
|
638
|
+
* specify a `'*'` device, to send the content to all devices
|
|
639
|
+
* of a user.
|
|
640
|
+
*/
|
|
641
|
+
sendToDeviceMessage<T>(eventType: string, encrypted: boolean, content: {
|
|
642
|
+
[userId: string]: {
|
|
643
|
+
[deviceId: string | '*']: T;
|
|
644
|
+
};
|
|
645
|
+
}): Promise<void>;
|
|
646
|
+
/**
|
|
647
|
+
* Observes all to device messages send to the current device.
|
|
648
|
+
*
|
|
649
|
+
* @param eventType - The type of the event.
|
|
650
|
+
*/
|
|
651
|
+
observeToDeviceMessages<T>(eventType: string): Observable<ToDeviceMessageEvent<T>>;
|
|
608
652
|
/**
|
|
609
653
|
* Open a new modal, wait until the modal closes, and return the result.
|
|
610
654
|
*
|
|
@@ -678,6 +722,28 @@ export declare type WidgetApi = {
|
|
|
678
722
|
* old one expired.
|
|
679
723
|
*/
|
|
680
724
|
requestOpenIDConnectToken(): Promise<IOpenIDCredentials>;
|
|
725
|
+
/**
|
|
726
|
+
* Returns an observable containing WebRTC Ice server credentials, like turn
|
|
727
|
+
* servers, if available.
|
|
728
|
+
*/
|
|
729
|
+
observeTurnServers(): Observable<TurnServer>;
|
|
730
|
+
/**
|
|
731
|
+
* Search for users in the user directory.
|
|
732
|
+
*
|
|
733
|
+
* @param searchTerm - The term to search for.
|
|
734
|
+
* @param options - Options for searching.
|
|
735
|
+
* Use `limit` to limit the number of results to return.
|
|
736
|
+
* @returns The search results.
|
|
737
|
+
*/
|
|
738
|
+
searchUserDirectory(searchTerm: string, options?: {
|
|
739
|
+
limit?: number;
|
|
740
|
+
}): Promise<{
|
|
741
|
+
results: Array<{
|
|
742
|
+
userId: string;
|
|
743
|
+
displayName?: string;
|
|
744
|
+
avatarUrl?: string;
|
|
745
|
+
}>;
|
|
746
|
+
}>;
|
|
681
747
|
};
|
|
682
748
|
|
|
683
749
|
/**
|
|
@@ -717,6 +783,7 @@ export declare class WidgetApiImpl implements WidgetApi {
|
|
|
717
783
|
private outstandingOpenIDConnectTokenRequest;
|
|
718
784
|
private cachedOpenIdToken;
|
|
719
785
|
private readonly events$;
|
|
786
|
+
private readonly toDeviceMessages$;
|
|
720
787
|
private readonly initialCapabilities;
|
|
721
788
|
constructor(
|
|
722
789
|
/**
|
|
@@ -797,6 +864,14 @@ export declare class WidgetApiImpl implements WidgetApi {
|
|
|
797
864
|
chunk: Array<RoomEvent | StateEvent>;
|
|
798
865
|
nextToken?: string;
|
|
799
866
|
}>;
|
|
867
|
+
/** {@inheritDoc WidgetApi.sendToDeviceMessage} */
|
|
868
|
+
sendToDeviceMessage<T>(eventType: string, encrypted: boolean, content: {
|
|
869
|
+
[userId: string]: {
|
|
870
|
+
[deviceId: string | '*']: T;
|
|
871
|
+
};
|
|
872
|
+
}): Promise<void>;
|
|
873
|
+
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
874
|
+
observeToDeviceMessages<T>(eventType: string): Observable<ToDeviceMessageEvent<T>>;
|
|
800
875
|
/** {@inheritDoc WidgetApi.openModal} */
|
|
801
876
|
openModal<T extends Record<string, unknown> = Record<string, unknown>, U extends IModalWidgetCreateData = IModalWidgetCreateData>(pathName: string, name: string, options?: {
|
|
802
877
|
buttons?: IModalWidgetOpenRequestDataButton[];
|
|
@@ -813,6 +888,18 @@ export declare class WidgetApiImpl implements WidgetApi {
|
|
|
813
888
|
/** {@inheritdoc WidgetApi.requestOpenIDConnectToken} */
|
|
814
889
|
requestOpenIDConnectToken(): Promise<IOpenIDCredentials>;
|
|
815
890
|
private requestOpenIDConnectTokenInternal;
|
|
891
|
+
/** {@inheritdoc WidgetApi.observeTurnServers} */
|
|
892
|
+
observeTurnServers(): Observable<TurnServer>;
|
|
893
|
+
/** {@inheritdoc WidgetApi.searchUserDirectory} */
|
|
894
|
+
searchUserDirectory(searchTerm: string, options?: {
|
|
895
|
+
limit?: number | undefined;
|
|
896
|
+
} | undefined): Promise<{
|
|
897
|
+
results: Array<{
|
|
898
|
+
userId: string;
|
|
899
|
+
displayName?: string;
|
|
900
|
+
avatarUrl?: string;
|
|
901
|
+
}>;
|
|
902
|
+
}>;
|
|
816
903
|
}
|
|
817
904
|
|
|
818
905
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matrix-widget-toolkit/api",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
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",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@craco/craco": "^6.4.5",
|
|
12
12
|
"@types/jest": "^27.5.2",
|
|
13
|
-
"@types/node": "^16.18.
|
|
13
|
+
"@types/node": "^16.18.23",
|
|
14
14
|
"@types/qs": "^6.9.7",
|
|
15
15
|
"typescript": "^4.8.4"
|
|
16
16
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"generate-api-report": "tsc && api-extractor run --verbose --local"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"matrix-widget-api": "^1.
|
|
30
|
+
"matrix-widget-api": "^1.3.1",
|
|
31
31
|
"qs": "^6.11.0",
|
|
32
32
|
"rxjs": "^7.8.0"
|
|
33
33
|
},
|