@datafinder/embed-sdk
Version:
Embed SDK for DataFinder
45 lines (42 loc) • 1.33 kB
JavaScript
import * as Comlink from 'comlink';
/**
* 在 DataFinder 嵌入页面中引入的 Servant 对象,用于处理外部接入方和内部 DataFinder 模块之间的通信
*/
var EmbeddingClient = /** @class */ (function () {
function EmbeddingClient() {
this._endpoint = Comlink.windowEndpoint(self.parent, self, '*');
this._remote = Comlink.wrap(this._endpoint, self);
}
/**
* 对外部 Master 暴露一个命名方法
*/
EmbeddingClient.prototype.exposeFunction = function (funcName, func) {
var _a;
if (func) {
Comlink.expose(Comlink.proxy((_a = {}, _a[funcName] = func, _a)), this._endpoint);
}
};
/**
* 返回远端的 Proxy 实例
*/
EmbeddingClient.prototype.remote = function () {
return this._remote;
};
/**
* 标记当前 client 已经准备好
*/
EmbeddingClient.prototype.ready = function () {
if (typeof this._remote.onReady === 'function') {
this._remote.onReady();
}
};
/**
* 销毁当前 Servant
*/
EmbeddingClient.prototype.destroy = function () {
this._remote[Comlink.releaseProxy]();
};
return EmbeddingClient;
}());
export { EmbeddingClient };
//# sourceMappingURL=client.js.map