parent
de845038d5
commit
14072226bf
@ -1,29 +0,0 @@
|
|||||||
/*! *****************************************************************************
|
|
||||||
Copyright (c) Microsoft Corporation.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
***************************************************************************** */
|
|
||||||
function n(n,t,e,r){return new(e||(e=Promise))((function(o,i){function a(n){try{u(r.next(n))}catch(n){i(n)}}function c(n){try{u(r.throw(n))}catch(n){i(n)}}function u(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(a,c)}u((r=r.apply(n,t||[])).next())}))}function t(n,t){var e,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;a;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(n,a)}catch(n){i=[6,n],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}
|
|
||||||
/*! *****************************************************************************
|
|
||||||
Copyright (c) Microsoft Corporation.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
***************************************************************************** */var e=function(){return(e=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n}).apply(this,arguments)};function r(n,t){void 0===t&&(t=!1);var e=function(){var n=new Int8Array(1);window.crypto.getRandomValues(n);var t=new Uint8Array(Math.max(16,Math.abs(n[0])));return window.crypto.getRandomValues(t),t.join("")}();return Object.defineProperty(window,e,{value:function(r){return t&&Reflect.deleteProperty(window,e),null==n?void 0:n(r)},writable:!1,configurable:!0}),e}function o(n,t){return void 0===t&&(t={}),function(n,t,e,r){return new(e||(e=Promise))((function(o,i){function a(n){try{u(r.next(n))}catch(n){i(n)}}function c(n){try{u(r.throw(n))}catch(n){i(n)}}function u(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(a,c)}u((r=r.apply(n,t||[])).next())}))}(this,void 0,void 0,(function(){return function(n,t){var e,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;a;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(n,a)}catch(n){i=[6,n],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,(function(o){return[2,new Promise((function(o,i){var a=r((function(n){o(n),Reflect.deleteProperty(window,c)}),!0),c=r((function(n){i(n),Reflect.deleteProperty(window,a)}),!0);window.rpc.notify(n,e({__invokeKey:__TAURI_INVOKE_KEY__,callback:a,error:c},t))}))]}))}))}Object.freeze({__proto__:null,transformCallback:r,invoke:o,convertFileSrc:function(n){return navigator.userAgent.includes("Windows")?"https://asset.localhost/"+n:"asset://"+n}});var i=function(){function e(n,t){this.id=n,this.listeners=t}return e.connect=function(i,a){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){return n=[],[2,o("plugin:websocket|connect",{url:i,callbackFunction:r((function(t){n.forEach((function(n){return n(t)}))})),options:a}).then((function(t){return new e(t,n)}))]}))}))},e.prototype.addListener=function(n){this.listeners.push(n)},e.prototype.send=function(n){var t;if("string"==typeof n)t={type:"Text",data:n};else if("object"==typeof n&&"type"in n)t=n;else{if(!Array.isArray(n))throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");t={type:"Binary",data:n}}return o("plugin:websocket|send",{id:this.id,message:t})},e.prototype.disconnect=function(){return this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})},e}();export{i as default};
|
|
@ -0,0 +1,15 @@
|
|||||||
|
/*! *****************************************************************************
|
||||||
|
Copyright (c) Microsoft Corporation.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
***************************************************************************** */
|
||||||
|
var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function t(e,t){void 0===t&&(t=!1);var n=function(){var e=new Int8Array(1);window.crypto.getRandomValues(e);var t=new Uint8Array(Math.max(16,Math.abs(e[0])));return window.crypto.getRandomValues(t),t.join("")}();return Object.defineProperty(window,n,{value:function(r){return t&&Reflect.deleteProperty(window,n),null==e?void 0:e(r)},writable:!1,configurable:!0}),n}function n(n,r){return void 0===r&&(r={}),function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function c(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}l((r=r.apply(e,t||[])).next())}))}(this,void 0,void 0,(function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,(function(o){return[2,new Promise((function(o,i){var a=t((function(e){o(e),Reflect.deleteProperty(window,c)}),!0),c=t((function(e){i(e),Reflect.deleteProperty(window,a)}),!0);window.rpc.notify(n,e({__invokeKey:__TAURI_INVOKE_KEY__,callback:a,error:c},r))}))]}))}))}Object.freeze({__proto__:null,transformCallback:t,invoke:n,convertFileSrc:function(e){return navigator.userAgent.includes("Windows")?"https://asset.localhost/"+e:"asset://"+e}});class r{constructor(e,t){this.id=e,this.listeners=t}static async connect(e,o){const i=[];return n("plugin:websocket|connect",{url:e,callbackFunction:t((e=>{i.forEach((t=>t(e)))})),options:o}).then((e=>new r(e,i)))}addListener(e){this.listeners.push(e)}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 n("plugin:websocket|send",{id:this.id,message:t})}disconnect(){return this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})}}export{r as default};
|
@ -0,0 +1,51 @@
|
|||||||
|
import { invoke, transformCallback } from '@tauri-apps/api/tauri';
|
||||||
|
|
||||||
|
class WebSocket {
|
||||||
|
constructor(id, listeners) {
|
||||||
|
this.id = id;
|
||||||
|
this.listeners = listeners;
|
||||||
|
}
|
||||||
|
static async connect(url, options) {
|
||||||
|
const listeners = [];
|
||||||
|
const handler = (message) => {
|
||||||
|
listeners.forEach(l => l(message));
|
||||||
|
};
|
||||||
|
return invoke('plugin:websocket|connect', {
|
||||||
|
url,
|
||||||
|
callbackFunction: transformCallback(handler),
|
||||||
|
options
|
||||||
|
}).then(id => new WebSocket(id, listeners));
|
||||||
|
}
|
||||||
|
addListener(cb) {
|
||||||
|
this.listeners.push(cb);
|
||||||
|
}
|
||||||
|
send(message) {
|
||||||
|
let m;
|
||||||
|
if (typeof message === 'string') {
|
||||||
|
m = { type: 'Text', data: message };
|
||||||
|
}
|
||||||
|
else if (typeof message === 'object' && ('type' in message)) {
|
||||||
|
m = message;
|
||||||
|
}
|
||||||
|
else if (Array.isArray(message)) {
|
||||||
|
m = { type: 'Binary', data: message };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array');
|
||||||
|
}
|
||||||
|
return invoke('plugin:websocket|send', {
|
||||||
|
id: this.id,
|
||||||
|
message: m
|
||||||
|
});
|
||||||
|
}
|
||||||
|
disconnect() {
|
||||||
|
return this.send({
|
||||||
|
type: 'Close', data: {
|
||||||
|
code: 1000,
|
||||||
|
reason: 'Disconnected by client'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { WebSocket as default };
|
@ -1,20 +1,35 @@
|
|||||||
import resolve from '@rollup/plugin-node-resolve'
|
import resolve from "@rollup/plugin-node-resolve";
|
||||||
import { terser } from 'rollup-plugin-terser'
|
import { terser } from "rollup-plugin-terser";
|
||||||
import typescript from '@rollup/plugin-typescript'
|
import typescript from "@rollup/plugin-typescript";
|
||||||
|
|
||||||
export default {
|
export default [
|
||||||
input: './webview-src/index.ts',
|
{
|
||||||
output: {
|
input: "./webview-src/index.ts",
|
||||||
dir: './webview-dist',
|
output: {
|
||||||
entryFileNames: '[name].js',
|
dir: "./webview-dist",
|
||||||
format: 'es',
|
entryFileNames: "[name].min.js",
|
||||||
exports: 'auto'
|
format: "esm",
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
resolve(),
|
resolve(),
|
||||||
terser(),
|
terser(),
|
||||||
typescript({
|
typescript({
|
||||||
tsconfig: './webview-src/tsconfig.json'
|
tsconfig: "./webview-src/tsconfig.json",
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
input: "./webview-src/index.ts",
|
||||||
|
external: ['@tauri-apps/api/tauri'],
|
||||||
|
output: {
|
||||||
|
dir: "./webview-dist",
|
||||||
|
entryFileNames: "[name].mjs",
|
||||||
|
format: "esm",
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
typescript({
|
||||||
|
tsconfig: "./webview-src/tsconfig.json",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
Loading…
Reference in new issue