matrix-widget-api
Advanced tools
Comparing version 0.1.0-beta.4 to 0.1.0-beta.5
@@ -0,4 +1,4 @@ | ||
import { EventEmitter } from "events"; | ||
import { ITransport } from "./transport/ITransport"; | ||
import { Widget } from "./models/Widget"; | ||
import { AlmostEventEmitter } from "./AlmostEventEmitter"; | ||
import { Capability } from "./interfaces/Capabilities"; | ||
@@ -33,3 +33,3 @@ import { WidgetDriver } from "./driver/WidgetDriver"; | ||
*/ | ||
export declare class ClientWidgetApi extends AlmostEventEmitter { | ||
export declare class ClientWidgetApi extends EventEmitter { | ||
readonly widget: Widget; | ||
@@ -36,0 +36,0 @@ private iframe; |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _events = require("events"); | ||
var _PostmessageTransport = require("./transport/PostmessageTransport"); | ||
@@ -13,4 +15,2 @@ | ||
var _AlmostEventEmitter2 = require("./AlmostEventEmitter"); | ||
var _WidgetApiAction = require("./interfaces/WidgetApiAction"); | ||
@@ -68,4 +68,4 @@ | ||
*/ | ||
var ClientWidgetApi = /*#__PURE__*/function (_AlmostEventEmitter) { | ||
_inherits(ClientWidgetApi, _AlmostEventEmitter); | ||
var ClientWidgetApi = /*#__PURE__*/function (_EventEmitter) { | ||
_inherits(ClientWidgetApi, _EventEmitter); | ||
@@ -117,3 +117,3 @@ var _super = _createSuper(ClientWidgetApi); | ||
_this.transport.addEventListener("message", _this.handleMessage.bind(_assertThisInitialized(_this))); | ||
_this.transport.on("message", _this.handleMessage.bind(_assertThisInitialized(_this))); | ||
@@ -157,3 +157,3 @@ if (widget.waitForIframeLoad) { | ||
this.dispatchEvent(new CustomEvent("preparing")); | ||
this.emit("preparing"); | ||
this.transport.send(_WidgetApiAction.WidgetApiToWidgetAction.Capabilities, {}).then(function (caps) { | ||
@@ -165,3 +165,3 @@ return _this2.driver.validateCapabilities(new Set(caps.capabilities)); | ||
_this2.dispatchEvent(new CustomEvent("ready")); | ||
_this2.emit("ready"); | ||
}); | ||
@@ -198,3 +198,3 @@ } | ||
}); | ||
this.dispatchEvent(actionEv); | ||
this.emit("action:".concat(ev.detail.action), actionEv); | ||
@@ -262,4 +262,4 @@ if (!actionEv.defaultPrevented) { | ||
return ClientWidgetApi; | ||
}(_AlmostEventEmitter2.AlmostEventEmitter); | ||
}(_events.EventEmitter); | ||
exports.ClientWidgetApi = ClientWidgetApi; |
@@ -34,4 +34,3 @@ export * from "./WidgetApi"; | ||
export * from "./models/WidgetParser"; | ||
export * from "./AlmostEventEmitter"; | ||
export * from "./templating/url-template"; | ||
export * from "./driver/WidgetDriver"; |
@@ -403,14 +403,2 @@ "use strict"; | ||
var _AlmostEventEmitter = require("./AlmostEventEmitter"); | ||
Object.keys(_AlmostEventEmitter).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _AlmostEventEmitter[key]; | ||
} | ||
}); | ||
}); | ||
var _urlTemplate = require("./templating/url-template"); | ||
@@ -417,0 +405,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { EventEmitter } from "events"; | ||
import { IWidgetApiAcknowledgeResponseData, IWidgetApiRequest, IWidgetApiRequestData, IWidgetApiResponse, IWidgetApiResponseData, WidgetApiAction } from ".."; | ||
@@ -7,3 +8,3 @@ /** | ||
*/ | ||
export interface ITransport extends EventTarget { | ||
export interface ITransport extends EventEmitter { | ||
/** | ||
@@ -10,0 +11,0 @@ * True if the transport is ready to start sending, false otherwise. |
@@ -0,1 +1,2 @@ | ||
import { EventEmitter } from "events"; | ||
import { ITransport } from "./ITransport"; | ||
@@ -6,3 +7,3 @@ import { IWidgetApiRequest, IWidgetApiRequestData, IWidgetApiResponse, IWidgetApiResponseData, WidgetApiAction, WidgetApiDirection } from ".."; | ||
*/ | ||
export declare class PostmessageTransport extends EventTarget implements ITransport { | ||
export declare class PostmessageTransport extends EventEmitter implements ITransport { | ||
private sendDirection; | ||
@@ -9,0 +10,0 @@ private initialWidgetId; |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _events = require("events"); | ||
var _ = require(".."); | ||
@@ -25,2 +27,4 @@ | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
@@ -32,12 +36,4 @@ | ||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } | ||
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
@@ -50,4 +46,4 @@ | ||
*/ | ||
var PostmessageTransport = /*#__PURE__*/function (_EventTarget) { | ||
_inherits(PostmessageTransport, _EventTarget); | ||
var PostmessageTransport = /*#__PURE__*/function (_EventEmitter) { | ||
_inherits(PostmessageTransport, _EventEmitter); | ||
@@ -216,3 +212,3 @@ var _super = _createSuper(PostmessageTransport); | ||
this.dispatchEvent(new CustomEvent("message", { | ||
this.emit("message", new CustomEvent("message", { | ||
detail: request | ||
@@ -257,4 +253,4 @@ })); | ||
return PostmessageTransport; | ||
}( /*#__PURE__*/_wrapNativeSuper(EventTarget)); | ||
}(_events.EventEmitter); | ||
exports.PostmessageTransport = PostmessageTransport; |
@@ -0,5 +1,5 @@ | ||
import { EventEmitter } from "events"; | ||
import { Capability } from "./interfaces/Capabilities"; | ||
import { ITransport } from "./transport/ITransport"; | ||
import { IStickerActionRequestData } from "./interfaces/StickerAction"; | ||
import { AlmostEventEmitter } from "./AlmostEventEmitter"; | ||
import { IOpenIDCredentials } from "./interfaces/GetOpenIDAction"; | ||
@@ -25,3 +25,3 @@ import { WidgetType } from "./interfaces/WidgetType"; | ||
*/ | ||
export declare class WidgetApi extends AlmostEventEmitter { | ||
export declare class WidgetApi extends EventEmitter { | ||
private clientOrigin; | ||
@@ -28,0 +28,0 @@ readonly transport: ITransport; |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _events = require("events"); | ||
var _WidgetApiDirection = require("./interfaces/WidgetApiDirection"); | ||
@@ -17,4 +19,2 @@ | ||
var _AlmostEventEmitter2 = require("./AlmostEventEmitter"); | ||
var _GetOpenIDAction = require("./interfaces/GetOpenIDAction"); | ||
@@ -65,4 +65,4 @@ | ||
*/ | ||
var WidgetApi = /*#__PURE__*/function (_AlmostEventEmitter) { | ||
_inherits(WidgetApi, _AlmostEventEmitter); | ||
var WidgetApi = /*#__PURE__*/function (_EventEmitter) { | ||
_inherits(WidgetApi, _EventEmitter); | ||
@@ -101,3 +101,3 @@ var _super = _createSuper(WidgetApi); | ||
_this.transport.addEventListener("message", _this.handleMessage.bind(_assertThisInitialized(_this))); | ||
_this.transport.on("message", _this.handleMessage.bind(_assertThisInitialized(_this))); | ||
@@ -185,6 +185,6 @@ return _this; | ||
_this3.removeEventListener("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials), handlerFn); | ||
_this3.off("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials), handlerFn); | ||
}; | ||
_this3.addEventListener("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials), handlerFn); | ||
_this3.on("action:".concat(_WidgetApiAction.WidgetApiToWidgetAction.OpenIDCredentials), handlerFn); | ||
} else { | ||
@@ -270,3 +270,3 @@ reject(new Error("Invalid state: " + rdata.state)); | ||
}); | ||
this.dispatchEvent(actionEv); | ||
this.emit("action:".concat(ev.detail.action), actionEv); | ||
@@ -313,3 +313,3 @@ if (!actionEv.defaultPrevented) { | ||
this.capabilitiesFinished = true; | ||
this.dispatchEvent(new CustomEvent("ready")); | ||
this.emit("ready"); | ||
return this.transport.reply(request, { | ||
@@ -322,4 +322,4 @@ capabilities: this.requestedCapabilities | ||
return WidgetApi; | ||
}(_AlmostEventEmitter2.AlmostEventEmitter); | ||
}(_events.EventEmitter); | ||
exports.WidgetApi = WidgetApi; |
{ | ||
"name": "matrix-widget-api", | ||
"version": "0.1.0-beta.4", | ||
"version": "0.1.0-beta.5", | ||
"description": "Matrix Widget API SDK", | ||
@@ -36,2 +36,3 @@ "main": "./lib/index.js", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@types/events": "^3.0.0", | ||
"babel-eslint": "^10.1.0", | ||
@@ -42,3 +43,6 @@ "eslint": "^7.8.1", | ||
"rimraf": "^3.0.2" | ||
}, | ||
"dependencies": { | ||
"events": "^3.2.0" | ||
} | ||
} |
@@ -24,3 +24,3 @@ # matrix-widget-api | ||
// Add custom action handlers (if needed) | ||
api.addEventListener(`action:${WidgetApiToWidgetAction.UpdateVisibility}`, (ev: CustomEvent<IVisibilityActionRequest>) => { | ||
api.on(`action:${WidgetApiToWidgetAction.UpdateVisibility}`, (ev: CustomEvent<IVisibilityActionRequest>) => { | ||
ev.preventDefault(); // we're handling it, so stop the widget API from doing something. | ||
@@ -30,3 +30,3 @@ console.log(ev.detail); // custom handling here | ||
}); | ||
api.addEventListener("com.example.my_action", (ev: CustomEvent<ICustomActionRequest>) => { | ||
api.on("com.example.my_action", (ev: CustomEvent<ICustomActionRequest>) => { | ||
ev.preventDefault(); // we're handling it, so stop the widget API from doing something. | ||
@@ -59,3 +59,3 @@ console.log(ev.detail); // custom handling here | ||
// The API is automatically started, so we just have to wait for a ready before doing something | ||
api.addEventListener("ready", () => { | ||
api.on("ready", () => { | ||
api.updateVisibility(true).then(() => console.log("Widget knows it is visible now")); | ||
@@ -62,0 +62,0 @@ api.transport.send("com.example.my_action", {isExample: true}); |
@@ -17,2 +17,3 @@ /* | ||
import { EventEmitter } from "events"; | ||
import { ITransport } from "./transport/ITransport"; | ||
@@ -23,3 +24,2 @@ import { Widget } from "./models/Widget"; | ||
import { IWidgetApiRequest, IWidgetApiRequestEmptyData } from "./interfaces/IWidgetApiRequest"; | ||
import { AlmostEventEmitter } from "./AlmostEventEmitter"; | ||
import { IContentLoadedActionRequest } from "./interfaces/ContentLoadedAction"; | ||
@@ -70,3 +70,3 @@ import { WidgetApiFromWidgetAction, WidgetApiToWidgetAction } from "./interfaces/WidgetApiAction"; | ||
*/ | ||
export class ClientWidgetApi extends AlmostEventEmitter { | ||
export class ClientWidgetApi extends EventEmitter { | ||
public readonly transport: ITransport; | ||
@@ -108,3 +108,3 @@ | ||
this.transport.targetOrigin = widget.origin; | ||
this.transport.addEventListener("message", this.handleMessage.bind(this)); | ||
this.transport.on("message", this.handleMessage.bind(this)); | ||
@@ -140,3 +140,3 @@ if (widget.waitForIframeLoad) { | ||
// widget has loaded - tell all the listeners that | ||
this.dispatchEvent(new CustomEvent("preparing")); | ||
this.emit("preparing"); | ||
@@ -150,3 +150,3 @@ this.transport.send<IWidgetApiRequestEmptyData, ICapabilitiesActionResponseData>( | ||
this.capabilitiesFinished = true; | ||
this.dispatchEvent(new CustomEvent("ready")); | ||
this.emit("ready"); | ||
}); | ||
@@ -180,3 +180,3 @@ } | ||
}); | ||
this.dispatchEvent(actionEv); | ||
this.emit(`action:${ev.detail.action}`, actionEv); | ||
if (!actionEv.defaultPrevented) { | ||
@@ -183,0 +183,0 @@ switch (ev.detail.action) { |
@@ -59,3 +59,2 @@ /* | ||
// Utilities | ||
export * from "./AlmostEventEmitter"; | ||
export * from "./templating/url-template"; | ||
@@ -62,0 +61,0 @@ |
@@ -17,2 +17,3 @@ /* | ||
import { EventEmitter } from "events"; | ||
import { | ||
@@ -32,3 +33,3 @@ IWidgetApiAcknowledgeResponseData, | ||
*/ | ||
export interface ITransport extends EventTarget { | ||
export interface ITransport extends EventEmitter { | ||
/** | ||
@@ -35,0 +36,0 @@ * True if the transport is ready to start sending, false otherwise. |
@@ -17,2 +17,3 @@ /* | ||
import { EventEmitter } from "events"; | ||
import { ITransport } from "./ITransport"; | ||
@@ -42,3 +43,3 @@ import { | ||
*/ | ||
export class PostmessageTransport extends EventTarget implements ITransport { | ||
export class PostmessageTransport extends EventEmitter implements ITransport { | ||
public strictOriginCheck: boolean; | ||
@@ -176,3 +177,3 @@ public targetOrigin: string; | ||
this.dispatchEvent(new CustomEvent("message", {detail: request})); | ||
this.emit("message", new CustomEvent("message", {detail: request})); | ||
} | ||
@@ -179,0 +180,0 @@ |
@@ -17,2 +17,3 @@ /* | ||
import { EventEmitter } from "events"; | ||
import { Capability } from "./interfaces/Capabilities"; | ||
@@ -33,3 +34,2 @@ import { IWidgetApiRequest, IWidgetApiRequestEmptyData } from "./interfaces/IWidgetApiRequest"; | ||
import { IStickyActionRequestData, IStickyActionResponseData } from "./interfaces/StickyAction"; | ||
import { AlmostEventEmitter } from "./AlmostEventEmitter"; | ||
import { | ||
@@ -67,3 +67,3 @@ IGetOpenIDActionRequestData, | ||
*/ | ||
export class WidgetApi extends AlmostEventEmitter { | ||
export class WidgetApi extends EventEmitter { | ||
public readonly transport: ITransport; | ||
@@ -92,3 +92,3 @@ | ||
this.transport.targetOrigin = clientOrigin; | ||
this.transport.addEventListener("message", this.handleMessage.bind(this)); | ||
this.transport.on("message", this.handleMessage.bind(this)); | ||
} | ||
@@ -155,5 +155,5 @@ | ||
} | ||
this.removeEventListener(`action:${WidgetApiToWidgetAction.OpenIDCredentials}`, handlerFn); | ||
this.off(`action:${WidgetApiToWidgetAction.OpenIDCredentials}`, handlerFn); | ||
}; | ||
this.addEventListener(`action:${WidgetApiToWidgetAction.OpenIDCredentials}`, handlerFn); | ||
this.on(`action:${WidgetApiToWidgetAction.OpenIDCredentials}`, handlerFn); | ||
} else { | ||
@@ -224,3 +224,3 @@ reject(new Error("Invalid state: " + rdata.state)); | ||
}); | ||
this.dispatchEvent(actionEv); | ||
this.emit(`action:${ev.detail.action}`, actionEv); | ||
if (!actionEv.defaultPrevented) { | ||
@@ -259,3 +259,3 @@ switch (ev.detail.action) { | ||
this.capabilitiesFinished = true; | ||
this.dispatchEvent(new CustomEvent("ready")); | ||
this.emit("ready"); | ||
return this.transport.reply<ICapabilitiesActionResponseData>(request, { | ||
@@ -262,0 +262,0 @@ capabilities: this.requestedCapabilities, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
206815
1
11
112
4415
+ Addedevents@^3.2.0
+ Addedevents@3.3.0(transitive)