forked from tauri-apps/plugins-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-iife.js
1 lines (1 loc) · 2.37 KB
/
api-iife.js
1
if("__TAURI__"in window){var __TAURI_PLUGIN_WEBSOCKET__=function(){"use strict";function e(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)}function t(e,t,r,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(e,r):n?n.value=r:t.set(e,r),r}var r,s,n;"function"==typeof SuppressedError&&SuppressedError;class i{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,r.set(this,(()=>{})),s.set(this,0),n.set(this,{}),this.id=function(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}((({message:i,id:a})=>{if(a===e(this,s,"f")){t(this,s,a+1,"f"),e(this,r,"f").call(this,i);const o=Object.keys(e(this,n,"f"));if(o.length>0){let t=a+1;for(const s of o.sort()){if(parseInt(s)!==t)break;{const i=e(this,n,"f")[s];delete e(this,n,"f")[s],e(this,r,"f").call(this,i),t+=1}}}}else e(this,n,"f")[a.toString()]=i}))}set onmessage(e){t(this,r,e,"f")}get onmessage(){return e(this,r,"f")}toJSON(){return`__CHANNEL__:${this.id}`}}async function a(e,t={},r){return window.__TAURI_INTERNALS__.invoke(e,t,r)}r=new WeakMap,s=new WeakMap,n=new WeakMap;class o{constructor(e,t){this.id=e,this.listeners=t}static async connect(e,t){const r=[],s=new i;return s.onmessage=e=>{r.forEach((t=>t(e)))},t?.headers&&(t.headers=Array.from(new Headers(t.headers).entries())),await a("plugin:websocket|connect",{url:e,onMessage:s,config:t}).then((e=>new o(e,r)))}addListener(e){this.listeners.push(e)}async send(e){let t;if("string"==typeof e)t={type:"Text",data:e};else if("object"==typeof e&&"type"in e)t=e;else{if(!Array.isArray(e))throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");t={type:"Binary",data:e}}return await a("plugin:websocket|send",{id:this.id,message:t})}async disconnect(){return await this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})}}return o}();Object.defineProperty(window.__TAURI__,"websocket",{value:__TAURI_PLUGIN_WEBSOCKET__})}