mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(plugins): use @tauri-apps namespace on NPM (#368)
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
This commit is contained in:
committed by
GitHub
parent
caf8456864
commit
22991af9f4
@@ -51,7 +51,7 @@ fn main() {
|
||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||
|
||||
```javascript
|
||||
import { WebSocket } from "tauri-plugin-websocket-api";
|
||||
import { WebSocket } from "@tauri-apps/plugin-websocket";
|
||||
|
||||
const ws = await WebSocket.connect("wss://example.com");
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/cli": "^2.0.0-alpha.8",
|
||||
"tauri-plugin-websocket-api": "link:../../"
|
||||
"@tauri-apps/plugin-websocket": "link:../../"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
@@ -1,35 +1,44 @@
|
||||
<script lang="ts">
|
||||
import WebSocket from 'tauri-plugin-websocket-api'
|
||||
import { onMount } from 'svelte'
|
||||
import WebSocket from "@tauri-apps/plugin-websocket";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
let ws
|
||||
let response = ''
|
||||
let message = ''
|
||||
let ws;
|
||||
let response = "";
|
||||
let message = "";
|
||||
|
||||
onMount(async () => {
|
||||
ws = await WebSocket.connect('ws://127.0.0.1:8080').then(r => {
|
||||
_updateResponse('Connected')
|
||||
return r
|
||||
}).catch(_updateResponse)
|
||||
ws.addListener(_updateResponse)
|
||||
})
|
||||
onMount(async () => {
|
||||
ws = await WebSocket.connect("ws://127.0.0.1:8080")
|
||||
.then((r) => {
|
||||
_updateResponse("Connected");
|
||||
return r;
|
||||
})
|
||||
.catch(_updateResponse);
|
||||
ws.addListener(_updateResponse);
|
||||
});
|
||||
|
||||
function _updateResponse(returnValue) {
|
||||
response += (typeof returnValue === 'string' ? returnValue : JSON.stringify(returnValue)) + '<br>'
|
||||
}
|
||||
function _updateResponse(returnValue) {
|
||||
response +=
|
||||
(typeof returnValue === "string"
|
||||
? returnValue
|
||||
: JSON.stringify(returnValue)) + "<br>";
|
||||
}
|
||||
|
||||
function send() {
|
||||
ws.send(message).then(() => _updateResponse('Message sent')).catch(_updateResponse)
|
||||
}
|
||||
function send() {
|
||||
ws.send(message)
|
||||
.then(() => _updateResponse("Message sent"))
|
||||
.catch(_updateResponse);
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
ws.disconnect().then(() => _updateResponse('Disconnected')).catch(_updateResponse)
|
||||
}
|
||||
function disconnect() {
|
||||
ws.disconnect()
|
||||
.then(() => _updateResponse("Disconnected"))
|
||||
.catch(_updateResponse);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<input bind:value={message}>
|
||||
<button on:click={send}>Send</button>
|
||||
<button on:click={disconnect}>Disconnect</button>
|
||||
<input bind:value={message} />
|
||||
<button on:click={send}>Send</button>
|
||||
<button on:click={disconnect}>Disconnect</button>
|
||||
</div>
|
||||
<div>{@html response}</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "tauri-plugin-websocket-api",
|
||||
"name": "@tauri-apps/plugin-websocket",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT or APACHE-2.0",
|
||||
"authors": [
|
||||
|
||||
Reference in New Issue
Block a user