diff --git a/plugins/websocket/webview-src/index.ts b/plugins/websocket/webview-src/index.ts deleted file mode 100755 index bdde79a9..00000000 --- a/plugins/websocket/webview-src/index.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { invoke, transformCallback } from '@tauri-apps/api/tauri' - -export interface MessageKind { - type: T - data: D -} - -export interface CloseFrame { - code: number - reason: string -} - -export type Message = - MessageKind<'Text', string> | - MessageKind<'Binary', number[]> | - MessageKind<'Ping', number[]> | - MessageKind<'Pong', number[]> | - MessageKind<'Close', CloseFrame | null> - -export default class WebSocket { - id: number - private listeners: Array<(arg: Message) => void> - - constructor(id: number, listeners: Array<(arg: Message) => void>) { - this.id = id - this.listeners = listeners - } - - static async connect(url: string, options?: any): Promise { - const listeners: Array<(arg: Message) => void> = [] - const handler = (message: Message) => { - listeners.forEach(l => l(message)) - } - - return invoke('plugin:websocket|connect', { - url, - callbackFunction: transformCallback(handler), - options - }).then(id => new WebSocket(id, listeners)) - } - - addListener(cb: (arg: Message) => void) { - this.listeners.push(cb) - } - - send(message: Message | string | number[]): Promise { - let m: Message - 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(): Promise { - return this.send({ - type: 'Close', data: { - code: 1000, - reason: 'Disconnected by client' - } - }) - } -} diff --git a/plugins/websocket/webview-src/rollup.config.js b/plugins/websocket/webview-src/rollup.config.js deleted file mode 100755 index 6f72924f..00000000 --- a/plugins/websocket/webview-src/rollup.config.js +++ /dev/null @@ -1,35 +0,0 @@ -import resolve from "@rollup/plugin-node-resolve"; -import { terser } from "rollup-plugin-terser"; -import typescript from "@rollup/plugin-typescript"; - -export default [ - { - input: "./webview-src/index.ts", - output: { - dir: "./webview-dist", - entryFileNames: "[name].min.js", - format: "esm", - }, - plugins: [ - resolve(), - terser(), - typescript({ - 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", - }), - ], - }, -]; diff --git a/plugins/websocket/webview-src/tsconfig.json b/plugins/websocket/webview-src/tsconfig.json deleted file mode 100755 index bda1b10d..00000000 --- a/plugins/websocket/webview-src/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2019", - "strict": true, - "lib": [ - "ES2019", - "ES2020.Promise", - "ES2020.String", - "DOM", - ], - "noEmitOnError": true, - "isolatedModules": true, - // module resolution - "esModuleInterop": true, - "moduleResolution": "node", - // advanced - "forceConsistentCasingInFileNames": true, - "skipLibCheck": true, - "declaration": true, - "declarationDir": "../webview-dist", - "rootDir": "./", - }, - "exclude": ["node_modules"] -} \ No newline at end of file