matrix-widget-api
JavaScript/TypeScript API for widgets & web clients to communicate.
For help and support, visit #matrix-dev:matrix.org on Matrix.
Not yet ready for usage
This is currently not validated and thus should not be relied upon until this notice goes away. Installation
instructions will take this notice's place.
Usage for widgets
The general usage for this would be:
const widgetId = null;
const api = new WidgetApi(widgetId);
api.requestCapability(MatrixCapabilities.Screenshots);
api.requestCapabilities(StickerpickerCapabilities);
api.addEventListener(`action:${WidgetApiToWidgetAction.UpdateVisibility}`, (ev: CustomEvent<IVisibilityActionRequest>) => {
ev.preventDefault();
console.log(ev.detail);
api.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{});
});
api.addEventListener("com.example.my_action", (ev: CustomEvent<ICustomActionRequest>) => {
ev.preventDefault();
console.log(ev.detail);
api.transport.reply(ev.detail, {custom: "reply"});
});
api.start();
api.sendContentLoaded();
api.setAlwaysOnScreen(true);
api.transport.send("com.example.my_action", {isExample: true});
Usage for web clients
Sorry, this JS API is geared towards web-based widgets and clients 😢
TODO: Improve this
const driver = new CustomDriver();
const api = new ClientWidgetApi(widget, iframe, driver);
api.addEventListener("ready", () => {
api.updateVisibility(true).then(() => console.log("Widget knows it is visible now"));
api.transport.send("com.example.my_action", {isExample: true});
});
api.stop();