mirror of
https://github.com/tauri-apps/tauri-plugin-websocket.git
synced 2026-01-31 00:35:19 +01:00
fix(deps): update tauri monorepo (#815)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/7288671708 Co-authored-by: FabianLars <FabianLars@users.noreply.github.com>
This commit is contained in:
71
dist-js/index.min.js
vendored
71
dist-js/index.min.js
vendored
@@ -1,6 +1,65 @@
|
||||
var d$1=Object.defineProperty;var e=(c,a)=>{for(var b in a)d$1(c,b,{get:a[b],enumerable:!0});};
|
||||
|
||||
var u={};e(u,{convertFileSrc:()=>d,invoke:()=>_,transformCallback:()=>s});function l(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function s(e,r=!1){let n=l(),t=`_${n}`;return Object.defineProperty(window,t,{value:o=>(r&&Reflect.deleteProperty(window,t),e?.(o)),writable:!1,configurable:!0}),n}async function _(e,r={}){return new Promise((n,t)=>{let o=s(i=>{n(i),Reflect.deleteProperty(window,`_${c}`);},!0),c=s(i=>{t(i),Reflect.deleteProperty(window,`_${o}`);},!0);window.__TAURI_IPC__({cmd:e,callback:o,error:c,...r});})}function d(e,r="asset"){return window.__TAURI__.convertFileSrc(e,r)}
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
/** @ignore */
|
||||
function uid() {
|
||||
return window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||
}
|
||||
/**
|
||||
* Transforms a callback function to a string identifier that can be passed to the backend.
|
||||
* The backend uses the identifier to `eval()` the callback.
|
||||
*
|
||||
* @return A unique identifier associated with the callback function.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function transformCallback(callback, once = false) {
|
||||
const identifier = uid();
|
||||
const prop = `_${identifier}`;
|
||||
Object.defineProperty(window, prop, {
|
||||
value: (result) => {
|
||||
if (once) {
|
||||
Reflect.deleteProperty(window, prop);
|
||||
}
|
||||
return callback?.(result);
|
||||
},
|
||||
writable: false,
|
||||
configurable: true
|
||||
});
|
||||
return identifier;
|
||||
}
|
||||
/**
|
||||
* Sends a message to the backend.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { invoke } from '@tauri-apps/api/tauri';
|
||||
* await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
|
||||
* ```
|
||||
*
|
||||
* @param cmd The command name.
|
||||
* @param args The optional arguments to pass to the command.
|
||||
* @return A promise resolving or rejecting to the backend response.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function invoke(cmd, args = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const callback = transformCallback((e) => {
|
||||
resolve(e);
|
||||
Reflect.deleteProperty(window, `_${error}`);
|
||||
}, true);
|
||||
const error = transformCallback((e) => {
|
||||
reject(e);
|
||||
Reflect.deleteProperty(window, `_${callback}`);
|
||||
}, true);
|
||||
window.__TAURI_IPC__({
|
||||
cmd,
|
||||
callback,
|
||||
error,
|
||||
...args
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class WebSocket {
|
||||
constructor(id, listeners) {
|
||||
@@ -15,9 +74,9 @@ class WebSocket {
|
||||
if (config === null || config === void 0 ? void 0 : config.headers) {
|
||||
config.headers = Array.from(new Headers(config.headers).entries());
|
||||
}
|
||||
return await _("plugin:websocket|connect", {
|
||||
return await invoke("plugin:websocket|connect", {
|
||||
url,
|
||||
callbackFunction: s(handler),
|
||||
callbackFunction: transformCallback(handler),
|
||||
config,
|
||||
}).then((id) => new WebSocket(id, listeners));
|
||||
}
|
||||
@@ -38,7 +97,7 @@ class WebSocket {
|
||||
else {
|
||||
throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");
|
||||
}
|
||||
return await _("plugin:websocket|send", {
|
||||
return await invoke("plugin:websocket|send", {
|
||||
id: this.id,
|
||||
message: m,
|
||||
});
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "1.5.7",
|
||||
"@tauri-apps/cli": "1.5.9",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.0.6"
|
||||
},
|
||||
|
||||
@@ -27,6 +27,6 @@
|
||||
"tslib": "2.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "1.5.1"
|
||||
"@tauri-apps/api": "1.5.3"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user