Files
matrix-quotes-bot/node_modules/matrix-widget-api/dist/api.js

6026 lines
692 KiB
JavaScript
Raw Normal View History

2026-09-12 23:57:45 -04:00
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.mxwidgets = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ClientWidgetApi = void 0;
var _events = require("events");
var _PostmessageTransport = require("./transport/PostmessageTransport");
var _WidgetApiDirection = require("./interfaces/WidgetApiDirection");
var _WidgetApiAction = require("./interfaces/WidgetApiAction");
var _Capabilities = require("./interfaces/Capabilities");
var _ApiVersion = require("./interfaces/ApiVersion");
var _WidgetEventCapability = require("./models/WidgetEventCapability");
var _GetOpenIDAction = require("./interfaces/GetOpenIDAction");
var _SimpleObservable = require("./util/SimpleObservable");
var _Symbols = require("./Symbols");
var _UpdateDelayedEventAction = require("./interfaces/UpdateDelayedEventAction");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function _OverloadYield(e, d) { this.v = e, this.k = d; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _asyncIterator(r) { var n, t, o, e = 2; for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) { if (t && null != (n = r[t])) return n.call(r); if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r)); t = "@@asyncIterator", o = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
function AsyncFromSyncIterator(r) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var n = r.done; return Promise.resolve(r.value).then(function (r) { return { value: r, done: n }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(r) { this.s = r, this.n = r.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(r) { var n = this.s["return"]; return void 0 === n ? Promise.resolve({ value: r, done: !0 }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); }, "throw": function _throw(r) { var n = this.s["return"]; return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(r); } /*
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* API handler for the client side of widgets. This raises events
* for each action received as `action:${action}` (eg: "action:screenshot").
* Default handling can be prevented by using preventDefault() on the
* raised event. The default handling varies for each action: ones
* which the SDK can handle safely are acknowledged appropriately and
* ones which are unhandled (custom or require the client to do something)
* are rejected with an error.
*
* Events which are preventDefault()ed must reply using the transport.
* The events raised will have a default of an IWidgetApiRequest
* interface.
*
* When the ClientWidgetApi is ready to start sending requests, it will
* raise a "ready" CustomEvent. After the ready event fires, actions can
* be sent and the transport will be ready.
*
* When the widget has indicated it has loaded, this class raises a
* "preparing" CustomEvent. The preparing event does not indicate that
* the widget is ready to receive communications - that is signified by
* the ready event exclusively.
*
* This class only handles one widget at a time.
*/
var ClientWidgetApi = /*#__PURE__*/function (_EventEmitter) {
_inherits(ClientWidgetApi, _EventEmitter);
var _super = _createSuper(ClientWidgetApi);
/**
* Creates a new client widget API. This will instantiate the transport
* and start everything. When the iframe is loaded under the widget's
* conditions, a "ready" event will be raised.
* @param {Widget} widget The widget to communicate with.
* @param {HTMLIFrameElement} iframe The iframe the widget is in.
* @param {WidgetDriver} driver The driver for this widget/client.
*/
function ClientWidgetApi(widget, iframe, driver) {
var _this;
_classCallCheck(this, ClientWidgetApi);
_this = _super.call(this);
_this.widget = widget;
_this.driver = driver;
_defineProperty(_assertThisInitialized(_this), "transport", void 0);
_defineProperty(_assertThisInitialized(_this), "cachedWidgetVersions", null);
// contentLoadedActionSent is used to check that only one ContentLoaded request is send.
_defineProperty(_assertThisInitialized(_this), "contentLoadedActionSent", false);
_defineProperty(_assertThisInitialized(_this), "allowedCapabilities", new Set());
_defineProperty(_assertThisInitialized(_this), "allowedEvents", []);
_defineProperty(_assertThisInitialized(_this), "isStopped", false);
_defineProperty(_assertThisInitialized(_this), "turnServers", null);
_defineProperty(_assertThisInitialized(_this), "contentLoadedWaitTimer", void 0);
// Stores pending requests to push a room's state to the widget
_defineProperty(_assertThisInitialized(_this), "pushRoomStateTasks", new Set());
// Room ID → event type → state key → events to be pushed
_defineProperty(_assertThisInitialized(_this), "pushRoomStateResult", new Map());
_defineProperty(_assertThisInitialized(_this), "flushRoomStateTask", null);
_defineProperty(_assertThisInitialized(_this), "viewedRoomId", null);
if (!(iframe !== null && iframe !== void 0 && iframe.contentWindow)) {
throw new Error("No iframe supplied");
}
if (!widget) {
throw new Error("Invalid widget");
}
if (!driver) {
throw new Error("Invalid driver");
}
_this.transport = new _PostmessageTransport.PostmessageTransport(_WidgetApiDirection.WidgetApiDirection.ToWidget, widget.id, iframe.contentWindow, globalThis);
_this.transport.targetOrigin = widget.origin;
_this.transport.on("message", _this.handleMessage.bind(_assertThisInitialized(_this)));
iframe.addEventListener("load", _this.onIframeLoad.bind(_assertThisInitialized(_this)));
_this.transport.start();
return _this;
}
_createClass(ClientWidgetApi, [{
key: "hasCapability",
value: function hasCapability(capability) {
return this.allowedCapabilities.has(capability);
}
}, {
key: "canUseRoomTimeline",
value: function canUseRoomTimeline(roomId) {
return this.hasCapability("org.matrix.msc2762.timeline:".concat(_Symbols.Symbols.AnyRoom)) || this.hasCapability("org.matrix.msc2762.timeline:".concat(roomId));
}
}, {
key: "canSendRoomEvent",
value: function canSendRoomEvent(eventType) {
var msgtype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
return this.allowedEvents.some(function (e) {
return e.matchesAsRoomEvent(_WidgetEventCapability.EventDirection.Send, eventType, msgtype);
});
}
}, {
key: "canSendStateEvent",
value: function canSendStateEvent(eventType, stateKey) {
return this.allowedEvents.some(function (e) {
return e.matchesAsStateEvent(_WidgetEventCapability.EventDirection.Send, eventType, stateKey);
});
}
}, {
key: "canSendToDeviceEvent",
value: function canSendToDeviceEvent(eventType) {
return this.allowedEvents.some(function (e) {
return e.matchesAsToDeviceEvent(_WidgetEventCapability.EventDirection.Send, eventType);
});
}
}, {
key: "canReceiveRoomEvent",
value: function canReceiveRoomEvent(eventType) {
var msgtype = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
return this.allowedEvents.some(function (e) {
return e.matchesAsRoomEvent(_WidgetEventCapability.EventDirection.Receive, eventType, msgtype);
});
}
}, {
key: "canReceiveStateEvent",
value: function canReceiveStateEvent(eventType, stateKey) {
return this.allowedEvents.some(function (e) {
return e.matchesAsStateEvent(_WidgetEventCapability.EventDirection.Receive, eventType, stateKey);
});
}
}, {
key: "canReceiveToDeviceEvent",
value: function canReceiveToDeviceEvent(eventType) {
return this.allowedEvents.some(function (e) {
return e.matchesAsToDeviceEvent(_WidgetEventCapability.EventDirection.Receive, eventType);
});
}
}, {
key: "canReceiveRoomAccountData",
value: function canReceiveRoomAccountData(eventType) {
return this.allowedEvents.some(function (e) {
return e.matchesAsRoomAccountData(_WidgetEventCapability.EventDirection.Receive, eventType);
});
}
}, {
key: "stop",
value: function stop() {
this.isStopped = true;
this.transport.stop();
}
}, {
key: "getWidgetVersions",
value: function () {
var _getWidgetVersions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var r;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!Array.isArray(this.cachedWidgetVersions)) {
_context.next = 2;
break;
}
return _context.abrupt("return", this.cachedWidgetVersions);
case 2:
_context.prev = 2;
_context.next = 5;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.SupportedApiVersions, {});
case 5:
r = _context.sent;
this.cachedWidgetVersions = r.supported_versions;
return _context.abrupt("return", r.supported_versions);
case 10:
_context.prev = 10;
_context.t0 = _context["catch"](2);
console.warn("non-fatal error getting supported widget versions: ", _context.t0);
return _context.abrupt("return", []);
case 14:
case "end":
return _context.stop();
}
}, _callee, this, [[2, 10]]);
}));
function getWidgetVersions() {
return _getWidgetVersions.apply(this, arguments);
}
return getWidgetVersions;
}()
}, {
key: "beginCapabilities",
value: function beginCapabilities() {
var _this2 = this;
// widget has loaded - tell all the listeners that
this.emit("preparing");
var requestedCaps;
this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.Capabilities, {}).then(function (caps) {
requestedCaps = caps.capabilities;
return _this2.driver.validateCapabilities(new Set(caps.capabilities));
}).then(function (allowedCaps) {
_this2.allowCapabilities(_toConsumableArray(allowedCaps), requestedCaps);
_this2.emit("ready");
})["catch"](function (e) {
_this2.emit("error:preparing", e);
});
}
}, {
key: "allowCapabilities",
value: function allowCapabilities(allowed, requested) {
var _this$allowedEvents,
_this3 = this;
console.log("Widget ".concat(this.widget.id, " is allowed capabilities:"), allowed);
var _iterator2 = _createForOfIteratorHelper(allowed),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var c = _step2.value;
this.allowedCapabilities.add(c);
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
var allowedEvents = _WidgetEventCapability.WidgetEventCapability.findEventCapabilities(allowed);
(_this$allowedEvents = this.allowedEvents).push.apply(_this$allowedEvents, _toConsumableArray(allowedEvents));
this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.NotifyCapabilities, {
requested: requested,
approved: Array.from(this.allowedCapabilities)
})["catch"](function (e) {
console.warn("non-fatal error notifying widget of approved capabilities:", e);
}).then(function () {
_this3.emit("capabilitiesNotified");
});
// Push the initial room state for all rooms with a timeline capability
var _iterator3 = _createForOfIteratorHelper(allowed),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var _c = _step3.value;
if ((0, _Capabilities.isTimelineCapability)(_c)) {
var roomId = (0, _Capabilities.getTimelineRoomIDFromCapability)(_c);
if (roomId === _Symbols.Symbols.AnyRoom) {
var _iterator5 = _createForOfIteratorHelper(this.driver.getKnownRooms()),
_step5;
try {
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var _roomId = _step5.value;
this.pushRoomState(_roomId);
}
} catch (err) {
_iterator5.e(err);
} finally {
_iterator5.f();
}
} else {
this.pushRoomState(roomId);
}
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
if (allowed.includes(_Capabilities.MatrixCapabilities.MSC4407ReceiveStickyEvent)) {
console.debug("Widget ".concat(this.widget.id, " is allowed to receive sticky events, check current sticky state."));
// If the widget can receive sticky events, push all sticky events in known rooms now.
// Sticky events are like a state, and passed history is needed to get the full state.
var roomIds = allowed.filter(function (capability) {
return (0, _Capabilities.isTimelineCapability)(capability);
}).map(function (timelineCapability) {
return (0, _Capabilities.getTimelineRoomIDFromCapability)(timelineCapability);
}).flatMap(function (roomIdOrWildcard) {
if (roomIdOrWildcard === _Symbols.Symbols.AnyRoom) {
// Do we support getting sticky state for any room?
return _this3.driver.getKnownRooms();
} else {
return roomIdOrWildcard;
}
});
console.debug("Widget ".concat(this.widget.id, " is allowed to receive sticky events in rooms:"), roomIds);
var _iterator4 = _createForOfIteratorHelper(roomIds),
_step4;
try {
var _loop = function _loop() {
var roomId = _step4.value;
_this3.pushStickyState(roomId)["catch"](function (err) {
console.error("Failed to push sticky events to widget ".concat(_this3.widget.id, " for room ").concat(roomId, ":"), err);
});
};
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
_loop();
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
}
// If new events are allowed and the currently viewed room isn't covered
// by a timeline capability, then we know that there could be some state
// in the viewed room that the widget hasn't learned about yet- push it.
if (allowedEvents.length > 0 && this.viewedRoomId !== null && !this.canUseRoomTimeline(this.viewedRoomId)) {
this.pushRoomState(this.viewedRoomId);
}
}
}, {
key: "onIframeLoad",
value: function onIframeLoad(ev) {
if (this.widget.waitForIframeLoad) {
// If the widget is set to waitForIframeLoad the capabilities immediately get setup after load.
// The client does not wait for the ContentLoaded action.
this.beginCapabilities();
} else {
// Reaching this means, that the Iframe got reloaded/loaded and
// the clientApi is awaiting the FIRST ContentLoaded action.
console.log("waitForIframeLoad is false: waiting for widget to send contentLoaded");
this.contentLoadedWaitTimer = setTimeout(function () {
console.error("Widget specified waitForIframeLoad=false but timed out waiting for contentLoaded event!");
}, 10000);
this.contentLoadedActionSent = false;
}
}
}, {
key: "handleContentLoadedAction",
value: function handleContentLoadedAction(action) {
if (this.contentLoadedWaitTimer !== undefined) {
clearTimeout(this.contentLoadedWaitTimer);
this.contentLoadedWaitTimer = undefined;
}
if (this.contentLoadedActionSent) {
throw new Error("Improper sequence: ContentLoaded Action can only be sent once after the widget loaded " + "and should only be used if waitForIframeLoad is false (default=true)");
}
if (this.widget.waitForIframeLoad) {
this.transport.reply(action, {
error: {
message: "Improper sequence: not expecting ContentLoaded event if " + "waitForIframeLoad is true (default=true)"
}
});
} else {
this.transport.reply(action, {});
this.beginCapabilities();
}
this.contentLoadedActionSent = true;
}
}, {
key: "replyVersions",
value: function replyVersions(request) {
this.transport.reply(request, {
supported_versions: _ApiVersion.CurrentApiVersions
});
}
}, {
key: "supportsUpdateState",
value: function () {
var _supportsUpdateState = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return this.getWidgetVersions();
case 2:
return _context2.abrupt("return", _context2.sent.includes(_ApiVersion.UnstableApiVersion.MSC2762_UPDATE_STATE));
case 3:
case "end":
return _context2.stop();
}
}, _callee2, this);
}));
function supportsUpdateState() {
return _supportsUpdateState.apply(this, arguments);
}
return supportsUpdateState;
}()
}, {
key: "handleCapabilitiesRenegotiate",
value: function handleCapabilitiesRenegotiate(request) {
var _request$data,
_this4 = this;
// acknowledge first
this.transport.reply(request, {});
var requested = ((_request$data = request.data) === null || _request$data === void 0 ? void 0 : _request$data.capabilities) || [];
var newlyRequested = new Set(requested.filter(function (r) {
return !_this4.hasCapability(r);
}));
if (newlyRequested.size === 0) {
// Nothing to do - skip validation
this.allowCapabilities([], []);
}
this.driver.validateCapabilities(newlyRequested).then(function (allowed) {
return _this4.allowCapabilities(_toConsumableArray(allowed), _toConsumableArray(newlyRequested));
});
}
}, {
key: "handleNavigate",
value: function handleNavigate(request) {
var _request$data2,
_this5 = this;
if (!this.hasCapability(_Capabilities.MatrixCapabilities.MSC2931Navigate)) {
return this.transport.reply(request, {
error: {
message: "Missing capability"
}
});
}
if (!((_request$data2 = request.data) !== null && _request$data2 !== void 0 && _request$data2.uri.startsWith("https://matrix.to/#"))) {
return this.transport.reply(request, {
error: {
message: "Invalid matrix.to URI"
}
});
}
var onErr = function onErr(e) {
console.error("[ClientWidgetApi] Failed to handle navigation: ", e);
_this5.handleDriverError(e, request, "Error handling navigation");
};
try {
this.driver.navigate(request.data.uri.toString())["catch"](function (e) {
return onErr(e);
}).then(function () {
return _this5.transport.reply(request, {});
});
} catch (e) {
return onErr(e);
}
}
}, {
key: "handleOIDC",
value: function handleOIDC(request) {
var _this6 = this;
var phase = 1; // 1 = initial request, 2 = after user manual confirmation
var replyState = function replyState(state, credential) {
credential = credential || {};
if (phase > 1) {
return _this6.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials, _objectSpread({
state: state,
original_request_id: request.requestId
}, credential));
} else {
return _this6.transport.reply(request, _objectSpread({
state: state
}, credential));
}
};
var replyError = function replyError(msg) {
console.error("[ClientWidgetApi] Failed to handle OIDC: ", msg);
if (phase > 1) {
// We don't have a way to indicate that a random error happened in this flow, so
// just block the attempt.
return replyState(_GetOpenIDAction.OpenIDRequestState.Blocked);
} else {
return _this6.transport.reply(request, {
error: {
message: msg
}
});
}
};
var observer = new _SimpleObservable.SimpleObservable(function (update) {
if (update.state === _GetOpenIDAction.OpenIDRequestState.PendingUserConfirmation && phase > 1) {
observer.close();
return replyError("client provided out-of-phase response to OIDC flow");
}
if (update.state === _GetOpenIDAction.OpenIDRequestState.PendingUserConfirmation) {
replyState(update.state);
phase++;
return;
}
if (update.state === _GetOpenIDAction.OpenIDRequestState.Allowed && !update.token) {
return replyError("client provided invalid OIDC token for an allowed request");
}
if (update.state === _GetOpenIDAction.OpenIDRequestState.Blocked) {
update.token = undefined; // just in case the client did something weird
}
observer.close();
return replyState(update.state, update.token);
});
this.driver.askOpenID(observer);
}
}, {
key: "handleReadRoomAccountData",
value: function handleReadRoomAccountData(request) {
var _this7 = this;
var events = this.driver.readRoomAccountData(request.data.type);
if (!this.canReceiveRoomAccountData(request.data.type)) {
return this.transport.reply(request, {
error: {
message: "Cannot read room account data of this type"
}
});
}
return events.then(function (evs) {
_this7.transport.reply(request, {
events: evs
});
});
}
}, {
key: "handleReadEvents",
value: function () {
var _handleReadEvents = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(request) {
var _this8 = this;
var askRoomIds, _iterator6, _step6, roomId, limit, since, stateKey, msgtype, _stateKey, events;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
if (request.data.type) {
_context3.next = 2;
break;
}
return _context3.abrupt("return", this.transport.reply(request, {
error: {
message: "Invalid request - missing event type"
}
}));
case 2:
if (!(request.data.limit !== undefined && (!request.data.limit || request.data.limit < 0))) {
_context3.next = 4;
break;
}
return _context3.abrupt("return", this.transport.reply(request, {
error: {
message: "Invalid request - limit out of range"
}
}));
case 4:
if (!(request.data.room_ids === undefined)) {
_context3.next = 8;
break;
}
askRoomIds = this.viewedRoomId === null ? [] : [this.viewedRoomId];
_context3.next = 30;
break;
case 8:
if (!(request.data.room_ids === _Symbols.Symbols.AnyRoom)) {
_context3.next = 12;
break;
}
askRoomIds = this.driver.getKnownRooms().filter(function (roomId) {
return _this8.canUseRoomTimeline(roomId);
});
_context3.next = 30;
break;
case 12:
askRoomIds = request.data.room_ids;
_iterator6 = _createForOfIteratorHelper(askRoomIds);
_context3.prev = 14;
_iterator6.s();
case 16:
if ((_step6 = _iterator6.n()).done) {
_context3.next = 22;
break;
}
roomId = _step6.value;
if (this.canUseRoomTimeline(roomId)) {
_context3.next = 20;
break;
}
return _context3.abrupt("return", this.transport.reply(request, {
error: {
message: "Unable to access room timeline: ".concat(roomId)
}
}));
case 20:
_context3.next = 16;
break;
case 22:
_context3.next = 27;
break;
case 24:
_context3.prev = 24;
_context3.t0 = _context3["catch"](14);
_iterator6.e(_context3.t0);
case 27:
_context3.prev = 27;
_iterator6.f();
return _context3.finish(27);
case 30:
limit = request.data.limit || 0;
since = request.data.since;
stateKey = undefined;
msgtype = undefined;
if (!(request.data.state_key !== undefined)) {
_context3.next = 40;
break;
}
stateKey = request.data.state_key === true ? undefined : request.data.state_key.toString();
if (this.canReceiveStateEvent(request.data.type, (_stateKey = stateKey) !== null && _stateKey !== void 0 ? _stateKey : null)) {
_context3.next = 38;
break;
}
return _context3.abrupt("return", this.transport.reply(request, {
error: {
message: "Cannot read state events of this type"
}
}));
case 38:
_context3.next = 43;
break;
case 40:
msgtype = request.data.msgtype;
if (this.canReceiveRoomEvent(request.data.type, msgtype)) {
_context3.next = 43;
break;
}
return _context3.abrupt("return", this.transport.reply(request, {
error: {
message: "Cannot read room events of this type"
}
}));
case 43:
if (!(request.data.room_ids === undefined && askRoomIds.length === 0)) {
_context3.next = 50;
break;
}
// For backwards compatibility we still call the deprecated
// readRoomEvents and readStateEvents methods in case the client isn't
// letting us know the currently viewed room via setViewedRoomId
//
// This can be considered as a deprecated implementation.
// A driver should call `setViewedRoomId` on the widget messaging and implement the new readRoomState and readRoomTimeline
// Methods.
// This block makes sure that it is also possible to not use setViewedRoomId.
// readRoomTimeline and readRoomState are required however! Otherwise widget requests that include
// `room_ids` will fail.
console.warn("The widgetDriver uses deprecated behaviour:\n It does not set the viewedRoomId using `setViewedRoomId`");
_context3.next = 47;
return (
// This returns [] with the current driver of Element Web.
// Add default implementations of the `readRoomEvents` and `readStateEvents`
// methods to use `readRoomTimeline` and `readRoomState` if they are not overwritten.
request.data.state_key === undefined ? this.driver.readRoomEvents(request.data.type, msgtype, limit, null, since) : this.driver.readStateEvents(request.data.type, stateKey, limit, null)
);
case 47:
events = _context3.sent;
_context3.next = 68;
break;
case 50:
_context3.next = 52;
return this.supportsUpdateState();
case 52:
if (!_context3.sent) {
_context3.next = 58;
break;
}
_context3.next = 55;
return Promise.all(askRoomIds.map(function (roomId) {
return _this8.driver.readRoomTimeline(roomId, request.data.type, msgtype, stateKey, limit, since);
}));
case 55:
events = _context3.sent.flat(1);
_context3.next = 68;
break;
case 58:
if (!(request.data.state_key === undefined)) {
_context3.next = 64;
break;
}
_context3.next = 61;
return Promise.all(askRoomIds.map(function (roomId) {
return _this8.driver.readRoomTimeline(roomId, request.data.type, msgtype, stateKey, limit, since);
}));
case 61:
_context3.t1 = _context3.sent;
_context3.next = 67;
break;
case 64:
_context3.next = 66;
return Promise.all(askRoomIds.map(function (roomId) {
return _this8.driver.readRoomState(roomId, request.data.type, stateKey);
}));
case 66:
_context3.t1 = _context3.sent;
case 67:
events = _context3.t1.flat(1);
case 68:
this.transport.reply(request, {
events: events
});
case 69:
case "end":
return _context3.stop();
}
}, _callee3, this, [[14, 24, 27, 30]]);
}));
function handleReadEvents(_x) {
return _handleReadEvents.apply(this, arguments);
}
return handleReadEvents;
}()
}, {
key: "handleSendEvent",
value: function handleSendEvent(request) {
var _this9 = this;
if (!request.data.type) {
return this.transport.reply(request, {
error: {
message: "Invalid request - missing event type"
}
});
}
if (!!request.data.room_id && !this.canUseRoomTimeline(request.data.room_id)) {
return this.transport.reply(request, {
error: {
message: "Unable to access room timeline: ".concat(request.data.room_id)
}
});
}
if (request.data.parent_delay_id !== undefined) {
console.warn("Data includes parent_delay_id, but the widgetDriver ignores it");
}
var delay = request.data.delay;
if (delay !== undefined && !this.hasCapability(_Capabilities.MatrixCapabilities.MSC4157SendDelayedEvent)) {
return this.transport.reply(request, {
error: {
message: "Missing capability for ".concat(_Capabilities.MatrixCapabilities.MSC4157SendDelayedEvent)
}
});
}
var isStickyEvent = request.data.sticky_duration_ms !== undefined;
if (isStickyEvent && !this.hasCapability(_Capabilities.MatrixCapabilities.MSC4407SendStickyEvent)) {
return this.transport.reply(request, {
error: {
message: "Missing capability for ".concat(_Capabilities.MatrixCapabilities.MSC4407SendStickyEvent)
}
});
}
var sendEventPromise;
if (request.data.state_key !== undefined) {
if (!this.canSendStateEvent(request.data.type, request.data.state_key)) {
return this.transport.reply(request, {
error: {
message: "Cannot send state events of this type"
}
});
}
if (isStickyEvent) {
return this.transport.reply(request, {
error: {
message: "Cannot send a state event with a sticky duration"
}
});
}
if (delay !== undefined) {
sendEventPromise = this.driver.sendDelayedEvent(delay, request.data.type, request.data.content || {}, request.data.state_key, request.data.room_id);
} else {
sendEventPromise = this.driver.sendEvent(request.data.type, request.data.content || {}, request.data.state_key, request.data.room_id);
}
} else {
var content = request.data.content || {};
var msgtype = content["msgtype"];
if (!this.canSendRoomEvent(request.data.type, msgtype)) {
return this.transport.reply(request, {
error: {
message: "Cannot send room events of this type"
}
});
}
// Events can be sticky, delayed, both, or neither. The following
// section of code takes the common parameters and uses the correct
// function depending on the request type.
var params = [request.data.type, content, null,
// not sending a state event
request.data.room_id];
if (delay !== undefined && request.data.sticky_duration_ms) {
sendEventPromise = this.driver.sendDelayedStickyEvent(delay, request.data.sticky_duration_ms, request.data.type, content, request.data.room_id);
} else if (delay !== undefined) {
var _this$driver;
sendEventPromise = (_this$driver = this.driver).sendDelayedEvent.apply(_this$driver, [delay].concat(params));
} else if (request.data.sticky_duration_ms) {
sendEventPromise = this.driver.sendStickyEvent(request.data.sticky_duration_ms, request.data.type, content, request.data.room_id);
} else {
var _this$driver2;
sendEventPromise = (_this$driver2 = this.driver).sendEvent.apply(_this$driver2, params);
}
}
sendEventPromise.then(function (sentEvent) {
return _this9.transport.reply(request, _objectSpread({
room_id: sentEvent.roomId
}, "eventId" in sentEvent ? {
event_id: sentEvent.eventId
} : {
delay_id: sentEvent.delayId
}));
})["catch"](function (e) {
console.error("error sending event: ", e);
_this9.handleDriverError(e, request, "Error sending event");
});
}
}, {
key: "handleUpdateDelayedEvent",
value: function handleUpdateDelayedEvent(request) {
var _this0 = this;
if (!request.data.delay_id) {
return this.transport.reply(request, {
error: {
message: "Invalid request - missing delay_id"
}
});
}
if (!this.hasCapability(_Capabilities.MatrixCapabilities.MSC4157UpdateDelayedEvent)) {
return this.transport.reply(request, {
error: {
message: "Missing capability"
}
});
}
var updateDelayedEvent;
switch (request.data.action) {
case _UpdateDelayedEventAction.UpdateDelayedEventAction.Cancel:
updateDelayedEvent = this.driver.cancelScheduledDelayedEvent;
break;
case _UpdateDelayedEventAction.UpdateDelayedEventAction.Restart:
updateDelayedEvent = this.driver.restartScheduledDelayedEvent;
break;
case _UpdateDelayedEventAction.UpdateDelayedEventAction.Send:
updateDelayedEvent = this.driver.sendScheduledDelayedEvent;
break;
default:
return this.transport.reply(request, {
error: {
message: "Invalid request - unsupported action"
}
});
}
updateDelayedEvent.call(this.driver, request.data.delay_id).then(function () {
return _this0.transport.reply(request, {});
})["catch"](function (e) {
console.error("error updating delayed event: ", e);
_this0.handleDriverError(e, request, "Error updating delayed event");
});
}
}, {
key: "handleSendToDevice",
value: function () {
var _handleSendToDevice = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(request) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
if (request.data.type) {
_context4.next = 4;
break;
}
this.transport.reply(request, {
error: {
message: "Invalid request - missing event type"
}
});
_context4.next = 26;
break;
case 4:
if (request.data.messages) {
_context4.next = 8;
break;
}
this.transport.reply(request, {
error: {
message: "Invalid request - missing event contents"
}
});
_context4.next = 26;
break;
case 8:
if (!(typeof request.data.encrypted !== "boolean")) {
_context4.next = 12;
break;
}
this.transport.reply(request, {
error: {
message: "Invalid request - missing encryption flag"
}
});
_context4.next = 26;
break;
case 12:
if (this.canSendToDeviceEvent(request.data.type)) {
_context4.next = 16;
break;
}
this.transport.reply(request, {
error: {
message: "Cannot send to-device events of this type"
}
});
_context4.next = 26;
break;
case 16:
_context4.prev = 16;
_context4.next = 19;
return this.driver.sendToDevice(request.data.type, request.data.encrypted, request.data.messages);
case 19:
this.transport.reply(request, {});
_context4.next = 26;
break;
case 22:
_context4.prev = 22;
_context4.t0 = _context4["catch"](16);
console.error("error sending to-device event", _context4.t0);
this.handleDriverError(_context4.t0, request, "Error sending event");
case 26:
case "end":
return _context4.stop();
}
}, _callee4, this, [[16, 22]]);
}));
function handleSendToDevice(_x2) {
return _handleSendToDevice.apply(this, arguments);
}
return handleSendToDevice;
}()
}, {
key: "pollTurnServers",
value: function () {
var _pollTurnServers = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(turnServers, initialServer) {
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, server;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
_context5.next = 3;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.UpdateTurnServers, initialServer // it's compatible, but missing the index signature
);
case 3:
// Pick the generator up where we left off
_iteratorAbruptCompletion = false;
_didIteratorError = false;
_context5.prev = 5;
_iterator = _asyncIterator(turnServers);
case 7:
_context5.next = 9;
return _iterator.next();
case 9:
if (!(_iteratorAbruptCompletion = !(_step = _context5.sent).done)) {
_context5.next = 16;
break;
}
server = _step.value;
_context5.next = 13;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.UpdateTurnServers, server // it's compatible, but missing the index signature
);
case 13:
_iteratorAbruptCompletion = false;
_context5.next = 7;
break;
case 16:
_context5.next = 22;
break;
case 18:
_context5.prev = 18;
_context5.t0 = _context5["catch"](5);
_didIteratorError = true;
_iteratorError = _context5.t0;
case 22:
_context5.prev = 22;
_context5.prev = 23;
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
_context5.next = 27;
break;
}
_context5.next = 27;
return _iterator["return"]();
case 27:
_context5.prev = 27;
if (!_didIteratorError) {
_context5.next = 30;
break;
}
throw _iteratorError;
case 30:
return _context5.finish(27);
case 31:
return _context5.finish(22);
case 32:
_context5.next = 37;
break;
case 34:
_context5.prev = 34;
_context5.t1 = _context5["catch"](0);
console.error("error polling for TURN servers", _context5.t1);
case 37:
case "end":
return _context5.stop();
}
}, _callee5, this, [[0, 34], [5, 18, 22, 32], [23,, 27, 31]]);
}));
function pollTurnServers(_x3, _x4) {
return _pollTurnServers.apply(this, arguments);
}
return pollTurnServers;
}()
}, {
key: "handleWatchTurnServers",
value: function () {
var _handleWatchTurnServers = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(request) {
var turnServers, _yield$turnServers$ne, done, value;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC3846TurnServers)) {
_context6.next = 4;
break;
}
this.transport.reply(request, {
error: {
message: "Missing capability"
}
});
_context6.next = 26;
break;
case 4:
if (!this.turnServers) {
_context6.next = 8;
break;
}
// We're already polling, so this is a no-op
this.transport.reply(request, {});
_context6.next = 26;
break;
case 8:
_context6.prev = 8;
turnServers = this.driver.getTurnServers(); // Peek at the first result, so we can at least verify that the
// client isn't banned from getting TURN servers entirely
_context6.next = 12;
return turnServers.next();
case 12:
_yield$turnServers$ne = _context6.sent;
done = _yield$turnServers$ne.done;
value = _yield$turnServers$ne.value;
if (!done) {
_context6.next = 17;
break;
}
throw new Error("Client refuses to provide any TURN servers");
case 17:
this.transport.reply(request, {});
// Start the poll loop, sending the widget the initial result
this.pollTurnServers(turnServers, value);
this.turnServers = turnServers;
_context6.next = 26;
break;
case 22:
_context6.prev = 22;
_context6.t0 = _context6["catch"](8);
console.error("error getting first TURN server results", _context6.t0);
this.transport.reply(request, {
error: {
message: "TURN servers not available"
}
});
case 26:
case "end":
return _context6.stop();
}
}, _callee6, this, [[8, 22]]);
}));
function handleWatchTurnServers(_x5) {
return _handleWatchTurnServers.apply(this, arguments);
}
return handleWatchTurnServers;
}()
}, {
key: "handleUnwatchTurnServers",
value: function () {
var _handleUnwatchTurnServers = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(request) {
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC3846TurnServers)) {
_context7.next = 4;
break;
}
this.transport.reply(request, {
error: {
message: "Missing capability"
}
});
_context7.next = 12;
break;
case 4:
if (this.turnServers) {
_context7.next = 8;
break;
}
// We weren't polling anyways, so this is a no-op
this.transport.reply(request, {});
_context7.next = 12;
break;
case 8:
_context7.next = 10;
return this.turnServers["return"](undefined);
case 10:
this.turnServers = null;
this.transport.reply(request, {});
case 12:
case "end":
return _context7.stop();
}
}, _callee7, this);
}));
function handleUnwatchTurnServers(_x6) {
return _handleUnwatchTurnServers.apply(this, arguments);
}
return handleUnwatchTurnServers;
}()
}, {
key: "handleReadRelations",
value: function () {
var _handleReadRelations = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(request) {
var _this1 = this;
var result, chunk;
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
if (request.data.event_id) {
_context8.next = 2;
break;
}
return _context8.abrupt("return", this.transport.reply(request, {
error: {
message: "Invalid request - missing event ID"
}
}));
case 2:
if (!(request.data.limit !== undefined && request.data.limit < 0)) {
_context8.next = 4;
break;
}
return _context8.abrupt("return", this.transport.reply(request, {
error: {
message: "Invalid request - limit out of range"
}
}));
case 4:
if (!(request.data.room_id !== undefined && !this.canUseRoomTimeline(request.data.room_id))) {
_context8.next = 6;
break;
}
return _context8.abrupt("return", this.transport.reply(request, {
error: {
message: "Unable to access room timeline: ".concat(request.data.room_id)
}
}));
case 6:
_context8.prev = 6;
_context8.next = 9;
return this.driver.readEventRelations(request.data.event_id, request.data.room_id, request.data.rel_type, request.data.event_type, request.data.from, request.data.to, request.data.limit, request.data.direction);
case 9:
result = _context8.sent;
// only return events that the user has the permission to receive
chunk = result.chunk.filter(function (e) {
if (e.state_key !== undefined) {
return _this1.canReceiveStateEvent(e.type, e.state_key);
} else {
return _this1.canReceiveRoomEvent(e.type, e.content["msgtype"]);
}
});
return _context8.abrupt("return", this.transport.reply(request, {
chunk: chunk,
prev_batch: result.prevBatch,
next_batch: result.nextBatch
}));
case 14:
_context8.prev = 14;
_context8.t0 = _context8["catch"](6);
console.error("error getting the relations", _context8.t0);
this.handleDriverError(_context8.t0, request, "Unexpected error while reading relations");
case 18:
case "end":
return _context8.stop();
}
}, _callee8, this, [[6, 14]]);
}));
function handleReadRelations(_x7) {
return _handleReadRelations.apply(this, arguments);
}
return handleReadRelations;
}()
}, {
key: "handleUserDirectorySearch",
value: function () {
var _handleUserDirectorySearch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(request) {
var result;
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC3973UserDirectorySearch)) {
_context9.next = 2;
break;
}
return _context9.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
if (!(typeof request.data.search_term !== "string")) {
_context9.next = 4;
break;
}
return _context9.abrupt("return", this.transport.reply(request, {
error: {
message: "Invalid request - missing search term"
}
}));
case 4:
if (!(request.data.limit !== undefined && request.data.limit < 0)) {
_context9.next = 6;
break;
}
return _context9.abrupt("return", this.transport.reply(request, {
error: {
message: "Invalid request - limit out of range"
}
}));
case 6:
_context9.prev = 6;
_context9.next = 9;
return this.driver.searchUserDirectory(request.data.search_term, request.data.limit);
case 9:
result = _context9.sent;
return _context9.abrupt("return", this.transport.reply(request, {
limited: result.limited,
results: result.results.map(function (r) {
return {
user_id: r.userId,
display_name: r.displayName,
avatar_url: r.avatarUrl
};
})
}));
case 13:
_context9.prev = 13;
_context9.t0 = _context9["catch"](6);
console.error("error searching in the user directory", _context9.t0);
this.handleDriverError(_context9.t0, request, "Unexpected error while searching in the user directory");
case 17:
case "end":
return _context9.stop();
}
}, _callee9, this, [[6, 13]]);
}));
function handleUserDirectorySearch(_x8) {
return _handleUserDirectorySearch.apply(this, arguments);
}
return handleUserDirectorySearch;
}()
}, {
key: "handleGetMediaConfig",
value: function () {
var _handleGetMediaConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(request) {
var result;
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
while (1) switch (_context0.prev = _context0.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC4039UploadFile)) {
_context0.next = 2;
break;
}
return _context0.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
_context0.prev = 2;
_context0.next = 5;
return this.driver.getMediaConfig();
case 5:
result = _context0.sent;
return _context0.abrupt("return", this.transport.reply(request, result));
case 9:
_context0.prev = 9;
_context0.t0 = _context0["catch"](2);
console.error("error while getting the media configuration", _context0.t0);
this.handleDriverError(_context0.t0, request, "Unexpected error while getting the media configuration");
case 13:
case "end":
return _context0.stop();
}
}, _callee0, this, [[2, 9]]);
}));
function handleGetMediaConfig(_x9) {
return _handleGetMediaConfig.apply(this, arguments);
}
return handleGetMediaConfig;
}()
}, {
key: "handleRtcTransports",
value: function () {
var _handleRtcTransports = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1(request) {
var result;
return _regeneratorRuntime().wrap(function _callee1$(_context1) {
while (1) switch (_context1.prev = _context1.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC4515RtcTransports)) {
_context1.next = 2;
break;
}
return _context1.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
_context1.prev = 2;
_context1.next = 5;
return this.driver.getRtcTransports();
case 5:
result = _context1.sent;
return _context1.abrupt("return", this.transport.reply(request, {
rtc_transports: result.rtc_transports
}));
case 9:
_context1.prev = 9;
_context1.t0 = _context1["catch"](2);
console.error("error while getting the RTC transports", _context1.t0);
this.handleDriverError(_context1.t0, request, "Unexpected error while getting the RTC transports");
case 13:
case "end":
return _context1.stop();
}
}, _callee1, this, [[2, 9]]);
}));
function handleRtcTransports(_x0) {
return _handleRtcTransports.apply(this, arguments);
}
return handleRtcTransports;
}()
}, {
key: "handleUploadFile",
value: function () {
var _handleUploadFile = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(request) {
var result;
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC4039UploadFile)) {
_context10.next = 2;
break;
}
return _context10.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
_context10.prev = 2;
_context10.next = 5;
return this.driver.uploadFile(request.data.file);
case 5:
result = _context10.sent;
return _context10.abrupt("return", this.transport.reply(request, {
content_uri: result.contentUri
}));
case 9:
_context10.prev = 9;
_context10.t0 = _context10["catch"](2);
console.error("error while uploading a file", _context10.t0);
this.handleDriverError(_context10.t0, request, "Unexpected error while uploading a file");
case 13:
case "end":
return _context10.stop();
}
}, _callee10, this, [[2, 9]]);
}));
function handleUploadFile(_x1) {
return _handleUploadFile.apply(this, arguments);
}
return handleUploadFile;
}()
}, {
key: "handleDownloadFile",
value: function () {
var _handleDownloadFile = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(request) {
var result;
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC4039DownloadFile)) {
_context11.next = 2;
break;
}
return _context11.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
_context11.prev = 2;
_context11.next = 5;
return this.driver.downloadFile(request.data.content_uri);
case 5:
result = _context11.sent;
return _context11.abrupt("return", this.transport.reply(request, {
file: result.file
}));
case 9:
_context11.prev = 9;
_context11.t0 = _context11["catch"](2);
console.error("error while downloading a file", _context11.t0);
this.handleDriverError(_context11.t0, request, "Unexpected error while downloading a file");
case 13:
case "end":
return _context11.stop();
}
}, _callee11, this, [[2, 9]]);
}));
function handleDownloadFile(_x10) {
return _handleDownloadFile.apply(this, arguments);
}
return handleDownloadFile;
}()
}, {
key: "handleRtcLivekitGetToken",
value: function () {
var _handleRtcLivekitGetToken = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(request) {
var result;
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC4533RtcLivekitGetToken)) {
_context12.next = 2;
break;
}
return _context12.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
_context12.prev = 2;
_context12.next = 5;
return this.driver.getRtcLivekitToken(request.data);
case 5:
result = _context12.sent;
return _context12.abrupt("return", this.transport.reply(request, result));
case 9:
_context12.prev = 9;
_context12.t0 = _context12["catch"](2);
console.error("error while getting a LiveKit token", _context12.t0);
this.handleDriverError(_context12.t0, request, "Unexpected error while getting a LiveKit token");
case 13:
case "end":
return _context12.stop();
}
}, _callee12, this, [[2, 9]]);
}));
function handleRtcLivekitGetToken(_x11) {
return _handleRtcLivekitGetToken.apply(this, arguments);
}
return handleRtcLivekitGetToken;
}()
}, {
key: "handleRtcLivekitDelegateDelayedLeave",
value: function () {
var _handleRtcLivekitDelegateDelayedLeave = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13(request) {
var result;
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
if (this.hasCapability(_Capabilities.MatrixCapabilities.MSC4533RtcLivekitDelegateDelayedLeave)) {
_context13.next = 2;
break;
}
return _context13.abrupt("return", this.transport.reply(request, {
error: {
message: "Missing capability"
}
}));
case 2:
_context13.prev = 2;
_context13.next = 5;
return this.driver.delegateRtcLivekitDelayedLeave(request.data);
case 5:
result = _context13.sent;
return _context13.abrupt("return", this.transport.reply(request, result));
case 9:
_context13.prev = 9;
_context13.t0 = _context13["catch"](2);
console.error("error while delegating a LiveKit delayed leave", _context13.t0);
this.handleDriverError(_context13.t0, request, "Unexpected error while delegating a LiveKit delayed leave");
case 13:
case "end":
return _context13.stop();
}
}, _callee13, this, [[2, 9]]);
}));
function handleRtcLivekitDelegateDelayedLeave(_x12) {
return _handleRtcLivekitDelegateDelayedLeave.apply(this, arguments);
}
return handleRtcLivekitDelegateDelayedLeave;
}()
}, {
key: "handleDriverError",
value: function handleDriverError(e, request, message) {
var data = this.driver.processError(e);
this.transport.reply(request, {
error: _objectSpread({
message: message
}, data)
});
}
}, {
key: "handleMessage",
value: function handleMessage(ev) {
if (this.isStopped) return;
var actionEv = new CustomEvent("action:".concat(ev.detail.action), {
detail: ev.detail,
cancelable: true
});
this.emit("action:".concat(ev.detail.action), actionEv);
if (!actionEv.defaultPrevented) {
switch (ev.detail.action) {
case _WidgetApiAction.WidgetApiFromWidgetAction.ContentLoaded:
return this.handleContentLoadedAction(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.SupportedApiVersions:
return this.replyVersions(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.SendEvent:
return this.handleSendEvent(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.SendToDevice:
return this.handleSendToDevice(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.GetOpenIDCredentials:
return this.handleOIDC(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC2931Navigate:
return this.handleNavigate(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC2974RenegotiateCapabilities:
return this.handleCapabilitiesRenegotiate(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC2876ReadEvents:
return this.handleReadEvents(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.WatchTurnServers:
return this.handleWatchTurnServers(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.UnwatchTurnServers:
return this.handleUnwatchTurnServers(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC3869ReadRelations:
return this.handleReadRelations(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC3973UserDirectorySearch:
return this.handleUserDirectorySearch(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.BeeperReadRoomAccountData:
return this.handleReadRoomAccountData(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4039GetMediaConfigAction:
return this.handleGetMediaConfig(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4515GetRtcTransports:
return this.handleRtcTransports(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4039UploadFileAction:
return this.handleUploadFile(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4039DownloadFileAction:
return this.handleDownloadFile(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4157UpdateDelayedEvent:
return this.handleUpdateDelayedEvent(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4533RtcLivekitGetToken:
return this.handleRtcLivekitGetToken(ev.detail);
case _WidgetApiAction.WidgetApiFromWidgetAction.MSC4533RtcLivekitDelegateDelayedLeave:
return this.handleRtcLivekitDelegateDelayedLeave(ev.detail);
default:
return this.transport.reply(ev.detail, {
error: {
message: "Unknown or unsupported from-widget action: " + ev.detail.action
}
});
}
}
}
/**
* Informs the widget that the client's theme has changed.
* @param theme The theme data, as an object with arbitrary contents.
*/
}, {
key: "updateTheme",
value: function updateTheme(theme) {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.ThemeChange, theme);
}
/**
* Informs the widget that the client's language has changed.
* @param lang The BCP 47 identifier representing the client's current language.
*/
}, {
key: "updateLanguage",
value: function updateLanguage(lang) {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.LanguageChange, {
lang: lang
});
}
/**
* Takes a screenshot of the widget.
* @returns Resolves to the widget's screenshot.
* @throws Throws if there is a problem.
*/
}, {
key: "takeScreenshot",
value: function takeScreenshot() {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.TakeScreenshot, {});
}
/**
* Alerts the widget to whether or not it is currently visible.
* @param {boolean} isVisible Whether the widget is visible or not.
* @returns {Promise<IWidgetApiResponseData>} Resolves when the widget acknowledges the update.
*/
}, {
key: "updateVisibility",
value: function updateVisibility(isVisible) {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.UpdateVisibility, {
visible: isVisible
});
}
}, {
key: "sendWidgetConfig",
value: function sendWidgetConfig(data) {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.WidgetConfig, data).then();
}
}, {
key: "notifyModalWidgetButtonClicked",
value: function notifyModalWidgetButtonClicked(id) {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.ButtonClicked, {
id: id
}).then();
}
}, {
key: "notifyModalWidgetClose",
value: function notifyModalWidgetClose(data) {
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.CloseModalWidget, data).then();
}
/**
* Feeds an event to the widget. As a client you are expected to call this
* for every new event in every room to which you are joined or invited.
* @param {IRoomEvent} rawEvent The event to (try to) send to the widget.
* @param {string} currentViewedRoomId The room ID the user is currently
* interacting with. Not the room ID of the event.
* @returns {Promise<void>} Resolves when delivered or if the widget is not
* able to read the event due to permissions, rejects if the widget failed
* to handle the event.
* @deprecated It is recommended to communicate the viewed room ID by calling
* {@link ClientWidgetApi.setViewedRoomId} rather than passing it to this
* method.
*/
}, {
key: "feedEvent",
value: function () {
var _feedEvent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14(rawEvent, currentViewedRoomId) {
var _rawEvent$content;
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
while (1) switch (_context14.prev = _context14.next) {
case 0:
if (currentViewedRoomId !== undefined) this.setViewedRoomId(currentViewedRoomId);
if (!(rawEvent.room_id !== this.viewedRoomId && !this.canUseRoomTimeline(rawEvent.room_id))) {
_context14.next = 3;
break;
}
return _context14.abrupt("return");
case 3:
if (!(rawEvent.state_key !== undefined && rawEvent.state_key !== null)) {
_context14.next = 8;
break;
}
if (this.canReceiveStateEvent(rawEvent.type, rawEvent.state_key)) {
_context14.next = 6;
break;
}
return _context14.abrupt("return");
case 6:
_context14.next = 10;
break;
case 8:
if (this.canReceiveRoomEvent(rawEvent.type, (_rawEvent$content = rawEvent.content) === null || _rawEvent$content === void 0 ? void 0 : _rawEvent$content["msgtype"])) {
_context14.next = 10;
break;
}
return _context14.abrupt("return");
case 10:
_context14.next = 12;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.SendEvent,
// it's compatible, but missing the index signature
rawEvent);
case 12:
case "end":
return _context14.stop();
}
}, _callee14, this);
}));
function feedEvent(_x13, _x14) {
return _feedEvent.apply(this, arguments);
}
return feedEvent;
}()
/**
* Feeds a to-device event to the widget. As a client you are expected to
* call this for every to-device event you receive.
* @param {IRoomEvent} rawEvent The event to (try to) send to the widget.
* @param {boolean} encrypted Whether the event contents were encrypted.
* @returns {Promise<void>} Resolves when delivered or if the widget is not
* able to receive the event due to permissions, rejects if the widget
* failed to handle the event.
*/
}, {
key: "feedToDevice",
value: (function () {
var _feedToDevice = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15(message, encrypted) {
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
while (1) switch (_context15.prev = _context15.next) {
case 0:
if (!this.canReceiveToDeviceEvent(message.type)) {
_context15.next = 3;
break;
}
_context15.next = 3;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.SendToDevice, _objectSpread(_objectSpread({}, message), {}, {
encrypted: encrypted
}));
case 3:
case "end":
return _context15.stop();
}
}, _callee15, this);
}));
function feedToDevice(_x15, _x16) {
return _feedToDevice.apply(this, arguments);
}
return feedToDevice;
}())
}, {
key: "setViewedRoomId",
value:
/**
* Indicate that a room is being viewed (making it possible for the widget
* to interact with it).
*/
function setViewedRoomId(roomId) {
this.viewedRoomId = roomId;
// If the widget doesn't have timeline permissions for the room then
// this is its opportunity to learn the room state. We push the entire
// room state, which could be redundant if this room had been viewed
// once before, but it's easier than selectively pushing just the bits
// of state that changed while the room was in the background.
if (roomId !== null && !this.canUseRoomTimeline(roomId)) this.pushRoomState(roomId);
}
}, {
key: "flushRoomState",
value: function () {
var _flushRoomState = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
var events, _iterator7, _step7, eventTypeMap, _iterator8, _step8, stateKeyMap;
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
while (1) switch (_context16.prev = _context16.next) {
case 0:
_context16.prev = 0;
case 1:
_context16.next = 3;
return Promise.all(this.pushRoomStateTasks);
case 3:
if (this.pushRoomStateTasks.size > 0) {
_context16.next = 1;
break;
}
case 4:
events = [];
_iterator7 = _createForOfIteratorHelper(this.pushRoomStateResult.values());
try {
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
eventTypeMap = _step7.value;
_iterator8 = _createForOfIteratorHelper(eventTypeMap.values());
try {
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
stateKeyMap = _step8.value;
events.push.apply(events, _toConsumableArray(stateKeyMap.values()));
}
} catch (err) {
_iterator8.e(err);
} finally {
_iterator8.f();
}
}
} catch (err) {
_iterator7.e(err);
} finally {
_iterator7.f();
}
_context16.next = 9;
return this.getWidgetVersions();
case 9:
if (!_context16.sent.includes(_ApiVersion.UnstableApiVersion.MSC2762_UPDATE_STATE)) {
_context16.next = 12;
break;
}
_context16.next = 12;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.UpdateState, {
state: events
});
case 12:
_context16.prev = 12;
this.flushRoomStateTask = null;
return _context16.finish(12);
case 15:
case "end":
return _context16.stop();
}
}, _callee16, this, [[0,, 12, 15]]);
}));
function flushRoomState() {
return _flushRoomState.apply(this, arguments);
}
return flushRoomState;
}()
/**
* Reads the current sticky state of the room and pushes it to the widget.
*
* It will only push events that the widget is allowed to receive.
* @param roomId
* @private
*/
}, {
key: "pushStickyState",
value: (function () {
var _pushStickyState = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee18(roomId) {
var _this10 = this;
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
while (1) switch (_context18.prev = _context18.next) {
case 0:
console.debug("Pushing sticky state to widget for room", roomId);
return _context18.abrupt("return", this.driver.readStickyEvents(roomId).then(function (events) {
// filter to the allowed sticky events
var filtered = events.filter(function (e) {
var _e$content;
return _this10.canReceiveRoomEvent(e.type, typeof ((_e$content = e.content) === null || _e$content === void 0 ? void 0 : _e$content.msgtype) === "string" ? e.content.msgtype : null);
});
return {
roomId: roomId,
stickyEvents: filtered
};
}).then(/*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref) {
var roomId, stickyEvents, promises;
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
while (1) switch (_context17.prev = _context17.next) {
case 0:
roomId = _ref.roomId, stickyEvents = _ref.stickyEvents;
console.debug("Pushing", stickyEvents.length, "sticky events to widget for room", roomId);
promises = stickyEvents.map(function (rawEvent) {
return _this10.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.SendEvent,
// copied from feedEvent; it's compatible, but missing the index signature
rawEvent);
});
_context17.next = 5;
return Promise.all(promises);
case 5:
case "end":
return _context17.stop();
}
}, _callee17);
}));
return function (_x18) {
return _ref2.apply(this, arguments);
};
}()));
case 2:
case "end":
return _context18.stop();
}
}, _callee18, this);
}));
function pushStickyState(_x17) {
return _pushStickyState.apply(this, arguments);
}
return pushStickyState;
}()
/**
* Read the room's state and push all entries that the widget is allowed to
* read through to the widget.
*/
)
}, {
key: "pushRoomState",
value: function pushRoomState(roomId) {
var _this11 = this;
var _iterator9 = _createForOfIteratorHelper(this.allowedEvents),
_step9;
try {
var _loop2 = function _loop2() {
var cap = _step9.value;
if (cap.kind === _WidgetEventCapability.EventKind.State && cap.direction === _WidgetEventCapability.EventDirection.Receive) {
var _cap$keyStr, _this11$flushRoomStat;
// Initiate the task
var events = _this11.driver.readRoomState(roomId, cap.eventType, (_cap$keyStr = cap.keyStr) !== null && _cap$keyStr !== void 0 ? _cap$keyStr : undefined);
var task = events.then(function (events) {
// When complete, queue the resulting events to be
// pushed to the widget
var _iterator0 = _createForOfIteratorHelper(events),
_step0;
try {
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
var event = _step0.value;
var eventTypeMap = _this11.pushRoomStateResult.get(roomId);
if (eventTypeMap === undefined) {
eventTypeMap = new Map();
_this11.pushRoomStateResult.set(roomId, eventTypeMap);
}
var stateKeyMap = eventTypeMap.get(cap.eventType);
if (stateKeyMap === undefined) {
stateKeyMap = new Map();
eventTypeMap.set(cap.eventType, stateKeyMap);
}
if (!stateKeyMap.has(event.state_key)) stateKeyMap.set(event.state_key, event);
}
} catch (err) {
_iterator0.e(err);
} finally {
_iterator0.f();
}
}, function (e) {
return console.error("Failed to read room state for ".concat(roomId, " (").concat(cap.eventType, ", ").concat(cap.keyStr, ")"), e);
}).then(function () {
// Mark request as no longer pending
_this11.pushRoomStateTasks["delete"](task);
});
// Mark task as pending
_this11.pushRoomStateTasks.add(task);
// Assuming no other tasks are already happening concurrently,
// schedule the widget action that actually pushes the events
(_this11$flushRoomStat = _this11.flushRoomStateTask) !== null && _this11$flushRoomStat !== void 0 ? _this11$flushRoomStat : _this11.flushRoomStateTask = _this11.flushRoomState();
_this11.flushRoomStateTask["catch"](function (e) {
return console.error("Failed to push room state", e);
});
}
};
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
_loop2();
}
} catch (err) {
_iterator9.e(err);
} finally {
_iterator9.f();
}
}
/**
* Feeds a room state update to the widget. As a client you are expected to
* call this for every state update in every room to which you are joined or
* invited.
* @param {IRoomEvent} rawEvent The state event corresponding to the updated
* room state entry.
* @returns {Promise<void>} Resolves when delivered or if the widget is not
* able to receive the room state due to permissions, rejects if the
* widget failed to handle the update.
*/
}, {
key: "feedStateUpdate",
value: (function () {
var _feedStateUpdate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee19(rawEvent) {
var eventTypeMap, stateKeyMap;
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
while (1) switch (_context19.prev = _context19.next) {
case 0:
if (!(rawEvent.state_key === undefined)) {
_context19.next = 2;
break;
}
throw new Error("Not a state event");
case 2:
if (!((rawEvent.room_id === this.viewedRoomId || this.canUseRoomTimeline(rawEvent.room_id)) && this.canReceiveStateEvent(rawEvent.type, rawEvent.state_key))) {
_context19.next = 21;
break;
}
if (!(this.pushRoomStateTasks.size === 0)) {
_context19.next = 11;
break;
}
_context19.next = 6;
return this.getWidgetVersions();
case 6:
if (!_context19.sent.includes(_ApiVersion.UnstableApiVersion.MSC2762_UPDATE_STATE)) {
_context19.next = 9;
break;
}
_context19.next = 9;
return this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.UpdateState, {
state: [rawEvent]
});
case 9:
_context19.next = 21;
break;
case 11:
// Lump the update in with whatever data will be sent in the
// initial push later. Even if we set it to an "outdated" entry
// here, we can count on any newer entries being passed to this
// same method eventually; this won't cause stuck state.
eventTypeMap = this.pushRoomStateResult.get(rawEvent.room_id);
if (eventTypeMap === undefined) {
eventTypeMap = new Map();
this.pushRoomStateResult.set(rawEvent.room_id, eventTypeMap);
}
stateKeyMap = eventTypeMap.get(rawEvent.type);
if (stateKeyMap === undefined) {
stateKeyMap = new Map();
eventTypeMap.set(rawEvent.type, stateKeyMap);
}
if (!stateKeyMap.has(rawEvent.type)) stateKeyMap.set(rawEvent.state_key, rawEvent);
case 16:
_context19.next = 18;
return Promise.all(this.pushRoomStateTasks);
case 18:
if (this.pushRoomStateTasks.size > 0) {
_context19.next = 16;
break;
}
case 19:
_context19.next = 21;
return this.flushRoomStateTask;
case 21:
case "end":
return _context19.stop();
}
}, _callee19, this);
}));
function feedStateUpdate(_x19) {
return _feedStateUpdate.apply(this, arguments);
}
return feedStateUpdate;
}())
}]);
return ClientWidgetApi;
}(_events.EventEmitter);
exports.ClientWidgetApi = ClientWidgetApi;
},{"./Symbols":2,"./interfaces/ApiVersion":6,"./interfaces/Capabilities":7,"./interfaces/GetOpenIDAction":8,"./interfaces/UpdateDelayedEventAction":12,"./interfaces/WidgetApiAction":13,"./interfaces/WidgetApiDirection":14,"./models/WidgetEventCapability":18,"./transport/PostmessageTransport":23,"./util/SimpleObservable":24,"events":25}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Symbols = void 0;
/*
* Copyright 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Symbols = /*#__PURE__*/function (Symbols) {
Symbols["AnyRoom"] = "*";
return Symbols;
}({});
exports.Symbols = Symbols;
},{}],3:[function(require,module,exports){
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetApiResponseError = exports.WidgetApi = void 0;
var _events = require("events");
var _Capabilities = require("./interfaces/Capabilities");
var _WidgetApiDirection = require("./interfaces/WidgetApiDirection");
var _ApiVersion = require("./interfaces/ApiVersion");
var _PostmessageTransport = require("./transport/PostmessageTransport");
var _WidgetApiAction = require("./interfaces/WidgetApiAction");
var _GetOpenIDAction = require("./interfaces/GetOpenIDAction");
var _WidgetType = require("./interfaces/WidgetType");
var _ModalWidgetActions = require("./interfaces/ModalWidgetActions");
var _WidgetEventCapability = require("./models/WidgetEventCapability");
var _Symbols = require("./Symbols");
var _UpdateDelayedEventAction = require("./interfaces/UpdateDelayedEventAction");
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _awaitAsyncGenerator(e) { return new _OverloadYield(e, 0); }
function _wrapAsyncGenerator(e) { return function () { return new AsyncGenerator(e.apply(this, arguments)); }; }
function AsyncGenerator(e) { var t, n; function resume(t, n) { try { var r = e[t](n), o = r.value, u = o instanceof _OverloadYield; Promise.resolve(u ? o.v : o).then(function (n) { if (u) { var i = "return" === t && o.k ? t : "next"; if (!o.k || n.done) return resume(i, n); n = e[i](n).value; } settle(!!r.done, n); }, function (e) { resume("throw", e); }); } catch (e) { settle(2, e); } } function settle(e, r) { 2 === e ? t.reject(r) : t.resolve({ value: r, done: e }), (t = t.next) ? resume(t.key, t.arg) : n = null; } this._invoke = function (e, r) { return new Promise(function (o, u) { var i = { key: e, arg: r, resolve: o, reject: u, next: null }; n ? n = n.next = i : (t = n = i, resume(e, r)); }); }, "function" != typeof e["return"] && (this["return"] = void 0); }
AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function () { return this; }, AsyncGenerator.prototype.next = function (e) { return this._invoke("next", e); }, AsyncGenerator.prototype["throw"] = function (e) { return this._invoke("throw", e); }, AsyncGenerator.prototype["return"] = function (e) { return this._invoke("return", e); };
function _OverloadYield(e, d) { this.v = e, this.k = d; } /*
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var WidgetApiResponseError = /*#__PURE__*/function (_Error) {
_inherits(WidgetApiResponseError, _Error);
var _super = _createSuper(WidgetApiResponseError);
function WidgetApiResponseError(message, data) {
var _this2;
_classCallCheck(this, WidgetApiResponseError);
_this2 = _super.call(this, message);
_this2.data = data;
return _this2;
}
return _createClass(WidgetApiResponseError);
}(/*#__PURE__*/_wrapNativeSuper(Error));
/**
* API handler for widgets. This raises events for each action
* received as `action:${action}` (eg: "action:screenshot").
* Default handling can be prevented by using preventDefault()
* on the raised event. The default handling varies for each
* action: ones which the SDK can handle safely are acknowledged
* appropriately and ones which are unhandled (custom or require
* the widget to do something) are rejected with an error.
*
* Events which are preventDefault()ed must reply using the
* transport. The events raised will have a detail of an
* IWidgetApiRequest interface.
*
* When the WidgetApi is ready to start sending requests, it will
* raise a "ready" CustomEvent. After the ready event fires, actions
* can be sent and the transport will be ready.
*/
exports.WidgetApiResponseError = WidgetApiResponseError;
WidgetApiResponseError.prototype.name = WidgetApiResponseError.name;
var WidgetApi = /*#__PURE__*/function (_EventEmitter) {
_inherits(WidgetApi, _EventEmitter);
var _super2 = _createSuper(WidgetApi);
/**
* Creates a new API handler for the given widget.
* @param {string} widgetId The widget ID to listen for. If not supplied then
* the API will use the widget ID from the first valid request it receives.
* @param {string} clientOrigin The origin of the client, or null if not known.
*/
function WidgetApi() {
var _this3;
var widgetId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var clientOrigin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
_classCallCheck(this, WidgetApi);
_this3 = _super2.call(this);
_defineProperty(_assertThisInitialized(_this3), "transport", void 0);
_defineProperty(_assertThisInitialized(_this3), "capabilitiesFinished", false);
_defineProperty(_assertThisInitialized(_this3), "supportsMSC2974Renegotiate", false);
_defineProperty(_assertThisInitialized(_this3), "requestedCapabilities", []);
_defineProperty(_assertThisInitialized(_this3), "approvedCapabilities", void 0);
_defineProperty(_assertThisInitialized(_this3), "cachedClientVersions", void 0);
_defineProperty(_assertThisInitialized(_this3), "turnServerWatchers", 0);
if (!globalThis.parent) {
throw new Error("No parent window. This widget doesn't appear to be embedded properly.");
}
_this3.transport = new _PostmessageTransport.PostmessageTransport(_WidgetApiDirection.WidgetApiDirection.FromWidget, widgetId, globalThis.parent, globalThis);
_this3.transport.targetOrigin = clientOrigin;
_this3.transport.on("message", _this3.handleMessage.bind(_assertThisInitialized(_this3)));
return _this3;
}
/**
* Determines if the widget was granted a particular capability. Note that on
* clients where the capabilities are not fed back to the widget this function
* will rely on requested capabilities instead.
* @param {Capability} capability The capability to check for approval of.
* @returns {boolean} True if the widget has approval for the given capability.
*/
_createClass(WidgetApi, [{
key: "hasCapability",
value: function hasCapability(capability) {
if (Array.isArray(this.approvedCapabilities)) {
return this.approvedCapabilities.includes(capability);
}
return this.requestedCapabilities.includes(capability);
}
/**
* Request a capability from the client. It is not guaranteed to be allowed,
* but will be asked for.
* @param {Capability} capability The capability to request.
* @throws Throws if the capabilities negotiation has already started and the
* widget is unable to request additional capabilities.
*/
}, {
key: "requestCapability",
value: function requestCapability(capability) {
if (this.capabilitiesFinished && !this.supportsMSC2974Renegotiate) {
throw new Error("Capabilities have already been negotiated");
}
this.requestedCapabilities.push(capability);
}
/**
* Request capabilities from the client. They are not guaranteed to be allowed,
* but will be asked for if the negotiation has not already happened.
* @param {Capability[]} capabilities The capabilities to request.
* @throws Throws if the capabilities negotiation has already started.
*/
}, {
key: "requestCapabilities",
value: function requestCapabilities(capabilities) {
var _iterator = _createForOfIteratorHelper(capabilities),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var cap = _step.value;
this.requestCapability(cap);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
/**
* Requests the capability to interact with rooms other than the user's currently
* viewed room. Applies to event receiving and sending.
* @param {string | Symbols.AnyRoom} roomId The room ID, or `Symbols.AnyRoom` to
* denote all known rooms.
*/
}, {
key: "requestCapabilityForRoomTimeline",
value: function requestCapabilityForRoomTimeline(roomId) {
this.requestCapability("org.matrix.msc2762.timeline:".concat(roomId));
}
/**
* Requests the capability to send a given state event with optional explicit
* state key. It is not guaranteed to be allowed, but will be asked for if the
* negotiation has not already happened.
* @param {string} eventType The state event type to ask for.
* @param {string} stateKey If specified, the specific state key to request.
* Otherwise all state keys will be requested.
*/
}, {
key: "requestCapabilityToSendState",
value: function requestCapabilityToSendState(eventType, stateKey) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forStateEvent(_WidgetEventCapability.EventDirection.Send, eventType, stateKey).raw);
}
/**
* Requests the capability to receive a given state event with optional explicit
* state key. It is not guaranteed to be allowed, but will be asked for if the
* negotiation has not already happened.
* @param {string} eventType The state event type to ask for.
* @param {string} stateKey If specified, the specific state key to request.
* Otherwise all state keys will be requested.
*/
}, {
key: "requestCapabilityToReceiveState",
value: function requestCapabilityToReceiveState(eventType, stateKey) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forStateEvent(_WidgetEventCapability.EventDirection.Receive, eventType, stateKey).raw);
}
/**
* Requests the capability to send a given to-device event. It is not
* guaranteed to be allowed, but will be asked for if the negotiation has
* not already happened.
* @param {string} eventType The room event type to ask for.
*/
}, {
key: "requestCapabilityToSendToDevice",
value: function requestCapabilityToSendToDevice(eventType) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forToDeviceEvent(_WidgetEventCapability.EventDirection.Send, eventType).raw);
}
/**
* Requests the capability to receive a given to-device event. It is not
* guaranteed to be allowed, but will be asked for if the negotiation has
* not already happened.
* @param {string} eventType The room event type to ask for.
*/
}, {
key: "requestCapabilityToReceiveToDevice",
value: function requestCapabilityToReceiveToDevice(eventType) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forToDeviceEvent(_WidgetEventCapability.EventDirection.Receive, eventType).raw);
}
/**
* Requests the capability to send a given room event. It is not guaranteed to be
* allowed, but will be asked for if the negotiation has not already happened.
* @param {string} eventType The room event type to ask for.
*/
}, {
key: "requestCapabilityToSendEvent",
value: function requestCapabilityToSendEvent(eventType) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forRoomEvent(_WidgetEventCapability.EventDirection.Send, eventType).raw);
}
/**
* Requests the capability to receive a given room event. It is not guaranteed to be
* allowed, but will be asked for if the negotiation has not already happened.
* @param {string} eventType The room event type to ask for.
*/
}, {
key: "requestCapabilityToReceiveEvent",
value: function requestCapabilityToReceiveEvent(eventType) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forRoomEvent(_WidgetEventCapability.EventDirection.Receive, eventType).raw);
}
/**
* Requests the capability to send a given message event with optional explicit
* `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
* negotiation has not already happened.
* @param {string} msgtype If specified, the specific msgtype to request.
* Otherwise all message types will be requested.
*/
}, {
key: "requestCapabilityToSendMessage",
value: function requestCapabilityToSendMessage(msgtype) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forRoomMessageEvent(_WidgetEventCapability.EventDirection.Send, msgtype).raw);
}
/**
* Requests the capability to receive a given message event with optional explicit
* `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
* negotiation has not already happened.
* @param {string} msgtype If specified, the specific msgtype to request.
* Otherwise all message types will be requested.
*/
}, {
key: "requestCapabilityToReceiveMessage",
value: function requestCapabilityToReceiveMessage(msgtype) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forRoomMessageEvent(_WidgetEventCapability.EventDirection.Receive, msgtype).raw);
}
/**
* Requests the capability to receive a given item in room account data. It is not guaranteed to be
* allowed, but will be asked for if the negotiation has not already happened.
* @param {string} eventType The state event type to ask for.
*/
}, {
key: "requestCapabilityToReceiveRoomAccountData",
value: function requestCapabilityToReceiveRoomAccountData(eventType) {
this.requestCapability(_WidgetEventCapability.WidgetEventCapability.forRoomAccountData(_WidgetEventCapability.EventDirection.Receive, eventType).raw);
}
/**
* Requests the capability to obtain a JWT for a LiveKit SFU through the client.
* It is not guaranteed to be allowed, but will be asked for if the negotiation
* has not already happened.
* @see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4533|MSC4533}
*/
}, {
key: "requestCapabilityToGetRtcLivekitToken",
value: function requestCapabilityToGetRtcLivekitToken() {
this.requestCapability(_Capabilities.MatrixCapabilities.MSC4533RtcLivekitGetToken);
}
/**
* Requests the capability to hand a MatrixRTC session's delayed leave event over
* to the server through the client. It is not guaranteed to be allowed, but will
* be asked for if the negotiation has not already happened.
* @see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4533|MSC4533}
*/
}, {
key: "requestCapabilityToDelegateRtcLivekitDelayedLeave",
value: function requestCapabilityToDelegateRtcLivekitDelayedLeave() {
this.requestCapability(_Capabilities.MatrixCapabilities.MSC4533RtcLivekitDelegateDelayedLeave);
}
/**
* Requests an OpenID Connect token from the client for the currently logged in
* user. This token can be validated server-side with the federation API. Note
* that the widget is responsible for validating the token and caching any results
* it needs.
* @returns {Promise<IOpenIDCredentials>} Resolves to a token for verification.
* @throws Throws if the user rejected the request or the request failed.
*/
}, {
key: "requestOpenIDConnectToken",
value: function requestOpenIDConnectToken() {
var _this4 = this;
return new Promise(function (resolve, reject) {
_this4.transport.sendComplete(_WidgetApiAction.WidgetApiFromWidgetAction.GetOpenIDCredentials, {}).then(function (response) {
var rdata = response.response;
if (rdata.state === _GetOpenIDAction.OpenIDRequestState.Allowed) {
resolve(rdata);
} else if (rdata.state === _GetOpenIDAction.OpenIDRequestState.Blocked) {
reject(new Error("User declined to verify their identity"));
} else if (rdata.state === _GetOpenIDAction.OpenIDRequestState.PendingUserConfirmation) {
var handlerFn = function handlerFn(ev) {
ev.preventDefault();
var request = ev.detail;
if (request.data.original_request_id !== response.requestId) return;
if (request.data.state === _GetOpenIDAction.OpenIDRequestState.Allowed) {
resolve(request.data);
_this4.transport.reply(request, {}); // ack
} else if (request.data.state === _GetOpenIDAction.OpenIDRequestState.Blocked) {
reject(new Error("User declined to verify their identity"));
_this4.transport.reply(request, {}); // ack
} else {
reject(new Error("Invalid state on reply: " + rdata.state));
_this4.transport.reply(request, {
error: {
message: "Invalid state"
}
});
}
_this4.off("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials), handlerFn);
};
_this4.on("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials), handlerFn);
} else {
reject(new Error("Invalid state: " + rdata.state));
}
})["catch"](reject);
});
}
/**
* Asks the client for additional capabilities. Capabilities can be queued for this
* request with the requestCapability() functions.
* @returns {Promise<void>} Resolves when complete. Note that the promise resolves when
* the capabilities request has gone through, not when the capabilities are approved/denied.
* Use the WidgetApiToWidgetAction.NotifyCapabilities action to detect changes.
*/
}, {
key: "updateRequestedCapabilities",
value: function updateRequestedCapabilities() {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC2974RenegotiateCapabilities, {
capabilities: this.requestedCapabilities
}).then();
}
/**
* Tell the client that the content has been loaded.
* @returns {Promise} Resolves when the client acknowledges the request.
*/
}, {
key: "sendContentLoaded",
value: function sendContentLoaded() {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.ContentLoaded, {}).then();
}
/**
* Sends a sticker to the client.
* @param {IStickerActionRequestData} sticker The sticker to send.
* @returns {Promise} Resolves when the client acknowledges the request.
*/
}, {
key: "sendSticker",
value: function sendSticker(sticker) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SendSticker, sticker).then();
}
/**
* Asks the client to set the always-on-screen status for this widget.
* @param {boolean} value The new state to request.
* @returns {Promise<boolean>} Resolve with true if the client was able to fulfill
* the request, resolves to false otherwise. Rejects if an error occurred.
*/
}, {
key: "setAlwaysOnScreen",
value: function setAlwaysOnScreen(value) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.UpdateAlwaysOnScreen, {
value: value
}).then(function (res) {
return res.success;
});
}
/**
* Opens a modal widget.
* @param {string} url The URL to the modal widget.
* @param {string} name The name of the widget.
* @param {IModalWidgetOpenRequestDataButton[]} buttons The buttons to have on the widget.
* @param {IModalWidgetCreateData} data Data to supply to the modal widget.
* @param {WidgetType} type The type of modal widget.
* @returns {Promise<void>} Resolves when the modal widget has been opened.
*/
}, {
key: "openModalWidget",
value: function openModalWidget(url, name) {
var buttons = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : _WidgetType.MatrixWidgetType.Custom;
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.OpenModalWidget, {
type: type,
url: url,
name: name,
buttons: buttons,
data: data
}).then();
}
/**
* Closes the modal widget. The widget's session will be terminated shortly after.
* @param {IModalWidgetReturnData} data Optional data to close the modal widget with.
* @returns {Promise<void>} Resolves when complete.
*/
}, {
key: "closeModalWidget",
value: function closeModalWidget() {
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.CloseModalWidget, data).then();
}
}, {
key: "sendRoomEvent",
value: function sendRoomEvent(eventType, content, roomId, delay, parentDelayIdOrStickyDurationMs, stickyDurationMs) {
var parentDelayId;
if (typeof parentDelayIdOrStickyDurationMs === "number") {
stickyDurationMs = parentDelayIdOrStickyDurationMs;
} else {
parentDelayId = parentDelayIdOrStickyDurationMs;
}
return this.sendEvent(eventType, undefined, content, roomId, delay, parentDelayId, stickyDurationMs);
}
}, {
key: "sendStateEvent",
value: function sendStateEvent(eventType, stateKey, content, roomId, delay, parentDelayId) {
return this.sendEvent(eventType, stateKey, content, roomId, delay, parentDelayId);
}
}, {
key: "sendEvent",
value: function sendEvent(eventType, stateKey, content, roomId, delay, parentDelayId, stickyDurationMs) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SendEvent, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
type: eventType,
content: content
}, stateKey !== undefined && {
state_key: stateKey
}), roomId !== undefined && {
room_id: roomId
}), delay !== undefined && {
delay: delay
}), parentDelayId !== undefined && {
parent_delay_id: parentDelayId
}), stickyDurationMs !== undefined && {
sticky_duration_ms: stickyDurationMs
}));
}
/**
* @experimental This currently relies on an unstable MSC (MSC4157).
*/
}, {
key: "cancelScheduledDelayedEvent",
value: function cancelScheduledDelayedEvent(delayId) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4157UpdateDelayedEvent, {
delay_id: delayId,
action: _UpdateDelayedEventAction.UpdateDelayedEventAction.Cancel
});
}
/**
* @experimental This currently relies on an unstable MSC (MSC4157).
*/
}, {
key: "restartScheduledDelayedEvent",
value: function restartScheduledDelayedEvent(delayId) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4157UpdateDelayedEvent, {
delay_id: delayId,
action: _UpdateDelayedEventAction.UpdateDelayedEventAction.Restart
});
}
/**
* @experimental This currently relies on an unstable MSC (MSC4157).
*/
}, {
key: "sendScheduledDelayedEvent",
value: function sendScheduledDelayedEvent(delayId) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4157UpdateDelayedEvent, {
delay_id: delayId,
action: _UpdateDelayedEventAction.UpdateDelayedEventAction.Send
});
}
/**
* Sends a to-device event.
* @param {string} eventType The type of events being sent.
* @param {boolean} encrypted Whether to encrypt the message contents.
* @param {Object} contentMap A map from user IDs to device IDs to message contents.
* @returns {Promise<ISendToDeviceFromWidgetResponseData>} Resolves when complete.
*/
}, {
key: "sendToDevice",
value: function sendToDevice(eventType, encrypted, contentMap) {
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SendToDevice, {
type: eventType,
encrypted: encrypted,
messages: contentMap
});
}
}, {
key: "readRoomAccountData",
value: function readRoomAccountData(eventType, roomIds) {
var data = {
type: eventType
};
if (roomIds) {
if (roomIds.includes(_Symbols.Symbols.AnyRoom)) {
data.room_ids = _Symbols.Symbols.AnyRoom;
} else {
data.room_ids = roomIds;
}
}
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.BeeperReadRoomAccountData, data).then(function (r) {
return r.events;
});
}
}, {
key: "readRoomEvents",
value: function readRoomEvents(eventType, limit, msgtype, roomIds, since) {
var data = {
type: eventType,
msgtype: msgtype
};
if (limit !== undefined) {
data.limit = limit;
}
if (roomIds) {
if (roomIds.includes(_Symbols.Symbols.AnyRoom)) {
data.room_ids = _Symbols.Symbols.AnyRoom;
} else {
data.room_ids = roomIds;
}
}
if (since) {
data.since = since;
}
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC2876ReadEvents, data).then(function (r) {
return r.events;
});
}
/**
* Reads all related events given a known eventId.
* @param eventId The id of the parent event to be read.
* @param roomId The room to look within. When undefined, the user's currently
* viewed room.
* @param relationType The relationship type of child events to search for.
* When undefined, all relations are returned.
* @param eventType The event type of child events to search for. When undefined,
* all related events are returned.
* @param limit The maximum number of events to retrieve per room. If not
* supplied, the server will apply a default limit.
* @param from The pagination token to start returning results from, as
* received from a previous call. If not supplied, results start at the most
* recent topological event known to the server.
* @param to The pagination token to stop returning results at. If not
* supplied, results continue up to limit or until there are no more events.
* @param direction The direction to search for according to MSC3715.
* @returns Resolves to the room relations.
*/
}, {
key: "readEventRelations",
value: (function () {
var _readEventRelations = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(eventId, roomId, relationType, eventType, limit, from, to, direction) {
var versions, data;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return this.getClientVersions();
case 2:
versions = _context.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC3869)) {
_context.next = 5;
break;
}
throw new Error("The read_relations action is not supported by the client.");
case 5:
data = {
event_id: eventId,
rel_type: relationType,
event_type: eventType,
room_id: roomId,
to: to,
from: from,
limit: limit,
direction: direction
};
return _context.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC3869ReadRelations, data));
case 7:
case "end":
return _context.stop();
}
}, _callee, this);
}));
function readEventRelations(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
return _readEventRelations.apply(this, arguments);
}
return readEventRelations;
}())
}, {
key: "readStateEvents",
value: function readStateEvents(eventType, limit, stateKey, roomIds) {
var data = {
type: eventType,
state_key: stateKey === undefined ? true : stateKey
};
if (limit !== undefined) {
data.limit = limit;
}
if (roomIds) {
if (roomIds.includes(_Symbols.Symbols.AnyRoom)) {
data.room_ids = _Symbols.Symbols.AnyRoom;
} else {
data.room_ids = roomIds;
}
}
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC2876ReadEvents, data).then(function (r) {
return r.events;
});
}
/**
* Sets a button as disabled or enabled on the modal widget. Buttons are enabled by default.
* @param {ModalButtonID} buttonId The button ID to enable/disable.
* @param {boolean} isEnabled Whether or not the button is enabled.
* @returns {Promise<void>} Resolves when complete.
* @throws Throws if the button cannot be disabled, or the client refuses to disable the button.
*/
}, {
key: "setModalButtonEnabled",
value: function setModalButtonEnabled(buttonId, isEnabled) {
if (buttonId === _ModalWidgetActions.BuiltInModalButtonID.Close) {
throw new Error("The close button cannot be disabled");
}
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SetModalButtonEnabled, {
button: buttonId,
enabled: isEnabled
}).then();
}
/**
* Attempts to navigate the client to the given URI. This can only be called with Matrix URIs
* (currently only matrix.to, but in future a Matrix URI scheme will be defined).
* @param {string} uri The URI to navigate to.
* @returns {Promise<void>} Resolves when complete.
* @throws Throws if the URI is invalid or cannot be processed.
* @experimental This currently relies on an unstable MSC (MSC2931).
*/
}, {
key: "navigateTo",
value: function navigateTo(uri) {
if (!uri || !uri.startsWith("https://matrix.to/#")) {
throw new Error("Invalid matrix.to URI");
}
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC2931Navigate, {
uri: uri
}).then();
}
/**
* Starts watching for TURN servers, yielding an initial set of credentials as soon as possible,
* and thereafter yielding new credentials whenever the previous ones expire.
* @yields {ITurnServer} The TURN server URIs and credentials currently available to the widget.
*/
}, {
key: "getTurnServers",
value: function getTurnServers() {
var _this = this;
return _wrapAsyncGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
var setTurnServer, onUpdateTurnServers;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
onUpdateTurnServers = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ev) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
ev.preventDefault();
setTurnServer(ev.detail.data);
_this.transport.reply(ev.detail, {});
case 3:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function onUpdateTurnServers(_x9) {
return _ref.apply(this, arguments);
};
}(); // Start listening for updates before we even start watching, to catch
// TURN data that is sent immediately
_this.on("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.UpdateTurnServers), onUpdateTurnServers);
// Only send the 'watch' action if we aren't already watching
if (!(_this.turnServerWatchers === 0)) {
_context3.next = 12;
break;
}
_context3.prev = 3;
_context3.next = 6;
return _awaitAsyncGenerator(_this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.WatchTurnServers, {}));
case 6:
_context3.next = 12;
break;
case 8:
_context3.prev = 8;
_context3.t0 = _context3["catch"](3);
_this.off("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.UpdateTurnServers), onUpdateTurnServers);
throw _context3.t0;
case 12:
_this.turnServerWatchers++;
_context3.prev = 13;
case 14:
if (!true) {
_context3.next = 21;
break;
}
_context3.next = 17;
return _awaitAsyncGenerator(new Promise(function (resolve) {
return setTurnServer = resolve;
}));
case 17:
_context3.next = 19;
return _context3.sent;
case 19:
_context3.next = 14;
break;
case 21:
_context3.prev = 21;
// The loop was broken by the caller - clean up
_this.off("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.UpdateTurnServers), onUpdateTurnServers);
// Since sending the 'unwatch' action will end updates for all other
// consumers, only send it if we're the only consumer remaining
_this.turnServerWatchers--;
if (!(_this.turnServerWatchers === 0)) {
_context3.next = 27;
break;
}
_context3.next = 27;
return _awaitAsyncGenerator(_this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.UnwatchTurnServers, {}));
case 27:
return _context3.finish(21);
case 28:
case "end":
return _context3.stop();
}
}, _callee3, null, [[3, 8], [13,, 21, 28]]);
}))();
}
/**
* Search for users in the user directory.
* @param searchTerm The term to search for.
* @param limit The maximum number of results to return. If not supplied, the
* @returns Resolves to the search results.
*/
}, {
key: "searchUserDirectory",
value: (function () {
var _searchUserDirectory = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(searchTerm, limit) {
var versions, data;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return this.getClientVersions();
case 2:
versions = _context4.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC3973)) {
_context4.next = 5;
break;
}
throw new Error("The user_directory_search action is not supported by the client.");
case 5:
data = {
search_term: searchTerm,
limit: limit
};
return _context4.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC3973UserDirectorySearch, data));
case 7:
case "end":
return _context4.stop();
}
}, _callee4, this);
}));
function searchUserDirectory(_x0, _x1) {
return _searchUserDirectory.apply(this, arguments);
}
return searchUserDirectory;
}()
/**
* Get the config for the media repository.
* @returns Promise which resolves with an object containing the config.
*/
)
}, {
key: "getMediaConfig",
value: (function () {
var _getMediaConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
var versions, data;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return this.getClientVersions();
case 2:
versions = _context5.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC4039)) {
_context5.next = 5;
break;
}
throw new Error("The get_media_config action is not supported by the client.");
case 5:
data = {};
return _context5.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4039GetMediaConfigAction, data));
case 7:
case "end":
return _context5.stop();
}
}, _callee5, this);
}));
function getMediaConfig() {
return _getMediaConfig.apply(this, arguments);
}
return getMediaConfig;
}()
/**
* Discover the RTC transports (e.g. SFUs, TURN servers) the homeserver
* supports (MSC4515 / MSC4143).
* @returns Promise which resolves with the available RTC transports.
*/
)
}, {
key: "getRtcTransports",
value: (function () {
var _getRtcTransports = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
var versions, data;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return this.getClientVersions();
case 2:
versions = _context6.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC4515)) {
_context6.next = 5;
break;
}
throw new Error("The get_rtc_transports action is not supported by the client.");
case 5:
data = {};
return _context6.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4515GetRtcTransports, data));
case 7:
case "end":
return _context6.stop();
}
}, _callee6, this);
}));
function getRtcTransports() {
return _getRtcTransports.apply(this, arguments);
}
return getRtcTransports;
}()
/**
* Upload a file to the media repository on the homeserver.
* @param file - The object to upload. Something that can be sent to
* XMLHttpRequest.send (typically a File).
* @returns Resolves to the location of the uploaded file.
*/
)
}, {
key: "uploadFile",
value: (function () {
var _uploadFile = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(file) {
var versions, data;
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return this.getClientVersions();
case 2:
versions = _context7.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC4039)) {
_context7.next = 5;
break;
}
throw new Error("The upload_file action is not supported by the client.");
case 5:
data = {
file: file
};
return _context7.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4039UploadFileAction, data));
case 7:
case "end":
return _context7.stop();
}
}, _callee7, this);
}));
function uploadFile(_x10) {
return _uploadFile.apply(this, arguments);
}
return uploadFile;
}()
/**
* Download a file from the media repository on the homeserver.
* @param contentUri - MXC URI of the file to download.
* @returns Resolves to the contents of the file.
*/
)
}, {
key: "downloadFile",
value: (function () {
var _downloadFile = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(contentUri) {
var versions, data;
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return this.getClientVersions();
case 2:
versions = _context8.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC4039)) {
_context8.next = 5;
break;
}
throw new Error("The download_file action is not supported by the client.");
case 5:
data = {
content_uri: contentUri
};
return _context8.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4039DownloadFileAction, data));
case 7:
case "end":
return _context8.stop();
}
}, _callee8, this);
}));
function downloadFile(_x11) {
return _downloadFile.apply(this, arguments);
}
return downloadFile;
}()
/**
* Obtains a JWT for a LiveKit SFU, by asking the client to call the homeserver's
* `/rtc/livekit/get_token` endpoint on the widget's behalf.
* @param data The request data, which the client uses as the request body verbatim.
* @returns Resolves to the response body of the endpoint, verbatim.
* @see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4533|MSC4533}
*/
)
}, {
key: "getRtcLivekitToken",
value: (function () {
var _getRtcLivekitToken = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(data) {
var versions;
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return this.getClientVersions();
case 2:
versions = _context9.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC4533)) {
_context9.next = 5;
break;
}
throw new Error("The rtc_livekit_get_token action is not supported by the client.");
case 5:
return _context9.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4533RtcLivekitGetToken, data));
case 6:
case "end":
return _context9.stop();
}
}, _callee9, this);
}));
function getRtcLivekitToken(_x12) {
return _getRtcLivekitToken.apply(this, arguments);
}
return getRtcLivekitToken;
}()
/**
* Hands a MatrixRTC session's delayed leave event over to the server, by asking the
* client to call the homeserver's `/rtc/livekit/delegate_delayed_leave` endpoint on
* the widget's behalf.
*
* Homeservers may not support this endpoint, in which case the request rejects with a
* {@link WidgetApiResponseError} whose `matrix_api_error` reports an HTTP 404 with
* `M_UNRECOGNIZED`. The widget is then responsible for refreshing the delayed leave
* event itself.
* @param data The request data, which the client uses as the request body verbatim.
* @returns Resolves to the response body of the endpoint, verbatim.
* @see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4533|MSC4533}
*/
)
}, {
key: "delegateRtcLivekitDelayedLeave",
value: (function () {
var _delegateRtcLivekitDelayedLeave = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(data) {
var versions;
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
while (1) switch (_context0.prev = _context0.next) {
case 0:
_context0.next = 2;
return this.getClientVersions();
case 2:
versions = _context0.sent;
if (versions.includes(_ApiVersion.UnstableApiVersion.MSC4533)) {
_context0.next = 5;
break;
}
throw new Error("The rtc_livekit_delegate_delayed_leave action is not supported by the client.");
case 5:
return _context0.abrupt("return", this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.MSC4533RtcLivekitDelegateDelayedLeave, data));
case 6:
case "end":
return _context0.stop();
}
}, _callee0, this);
}));
function delegateRtcLivekitDelayedLeave(_x13) {
return _delegateRtcLivekitDelayedLeave.apply(this, arguments);
}
return delegateRtcLivekitDelayedLeave;
}()
/**
* Starts the communication channel. This should be done early to ensure
* that messages are not missed. Communication can only be stopped by the client.
*/
)
}, {
key: "start",
value: function start() {
var _this5 = this;
this.transport.start();
this.getClientVersions().then(function (v) {
if (v.includes(_ApiVersion.UnstableApiVersion.MSC2974)) {
_this5.supportsMSC2974Renegotiate = true;
}
});
}
}, {
key: "handleMessage",
value: function handleMessage(ev) {
var actionEv = new CustomEvent("action:".concat(ev.detail.action), {
detail: ev.detail,
cancelable: true
});
this.emit("action:".concat(ev.detail.action), actionEv);
if (!actionEv.defaultPrevented) {
switch (ev.detail.action) {
case _WidgetApiAction.WidgetApiToWidgetAction.SupportedApiVersions:
return this.replyVersions(ev.detail);
case _WidgetApiAction.WidgetApiToWidgetAction.Capabilities:
return this.handleCapabilities(ev.detail);
case _WidgetApiAction.WidgetApiToWidgetAction.UpdateVisibility:
return this.transport.reply(ev.detail, {});
// ack to avoid error spam
case _WidgetApiAction.WidgetApiToWidgetAction.NotifyCapabilities:
return this.transport.reply(ev.detail, {});
// ack to avoid error spam
default:
return this.transport.reply(ev.detail, {
error: {
message: "Unknown or unsupported to-widget action: " + ev.detail.action
}
});
}
}
}
}, {
key: "replyVersions",
value: function replyVersions(request) {
this.transport.reply(request, {
supported_versions: _ApiVersion.CurrentApiVersions
});
}
}, {
key: "getClientVersions",
value: function getClientVersions() {
var _this6 = this;
if (Array.isArray(this.cachedClientVersions)) {
return Promise.resolve(this.cachedClientVersions);
}
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SupportedApiVersions, {}).then(function (r) {
_this6.cachedClientVersions = r.supported_versions;
return r.supported_versions;
})["catch"](function (e) {
console.warn("non-fatal error getting supported client versions: ", e);
return [];
});
}
}, {
key: "handleCapabilities",
value: function handleCapabilities(request) {
var _this7 = this;
if (this.capabilitiesFinished) {
return this.transport.reply(request, {
error: {
message: "Capability negotiation already completed"
}
});
}
// See if we can expect a capabilities notification or not
return this.getClientVersions().then(function (v) {
if (v.includes(_ApiVersion.UnstableApiVersion.MSC2871)) {
_this7.once("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.NotifyCapabilities), function (ev) {
_this7.approvedCapabilities = ev.detail.data.approved;
_this7.emit("ready");
});
} else {
// if we can't expect notification, we're as done as we can be
_this7.emit("ready");
}
// in either case, reply to that capabilities request
_this7.capabilitiesFinished = true;
return _this7.transport.reply(request, {
capabilities: _this7.requestedCapabilities
});
});
}
}]);
return WidgetApi;
}(_events.EventEmitter);
exports.WidgetApi = WidgetApi;
},{"./Symbols":2,"./interfaces/ApiVersion":6,"./interfaces/Capabilities":7,"./interfaces/GetOpenIDAction":8,"./interfaces/ModalWidgetActions":11,"./interfaces/UpdateDelayedEventAction":12,"./interfaces/WidgetApiAction":13,"./interfaces/WidgetApiDirection":14,"./interfaces/WidgetType":16,"./models/WidgetEventCapability":18,"./transport/PostmessageTransport":23,"events":25}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetDriver = void 0;
var _ = require("..");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Represents the functions and behaviour the widget-api is unable to
* do, such as prompting the user for information or interacting with
* the UI. Clients are expected to implement this class and override
* any functions they need/want to support.
*
* This class assumes the client will have a context of a Widget
* instance already.
*/
var WidgetDriver = /*#__PURE__*/function () {
function WidgetDriver() {
_classCallCheck(this, WidgetDriver);
}
_createClass(WidgetDriver, [{
key: "validateCapabilities",
value:
/**
* Verifies the widget's requested capabilities, returning the ones
* it is approved to use. Mutating the requested capabilities will
* have no effect.
*
* This SHOULD result in the user being prompted to approve/deny
* capabilities.
*
* By default this rejects all capabilities (returns an empty set).
* @param {Set<Capability>} requested The set of requested capabilities.
* @returns {Promise<Set<Capability>>} Resolves to the allowed capabilities.
*/
function validateCapabilities(requested) {
return Promise.resolve(new Set());
}
/**
* Sends an event into a room. If `roomId` is falsy, the client should send the event
* into the room the user is currently looking at. The widget API will have already
* verified that the widget is capable of sending the event to that room.
* @param {string} eventType The event type to be sent.
* @param {*} content The content for the event.
* @param {string|null} stateKey The state key if this is a state event, otherwise null.
* May be an empty string.
* @param {string|null} roomId The room ID to send the event to. If falsy, the room the
* user is currently looking at.
* @returns {Promise<ISendEventDetails>} Resolves when the event has been sent with
* details of that event.
* @throws Rejected when the event could not be sent.
*/
}, {
key: "sendEvent",
value: function sendEvent(eventType, content) {
var stateKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var roomId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
return Promise.reject(new Error("Failed to override function"));
}
/**
* @experimental Part of MSC4407
* Sends a sticky event into a room. If `roomId` is falsy, the client should send the event
* into the room the user is currently looking at. The widget API will have already
* verified that the widget is capable of sending the event to that room.
* @param {number} stickyDurationMs The length of time a sticky event may remain sticky, in milliseconds.
* @param {string} eventType The event type to be sent.
* @param {*} content The content for the event.
* @param {string|null} roomId The room ID to send the event to. If falsy, the room the
* user is currently looking at.
* @returns {Promise<ISendEventDetails>} Resolves when the event has been sent with
* details of that event.
* @throws Rejected when the event could not be sent.
*/
}, {
key: "sendStickyEvent",
value: function sendStickyEvent(stickyDurationMs, eventType, content) {
var roomId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
throw new Error("Method not implemented.");
}
/**
* @experimental Part of MSC4140 & MSC4157
* Sends a delayed event into a room. If `roomId` is falsy, the client should send it
* into the room the user is currently looking at. The widget API will have already
* verified that the widget is capable of sending the event to that room.
* @param {number} delay How much later to send the event.
* @param {string} eventType The event type of the event to be sent.
* @param {*} content The content for the event to be sent.
* @param {string|null} stateKey The state key if the event to be sent a state event,
* otherwise null. May be an empty string.
* @param {string|null} roomId The room ID to send the event to. If falsy, the room the
* user is currently looking at.
* @returns {Promise<ISendDelayedEventDetails>} Resolves when the delayed event has been
* prepared with details of how to refer to it for updating/sending/canceling it later.
* @throws Rejected when the delayed event could not be sent.
*/
}, {
key: "sendDelayedEvent",
value: function sendDelayedEvent(delay, eventType, content) {
var stateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var roomId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
return Promise.reject(new Error("Failed to override function"));
}
/**
* @experimental Part of MSC4140, MSC4157 and MSC4407
* Sends a delayed sticky event into a room. If `roomId` is falsy, the client should send the event
* into the room the user is currently looking at. The widget API will have already
* verified that the widget is capable of sending the event to that room.
* @param {number} stickyDurationMs The length of time a sticky event may remain sticky, in milliseconds.
* @param {number} delay How much later to send the event.
* @param {string} eventType The event type to be sent.
* @param {*} content The content for the event.
* @param {string|null} roomId The room ID to send the event to. If falsy, the room the
* user is currently looking at.
* @returns {Promise<ISendDelayedEventDetails>} Resolves when the event has been sent with
* details of that event.
* @throws Rejected when the event could not be sent.
*/
}, {
key: "sendDelayedStickyEvent",
value: function sendDelayedStickyEvent(delay, stickyDurationMs, eventType, content) {
var roomId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
throw new Error("Method not implemented.");
}
/**
* @experimental Part of MSC4140 & MSC4157
* Cancel the scheduled delivery of the delayed event matching the provided {@link delayId}.
* @throws Rejected when there is no matching delayed event,
* or when the delayed event failed to be cancelled.
*/
}, {
key: "cancelScheduledDelayedEvent",
value: function cancelScheduledDelayedEvent(delayId) {
return Promise.reject(new Error("Failed to override function"));
}
/**
* @experimental Part of MSC4140 & MSC4157
* Restart the scheduled delivery of the delayed event matching the provided {@link delayId}.
* @throws Rejected when there is no matching delayed event,
* or when the delayed event failed to be restarted.
*/
}, {
key: "restartScheduledDelayedEvent",
value: function restartScheduledDelayedEvent(delayId) {
return Promise.reject(new Error("Failed to override function"));
}
/**
* @experimental Part of MSC4140 & MSC4157
* Immediately send the delayed event matching the provided {@link delayId},
* instead of waiting for its scheduled delivery.
* @throws Rejected when there is no matching delayed event,
* or when the delayed event failed to be sent.
*/
}, {
key: "sendScheduledDelayedEvent",
value: function sendScheduledDelayedEvent(delayId) {
return Promise.reject(new Error("Failed to override function"));
}
/**
* Sends a to-device event. The widget API will have already verified that the widget
* is capable of sending the event.
* @param {string} eventType The event type to be sent.
* @param {boolean} encrypted Whether to encrypt the message contents.
* @param {Object} contentMap A map from user ID and device ID to event content.
* @returns {Promise<void>} Resolves when the event has been sent.
* @throws Rejected when the event could not be sent.
*/
}, {
key: "sendToDevice",
value: function sendToDevice(eventType, encrypted, contentMap) {
return Promise.reject(new Error("Failed to override function"));
}
/**
* Reads an element of room account data. The widget API will have already verified that the widget is
* capable of receiving the `eventType` of the requested information. If `roomIds` is supplied, it may
* contain `Symbols.AnyRoom` to denote that the piece of room account data in each of the client's known
* rooms should be returned. When `null`, only the room the user is currently looking at should be considered.
* @param eventType The event type to be read.
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
* to look within, possibly containing Symbols.AnyRoom to denote all known rooms.
* @returns {Promise<IRoomAccountData[]>} Resolves to the element of room account data, or an empty array.
*/
}, {
key: "readRoomAccountData",
value: function readRoomAccountData(eventType) {
var roomIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
return Promise.resolve([]);
}
/**
* Reads all events of the given type, and optionally `msgtype` (if applicable/defined),
* the user has access to. The widget API will have already verified that the widget is
* capable of receiving the events. Less events than the limit are allowed to be returned,
* but not more. If `roomIds` is supplied, it may contain `Symbols.AnyRoom` to denote that
* `limit` in each of the client's known rooms should be returned. When `null`, only the
* room the user is currently looking at should be considered. If `since` is specified but
* the event ID isn't present in the number of events fetched by the client due to `limit`,
* the client will return all the events.
* @param eventType The event type to be read.
* @param msgtype The msgtype of the events to be read, if applicable/defined.
* @param stateKey The state key of the events to be read, if applicable/defined.
* @param limit The maximum number of events to retrieve per room. Will be zero to denote "as many
* as possible".
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
* to look within, possibly containing Symbols.AnyRoom to denote all known rooms.
* @param since When null, retrieves the number of events specified by the "limit" parameter.
* Otherwise, the event ID at which only subsequent events will be returned, as many as specified
* in "limit".
* @returns {Promise<IRoomEvent[]>} Resolves to the room events, or an empty array.
* @deprecated Clients are advised to implement {@link WidgetDriver.readRoomTimeline} instead.
*/
}, {
key: "readRoomEvents",
value: function readRoomEvents(eventType, msgtype, limit) {
var roomIds = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var since = arguments.length > 4 ? arguments[4] : undefined;
return Promise.resolve([]);
}
/**
* Reads all events of the given type, and optionally state key (if applicable/defined),
* the user has access to. The widget API will have already verified that the widget is
* capable of receiving the events. Less events than the limit are allowed to be returned,
* but not more. If `roomIds` is supplied, it may contain `Symbols.AnyRoom` to denote that
* `limit` in each of the client's known rooms should be returned. When `null`, only the
* room the user is currently looking at should be considered.
* @param eventType The event type to be read.
* @param stateKey The state key of the events to be read, if applicable/defined.
* @param limit The maximum number of events to retrieve. Will be zero to denote "as many
* as possible".
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
* to look within, possibly containing Symbols.AnyRoom to denote all known rooms.
* @returns {Promise<IRoomEvent[]>} Resolves to the state events, or an empty array.
* @deprecated Clients are advised to implement {@link WidgetDriver.readRoomTimeline} instead.
*/
}, {
key: "readStateEvents",
value: function readStateEvents(eventType, stateKey, limit) {
var roomIds = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
return Promise.resolve([]);
}
/**
* Gets all sticky events of the given type the user has access to.
* The widget API will have already verified that the widget is capable of receiving the events.
*
* This is needed because widgets will get only live messages as they appear in the timeline.
* However, sticky events act like a state, and the current state is made by events that may have been
* sent before the widget was loaded.
* Events are sticky for 1h maximum, so the widget has access to the past hour of sticky events maximum.
*
* @experimental Part of MSC4407 - Sticky Events (Widget API)
* @param roomId - The ID of the room.
*/
}, {
key: "readStickyEvents",
value: function readStickyEvents(roomId) {
throw new Error("readStickyEvents is not implemented");
}
/**
* Reads all events of the given type, and optionally `msgtype` (if applicable/defined),
* the user has access to. The widget API will have already verified that the widget is
* capable of receiving the events. Less events than the limit are allowed to be returned,
* but not more.
* @param roomId The ID of the room to look within.
* @param eventType The event type to be read.
* @param msgtype The msgtype of the events to be read, if applicable/defined.
* @param stateKey The state key of the events to be read, if applicable/defined.
* @param limit The maximum number of events to retrieve. Will be zero to denote "as many as
* possible".
* @param since When null, retrieves the number of events specified by the "limit" parameter.
* Otherwise, the event ID at which only subsequent events will be returned, as many as specified
* in "limit".
* @returns {Promise<IRoomEvent[]>} Resolves to the room events, or an empty array.
*/
}, {
key: "readRoomTimeline",
value: function readRoomTimeline(roomId, eventType, msgtype, stateKey, limit, since) {
// For backward compatibility we try the deprecated methods, in case
// they're implemented
if (stateKey === undefined) return this.readRoomEvents(eventType, msgtype, limit, [roomId], since);else return this.readStateEvents(eventType, stateKey, limit, [roomId]);
}
/**
* Reads the current values of all matching room state entries.
* @param roomId The ID of the room.
* @param eventType The event type of the entries to be read.
* @param stateKey The state key of the entry to be read. If undefined,
* all room state entries with a matching event type should be returned.
* @returns {Promise<IRoomEvent[]>} Resolves to the events representing the
* current values of the room state entries.
*/
}, {
key: "readRoomState",
value: function readRoomState(roomId, eventType, stateKey) {
return this.readStateEvents(eventType, stateKey, Number.MAX_SAFE_INTEGER, [roomId]);
}
/**
* Reads all events that are related to a given event. The widget API will
* have already verified that the widget is capable of receiving the event,
* or will make sure to reject access to events which are returned from this
* function, but are not capable of receiving. If `relationType` or `eventType`
* are set, the returned events should already be filtered. Less events than
* the limit are allowed to be returned, but not more.
* @param eventId The id of the parent event to be read.
* @param roomId The room to look within. When undefined, the user's
* currently viewed room.
* @param relationType The relationship type of child events to search for.
* When undefined, all relations are returned.
* @param eventType The event type of child events to search for. When undefined,
* all related events are returned.
* @param from The pagination token to start returning results from, as
* received from a previous call. If not supplied, results start at the most
* recent topological event known to the server.
* @param to The pagination token to stop returning results at. If not
* supplied, results continue up to limit or until there are no more events.
* @param limit The maximum number of events to retrieve per room. If not
* supplied, the server will apply a default limit.
* @param direction The direction to search for according to MSC3715
* @returns Resolves to the room relations.
*/
}, {
key: "readEventRelations",
value: function readEventRelations(eventId, roomId, relationType, eventType, from, to, limit, direction) {
return Promise.resolve({
chunk: []
});
}
/**
* Asks the user for permission to validate their identity through OpenID Connect. The
* interface for this function is an observable which accepts the state machine of the
* OIDC exchange flow. For example, if the client/user blocks the request then it would
* feed back a `{state: Blocked}` into the observable. Similarly, if the user already
* approved the widget then a `{state: Allowed}` would be fed into the observable alongside
* the token itself. If the client is asking for permission, it should feed in a
* `{state: PendingUserConfirmation}` followed by the relevant Allowed or Blocked state.
*
* The widget API will reject the widget's request with an error if this contract is not
* met properly. By default, the widget driver will block all OIDC requests.
* @param {SimpleObservable<IOpenIDUpdate>} observer The observable to feed updates into.
*/
}, {
key: "askOpenID",
value: function askOpenID(observer) {
observer.update({
state: _.OpenIDRequestState.Blocked
});
}
/**
* Navigates the client with a matrix.to URI. In future this function will also be provided
* with the Matrix URIs once matrix.to is replaced. The given URI will have already been
* lightly checked to ensure it looks like a valid URI, though the implementation is recommended
* to do further checks on the URI.
* @param {string} uri The URI to navigate to.
* @returns {Promise<void>} Resolves when complete.
* @throws Throws if there's a problem with the navigation, such as invalid format.
*/
}, {
key: "navigate",
value: function navigate(uri) {
throw new Error("Navigation is not implemented");
}
/**
* Polls for TURN server data, yielding an initial set of credentials as soon as possible, and
* thereafter yielding new credentials whenever the previous ones expire. The widget API will
* have already verified that the widget has permission to access TURN servers.
* @yields {ITurnServer} The TURN server URIs and credentials currently available to the client.
*/
}, {
key: "getTurnServers",
value: function getTurnServers() {
throw new Error("TURN server support is not implemented");
}
/**
* Search for users in the user directory.
* @param searchTerm The term to search for.
* @param limit The maximum number of results to return. If not supplied, the
* @returns Resolves to the search results.
*/
}, {
key: "searchUserDirectory",
value: function searchUserDirectory(searchTerm, limit) {
return Promise.resolve({
limited: false,
results: []
});
}
/**
* Get the config for the media repository.
* @returns Promise which resolves with an object containing the config.
*/
}, {
key: "getMediaConfig",
value: function getMediaConfig() {
throw new Error("Get media config is not implemented");
}
/**
* Discover the RTC transports (e.g. SFUs, TURN servers) the homeserver
* supports, by delegating to the authenticated
* `GET /_matrix/client/v1/rtc/transports` Client-Server endpoint (MSC4143).
* @returns Promise which resolves with the available transports.
*/
}, {
key: "getRtcTransports",
value: function getRtcTransports() {
throw new Error("Get RTC transports is not implemented");
}
/**
* Upload a file to the media repository on the homeserver.
* @param file - The object to upload. Something that can be sent to
* XMLHttpRequest.send (typically a File).
* @returns Resolves to the location of the uploaded file.
*/
}, {
key: "uploadFile",
value: function uploadFile(file) {
throw new Error("Upload file is not implemented");
}
/**
* Download a file from the media repository on the homeserver.
* @param contentUri - MXC URI of the file to download.
* @returns Resolves to the contents of the file.
*/
}, {
key: "downloadFile",
value: function downloadFile(contentUri) {
throw new Error("Download file is not implemented");
}
/**
* Obtains a JWT for a LiveKit SFU by calling the homeserver's
* `/rtc/livekit/get_token` endpoint on the widget's behalf. The widget API
* will have already verified that the widget has permission to do so.
* @param data The request data, to be used as the request body verbatim.
* @returns Resolves to the response body of the endpoint, verbatim.
* @see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4533|MSC4533}
*/
}, {
key: "getRtcLivekitToken",
value: function getRtcLivekitToken(data) {
throw new Error("Getting a LiveKit token is not implemented");
}
/**
* Hands a MatrixRTC session's delayed leave event over to the server by
* calling the homeserver's `/rtc/livekit/delegate_delayed_leave` endpoint on
* the widget's behalf. The widget API will have already verified that the
* widget has permission to do so.
* @param data The request data, to be used as the request body verbatim.
* @returns Resolves to the response body of the endpoint, verbatim.
* @see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4533|MSC4533}
*/
}, {
key: "delegateRtcLivekitDelayedLeave",
value: function delegateRtcLivekitDelayedLeave(data) {
throw new Error("Delegating a LiveKit delayed leave is not implemented");
}
/**
* Gets the IDs of all joined or invited rooms currently known to the
* client.
* @returns The room IDs.
*/
}, {
key: "getKnownRooms",
value: function getKnownRooms() {
throw new Error("Querying known rooms is not implemented");
}
/**
* Expresses an error thrown by this driver in a format compatible with the Widget API.
* @param error The error to handle.
* @returns The error expressed as a {@link IWidgetApiErrorResponseDataDetails},
* or undefined if it cannot be expressed as one.
*/
}, {
key: "processError",
value: function processError(error) {
return undefined;
}
}]);
return WidgetDriver;
}();
exports.WidgetDriver = WidgetDriver;
},{"..":5}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _WidgetApi = require("./WidgetApi");
Object.keys(_WidgetApi).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetApi[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetApi[key];
}
});
});
var _ClientWidgetApi = require("./ClientWidgetApi");
Object.keys(_ClientWidgetApi).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ClientWidgetApi[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ClientWidgetApi[key];
}
});
});
var _Symbols = require("./Symbols");
Object.keys(_Symbols).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _Symbols[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _Symbols[key];
}
});
});
var _PostmessageTransport = require("./transport/PostmessageTransport");
Object.keys(_PostmessageTransport).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _PostmessageTransport[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _PostmessageTransport[key];
}
});
});
var _WidgetType = require("./interfaces/WidgetType");
Object.keys(_WidgetType).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetType[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetType[key];
}
});
});
var _IWidgetApiErrorResponse = require("./interfaces/IWidgetApiErrorResponse");
Object.keys(_IWidgetApiErrorResponse).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _IWidgetApiErrorResponse[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _IWidgetApiErrorResponse[key];
}
});
});
var _WidgetApiAction = require("./interfaces/WidgetApiAction");
Object.keys(_WidgetApiAction).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetApiAction[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetApiAction[key];
}
});
});
var _WidgetApiDirection = require("./interfaces/WidgetApiDirection");
Object.keys(_WidgetApiDirection).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetApiDirection[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetApiDirection[key];
}
});
});
var _ApiVersion = require("./interfaces/ApiVersion");
Object.keys(_ApiVersion).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ApiVersion[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ApiVersion[key];
}
});
});
var _Capabilities = require("./interfaces/Capabilities");
Object.keys(_Capabilities).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _Capabilities[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _Capabilities[key];
}
});
});
var _GetOpenIDAction = require("./interfaces/GetOpenIDAction");
Object.keys(_GetOpenIDAction).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _GetOpenIDAction[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _GetOpenIDAction[key];
}
});
});
var _WidgetKind = require("./interfaces/WidgetKind");
Object.keys(_WidgetKind).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetKind[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetKind[key];
}
});
});
var _ModalButtonKind = require("./interfaces/ModalButtonKind");
Object.keys(_ModalButtonKind).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ModalButtonKind[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ModalButtonKind[key];
}
});
});
var _ModalWidgetActions = require("./interfaces/ModalWidgetActions");
Object.keys(_ModalWidgetActions).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ModalWidgetActions[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ModalWidgetActions[key];
}
});
});
var _UpdateDelayedEventAction = require("./interfaces/UpdateDelayedEventAction");
Object.keys(_UpdateDelayedEventAction).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _UpdateDelayedEventAction[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _UpdateDelayedEventAction[key];
}
});
});
var _WidgetEventCapability = require("./models/WidgetEventCapability");
Object.keys(_WidgetEventCapability).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetEventCapability[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetEventCapability[key];
}
});
});
var _url = require("./models/validation/url");
Object.keys(_url).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _url[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _url[key];
}
});
});
var _utils = require("./models/validation/utils");
Object.keys(_utils).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _utils[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _utils[key];
}
});
});
var _Widget = require("./models/Widget");
Object.keys(_Widget).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _Widget[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _Widget[key];
}
});
});
var _WidgetParser = require("./models/WidgetParser");
Object.keys(_WidgetParser).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetParser[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetParser[key];
}
});
});
var _urlTemplate = require("./templating/url-template");
Object.keys(_urlTemplate).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _urlTemplate[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _urlTemplate[key];
}
});
});
var _SimpleObservable = require("./util/SimpleObservable");
Object.keys(_SimpleObservable).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _SimpleObservable[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _SimpleObservable[key];
}
});
});
var _WidgetDriver = require("./driver/WidgetDriver");
Object.keys(_WidgetDriver).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _WidgetDriver[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _WidgetDriver[key];
}
});
});
},{"./ClientWidgetApi":1,"./Symbols":2,"./WidgetApi":3,"./driver/WidgetDriver":4,"./interfaces/ApiVersion":6,"./interfaces/Capabilities":7,"./interfaces/GetOpenIDAction":8,"./interfaces/IWidgetApiErrorResponse":9,"./interfaces/ModalButtonKind":10,"./interfaces/ModalWidgetActions":11,"./interfaces/UpdateDelayedEventAction":12,"./interfaces/WidgetApiAction":13,"./interfaces/WidgetApiDirection":14,"./interfaces/WidgetKind":15,"./interfaces/WidgetType":16,"./models/Widget":17,"./models/WidgetEventCapability":18,"./models/WidgetParser":19,"./models/validation/url":20,"./models/validation/utils":21,"./templating/url-template":22,"./transport/PostmessageTransport":23,"./util/SimpleObservable":24}],6:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UnstableApiVersion = exports.MatrixApiVersion = exports.CurrentApiVersions = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var MatrixApiVersion = /*#__PURE__*/function (MatrixApiVersion) {
MatrixApiVersion["Prerelease1"] = "0.0.1";
MatrixApiVersion["Prerelease2"] = "0.0.2";
return MatrixApiVersion;
}({});
exports.MatrixApiVersion = MatrixApiVersion;
var UnstableApiVersion = /*#__PURE__*/function (UnstableApiVersion) {
UnstableApiVersion["MSC2762"] = "org.matrix.msc2762";
UnstableApiVersion["MSC2762_UPDATE_STATE"] = "org.matrix.msc2762_update_state";
UnstableApiVersion["MSC2871"] = "org.matrix.msc2871";
UnstableApiVersion["MSC2873"] = "org.matrix.msc2873";
UnstableApiVersion["MSC2931"] = "org.matrix.msc2931";
UnstableApiVersion["MSC2974"] = "org.matrix.msc2974";
UnstableApiVersion["MSC2876"] = "org.matrix.msc2876";
UnstableApiVersion["MSC3819"] = "org.matrix.msc3819";
UnstableApiVersion["MSC3846"] = "town.robin.msc3846";
UnstableApiVersion["MSC3869"] = "org.matrix.msc3869";
UnstableApiVersion["MSC3973"] = "org.matrix.msc3973";
UnstableApiVersion["MSC4039"] = "org.matrix.msc4039";
UnstableApiVersion["MSC4515"] = "org.matrix.msc4515";
UnstableApiVersion["MSC4533"] = "org.matrix.msc4533";
return UnstableApiVersion;
}({});
exports.UnstableApiVersion = UnstableApiVersion;
var CurrentApiVersions = [MatrixApiVersion.Prerelease1, MatrixApiVersion.Prerelease2,
//MatrixApiVersion.V010,
UnstableApiVersion.MSC2762, UnstableApiVersion.MSC2762_UPDATE_STATE, UnstableApiVersion.MSC2871, UnstableApiVersion.MSC2873, UnstableApiVersion.MSC2931, UnstableApiVersion.MSC2974, UnstableApiVersion.MSC2876, UnstableApiVersion.MSC3819, UnstableApiVersion.MSC3846, UnstableApiVersion.MSC3869, UnstableApiVersion.MSC3973, UnstableApiVersion.MSC4039, UnstableApiVersion.MSC4515, UnstableApiVersion.MSC4533];
exports.CurrentApiVersions = CurrentApiVersions;
},{}],7:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.VideoConferenceCapabilities = exports.StickerpickerCapabilities = exports.MatrixCapabilities = void 0;
exports.getTimelineRoomIDFromCapability = getTimelineRoomIDFromCapability;
exports.isTimelineCapability = isTimelineCapability;
exports.isTimelineCapabilityFor = isTimelineCapabilityFor;
/*
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var MatrixCapabilities = /*#__PURE__*/function (MatrixCapabilities) {
MatrixCapabilities["Screenshots"] = "m.capability.screenshot";
MatrixCapabilities["StickerSending"] = "m.sticker";
MatrixCapabilities["AlwaysOnScreen"] = "m.always_on_screen";
MatrixCapabilities["RequiresClient"] = "io.element.requires_client";
MatrixCapabilities["MSC2931Navigate"] = "org.matrix.msc2931.navigate";
MatrixCapabilities["MSC3846TurnServers"] = "town.robin.msc3846.turn_servers";
MatrixCapabilities["MSC3973UserDirectorySearch"] = "org.matrix.msc3973.user_directory_search";
MatrixCapabilities["MSC4039UploadFile"] = "org.matrix.msc4039.upload_file";
MatrixCapabilities["MSC4039DownloadFile"] = "org.matrix.msc4039.download_file";
MatrixCapabilities["MSC4157SendDelayedEvent"] = "org.matrix.msc4157.send.delayed_event";
MatrixCapabilities["MSC4157UpdateDelayedEvent"] = "org.matrix.msc4157.update_delayed_event";
MatrixCapabilities["MSC4407SendStickyEvent"] = "org.matrix.msc4407.send.sticky_event";
MatrixCapabilities["MSC4407ReceiveStickyEvent"] = "org.matrix.msc4407.receive.sticky_event";
MatrixCapabilities["MSC4515RtcTransports"] = "org.matrix.msc4515.rtc_transports";
MatrixCapabilities["MSC4533RtcLivekitGetToken"] = "org.matrix.msc4533.rtc_livekit_get_token";
MatrixCapabilities["MSC4533RtcLivekitDelegateDelayedLeave"] = "org.matrix.msc4533.rtc_livekit_delegate_delayed_leave";
return MatrixCapabilities;
}({});
exports.MatrixCapabilities = MatrixCapabilities;
var StickerpickerCapabilities = [MatrixCapabilities.StickerSending];
exports.StickerpickerCapabilities = StickerpickerCapabilities;
var VideoConferenceCapabilities = [MatrixCapabilities.AlwaysOnScreen];
/**
* Determines if a capability is a capability for a timeline.
* @param {Capability} capability The capability to test.
* @returns {boolean} True if a timeline capability, false otherwise.
*/
exports.VideoConferenceCapabilities = VideoConferenceCapabilities;
function isTimelineCapability(capability) {
// TODO: Change when MSC2762 becomes stable.
return capability === null || capability === void 0 ? void 0 : capability.startsWith("org.matrix.msc2762.timeline:");
}
/**
* Determines if a capability is a timeline capability for the given room.
* @param {Capability} capability The capability to test.
* @param {string | Symbols.AnyRoom} roomId The room ID, or `Symbols.AnyRoom` for that designation.
* @returns {boolean} True if a matching capability, false otherwise.
*/
function isTimelineCapabilityFor(capability, roomId) {
return capability === "org.matrix.msc2762.timeline:".concat(roomId);
}
/**
* Gets the room ID described by a timeline capability.
* @param {string} capability The capability to parse.
* @returns {string} The room ID.
*/
function getTimelineRoomIDFromCapability(capability) {
return capability.substring(capability.indexOf(":") + 1);
}
},{}],8:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.OpenIDRequestState = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var OpenIDRequestState = /*#__PURE__*/function (OpenIDRequestState) {
OpenIDRequestState["Allowed"] = "allowed";
OpenIDRequestState["Blocked"] = "blocked";
OpenIDRequestState["PendingUserConfirmation"] = "request";
return OpenIDRequestState;
}({});
exports.OpenIDRequestState = OpenIDRequestState;
},{}],9:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isErrorResponse = isErrorResponse;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/*
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The format of errors returned by Matrix API requests
* made by a WidgetDriver.
*/
function isErrorResponse(responseData) {
var error = responseData.error;
return _typeof(error) === "object" && error !== null && "message" in error && typeof error.message === "string";
}
},{}],10:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ModalButtonKind = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var ModalButtonKind = /*#__PURE__*/function (ModalButtonKind) {
ModalButtonKind["Primary"] = "m.primary";
ModalButtonKind["Secondary"] = "m.secondary";
ModalButtonKind["Warning"] = "m.warning";
ModalButtonKind["Danger"] = "m.danger";
ModalButtonKind["Link"] = "m.link";
return ModalButtonKind;
}({});
exports.ModalButtonKind = ModalButtonKind;
},{}],11:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BuiltInModalButtonID = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var BuiltInModalButtonID = /*#__PURE__*/function (BuiltInModalButtonID) {
BuiltInModalButtonID["Close"] = "m.close";
return BuiltInModalButtonID;
}({}); // Types for a normal modal requesting the opening a modal widget
// Types for a modal widget receiving notifications that its buttons have been pressed
// Types for a modal widget requesting close
// Types for a normal widget being notified that the modal widget it opened has been closed
exports.BuiltInModalButtonID = BuiltInModalButtonID;
},{}],12:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UpdateDelayedEventAction = void 0;
/*
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var UpdateDelayedEventAction = /*#__PURE__*/function (UpdateDelayedEventAction) {
UpdateDelayedEventAction["Cancel"] = "cancel";
UpdateDelayedEventAction["Restart"] = "restart";
UpdateDelayedEventAction["Send"] = "send";
return UpdateDelayedEventAction;
}({});
exports.UpdateDelayedEventAction = UpdateDelayedEventAction;
},{}],13:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetApiToWidgetAction = exports.WidgetApiFromWidgetAction = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var WidgetApiToWidgetAction = /*#__PURE__*/function (WidgetApiToWidgetAction) {
WidgetApiToWidgetAction["SupportedApiVersions"] = "supported_api_versions";
WidgetApiToWidgetAction["Capabilities"] = "capabilities";
WidgetApiToWidgetAction["NotifyCapabilities"] = "notify_capabilities";
WidgetApiToWidgetAction["ThemeChange"] = "theme_change";
WidgetApiToWidgetAction["LanguageChange"] = "language_change";
WidgetApiToWidgetAction["TakeScreenshot"] = "screenshot";
WidgetApiToWidgetAction["UpdateVisibility"] = "visibility";
WidgetApiToWidgetAction["OpenIDCredentials"] = "openid_credentials";
WidgetApiToWidgetAction["WidgetConfig"] = "widget_config";
WidgetApiToWidgetAction["CloseModalWidget"] = "close_modal";
WidgetApiToWidgetAction["ButtonClicked"] = "button_clicked";
WidgetApiToWidgetAction["SendEvent"] = "send_event";
WidgetApiToWidgetAction["SendToDevice"] = "send_to_device";
WidgetApiToWidgetAction["UpdateState"] = "update_state";
WidgetApiToWidgetAction["UpdateTurnServers"] = "update_turn_servers";
return WidgetApiToWidgetAction;
}({});
exports.WidgetApiToWidgetAction = WidgetApiToWidgetAction;
var WidgetApiFromWidgetAction = /*#__PURE__*/function (WidgetApiFromWidgetAction) {
WidgetApiFromWidgetAction["SupportedApiVersions"] = "supported_api_versions";
WidgetApiFromWidgetAction["ContentLoaded"] = "content_loaded";
WidgetApiFromWidgetAction["SendSticker"] = "m.sticker";
WidgetApiFromWidgetAction["UpdateAlwaysOnScreen"] = "set_always_on_screen";
WidgetApiFromWidgetAction["GetOpenIDCredentials"] = "get_openid";
WidgetApiFromWidgetAction["CloseModalWidget"] = "close_modal";
WidgetApiFromWidgetAction["OpenModalWidget"] = "open_modal";
WidgetApiFromWidgetAction["SetModalButtonEnabled"] = "set_button_enabled";
WidgetApiFromWidgetAction["SendEvent"] = "send_event";
WidgetApiFromWidgetAction["SendToDevice"] = "send_to_device";
WidgetApiFromWidgetAction["WatchTurnServers"] = "watch_turn_servers";
WidgetApiFromWidgetAction["UnwatchTurnServers"] = "unwatch_turn_servers";
WidgetApiFromWidgetAction["BeeperReadRoomAccountData"] = "com.beeper.read_room_account_data";
WidgetApiFromWidgetAction["MSC2876ReadEvents"] = "org.matrix.msc2876.read_events";
WidgetApiFromWidgetAction["MSC2931Navigate"] = "org.matrix.msc2931.navigate";
WidgetApiFromWidgetAction["MSC2974RenegotiateCapabilities"] = "org.matrix.msc2974.request_capabilities";
WidgetApiFromWidgetAction["MSC3869ReadRelations"] = "org.matrix.msc3869.read_relations";
WidgetApiFromWidgetAction["MSC3973UserDirectorySearch"] = "org.matrix.msc3973.user_directory_search";
WidgetApiFromWidgetAction["MSC4039GetMediaConfigAction"] = "org.matrix.msc4039.get_media_config";
WidgetApiFromWidgetAction["MSC4039UploadFileAction"] = "org.matrix.msc4039.upload_file";
WidgetApiFromWidgetAction["MSC4039DownloadFileAction"] = "org.matrix.msc4039.download_file";
WidgetApiFromWidgetAction["MSC4157UpdateDelayedEvent"] = "org.matrix.msc4157.update_delayed_event";
WidgetApiFromWidgetAction["MSC4515GetRtcTransports"] = "org.matrix.msc4515.get_rtc_transports";
WidgetApiFromWidgetAction["MSC4533RtcLivekitGetToken"] = "org.matrix.msc4533.rtc_livekit_get_token";
WidgetApiFromWidgetAction["MSC4533RtcLivekitDelegateDelayedLeave"] = "org.matrix.msc4533.rtc_livekit_delegate_delayed_leave";
return WidgetApiFromWidgetAction;
}({});
exports.WidgetApiFromWidgetAction = WidgetApiFromWidgetAction;
},{}],14:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetApiDirection = void 0;
exports.invertedDirection = invertedDirection;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var WidgetApiDirection = /*#__PURE__*/function (WidgetApiDirection) {
WidgetApiDirection["ToWidget"] = "toWidget";
WidgetApiDirection["FromWidget"] = "fromWidget";
return WidgetApiDirection;
}({});
exports.WidgetApiDirection = WidgetApiDirection;
function invertedDirection(dir) {
if (dir === WidgetApiDirection.ToWidget) {
return WidgetApiDirection.FromWidget;
} else if (dir === WidgetApiDirection.FromWidget) {
return WidgetApiDirection.ToWidget;
} else {
throw new Error("Invalid direction");
}
}
},{}],15:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetKind = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var WidgetKind = /*#__PURE__*/function (WidgetKind) {
WidgetKind["Room"] = "room";
WidgetKind["Account"] = "account";
WidgetKind["Modal"] = "modal";
return WidgetKind;
}({});
exports.WidgetKind = WidgetKind;
},{}],16:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MatrixWidgetType = void 0;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var MatrixWidgetType = /*#__PURE__*/function (MatrixWidgetType) {
MatrixWidgetType["Custom"] = "m.custom";
MatrixWidgetType["JitsiMeet"] = "m.jitsi";
MatrixWidgetType["Stickerpicker"] = "m.stickerpicker";
return MatrixWidgetType;
}({});
exports.MatrixWidgetType = MatrixWidgetType;
},{}],17:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Widget = void 0;
var _ = require("..");
var _utils = require("./validation/utils");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Represents the barest form of widget.
*/
var Widget = /*#__PURE__*/function () {
function Widget(definition) {
_classCallCheck(this, Widget);
this.definition = definition;
if (!this.definition) throw new Error("Definition is required");
(0, _utils.assertPresent)(definition, "id");
(0, _utils.assertPresent)(definition, "creatorUserId");
(0, _utils.assertPresent)(definition, "type");
(0, _utils.assertPresent)(definition, "url");
}
/**
* The user ID who created the widget.
*/
_createClass(Widget, [{
key: "creatorUserId",
get: function get() {
return this.definition.creatorUserId;
}
/**
* The type of widget.
*/
}, {
key: "type",
get: function get() {
return this.definition.type;
}
/**
* The ID of the widget.
*/
}, {
key: "id",
get: function get() {
return this.definition.id;
}
/**
* The name of the widget, or null if not set.
*/
}, {
key: "name",
get: function get() {
return this.definition.name || null;
}
/**
* The title for the widget, or null if not set.
*/
}, {
key: "title",
get: function get() {
return this.rawData.title || null;
}
/**
* The templated URL for the widget.
*/
}, {
key: "templateUrl",
get: function get() {
return this.definition.url;
}
/**
* The origin for this widget.
*/
}, {
key: "origin",
get: function get() {
return new URL(this.templateUrl).origin;
}
/**
* Whether or not the client should wait for the iframe to load. Defaults
* to true.
*/
}, {
key: "waitForIframeLoad",
get: function get() {
if (this.definition.waitForIframeLoad === false) return false;
if (this.definition.waitForIframeLoad === true) return true;
return true; // default true
}
/**
* The raw data for the widget. This will always be defined, though
* may be empty.
*/
}, {
key: "rawData",
get: function get() {
return this.definition.data || {};
}
/**
* Gets a complete widget URL for the client to render.
* @param {ITemplateParams} params The template parameters.
* @returns {string} A templated URL.
*/
}, {
key: "getCompleteUrl",
value: function getCompleteUrl(params) {
return (0, _.runTemplate)(this.templateUrl, this.definition, params);
}
}]);
return Widget;
}();
exports.Widget = Widget;
},{"..":5,"./validation/utils":21}],18:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetEventCapability = exports.EventKind = exports.EventDirection = void 0;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var EventKind = /*#__PURE__*/function (EventKind) {
EventKind["Event"] = "event";
EventKind["State"] = "state_event";
EventKind["ToDevice"] = "to_device";
EventKind["RoomAccount"] = "room_account";
return EventKind;
}({});
exports.EventKind = EventKind;
var EventDirection = /*#__PURE__*/function (EventDirection) {
EventDirection["Send"] = "send";
EventDirection["Receive"] = "receive";
return EventDirection;
}({});
exports.EventDirection = EventDirection;
var WidgetEventCapability = /*#__PURE__*/function () {
function WidgetEventCapability(direction, eventType, kind, keyStr, raw) {
_classCallCheck(this, WidgetEventCapability);
this.direction = direction;
this.eventType = eventType;
this.kind = kind;
this.keyStr = keyStr;
this.raw = raw;
}
_createClass(WidgetEventCapability, [{
key: "matchesAsStateEvent",
value: function matchesAsStateEvent(direction, eventType, stateKey) {
if (this.kind !== EventKind.State) return false; // not a state event
if (this.direction !== direction) return false; // direction mismatch
if (this.eventType !== eventType) return false; // event type mismatch
if (this.keyStr === null) return true; // all state keys are allowed
if (this.keyStr === stateKey) return true; // this state key is allowed
// Default not allowed
return false;
}
}, {
key: "matchesAsToDeviceEvent",
value: function matchesAsToDeviceEvent(direction, eventType) {
if (this.kind !== EventKind.ToDevice) return false; // not a to-device event
if (this.direction !== direction) return false; // direction mismatch
if (this.eventType !== eventType) return false; // event type mismatch
// Checks passed, the event is allowed
return true;
}
}, {
key: "matchesAsRoomEvent",
value: function matchesAsRoomEvent(direction, eventType) {
var msgtype = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
if (this.kind !== EventKind.Event) return false; // not a room event
if (this.direction !== direction) return false; // direction mismatch
if (this.eventType !== eventType) return false; // event type mismatch
if (this.eventType === "m.room.message") {
if (this.keyStr === null) return true; // all message types are allowed
if (this.keyStr === msgtype) return true; // this message type is allowed
} else {
return true; // already passed the check for if the event is allowed
}
// Default not allowed
return false;
}
}, {
key: "matchesAsRoomAccountData",
value: function matchesAsRoomAccountData(direction, eventType) {
if (this.kind !== EventKind.RoomAccount) return false; // not room account data
if (this.direction !== direction) return false; // direction mismatch
if (this.eventType !== eventType) return false; // event type mismatch
// Checks passed, the event is allowed
return true;
}
}], [{
key: "forStateEvent",
value: function forStateEvent(direction, eventType, stateKey) {
// TODO: Enable support for m.* namespace once the MSC lands.
// https://github.com/matrix-org/matrix-widget-api/issues/22
eventType = eventType.replace(/#/g, "\\#");
stateKey = stateKey !== null && stateKey !== undefined ? "#".concat(stateKey) : "";
var str = "org.matrix.msc2762.".concat(direction, ".state_event:").concat(eventType).concat(stateKey);
// cheat by sending it through the processor
return WidgetEventCapability.findEventCapabilities([str])[0];
}
}, {
key: "forToDeviceEvent",
value: function forToDeviceEvent(direction, eventType) {
// TODO: Enable support for m.* namespace once the MSC lands.
// https://github.com/matrix-org/matrix-widget-api/issues/56
var str = "org.matrix.msc3819.".concat(direction, ".to_device:").concat(eventType);
// cheat by sending it through the processor
return WidgetEventCapability.findEventCapabilities([str])[0];
}
}, {
key: "forRoomEvent",
value: function forRoomEvent(direction, eventType) {
// TODO: Enable support for m.* namespace once the MSC lands.
// https://github.com/matrix-org/matrix-widget-api/issues/22
var str = "org.matrix.msc2762.".concat(direction, ".event:").concat(eventType);
// cheat by sending it through the processor
return WidgetEventCapability.findEventCapabilities([str])[0];
}
}, {
key: "forRoomMessageEvent",
value: function forRoomMessageEvent(direction, msgtype) {
// TODO: Enable support for m.* namespace once the MSC lands.
// https://github.com/matrix-org/matrix-widget-api/issues/22
msgtype = msgtype === null || msgtype === undefined ? "" : msgtype;
var str = "org.matrix.msc2762.".concat(direction, ".event:m.room.message#").concat(msgtype);
// cheat by sending it through the processor
return WidgetEventCapability.findEventCapabilities([str])[0];
}
}, {
key: "forRoomAccountData",
value: function forRoomAccountData(direction, eventType) {
var str = "com.beeper.capabilities.".concat(direction, ".room_account_data:").concat(eventType);
return WidgetEventCapability.findEventCapabilities([str])[0];
}
/**
* Parses a capabilities request to find all the event capability requests.
* @param {Iterable<Capability>} capabilities The capabilities requested/to parse.
* @returns {WidgetEventCapability[]} An array of event capability requests. May be empty, but never null.
*/
}, {
key: "findEventCapabilities",
value: function findEventCapabilities(capabilities) {
var parsed = [];
var _iterator = _createForOfIteratorHelper(capabilities),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var cap = _step.value;
var _direction = null;
var eventSegment = void 0;
var _kind = null;
// TODO: Enable support for m.* namespace once the MSCs land.
// https://github.com/matrix-org/matrix-widget-api/issues/22
// https://github.com/matrix-org/matrix-widget-api/issues/56
if (cap.startsWith("org.matrix.msc2762.send.event:")) {
_direction = EventDirection.Send;
_kind = EventKind.Event;
eventSegment = cap.substring("org.matrix.msc2762.send.event:".length);
} else if (cap.startsWith("org.matrix.msc2762.send.state_event:")) {
_direction = EventDirection.Send;
_kind = EventKind.State;
eventSegment = cap.substring("org.matrix.msc2762.send.state_event:".length);
} else if (cap.startsWith("org.matrix.msc3819.send.to_device:")) {
_direction = EventDirection.Send;
_kind = EventKind.ToDevice;
eventSegment = cap.substring("org.matrix.msc3819.send.to_device:".length);
} else if (cap.startsWith("org.matrix.msc2762.receive.event:")) {
_direction = EventDirection.Receive;
_kind = EventKind.Event;
eventSegment = cap.substring("org.matrix.msc2762.receive.event:".length);
} else if (cap.startsWith("org.matrix.msc2762.receive.state_event:")) {
_direction = EventDirection.Receive;
_kind = EventKind.State;
eventSegment = cap.substring("org.matrix.msc2762.receive.state_event:".length);
} else if (cap.startsWith("org.matrix.msc3819.receive.to_device:")) {
_direction = EventDirection.Receive;
_kind = EventKind.ToDevice;
eventSegment = cap.substring("org.matrix.msc3819.receive.to_device:".length);
} else if (cap.startsWith("com.beeper.capabilities.receive.room_account_data:")) {
_direction = EventDirection.Receive;
_kind = EventKind.RoomAccount;
eventSegment = cap.substring("com.beeper.capabilities.receive.room_account_data:".length);
}
if (_direction === null || _kind === null || eventSegment === undefined) continue;
// The capability uses `#` as a separator between event type and state key/msgtype,
// so we split on that. However, a # is also valid in either one of those so we
// join accordingly.
// Eg: `m.room.message##m.text` is "m.room.message" event with msgtype "#m.text".
var expectingKeyStr = eventSegment.startsWith("m.room.message#") || _kind === EventKind.State;
var _keyStr = null;
if (eventSegment.includes("#") && expectingKeyStr) {
// Dev note: regex is difficult to write, so instead the rules are manually written
// out. This is probably just as understandable as a boring regex though, so win-win?
// Test cases:
// str eventSegment keyStr
// -------------------------------------------------------------
// m.room.message# m.room.message <empty string>
// m.room.message#test m.room.message test
// m.room.message\# m.room.message# test
// m.room.message##test m.room.message #test
// m.room.message\##test m.room.message# test
// m.room.message\\##test m.room.message\# test
// m.room.message\\###test m.room.message\# #test
// First step: explode the string
var parts = eventSegment.split("#");
// To form the eventSegment, we'll keep finding parts of the exploded string until
// there's one that doesn't end with the escape character (\). We'll then join those
// segments together with the exploding character. We have to remember to consume the
// escape character as well.
var idx = parts.findIndex(function (p) {
return !p.endsWith("\\");
});
eventSegment = parts.slice(0, idx + 1).map(function (p) {
return p.endsWith("\\") ? p.substring(0, p.length - 1) : p;
}).join("#");
// The keyStr is whatever is left over.
_keyStr = parts.slice(idx + 1).join("#");
}
parsed.push(new WidgetEventCapability(_direction, eventSegment, _kind, _keyStr, cap));
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return parsed;
}
}]);
return WidgetEventCapability;
}();
exports.WidgetEventCapability = WidgetEventCapability;
},{}],19:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WidgetParser = void 0;
var _Widget = require("./Widget");
var _url = require("./validation/url");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var WidgetParser = /*#__PURE__*/function () {
function WidgetParser() {
_classCallCheck(this, WidgetParser);
} // private constructor because this is a util class
/**
* Parses widgets from the "m.widgets" account data event. This will always
* return an array, though may be empty if no valid widgets were found.
* @param {IAccountDataWidgets} content The content of the "m.widgets" account data.
* @returns {Widget[]} The widgets in account data, or an empty array.
*/
_createClass(WidgetParser, null, [{
key: "parseAccountData",
value: function parseAccountData(content) {
if (!content) return [];
var result = [];
for (var _i = 0, _Object$keys = Object.keys(content); _i < _Object$keys.length; _i++) {
var _widgetId = _Object$keys[_i];
var roughWidget = content[_widgetId];
if (!roughWidget) continue;
if (roughWidget.type !== "m.widget" && roughWidget.type !== "im.vector.modular.widgets") continue;
if (!roughWidget.sender) continue;
var probableWidgetId = roughWidget.state_key || roughWidget.id;
if (probableWidgetId !== _widgetId) continue;
var asStateEvent = {
content: roughWidget.content,
sender: roughWidget.sender,
type: "m.widget",
state_key: _widgetId,
event_id: "$example",
room_id: "!example",
origin_server_ts: 1
};
var widget = WidgetParser.parseRoomWidget(asStateEvent);
if (widget) result.push(widget);
}
return result;
}
/**
* Parses all the widgets possible in the given array. This will always return
* an array, though may be empty if no widgets could be parsed.
* @param {IStateEvent[]} currentState The room state to parse.
* @returns {Widget[]} The widgets in the state, or an empty array.
*/
}, {
key: "parseWidgetsFromRoomState",
value: function parseWidgetsFromRoomState(currentState) {
if (!currentState) return [];
var result = [];
var _iterator = _createForOfIteratorHelper(currentState),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var state = _step.value;
var widget = WidgetParser.parseRoomWidget(state);
if (widget) result.push(widget);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return result;
}
/**
* Parses a state event into a widget. If the state event does not represent
* a widget (wrong event type, invalid widget, etc) then null is returned.
* @param {IStateEvent} stateEvent The state event.
* @returns {Widget|null} The widget, or null if invalid
*/
}, {
key: "parseRoomWidget",
value: function parseRoomWidget(stateEvent) {
if (!stateEvent) return null;
// TODO: [Legacy] Remove legacy support
if (stateEvent.type !== "m.widget" && stateEvent.type !== "im.vector.modular.widgets") {
return null;
}
// Dev note: Throughout this function we have null safety to ensure that
// if the caller did not supply something useful that we don't error. This
// is done against the requirements of the interface because not everyone
// will have an interface to validate against.
var content = stateEvent.content || {};
// Form our best approximation of a widget with the information we have
var estimatedWidget = {
id: stateEvent.state_key,
creatorUserId: content["creatorUserId"] || stateEvent.sender,
name: content["name"],
type: content["type"],
url: content["url"],
waitForIframeLoad: content["waitForIframeLoad"],
data: content["data"]
};
// Finally, process that widget
return WidgetParser.processEstimatedWidget(estimatedWidget);
}
}, {
key: "processEstimatedWidget",
value: function processEstimatedWidget(widget) {
// Validate that the widget has the best chance of passing as a widget
if (!widget.id || !widget.creatorUserId || !widget.type) {
return null;
}
if (!(0, _url.isValidUrl)(widget.url)) {
return null;
}
// TODO: Validate data for known widget types
return new _Widget.Widget(widget);
}
}]);
return WidgetParser;
}();
exports.WidgetParser = WidgetParser;
},{"./Widget":17,"./validation/url":20}],20:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isValidUrl = isValidUrl;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function isValidUrl(val) {
if (!val) return false; // easy: not valid if not present
try {
var parsed = new URL(val);
if (parsed.protocol !== "http" && parsed.protocol !== "https") {
return false;
}
return true;
} catch (e) {
if (e instanceof TypeError) {
return false;
}
throw e;
}
}
},{}],21:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assertPresent = assertPresent;
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function assertPresent(obj, key) {
if (!obj[key]) {
throw new Error("".concat(String(key), " is required"));
}
}
},{}],22:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.runTemplate = runTemplate;
exports.toString = toString;
/*
* Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function runTemplate(url, widget, params) {
// Always apply the supplied params over top of data to ensure the data can't lie about them.
var variables = Object.assign({}, widget.data, {
"matrix_room_id": params.widgetRoomId || "",
"matrix_user_id": params.currentUserId,
"matrix_display_name": params.userDisplayName || params.currentUserId,
"matrix_avatar_url": params.userHttpAvatarUrl || "",
"matrix_widget_id": widget.id,
// TODO: Convert to stable (https://github.com/matrix-org/matrix-doc/pull/2873)
"org.matrix.msc2873.client_id": params.clientId || "",
"org.matrix.msc2873.client_theme": params.clientTheme || "",
"org.matrix.msc2873.client_language": params.clientLanguage || "",
// TODO: Convert to stable (https://github.com/matrix-org/matrix-spec-proposals/pull/3819)
"org.matrix.msc3819.matrix_device_id": params.deviceId || "",
// TODO: Convert to stable (https://github.com/matrix-org/matrix-spec-proposals/pull/4039)
"org.matrix.msc4039.matrix_base_url": params.baseUrl || ""
});
var result = url;
for (var _i = 0, _Object$keys = Object.keys(variables); _i < _Object$keys.length; _i++) {
var key = _Object$keys[_i];
// Regex escape from https://stackoverflow.com/a/6969486/7037379
var pattern = "$".concat(key).replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
var rexp = new RegExp(pattern, "g");
// This is technically not what we're supposed to do for a couple of reasons:
// 1. We are assuming that there won't later be a $key match after we replace a variable.
// 2. We are assuming that the variable is in a place where it can be escaped (eg: path or query string).
result = result.replace(rexp, encodeURIComponent(toString(variables[key])));
}
return result;
}
function toString(a) {
if (a === null || a === undefined) {
return "".concat(a);
}
// eslint-disable-next-line @typescript-eslint/no-base-to-string
return String(a);
}
},{}],23:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PostmessageTransport = void 0;
var _events = require("events");
var _ = require("..");
var _excluded = ["message"];
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Transport for the Widget API over postMessage.
*/
var PostmessageTransport = /*#__PURE__*/function (_EventEmitter) {
_inherits(PostmessageTransport, _EventEmitter);
var _super = _createSuper(PostmessageTransport);
function PostmessageTransport(sendDirection, initialWidgetId, transportWindow, inboundWindow) {
var _this;
_classCallCheck(this, PostmessageTransport);
_this = _super.call(this);
_this.sendDirection = sendDirection;
_this.transportWindow = transportWindow;
_this.inboundWindow = inboundWindow;
_defineProperty(_assertThisInitialized(_this), "strictOriginCheck", false);
_defineProperty(_assertThisInitialized(_this), "targetOrigin", "*");
_defineProperty(_assertThisInitialized(_this), "timeoutSeconds", 10);
_defineProperty(_assertThisInitialized(_this), "_ready", false);
_defineProperty(_assertThisInitialized(_this), "_widgetId", void 0);
_defineProperty(_assertThisInitialized(_this), "outboundRequests", new Map());
_defineProperty(_assertThisInitialized(_this), "stopController", new AbortController());
_defineProperty(_assertThisInitialized(_this), "handleMessage", function (ev) {
if (_this.stopController.signal.aborted) return;
if (!ev.data) return; // invalid event
if (_this.strictOriginCheck && ev.origin !== globalThis.origin) return; // bad origin
// treat the message as a response first, then downgrade to a request
var response = ev.data;
if (!response.action || !response.requestId || !response.widgetId) return; // invalid request/response
if (response.response) {
if (response.api !== _this.sendDirection) return; // wrong direction
_this.handleResponse(response);
} else {
var request = response;
if (request.api !== (0, _.invertedDirection)(_this.sendDirection)) return; // wrong direction
_this.handleRequest(request);
}
});
_this._widgetId = initialWidgetId;
return _this;
}
_createClass(PostmessageTransport, [{
key: "ready",
get: function get() {
return this._ready;
}
}, {
key: "widgetId",
get: function get() {
return this._widgetId || null;
}
}, {
key: "nextRequestId",
get: function get() {
var idBase = "widgetapi-".concat(Date.now());
var index = 0;
var id = idBase;
while (this.outboundRequests.has(id)) {
id = "".concat(idBase, "-").concat(index++);
}
// reserve the ID
this.outboundRequests.set(id, null);
return id;
}
}, {
key: "sendInternal",
value: function sendInternal(message) {
console.log("[PostmessageTransport] Sending object to ".concat(this.targetOrigin, ": "), message);
this.transportWindow.postMessage(message, this.targetOrigin);
}
}, {
key: "reply",
value: function reply(request, responseData) {
return this.sendInternal(_objectSpread(_objectSpread({}, request), {}, {
response: responseData
}));
}
}, {
key: "send",
value: function send(action, data) {
return this.sendComplete(action, data).then(function (r) {
return r.response;
});
}
}, {
key: "sendComplete",
value: function sendComplete(action, data) {
var _this2 = this;
if (!this.ready || !this.widgetId) {
return Promise.reject(new Error("Not ready or unknown widget ID"));
}
var request = {
api: this.sendDirection,
widgetId: this.widgetId,
requestId: this.nextRequestId,
action: action,
data: data
};
if (action === _.WidgetApiToWidgetAction.UpdateVisibility) {
request["visible"] = data["visible"];
}
return new Promise(function (prResolve, prReject) {
var resolve = function resolve(response) {
cleanUp();
prResolve(response);
};
var reject = function reject(err) {
cleanUp();
prReject(err);
};
var timerId = setTimeout(function () {
return reject(new Error("Request timed out"));
}, (_this2.timeoutSeconds || 1) * 1000);
var onStop = function onStop() {
return reject(new Error("Transport stopped"));
};
_this2.stopController.signal.addEventListener("abort", onStop);
var cleanUp = function cleanUp() {
_this2.outboundRequests["delete"](request.requestId);
clearTimeout(timerId);
_this2.stopController.signal.removeEventListener("abort", onStop);
};
_this2.outboundRequests.set(request.requestId, {
request: request,
resolve: resolve,
reject: reject
});
_this2.sendInternal(request);
});
}
}, {
key: "start",
value: function start() {
this.inboundWindow.addEventListener("message", this.handleMessage);
this._ready = true;
}
}, {
key: "stop",
value: function stop() {
this._ready = false;
this.stopController.abort();
this.inboundWindow.removeEventListener("message", this.handleMessage);
}
}, {
key: "handleRequest",
value: function handleRequest(request) {
if (this.widgetId) {
if (this.widgetId !== request.widgetId) return; // wrong widget
} else {
this._widgetId = request.widgetId;
}
this.emit("message", new CustomEvent("message", {
detail: request
}));
}
}, {
key: "handleResponse",
value: function handleResponse(response) {
if (response.widgetId !== this.widgetId) return; // wrong widget
var req = this.outboundRequests.get(response.requestId);
if (!req) return; // response to an unknown request
if ((0, _.isErrorResponse)(response.response)) {
var _response$response$er = response.response.error,
message = _response$response$er.message,
data = _objectWithoutProperties(_response$response$er, _excluded);
req.reject(new _.WidgetApiResponseError(message, data));
} else {
req.resolve(response);
}
}
}]);
return PostmessageTransport;
}(_events.EventEmitter);
exports.PostmessageTransport = PostmessageTransport;
},{"..":5,"events":25}],24:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SimpleObservable = void 0;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var SimpleObservable = /*#__PURE__*/function () {
function SimpleObservable(initialFn) {
_classCallCheck(this, SimpleObservable);
_defineProperty(this, "listeners", []);
if (initialFn) this.listeners.push(initialFn);
}
_createClass(SimpleObservable, [{
key: "onUpdate",
value: function onUpdate(fn) {
this.listeners.push(fn);
}
}, {
key: "update",
value: function update(val) {
var _iterator = _createForOfIteratorHelper(this.listeners),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var listener = _step.value;
listener(val);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
}, {
key: "close",
value: function close() {
this.listeners = []; // reset
}
}]);
return SimpleObservable;
}();
exports.SimpleObservable = SimpleObservable;
},{}],25:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
var R = typeof Reflect === 'object' ? Reflect : null
var ReflectApply = R && typeof R.apply === 'function'
? R.apply
: function ReflectApply(target, receiver, args) {
return Function.prototype.apply.call(target, receiver, args);
}
var ReflectOwnKeys
if (R && typeof R.ownKeys === 'function') {
ReflectOwnKeys = R.ownKeys
} else if (Object.getOwnPropertySymbols) {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target)
.concat(Object.getOwnPropertySymbols(target));
};
} else {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target);
};
}
function ProcessEmitWarning(warning) {
if (console && console.warn) console.warn(warning);
}
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
return value !== value;
}
function EventEmitter() {
EventEmitter.init.call(this);
}
module.exports = EventEmitter;
module.exports.once = once;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._eventsCount = 0;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
var defaultMaxListeners = 10;
function checkListener(listener) {
if (typeof listener !== 'function') {
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
}
}
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
enumerable: true,
get: function() {
return defaultMaxListeners;
},
set: function(arg) {
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
}
defaultMaxListeners = arg;
}
});
EventEmitter.init = function() {
if (this._events === undefined ||
this._events === Object.getPrototypeOf(this)._events) {
this._events = Object.create(null);
this._eventsCount = 0;
}
this._maxListeners = this._maxListeners || undefined;
};
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
}
this._maxListeners = n;
return this;
};
function _getMaxListeners(that) {
if (that._maxListeners === undefined)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return _getMaxListeners(this);
};
EventEmitter.prototype.emit = function emit(type) {
var args = [];
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
var doError = (type === 'error');
var events = this._events;
if (events !== undefined)
doError = (doError && events.error === undefined);
else if (!doError)
return false;
// If there is no 'error' event listener then throw.
if (doError) {
var er;
if (args.length > 0)
er = args[0];
if (er instanceof Error) {
// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
throw er; // Unhandled 'error' event
}
// At least give some kind of context to the user
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
err.context = er;
throw err; // Unhandled 'error' event
}
var handler = events[type];
if (handler === undefined)
return false;
if (typeof handler === 'function') {
ReflectApply(handler, this, args);
} else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
ReflectApply(listeners[i], this, args);
}
return true;
};
function _addListener(target, type, listener, prepend) {
var m;
var events;
var existing;
checkListener(listener);
events = target._events;
if (events === undefined) {
events = target._events = Object.create(null);
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener !== undefined) {
target.emit('newListener', type,
listener.listener ? listener.listener : listener);
// Re-assign `events` because a newListener handler could have caused the
// this._events to be assigned to a new object
events = target._events;
}
existing = events[type];
}
if (existing === undefined) {
// Optimize the case of one listener. Don't need the extra array object.
existing = events[type] = listener;
++target._eventsCount;
} else {
if (typeof existing === 'function') {
// Adding the second element, need to change to array.
existing = events[type] =
prepend ? [listener, existing] : [existing, listener];
// If we've already got an array, just append.
} else if (prepend) {
existing.unshift(listener);
} else {
existing.push(listener);
}
// Check for listener leak
m = _getMaxListeners(target);
if (m > 0 && existing.length > m && !existing.warned) {
existing.warned = true;
// No error code for this since it is a Warning
// eslint-disable-next-line no-restricted-syntax
var w = new Error('Possible EventEmitter memory leak detected. ' +
existing.length + ' ' + String(type) + ' listeners ' +
'added. Use emitter.setMaxListeners() to ' +
'increase limit');
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;
ProcessEmitWarning(w);
}
}
return target;
}
EventEmitter.prototype.addListener = function addListener(type, listener) {
return _addListener(this, type, listener, false);
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.prependListener =
function prependListener(type, listener) {
return _addListener(this, type, listener, true);
};
function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
if (arguments.length === 0)
return this.listener.call(this.target);
return this.listener.apply(this.target, arguments);
}
}
function _onceWrap(target, type, listener) {
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
var wrapped = onceWrapper.bind(state);
wrapped.listener = listener;
state.wrapFn = wrapped;
return wrapped;
}
EventEmitter.prototype.once = function once(type, listener) {
checkListener(listener);
this.on(type, _onceWrap(this, type, listener));
return this;
};
EventEmitter.prototype.prependOnceListener =
function prependOnceListener(type, listener) {
checkListener(listener);
this.prependListener(type, _onceWrap(this, type, listener));
return this;
};
// Emits a 'removeListener' event if and only if the listener was removed.
EventEmitter.prototype.removeListener =
function removeListener(type, listener) {
var list, events, position, i, originalListener;
checkListener(listener);
events = this._events;
if (events === undefined)
return this;
list = events[type];
if (list === undefined)
return this;
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else {
delete events[type];
if (events.removeListener)
this.emit('removeListener', type, list.listener || listener);
}
} else if (typeof list !== 'function') {
position = -1;
for (i = list.length - 1; i >= 0; i--) {
if (list[i] === listener || list[i].listener === listener) {
originalListener = list[i].listener;
position = i;
break;
}
}
if (position < 0)
return this;
if (position === 0)
list.shift();
else {
spliceOne(list, position);
}
if (list.length === 1)
events[type] = list[0];
if (events.removeListener !== undefined)
this.emit('removeListener', type, originalListener || listener);
}
return this;
};
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var listeners, events, i;
events = this._events;
if (events === undefined)
return this;
// not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = Object.create(null);
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else
delete events[type];
}
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
var keys = Object.keys(events);
var key;
for (i = 0; i < keys.length; ++i) {
key = keys[i];
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = Object.create(null);
this._eventsCount = 0;
return this;
}
listeners = events[type];
if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners !== undefined) {
// LIFO order
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
}
}
return this;
};
function _listeners(target, type, unwrap) {
var events = target._events;
if (events === undefined)
return [];
var evlistener = events[type];
if (evlistener === undefined)
return [];
if (typeof evlistener === 'function')
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
return unwrap ?
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type) {
return _listeners(this, type, true);
};
EventEmitter.prototype.rawListeners = function rawListeners(type) {
return _listeners(this, type, false);
};
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
};
EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type) {
var events = this._events;
if (events !== undefined) {
var evlistener = events[type];
if (typeof evlistener === 'function') {
return 1;
} else if (evlistener !== undefined) {
return evlistener.length;
}
}
return 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
};
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
function spliceOne(list, index) {
for (; index + 1 < list.length; index++)
list[index] = list[index + 1];
list.pop();
}
function unwrapListeners(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
}
return ret;
}
function once(emitter, name) {
return new Promise(function (resolve, reject) {
function errorListener(err) {
emitter.removeListener(name, resolver);
reject(err);
}
function resolver() {
if (typeof emitter.removeListener === 'function') {
emitter.removeListener('error', errorListener);
}
resolve([].slice.call(arguments));
};
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
if (name !== 'error') {
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
}
});
}
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
if (typeof emitter.on === 'function') {
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
}
}
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
if (typeof emitter.on === 'function') {
if (flags.once) {
emitter.once(name, listener);
} else {
emitter.on(name, listener);
}
} else if (typeof emitter.addEventListener === 'function') {
// EventTarget does not have `error` event semantics like Node
// EventEmitters, we do not listen for `error` events here.
emitter.addEventListener(name, function wrapListener(arg) {
// IE does not have builtin `{ once: true }` support so we
// have to do it manually.
if (flags.once) {
emitter.removeEventListener(name, wrapListener);
}
listener(arg);
});
} else {
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
}
}
},{}]},{},[5])(5)
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaWIvQ2xpZW50V2lkZ2V0QXBpLmpzIiwibGliL1N5bWJvbHMuanMiLCJsaWIvV2lkZ2V0QXBpLmpzIiwibGliL2RyaXZlci9XaWRnZXREcml2ZXIuanMiLCJsaWIvaW5kZXguanMiLCJsaWIvaW50ZXJmYWNlcy9BcGlWZXJzaW9uLmpzIiwibGliL2ludGVyZmFjZXMvQ2FwYWJpbGl0aWVzLmpzIiwibGliL2ludGVyZmFjZXMvR2V0T3BlbklEQWN0aW9uLmpzIiwibGliL2ludGVyZmFjZXMvSVdpZGdldEFwaUVycm9yUmVzcG9uc2UuanMiLCJsaWIvaW50ZXJmYWNlcy9Nb2RhbEJ1dHRvbktpbmQuanMiLCJsaWIvaW50ZXJmYWNlcy9Nb2RhbFdpZGdldEFjdGlvbnMuanMiLCJsaWIvaW50ZXJmYWNlcy9VcGRhdGVEZWxheWVkRXZlbnRBY3Rpb24uanMiLCJsaWIvaW50ZXJmYWNlcy9XaWRnZXRBcGlBY3Rpb24uanMiLCJsaWIvaW50ZXJmYWNlcy9XaWRnZXRBcGlEaXJlY3Rpb24uanMiLCJsaWIvaW50ZXJmYWNlcy9XaWRnZXRLaW5kLmpzIiwibGliL2ludGVyZmFjZXMvV2lkZ2V0VHlwZS5qcyIsImxpYi9tb2RlbHMvV2lkZ2V0LmpzIiwibGliL21vZGVscy9XaWRnZXRFdmVudENhcGFiaWxpdHkuanMiLCJsaWIvbW9kZWxzL1dpZGdldFBhcnNlci5qcyIsImxpYi9tb2RlbHMvdmFsaWRhdGlvbi91cmwuanMiLCJsaWIvbW9kZWxzL3ZhbGlkYXRpb24vdXRpbHMuanMiLCJsaWIvdGVtcGxhdGluZy91cmwtdGVtcGxhdGUuanMiLCJsaWIvdHJhbnNwb3J0L1Bvc3RtZXNzYWdlVHJhbnNwb3J0LmpzIiwibGliL3V0aWwvU2ltcGxlT2JzZXJ2YWJsZS5qcyIsIm5vZGVfbW9kdWxlcy9ldmVudHMvZXZlbnRzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FDQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E