-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.webworker.js.map
1 lines (1 loc) · 81.7 KB
/
plugin.webworker.js.map
1
{"version":3,"sources":["webpack://[name]/webpack/bootstrap","webpack://[name]/./src/utils.js","webpack://[name]/./src/rpc.js","webpack://[name]/./src/pluginCore.js","webpack://[name]/./src/plugin.webworker.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","randId","Math","random","toString","substr","Date","getTime","dtypeToTypedArray","int8","Int8Array","int16","Int16Array","int32","Int32Array","uint8","Uint8Array","uint16","Uint16Array","uint32","Uint32Array","float32","Float32Array","float64","Float64Array","array","Array","async","loadRequirementsInWindow","requirements","_importScript","url","Promise","resolve","reject","scriptTag","document","createElement","src","type","onload","onreadystatechange","this","readyState","onerror","head","appendChild","importScripts","args","slice","arguments","len","length","isArray","link_node","toLowerCase","endsWith","startsWith","rel","href","import","console","log","e","loadRequirementsInWebworker","loadRequirements","WorkerGlobalScope","self","normalizeConfig","config","version","description","id","target_origin","allow_execution","keys","reduce","typedArrayToDtypeMapping","typedArrayToDtypeKeys","arrType","push","eval","typedArrayToDtype","obj","dtype","constructor","pt","getPrototypeOf","cacheUrlInServiceWorker","message","command","navigator","serviceWorker","register","messageChannel","MessageChannel","port1","onmessage","event","data","error","result","controller","postMessage","port2","cacheRequirements","req","catch","setupServiceWorker","baseUrl","targetOrigin","cacheCallback","then","registration","scope","err","Error","window","addEventListener","origin","urlJoin","join","replace","MessageEmitter","debug","_event_handlers","_once_handlers","_debug","emit","on","handler","once","___event_run_once","off","idx","indexOf","splice","_fire","warn","API_VERSION","ArrayBufferView","_appendBuffer","buffer1","buffer2","tmp","byteLength","set","buffer","indexObject","is","split","RPC","connection","codecs","super","_connection","_codecs","_object_store","_method_weakmap","WeakMap","_object_weakmap","_local_api","_remote_set","execute","_store","ReferenceStore","_method_refs","onReady","onBusy","_setupMessageHanlders","init","peer_id","setConfig","k","getRemoteCallStack","getStack","getRemote","_remote_interface","setInterface","_interface","forwarding_functions","func_name","_remote","Function","sendInterface","_encode","api","_disposeObject","objectId","disposeObject","has","object_id","code","String","method","method_this","promise","_unwrap","includes","apply","fetch","_setRemoteInterface","disconnect","requestRemote","_ndarray","typedArray","shape","_dtype","_rtype","_rvalue","_rshape","_rdtype","_decode","intf","assign","_reportRemoteSet","_genRemoteMethod","targetId","me","remoteMethod","put","wrapped_resolve","wrapped_reject","encodedPromise","_wrap","__promise_pair","argLength","withKwargs","_rkwargs","transferables","__transferables__","target_id","with_kwargs","__remote_method","aObject","asInterface","aType","ArrayBuffer","bObject","_rtarget_id","_rintf","cid","_rname","temp","_transfer","isarray","tp","codec","encoder","encodedObj","tf","Tensor","v_buffer","dataSync","nj","NdArray","selection","File","_rpath","_path","webkitRelativePath","Boolean","RegExp","ImageData","FileList","FileSystemDirectoryHandle","FileSystemFileHandle","FileSystemHandle","FileSystemWritableFileStream","_rmime","Blob","DataView","Set","from","Map","getOwnPropertyNames","concat","hasFunction","withPromise","decoder","_genRemoteCallback","Uint8","reshape","arraytype","tensor","v","undefined","remoteCallback","reset","setTimeout","_indices","_readyHandler","_busyHandler","readyHandler","busyHandler","_genId","shift","_releaseId","pop","connectRPC","rpc","launchConnected","registerCodec","setup","export","onLoad","checkHandler","connected","connectedHandlers","dispose","_rpc","dispatchEvent","CustomEvent","detail","executeEsModule","content","dataUri","encodeURIComponent","Connection","close","attrs","stack","dedicated_thread","lang","api_version","conn","connect"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAO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AK3B,MAAMwC,OAAS,CACb9B,KAAM,aACN2R,kBAAkB,EAClBxP,iBAAiB,EACjByP,KAAM,aACNC,YAAa,wCAETC,KAAO,IAAIP,WAAWzP,QAC5BgQ,KAAKpM,GAAG,aAAc9B,IACpB,sDAAWkO,KAAM1V,OAAO2O,OAAOnH,EAAK9B,OAAQA,WAE9CgQ,KAAKC,UACLnQ,KAAKoC,YAAY,CACfhE,KAAM","file":"plugin.webworker.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 3);\n","export function randId() {\n return (\n Math.random()\n .toString(36)\n .substr(2, 10) + new Date().getTime()\n );\n}\n\nexport const dtypeToTypedArray = {\n int8: Int8Array,\n int16: Int16Array,\n int32: Int32Array,\n uint8: Uint8Array,\n uint16: Uint16Array,\n uint32: Uint32Array,\n float32: Float32Array,\n float64: Float64Array,\n array: Array\n};\n\nexport async function loadRequirementsInWindow(requirements) {\n function _importScript(url) {\n //url is URL of external file, implementationCode is the code\n //to be called from the file, location is the location to\n //insert the <script> element\n return new Promise((resolve, reject) => {\n var scriptTag = document.createElement(\"script\");\n scriptTag.src = url;\n scriptTag.type = \"text/javascript\";\n scriptTag.onload = resolve;\n scriptTag.onreadystatechange = function() {\n if (this.readyState === \"loaded\" || this.readyState === \"complete\") {\n resolve();\n }\n };\n scriptTag.onerror = reject;\n document.head.appendChild(scriptTag);\n });\n }\n\n // support importScripts outside web worker\n async function importScripts() {\n var args = Array.prototype.slice.call(arguments),\n len = args.length,\n i = 0;\n for (; i < len; i++) {\n await _importScript(args[i]);\n }\n }\n\n if (\n requirements &&\n (Array.isArray(requirements) || typeof requirements === \"string\")\n ) {\n try {\n var link_node;\n requirements =\n typeof requirements === \"string\" ? [requirements] : requirements;\n if (Array.isArray(requirements)) {\n for (var i = 0; i < requirements.length; i++) {\n if (\n requirements[i].toLowerCase().endsWith(\".css\") ||\n requirements[i].startsWith(\"css:\")\n ) {\n if (requirements[i].startsWith(\"css:\")) {\n requirements[i] = requirements[i].slice(4);\n }\n link_node = document.createElement(\"link\");\n link_node.rel = \"stylesheet\";\n link_node.href = requirements[i];\n document.head.appendChild(link_node);\n } else if (\n requirements[i].toLowerCase().endsWith(\".mjs\") ||\n requirements[i].startsWith(\"mjs:\")\n ) {\n // import esmodule\n if (requirements[i].startsWith(\"mjs:\")) {\n requirements[i] = requirements[i].slice(4);\n }\n await import(/* webpackIgnore: true */ requirements[i]);\n } else if (\n requirements[i].toLowerCase().endsWith(\".js\") ||\n requirements[i].startsWith(\"js:\")\n ) {\n if (requirements[i].startsWith(\"js:\")) {\n requirements[i] = requirements[i].slice(3);\n }\n await importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"http\")) {\n await importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"cache:\")) {\n //ignore cache\n } else {\n console.log(\"Unprocessed requirements url: \" + requirements[i]);\n }\n }\n } else {\n throw \"unsupported requirements definition\";\n }\n } catch (e) {\n throw \"failed to import required scripts: \" + requirements.toString();\n }\n }\n}\n\nexport async function loadRequirementsInWebworker(requirements) {\n if (\n requirements &&\n (Array.isArray(requirements) || typeof requirements === \"string\")\n ) {\n try {\n if (!Array.isArray(requirements)) {\n requirements = [requirements];\n }\n for (var i = 0; i < requirements.length; i++) {\n if (\n requirements[i].toLowerCase().endsWith(\".css\") ||\n requirements[i].startsWith(\"css:\")\n ) {\n throw \"unable to import css in a webworker\";\n } else if (\n requirements[i].toLowerCase().endsWith(\".js\") ||\n requirements[i].startsWith(\"js:\")\n ) {\n if (requirements[i].startsWith(\"js:\")) {\n requirements[i] = requirements[i].slice(3);\n }\n importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"http\")) {\n importScripts(requirements[i]);\n } else if (requirements[i].startsWith(\"cache:\")) {\n //ignore cache\n } else {\n console.log(\"Unprocessed requirements url: \" + requirements[i]);\n }\n }\n } catch (e) {\n throw \"failed to import required scripts: \" + requirements.toString();\n }\n }\n}\n\nexport function loadRequirements(requirements) {\n if (\n typeof WorkerGlobalScope !== \"undefined\" &&\n self instanceof WorkerGlobalScope\n ) {\n return loadRequirementsInWebworker(requirements);\n } else {\n return loadRequirementsInWindow(requirements);\n }\n}\n\nexport function normalizeConfig(config) {\n config.version = config.version || \"0.1.0\";\n config.description =\n config.description || `[TODO: add description for ${config.name} ]`;\n config.type = config.type || \"rpc-window\";\n config.id = config.id || randId();\n config.target_origin = config.target_origin || \"*\";\n config.allow_execution = config.allow_execution || false;\n // remove functions\n config = Object.keys(config).reduce((p, c) => {\n if (typeof config[c] !== \"function\") p[c] = config[c];\n return p;\n }, {});\n return config;\n}\nexport const typedArrayToDtypeMapping = {\n Int8Array: \"int8\",\n Int16Array: \"int16\",\n Int32Array: \"int32\",\n Uint8Array: \"uint8\",\n Uint16Array: \"uint16\",\n Uint32Array: \"uint32\",\n Float32Array: \"float32\",\n Float64Array: \"float64\",\n Array: \"array\"\n};\n\nconst typedArrayToDtypeKeys = [];\nfor (const arrType of Object.keys(typedArrayToDtypeMapping)) {\n typedArrayToDtypeKeys.push(eval(arrType));\n}\n\nexport function typedArrayToDtype(obj) {\n let dtype = typedArrayToDtypeMapping[obj.constructor.name];\n if (!dtype) {\n const pt = Object.getPrototypeOf(obj);\n for (const arrType of typedArrayToDtypeKeys) {\n if (pt instanceof arrType) {\n dtype = typedArrayToDtypeMapping[arrType.name];\n break;\n }\n }\n }\n return dtype;\n}\n\nfunction cacheUrlInServiceWorker(url) {\n return new Promise(function(resolve, reject) {\n const message = {\n command: \"add\",\n url: url\n };\n if (!navigator.serviceWorker || !navigator.serviceWorker.register) {\n reject(\"Service worker is not supported.\");\n return;\n }\n const messageChannel = new MessageChannel();\n messageChannel.port1.onmessage = function(event) {\n if (event.data && event.data.error) {\n reject(event.data.error);\n } else {\n resolve(event.data && event.data.result);\n }\n };\n\n if (navigator.serviceWorker && navigator.serviceWorker.controller) {\n navigator.serviceWorker.controller.postMessage(message, [\n messageChannel.port2\n ]);\n } else {\n reject(\"Service worker controller is not available\");\n }\n });\n}\n\nexport async function cacheRequirements(requirements) {\n requirements = requirements || [];\n if (!Array.isArray(requirements)) {\n requirements = [requirements];\n }\n for (let req of requirements) {\n //remove prefix\n if (req.startsWith(\"js:\")) req = req.slice(3);\n if (req.startsWith(\"css:\")) req = req.slice(4);\n if (req.startsWith(\"cache:\")) req = req.slice(6);\n if (!req.startsWith(\"http\")) continue;\n\n await cacheUrlInServiceWorker(req).catch(e => {\n console.error(e);\n });\n }\n}\n\nexport function setupServiceWorker(baseUrl, targetOrigin, cacheCallback) {\n // register service worker for offline access\n if (\"serviceWorker\" in navigator) {\n baseUrl = baseUrl || \"/\";\n navigator.serviceWorker.register(baseUrl + \"plugin-service-worker.js\").then(\n function(registration) {\n // Registration was successful\n console.log(\n \"ServiceWorker registration successful with scope: \",\n registration.scope\n );\n },\n function(err) {\n // registration failed :(\n console.log(\"ServiceWorker registration failed: \", err);\n }\n );\n targetOrigin = targetOrigin || \"*\";\n cacheCallback = cacheCallback || cacheRequirements;\n if (cacheCallback && typeof cacheCallback !== \"function\") {\n throw new Error(\"config.cache_requirements must be a function\");\n }\n window.addEventListener(\"message\", function(e) {\n if (targetOrigin === \"*\" || e.origin === targetOrigin) {\n const m = e.data;\n if (m.type === \"cacheRequirements\") {\n cacheCallback(m.requirements);\n }\n }\n });\n }\n}\n\n//#Source https://bit.ly/2neWfJ2\nexport function urlJoin(...args) {\n return args\n .join(\"/\")\n .replace(/[\\/]+/g, \"/\")\n .replace(/^(.+):\\//, \"$1://\")\n .replace(/^file:/, \"file:/\")\n .replace(/\\/(\\?|&|#[^!])/g, \"$1\")\n .replace(/\\?/g, \"&\")\n .replace(\"&\", \"?\");\n}\n\nexport class MessageEmitter {\n constructor(debug) {\n this._event_handlers = {};\n this._once_handlers = {};\n this._debug = debug;\n }\n emit() {\n throw new Error(\"emit is not implemented\");\n }\n on(event, handler) {\n if (!this._event_handlers[event]) {\n this._event_handlers[event] = [];\n }\n this._event_handlers[event].push(handler);\n }\n once(event, handler) {\n handler.___event_run_once = true;\n this.on(event, handler);\n }\n off(event, handler) {\n if (!event && !handler) {\n // remove all events handlers\n this._event_handlers = {};\n } else if (event && !handler) {\n // remove all hanlders for the event\n if (this._event_handlers[event]) this._event_handlers[event] = [];\n } else {\n // remove a specific handler\n if (this._event_handlers[event]) {\n const idx = this._event_handlers[event].indexOf(handler);\n if (idx >= 0) {\n this._event_handlers[event].splice(idx, 1);\n }\n }\n }\n }\n _fire(event, data) {\n if (this._event_handlers[event]) {\n var i = this._event_handlers[event].length;\n while (i--) {\n const handler = this._event_handlers[event][i];\n try {\n handler(data);\n } catch (e) {\n console.error(e);\n } finally {\n if (handler.___event_run_once) {\n this._event_handlers[event].splice(i, 1);\n }\n }\n }\n } else {\n if (this._debug) {\n console.warn(\"unhandled event\", event, data);\n }\n }\n }\n}\n","/**\n * Contains the RPC object used both by the application\n * site, and by each plugin\n */\nimport {\n randId,\n typedArrayToDtype,\n dtypeToTypedArray,\n MessageEmitter\n} from \"./utils.js\";\n\nexport const API_VERSION = \"0.2.3\";\n\nconst ArrayBufferView = Object.getPrototypeOf(\n Object.getPrototypeOf(new Uint8Array())\n).constructor;\n\nfunction _appendBuffer(buffer1, buffer2) {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);\n tmp.set(new Uint8Array(buffer1), 0);\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength);\n return tmp.buffer;\n}\n\nfunction indexObject(obj, is) {\n if (!is) throw new Error(\"undefined index\");\n if (typeof is === \"string\") return indexObject(obj, is.split(\".\"));\n else if (is.length === 0) return obj;\n else return indexObject(obj[is[0]], is.slice(1));\n}\n\n/**\n * RPC object represents a single site in the\n * communication protocol between the application and the plugin\n *\n * @param {Object} connection a special object allowing to send\n * and receive messages from the opposite site (basically it\n * should only provide send() and onMessage() methods)\n */\nexport class RPC extends MessageEmitter {\n constructor(connection, config, codecs) {\n super(config && config.debug);\n this._connection = connection;\n this.config = config || {};\n this._codecs = codecs || {};\n this._object_store = {};\n this._method_weakmap = new WeakMap();\n this._object_weakmap = new WeakMap();\n this._local_api = null;\n this._remote_set = false;\n // make sure there is an execute function\n const name = this.config.name;\n this._connection.execute =\n this._connection.execute ||\n function() {\n throw new Error(`connection.execute not implemented (in \"${name}\")`);\n };\n this._store = new ReferenceStore();\n this._method_refs = new ReferenceStore();\n this._method_refs.onReady(() => {\n this._fire(\"remoteIdle\");\n });\n this._method_refs.onBusy(() => {\n this._fire(\"remoteBusy\");\n });\n this._setupMessageHanlders();\n }\n\n init() {\n this._connection.emit({\n type: \"initialized\",\n config: this.config,\n peer_id: this._connection.peer_id\n });\n }\n\n setConfig(config) {\n if (config)\n for (const k of Object.keys(config)) {\n this.config[k] = config[k];\n }\n }\n /**\n * Set a handler to be called when received a responce from the\n * remote site reporting that the previously provided interface\n * has been successfully set as remote for that site\n *\n * @param {Function} handler\n */\n\n getRemoteCallStack() {\n return this._method_refs.getStack();\n }\n\n /**\n * @returns {Object} set of remote interface methods\n */\n getRemote() {\n return this._remote_interface;\n }\n\n /**\n * Sets the interface of this site making it available to the\n * remote site by sending a message with a set of methods names\n *\n * @param {Object} _interface to set\n */\n setInterface(_interface, config) {\n config = config || {};\n this.config.name = config.name || this.config.name;\n this.config.description = config.description || this.config.description;\n if (this.config.forwarding_functions) {\n for (let func_name of this.config.forwarding_functions) {\n const _remote = this._remote_interface;\n if (_remote[func_name]) {\n if (_interface.constructor === Object) {\n if (!_interface[func_name]) {\n _interface[func_name] = (...args) => {\n _remote[func_name](...args);\n };\n }\n } else if (_interface.constructor.constructor === Function) {\n if (!_interface.constructor.prototype[func_name]) {\n _interface.constructor.prototype[func_name] = (...args) => {\n _remote[func_name](...args);\n };\n }\n }\n }\n }\n }\n this._local_api = _interface;\n if (!this._remote_set) this._fire(\"interfaceAvailable\");\n else this.sendInterface();\n return new Promise(resolve => {\n this.once(\"interfaceSetAsRemote\", resolve);\n });\n }\n\n /**\n * Sends the actual interface to the remote site upon it was\n * updated or by a special request of the remote site\n */\n sendInterface() {\n if (!this._local_api) {\n throw new Error(\"interface is not set.\");\n }\n this._encode(this._local_api, true).then(api => {\n this._connection.emit({ type: \"setInterface\", api: api });\n });\n }\n\n _disposeObject(objectId) {\n if (this._object_store[objectId]) {\n delete this._object_store[objectId];\n } else {\n throw new Error(`Object (id=${objectId}) not found.`);\n }\n }\n\n disposeObject(obj) {\n return new Promise((resolve, reject) => {\n if (this._object_weakmap.has(obj)) {\n const objectId = this._object_weakmap.get(obj);\n this._connection.once(\"disposed\", data => {\n if (data.error) reject(new Error(data.error));\n else resolve();\n });\n this._connection.emit({\n type: \"disposeObject\",\n object_id: objectId\n });\n } else {\n throw new Error(\"Invalid object\");\n }\n });\n }\n\n /**\n * Handles a message from the remote site\n */\n _setupMessageHanlders() {\n this._connection.on(\"init\", this.init);\n this._connection.on(\"execute\", data => {\n Promise.resolve(this._connection.execute(data.code))\n .then(() => {\n this._connection.emit({ type: \"executed\" });\n })\n .catch(e => {\n console.error(e);\n this._connection.emit({\n type: \"executed\",\n error: String(e)\n });\n });\n });\n\n this._connection.on(\"method\", async data => {\n let resolve, reject, method, method_this, args, result;\n try {\n if (data.promise) {\n [resolve, reject] = await this._unwrap(data.promise, false);\n }\n const _interface = this._object_store[data.object_id];\n method = indexObject(_interface, data.name);\n if (data.name.includes(\".\")) {\n const tmp = data.name.split(\".\");\n const intf_index = tmp.slice(0, tmp.length - 1).join(\".\");\n method_this = indexObject(_interface, intf_index);\n } else {\n method_this = _interface;\n }\n args = await this._unwrap(data.args, true);\n if (data.promise) {\n result = method.apply(method_this, args);\n if (\n result instanceof Promise ||\n (method.constructor && method.constructor.name === \"AsyncFunction\")\n ) {\n result.then(resolve).catch(reject);\n } else {\n resolve(result);\n }\n } else {\n method.apply(method_this, args);\n }\n } catch (err) {\n console.error(this.config.name, err);\n if (reject) {\n reject(err);\n }\n }\n });\n\n this._connection.on(\"callback\", async data => {\n let resolve, reject, method, args, result;\n try {\n if (data.promise) {\n [resolve, reject] = await this._unwrap(data.promise, false);\n }\n if (data.promise) {\n method = this._store.fetch(data.id);\n args = await this._unwrap(data.args, true);\n if (!method) {\n throw new Error(\n \"Callback function can only called once, if you want to call a function for multiple times, please make it as a plugin api function. See https://imjoy.io/docs for more details.\"\n );\n }\n result = method.apply(null, args);\n if (\n result instanceof Promise ||\n (method.constructor && method.constructor.name === \"AsyncFunction\")\n ) {\n result.then(resolve).catch(reject);\n } else {\n resolve(result);\n }\n } else {\n method = this._store.fetch(data.id);\n args = await this._unwrap(data.args, true);\n if (!method) {\n throw new Error(\n \"Please notice that callback function can only called once, if you want to call a function for multiple times, please make it as a plugin api function. See https://imjoy.io/docs for more details.\"\n );\n }\n method.apply(null, args);\n }\n } catch (err) {\n console.error(this.config.name, err);\n if (reject) {\n reject(err);\n }\n }\n });\n this._connection.on(\"disposeObject\", data => {\n try {\n this._disposeObject(data.object_id);\n this._connection.emit({\n type: \"disposed\"\n });\n } catch (e) {\n console.error(e);\n this._connection.emit({\n type: \"disposed\",\n error: String(e)\n });\n }\n });\n this._connection.on(\"setInterface\", data => {\n this._setRemoteInterface(data.api);\n });\n this._connection.on(\"getInterface\", () => {\n this._fire(\"getInterface\");\n if (this._local_api) {\n this.sendInterface();\n } else {\n this.once(\"interfaceAvailable\", () => {\n this.sendInterface();\n });\n }\n });\n this._connection.on(\"interfaceSetAsRemote\", () => {\n this._remote_set = true;\n this._fire(\"interfaceSetAsRemote\");\n });\n this._connection.on(\"disconnect\", () => {\n this._fire(\"beforeDisconnect\");\n this._connection.disconnect();\n this._fire(\"disconnected\");\n });\n }\n\n /**\n * Sends a requests to the remote site asking it to provide its\n * current interface\n */\n requestRemote() {\n this._connection.emit({ type: \"getInterface\" });\n }\n\n _ndarray(typedArray, shape, dtype) {\n const _dtype = typedArrayToDtype(typedArray);\n if (dtype && dtype !== _dtype) {\n throw \"dtype doesn't match the type of the array: \" +\n _dtype +\n \" != \" +\n dtype;\n }\n shape = shape || [typedArray.length];\n return {\n _rtype: \"ndarray\",\n _rvalue: typedArray.buffer,\n _rshape: shape,\n _rdtype: _dtype\n };\n }\n\n /**\n * Sets the new remote interface provided by the other site\n *\n * @param {Array} names list of function names\n */\n _setRemoteInterface(api) {\n this._decode(api).then(intf => {\n // update existing interface instead of recreating it\n // this will preserve the object reference\n if (this._remote_interface) {\n // clear the interface\n for (let k in this._remote_interface) delete this._remote_interface[k];\n // then assign the new interfaces\n Object.assign(this._remote_interface, intf);\n } else this._remote_interface = intf;\n this._fire(\"remoteReady\");\n this._reportRemoteSet();\n });\n }\n\n /**\n * Generates the wrapped function corresponding to a single remote\n * method. When the generated function is called, it will send the\n * corresponding message to the remote site asking it to execute\n * the particular method of its interface\n *\n * @param {String} name of the remote method\n *\n * @returns {Function} wrapped remote method\n */\n _genRemoteMethod(targetId, name, objectId) {\n const me = this;\n const remoteMethod = function() {\n return new Promise(async (resolve, reject) => {\n let id = null;\n try {\n id = me._method_refs.put(objectId ? objectId + \"/\" + name : name);\n const wrapped_resolve = function() {\n if (id !== null) me._method_refs.fetch(id);\n return resolve.apply(this, arguments);\n };\n const wrapped_reject = function() {\n if (id !== null) me._method_refs.fetch(id);\n return reject.apply(this, arguments);\n };\n\n const encodedPromise = await me._wrap([\n wrapped_resolve,\n wrapped_reject\n ]);\n\n // store the key id for removing them from the reference store together\n wrapped_resolve.__promise_pair = encodedPromise[1]._rvalue;\n wrapped_reject.__promise_pair = encodedPromise[0]._rvalue;\n\n let args = Array.prototype.slice.call(arguments);\n const argLength = args.length;\n // if the last argument is an object, mark it as kwargs\n const withKwargs =\n argLength > 0 &&\n typeof args[argLength - 1] === \"object\" &&\n args[argLength - 1] !== null &&\n args[argLength - 1]._rkwargs;\n if (withKwargs) delete args[argLength - 1]._rkwargs;\n if (\n name === \"register\" ||\n name === \"registerService\" ||\n name === \"register_service\" ||\n name === \"export\" ||\n name === \"on\"\n ) {\n args = await me._wrap(args, true);\n } else {\n args = await me._wrap(args);\n }\n const transferables = args.__transferables__;\n if (transferables) delete args.__transferables__;\n me._connection.emit(\n {\n type: \"method\",\n target_id: targetId,\n name: name,\n object_id: objectId,\n args: args,\n promise: encodedPromise,\n with_kwargs: withKwargs\n },\n transferables\n );\n } catch (e) {\n if (id) me._method_refs.fetch(id);\n reject(\n `Failed to exectue remote method (interface: ${objectId ||\n me.id}, method: ${name}), error: ${e}`\n );\n }\n });\n };\n remoteMethod.__remote_method = true;\n return remoteMethod;\n }\n\n /**\n * Sends a responce reporting that interface just provided by the\n * remote site was successfully set by this site as remote\n */\n _reportRemoteSet() {\n this._connection.emit({ type: \"interfaceSetAsRemote\" });\n }\n\n /**\n * Prepares the provided set of remote method arguments for\n * sending to the remote site, replaces all the callbacks with\n * identifiers\n *\n * @param {Array} args to wrap\n *\n * @returns {Array} wrapped arguments\n */\n async _encode(aObject, asInterface, objectId) {\n const aType = typeof aObject;\n if (\n aType === \"number\" ||\n aType === \"string\" ||\n aType === \"boolean\" ||\n aObject === null ||\n aObject === undefined ||\n aObject instanceof ArrayBuffer\n ) {\n return aObject;\n }\n\n let bObject;\n if (typeof aObject === \"function\") {\n if (asInterface) {\n if (!objectId) throw new Error(\"objectId is not specified.\");\n bObject = {\n _rtype: \"interface\",\n _rtarget_id: this._connection.peer_id,\n _rintf: objectId,\n _rvalue: asInterface\n };\n this._method_weakmap.set(aObject, bObject);\n } else if (this._method_weakmap.has(aObject)) {\n bObject = this._method_weakmap.get(aObject);\n } else {\n const cid = this._store.put(aObject);\n bObject = {\n _rtype: \"callback\",\n _rtarget_id: this._connection.peer_id,\n _rname: (aObject.constructor && aObject.constructor.name) || cid,\n _rvalue: cid\n };\n }\n return bObject;\n }\n\n // skip if already encoded\n if (aObject.constructor instanceof Object && aObject._rtype) {\n // make sure the interface functions are encoded\n if (aObject._rintf) {\n const temp = aObject._rtype;\n delete aObject._rtype;\n\n bObject = await this._encode(aObject, asInterface, objectId);\n bObject._rtype = temp;\n } else {\n bObject = aObject;\n }\n return bObject;\n }\n\n const transferables = [];\n const _transfer = aObject._transfer;\n const isarray = Array.isArray(aObject);\n\n for (let tp of Object.keys(this._codecs)) {\n const codec = this._codecs[tp];\n if (codec.encoder && aObject instanceof codec.type) {\n // TODO: what if multiple encoders found\n let encodedObj = await Promise.resolve(codec.encoder(aObject));\n if (encodedObj && !encodedObj._rtype) encodedObj._rtype = codec.name;\n // encode the functions in the interface object\n if (encodedObj && encodedObj._rintf) {\n const temp = encodedObj._rtype;\n delete encodedObj._rtype;\n encodedObj = await this._encode(encodedObj, asInterface, objectId);\n encodedObj._rtype = temp;\n }\n bObject = encodedObj;\n return bObject;\n }\n }\n\n if (\n /*global tf*/\n typeof tf !== \"undefined\" &&\n tf.Tensor &&\n aObject instanceof tf.Tensor\n ) {\n const v_buffer = aObject.dataSync();\n if (aObject._transfer || _transfer) {\n transferables.push(v_buffer.buffer);\n delete aObject._transfer;\n }\n bObject = {\n _rtype: \"ndarray\",\n _rvalue: v_buffer.buffer,\n _rshape: aObject.shape,\n _rdtype: aObject.dtype\n };\n } else if (\n /*global nj*/\n typeof nj !== \"undefined\" &&\n nj.NdArray &&\n aObject instanceof nj.NdArray\n ) {\n const dtype = typedArrayToDtype(aObject.selection.data);\n if (aObject._transfer || _transfer) {\n transferables.push(aObject.selection.data.buffer);\n delete aObject._transfer;\n }\n bObject = {\n _rtype: \"ndarray\",\n _rvalue: aObject.selection.data.buffer,\n _rshape: aObject.shape,\n _rdtype: dtype\n };\n } else if (aObject instanceof Error) {\n console.error(aObject);\n bObject = { _rtype: \"error\", _rvalue: aObject.toString() };\n } else if (typeof File !== \"undefined\" && aObject instanceof File) {\n bObject = {\n _rtype: \"file\",\n _rvalue: aObject,\n _rpath: aObject._path || aObject.webkitRelativePath\n };\n }\n // send objects supported by structure clone algorithm\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\n else if (\n aObject !== Object(aObject) ||\n aObject instanceof Boolean ||\n aObject instanceof String ||\n aObject instanceof Date ||\n aObject instanceof RegExp ||\n aObject instanceof ImageData ||\n (typeof FileList !== \"undefined\" && aObject instanceof FileList) ||\n (typeof FileSystemDirectoryHandle !== \"undefined\" &&\n aObject instanceof FileSystemDirectoryHandle) ||\n (typeof FileSystemFileHandle !== \"undefined\" &&\n aObject instanceof FileSystemFileHandle) ||\n (typeof FileSystemHandle !== \"undefined\" &&\n aObject instanceof FileSystemHandle) ||\n (typeof FileSystemWritableFileStream !== \"undefined\" &&\n aObject instanceof FileSystemWritableFileStream)\n ) {\n bObject = aObject;\n // TODO: avoid object such as DynamicPlugin instance.\n } else if (typeof File !== \"undefined\" && aObject instanceof File) {\n bObject = {\n _rtype: \"file\",\n _rname: aObject.name,\n _rmime: aObject.type,\n _rvalue: aObject,\n _rpath: aObject._path || aObject.webkitRelativePath\n };\n } else if (aObject instanceof Blob) {\n bObject = { _rtype: \"blob\", _rvalue: aObject };\n } else if (aObject instanceof ArrayBufferView) {\n if (aObject._transfer || _transfer) {\n transferables.push(aObject.buffer);\n delete aObject._transfer;\n }\n const dtype = typedArrayToDtype(aObject);\n bObject = {\n _rtype: \"typedarray\",\n _rvalue: aObject.buffer,\n _rdtype: dtype\n };\n } else if (aObject instanceof DataView) {\n if (aObject._transfer || _transfer) {\n transferables.push(aObject.buffer);\n delete aObject._transfer;\n }\n bObject = { _rtype: \"memoryview\", _rvalue: aObject.buffer };\n } else if (aObject instanceof Set) {\n bObject = {\n _rtype: \"set\",\n _rvalue: await this._encode(Array.from(aObject), asInterface)\n };\n } else if (aObject instanceof Map) {\n bObject = {\n _rtype: \"orderedmap\",\n _rvalue: await this._encode(Array.from(aObject), asInterface)\n };\n } else if (\n aObject.constructor instanceof Object ||\n Array.isArray(aObject)\n ) {\n bObject = isarray ? [] : {};\n let keys;\n // an object/array\n if (aObject.constructor === Object || Array.isArray(aObject)) {\n keys = Object.keys(aObject);\n }\n // a class\n else if (aObject.constructor === Function) {\n throw new Error(\"Please instantiate the class before exportting it.\");\n }\n // instance of a class\n else if (aObject.constructor.constructor === Function) {\n keys = Object.getOwnPropertyNames(\n Object.getPrototypeOf(aObject)\n ).concat(Object.keys(aObject));\n // TODO: use a proxy object to represent the actual object\n // always encode class instance as interface\n asInterface = true;\n } else {\n throw Error(\"Unsupported interface type\");\n }\n\n let hasFunction = false;\n // encode interfaces\n if (aObject._rintf || asInterface) {\n if (!objectId) {\n if (typeof aObject._rintf === \"string\" && aObject._rintf.length > 0) {\n objectId = aObject._rintf; // enable custom object id\n } else {\n objectId = randId();\n }\n // Note: object with the same id will be overwritten\n if (this._object_store[objectId])\n console.warn(\n `Overwritting interface object with the same id: ${objectId}`\n );\n this._object_store[objectId] = aObject;\n }\n for (let k of keys) {\n if (k === \"constructor\") continue;\n if (k.startsWith(\"_\")) {\n continue;\n }\n bObject[k] = await this._encode(\n aObject[k],\n typeof asInterface === \"string\" ? asInterface + \".\" + k : k,\n objectId\n );\n if (typeof aObject[k] === \"function\") {\n hasFunction = true;\n }\n }\n // object id for dispose the object remotely\n if (hasFunction) bObject._rintf = objectId;\n // remove interface when closed\n if (aObject.on && typeof aObject.on === \"function\") {\n aObject.on(\"close\", () => {\n delete this._object_store[objectId];\n });\n }\n } else {\n for (let k of keys) {\n if ([\"hasOwnProperty\", \"constructor\"].includes(k)) continue;\n bObject[k] = await this._encode(aObject[k]);\n }\n }\n // for example, browserFS object\n } else if (typeof aObject === \"object\") {\n const keys = Object.getOwnPropertyNames(\n Object.getPrototypeOf(aObject)\n ).concat(Object.keys(aObject));\n const objectId = randId();\n\n for (let k of keys) {\n if ([\"hasOwnProperty\", \"constructor\"].includes(k)) continue;\n // encode as interface\n bObject[k] = await this._encode(aObject[k], k, bObject);\n }\n // object id, used for dispose the object\n bObject._rintf = objectId;\n } else {\n throw \"imjoy-rpc: Unsupported data type:\" + aObject;\n }\n\n if (transferables.length > 0) {\n bObject.__transferables__ = transferables;\n }\n if (!bObject) {\n throw new Error(\"Failed to encode object\");\n }\n return bObject;\n }\n\n async _decode(aObject, withPromise) {\n if (!aObject) {\n return aObject;\n }\n let bObject;\n if (aObject[\"_rtype\"]) {\n if (\n this._codecs[aObject._rtype] &&\n this._codecs[aObject._rtype].decoder\n ) {\n if (aObject._rintf) {\n const temp = aObject._rtype;\n delete aObject._rtype;\n aObject = await this._decode(aObject, withPromise);\n aObject._rtype = temp;\n }\n bObject = await Promise.resolve(\n this._codecs[aObject._rtype].decoder(aObject)\n );\n } else if (aObject._rtype === \"callback\") {\n bObject = this._genRemoteCallback(\n aObject._rtarget_id,\n aObject._rvalue,\n withPromise\n );\n } else if (aObject._rtype === \"interface\") {\n bObject = this._genRemoteMethod(\n aObject._rtarget_id,\n aObject._rvalue,\n aObject._rintf\n );\n } else if (aObject._rtype === \"ndarray\") {\n /*global nj tf*/\n //create build array/tensor if used in the plugin\n if (typeof nj !== \"undefined\" && nj.array) {\n if (Array.isArray(aObject._rvalue)) {\n aObject._rvalue = aObject._rvalue.reduce(_appendBuffer);\n }\n bObject = nj\n .array(new Uint8(aObject._rvalue), aObject._rdtype)\n .reshape(aObject._rshape);\n } else if (typeof tf !== \"undefined\" && tf.Tensor) {\n if (Array.isArray(aObject._rvalue)) {\n aObject._rvalue = aObject._rvalue.reduce(_appendBuffer);\n }\n const arraytype = dtypeToTypedArray[aObject._rdtype];\n bObject = tf.tensor(\n new arraytype(aObject._rvalue),\n aObject._rshape,\n aObject._rdtype\n );\n } else {\n //keep it as regular if transfered to the main app\n bObject = aObject;\n }\n } else if (aObject._rtype === \"error\") {\n bObject = new Error(aObject._rvalue);\n } else if (aObject._rtype === \"file\") {\n if (aObject._rvalue instanceof File) {\n bObject = aObject._rvalue;\n //patch _path\n bObject._path = aObject._rpath;\n } else {\n bObject = new File([aObject._rvalue], aObject._rname, {\n type: aObject._rmime\n });\n bObject._path = aObject._rpath;\n }\n } else if (aObject._rtype === \"typedarray\") {\n const arraytype = dtypeToTypedArray[aObject._rdtype];\n if (!arraytype)\n throw new Error(\"unsupported dtype: \" + aObject._rdtype);\n bObject = new arraytype(aObject._rvalue);\n } else if (aObject._rtype === \"memoryview\") {\n bObject = new DataView(aObject._rvalue);\n } else if (aObject._rtype === \"blob\") {\n if (aObject._rvalue instanceof Blob) {\n bObject = aObject._rvalue;\n } else {\n bObject = new Blob([aObject._rvalue], { type: aObject._rmime });\n }\n } else if (aObject._rtype === \"orderedmap\") {\n bObject = new Map(await this._decode(aObject._rvalue, withPromise));\n } else if (aObject._rtype === \"set\") {\n bObject = new Set(await this._decode(aObject._rvalue, withPromise));\n } else {\n // make sure all the interface functions are decoded\n if (aObject._rintf) {\n const temp = aObject._rtype;\n delete aObject._rtype;\n bObject = await this._decode(aObject, withPromise);\n bObject._rtype = temp;\n } else bObject = aObject;\n }\n } else if (aObject.constructor === Object || Array.isArray(aObject)) {\n const isarray = Array.isArray(aObject);\n bObject = isarray ? [] : {};\n for (let k of Object.keys(aObject)) {\n if (isarray || aObject.hasOwnProperty(k)) {\n const v = aObject[k];\n bObject[k] = await this._decode(v, withPromise);\n }\n }\n } else {\n bObject = aObject;\n }\n if (bObject === undefined) {\n throw new Error(\"Failed to decode object\");\n }\n // store the object id for dispose\n if (aObject._rintf) {\n this._object_weakmap.set(bObject, aObject._rintf);\n }\n return bObject;\n }\n\n async _wrap(args, asInterface) {\n return await this._encode(args, asInterface);\n }\n\n /**\n * Unwraps the set of arguments delivered from the remote site,\n * replaces all callback identifiers with a function which will\n * initiate sending that callback identifier back to other site\n *\n * @param {Object} args to unwrap\n *\n * @param {Boolean} withPromise is true means this the callback should contain a promise\n *\n * @returns {Array} unwrapped args\n */\n async _unwrap(args, withPromise) {\n return await this._decode(args, withPromise);\n }\n\n /**\n * Generates the wrapped function corresponding to a single remote\n * callback. When the generated function is called, it will send\n * the corresponding message to the remote site asking it to\n * execute the particular callback previously saved during a call\n * by the remote site a method from the interface of this site\n *\n * @param {Number} id of the remote callback to execute\n * @param {Number} argNum argument index of the callback\n * @param {Boolean} withPromise is true means this the callback should contain a promise\n *\n * @returns {Function} wrapped remote callback\n */\n _genRemoteCallback(targetId, cid, withPromise) {\n const me = this;\n let remoteCallback;\n if (withPromise) {\n remoteCallback = function() {\n return new Promise(async (resolve, reject) => {\n const args = await me._wrap(Array.prototype.slice.call(arguments));\n const argLength = args.length;\n // if the last argument is an object, mark it as kwargs\n const withKwargs =\n argLength > 0 &&\n typeof args[argLength - 1] === \"object\" &&\n args[argLength - 1] !== null &&\n args[argLength - 1]._rkwargs;\n if (withKwargs) delete args[argLength - 1]._rkwargs;\n const transferables = args.__transferables__;\n if (transferables) delete args.__transferables__;\n\n const encodedPromise = await me._wrap([resolve, reject]);\n // store the key id for removing them from the reference store together\n resolve.__promise_pair = encodedPromise[1]._rvalue;\n reject.__promise_pair = encodedPromise[0]._rvalue;\n try {\n me._connection.emit(\n {\n type: \"callback\",\n target_id: targetId,\n id: cid,\n args: args,\n promise: encodedPromise,\n with_kwargs: withKwargs\n },\n transferables\n );\n } catch (e) {\n reject(`Failed to exectue remote callback ( id: ${cid}).`);\n }\n });\n };\n return remoteCallback;\n } else {\n remoteCallback = async function() {\n const args = await me._wrap(Array.prototype.slice.call(arguments));\n const argLength = args.length;\n // if the last argument is an object, mark it as kwargs\n const withKwargs =\n argLength > 0 &&\n typeof args[argLength - 1] === \"object\" &&\n args[argLength - 1] !== null &&\n args[argLength - 1]._rkwargs;\n if (withKwargs) delete args[argLength - 1]._rkwargs;\n const transferables = args.__transferables__;\n if (transferables) delete args.__transferables__;\n return me._connection.emit(\n {\n type: \"callback\",\n target_id: targetId,\n id: cid,\n args: args,\n with_kwargs: withKwargs\n },\n transferables\n );\n };\n return remoteCallback;\n }\n }\n\n reset() {\n this._event_handlers = {};\n this._once_handlers = {};\n this._remote_interface = null;\n this._object_store = {};\n this._method_weakmap = new WeakMap();\n this._object_weakmap = new WeakMap();\n this._local_api = null;\n this._store = new ReferenceStore();\n this._method_refs = new ReferenceStore();\n }\n\n /**\n * Sends the notification message and breaks the connection\n */\n disconnect() {\n this._connection.emit({ type: \"disconnect\" });\n this.reset();\n setTimeout(() => {\n this._connection.disconnect();\n }, 2000);\n }\n}\n\n/**\n * ReferenceStore is a special object which stores other objects\n * and provides the references (number) instead. This reference\n * may then be sent over a json-based communication channel (IPC\n * to another Node.js process or a message to the Worker). Other\n * site may then provide the reference in the responce message\n * implying the given object should be activated.\n *\n * Primary usage for the ReferenceStore is a storage for the\n * callbacks, which therefore makes it possible to initiate a\n * callback execution by the opposite site (which normally cannot\n * directly execute functions over the communication channel).\n *\n * Each stored object can only be fetched once and is not\n * available for the second time. Each stored object must be\n * fetched, since otherwise it will remain stored forever and\n * consume memory.\n *\n * Stored object indeces are simply the numbers, which are however\n * released along with the objects, and are later reused again (in\n * order to postpone the overflow, which should not likely happen,\n * but anyway).\n */\nclass ReferenceStore {\n constructor() {\n this._store = {}; // stored object\n this._indices = [0]; // smallest available indices\n this._readyHandler = function() {};\n this._busyHandler = function() {};\n this._readyHandler();\n }\n\n /**\n * call handler when the store is empty\n *\n * @param {FUNCTION} id of a handler\n */\n onReady(readyHandler) {\n this._readyHandler = readyHandler || function() {};\n }\n\n /**\n * call handler when the store is not empty\n *\n * @param {FUNCTION} id of a handler\n */\n onBusy(busyHandler) {\n this._busyHandler = busyHandler || function() {};\n }\n\n /**\n * get the length of the store\n *\n */\n getStack() {\n return Object.keys(this._store).length;\n }\n\n /**\n * @function _genId() generates the new reference id\n *\n * @returns {Number} smallest available id and reserves it\n */\n _genId() {\n let id;\n if (this._indices.length === 1) {\n id = this._indices[0]++;\n } else {\n id = this._indices.shift();\n }\n\n return id;\n }\n\n /**\n * Releases the given reference id so that it will be available by\n * another object stored\n *\n * @param {Number} id to release\n */\n _releaseId(id) {\n for (let i = 0; i < this._indices.length; i++) {\n if (id < this._indices[i]) {\n this._indices.splice(i, 0, id);\n break;\n }\n }\n\n // cleaning-up the sequence tail\n for (let i = this._indices.length - 1; i >= 0; i--) {\n if (this._indices[i] - 1 === this._indices[i - 1]) {\n this._indices.pop();\n } else {\n break;\n }\n }\n }\n\n /**\n * Stores the given object and returns the refernce id instead\n *\n * @param {Object} obj to store\n *\n * @returns {Number} reference id of the stored object\n */\n put(obj) {\n if (this._busyHandler && Object.keys(this._store).length === 0) {\n this._busyHandler();\n }\n const id = this._genId();\n this._store[id] = obj;\n return id;\n }\n\n /**\n * Retrieves previously stored object and releases its reference\n *\n * @param {Number} id of an object to retrieve\n */\n fetch(id) {\n const obj = this._store[id];\n if (obj && !obj.__remote_method) {\n delete this._store[id];\n this._releaseId(id);\n if (this._readyHandler && Object.keys(this._store).length === 0) {\n this._readyHandler();\n }\n }\n if (obj && obj.__promise_pair) {\n this.fetch(obj.__promise_pair);\n }\n return obj;\n }\n}\n","/**\n * Core plugin script loaded into the plugin process/thread.\n *\n * Initializes the plugin-site API global methods.\n */\nimport { RPC } from \"./rpc.js\";\n\nexport function connectRPC(connection, config) {\n config = config || {};\n const codecs = {};\n\n const rpc = new RPC(connection, config, codecs);\n rpc.on(\"getInterface\", function() {\n launchConnected();\n });\n\n rpc.on(\"remoteReady\", function() {\n const api = rpc.getRemote() || {};\n api.registerCodec = function(config) {\n if (!config[\"name\"] || (!config[\"encoder\"] && !config[\"decoder\"])) {\n throw new Error(\n \"Invalid codec format, please make sure you provide a name, type, encoder and decoder.\"\n );\n } else {\n if (config.type) {\n for (let k of Object.keys(codecs)) {\n if (codecs[k].type === config.type || k === config.name) {\n delete codecs[k];\n console.warn(\"Remove duplicated codec: \" + k);\n }\n }\n }\n codecs[config[\"name\"]] = config;\n }\n };\n api.init = function(config) {\n // register a minimal plugin api\n rpc.setInterface({ setup() {} }, config);\n };\n api.disposeObject = function(obj) {\n rpc.disposeObject(obj);\n };\n api.export = function(_interface, config) {\n rpc.setInterface(_interface, config);\n };\n api.onLoad = function(handler) {\n handler = checkHandler(handler);\n if (connected) {\n handler();\n } else {\n connectedHandlers.push(handler);\n }\n };\n api.dispose = function(_interface) {\n rpc.disconnect();\n };\n api._rpc = rpc;\n\n if (\n typeof WorkerGlobalScope !== \"undefined\" &&\n self instanceof WorkerGlobalScope\n ) {\n self.api = api;\n self.postMessage({\n type: \"imjoy_remote_api_ready\"\n });\n self.dispatchEvent(\n new CustomEvent(\"imjoy_remote_api_ready\", { detail: api })\n );\n } else if (typeof window) {\n window.dispatchEvent(\n new CustomEvent(\"imjoy_remote_api_ready\", { detail: api })\n );\n }\n });\n\n let connected = false;\n const connectedHandlers = [];\n\n const launchConnected = function() {\n if (!connected) {\n connected = true;\n\n let handler;\n while ((handler = connectedHandlers.pop())) {\n handler();\n }\n }\n };\n\n const checkHandler = function(handler) {\n const type = typeof handler;\n if (type !== \"function\") {\n const msg =\n \"A function may only be subsribed to the event, \" +\n type +\n \" was provided instead\";\n throw new Error(msg);\n }\n return handler;\n };\n\n return rpc;\n}\n","/**\n * Contains the routines loaded by the plugin Worker under web-browser.\n *\n * Initializes the web environment version of the platform-dependent\n * connection object for the plugin site\n */\nimport { connectRPC } from \"./pluginCore.js\";\nimport { API_VERSION } from \"./rpc.js\";\nimport { MessageEmitter, loadRequirementsInWebworker } from \"./utils.js\";\n\n// make sure this runs inside a webworker\nif (\n typeof WorkerGlobalScope === \"undefined\" ||\n !self ||\n !(self instanceof WorkerGlobalScope)\n) {\n throw new Error(\"This script can only loaded in a webworker\");\n}\n\nasync function executeEsModule(content) {\n const dataUri =\n \"data:text/javascript;charset=utf-8,\" + encodeURIComponent(content);\n await import(/* webpackIgnore: true */ dataUri);\n}\n\n/**\n * Connection object provided to the RPC constructor,\n * plugin site implementation for the web-based environment.\n * Global will be then cleared to prevent exposure into the\n * Worker, so we put this local connection object into a closure\n */\nclass Connection extends MessageEmitter {\n constructor(config) {\n super(config && config.debug);\n this.config = config || {};\n }\n connect() {\n self.addEventListener(\"message\", e => {\n this._fire(e.data.type, e.data);\n });\n this.emit({\n type: \"initialized\",\n config: this.config\n });\n }\n disconnect() {\n this._fire(\"beforeDisconnect\");\n self.close();\n this._fire(\"disconnected\");\n }\n emit(data) {\n let transferables = undefined;\n if (data.__transferables__) {\n transferables = data.__transferables__;\n delete data.__transferables__;\n }\n self.postMessage(data, transferables);\n }\n async execute(code) {\n if (code.type === \"requirements\") {\n await loadRequirementsInWebworker(code.requirements);\n } else if (code.type === \"script\") {\n try {\n if (code.attrs.type === \"module\") {\n await executeEsModule(code.content);\n } else {\n eval(code.content);\n }\n } catch (e) {\n console.error(e.message, e.stack);\n throw e;\n }\n } else {\n throw \"unsupported code type.\";\n }\n if (code.type === \"requirements\") {\n self.postMessage({\n type: \"cacheRequirements\",\n requirements: code.requirements\n });\n }\n }\n}\nconst config = {\n type: \"web-worker\",\n dedicated_thread: true,\n allow_execution: true,\n lang: \"javascript\",\n api_version: API_VERSION\n};\nconst conn = new Connection(config);\nconn.on(\"connectRPC\", data => {\n connectRPC(conn, Object.assign(data.config, config));\n});\nconn.connect();\nself.postMessage({\n type: \"worker-ready\"\n});\n"],"sourceRoot":""}