Skip to content

Commit

Permalink
Can now use websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Nov 29, 2023
1 parent 5b0bd55 commit e2fff74
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.27.4",
"@types/node": "^20.10.0",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
Expand Down
51 changes: 45 additions & 6 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<script lang="ts">
var webSocket = new WebSocket("./chat");
webSocket.addEventListener("message", (event) => {
console.log(event);
})
import { websocket_url } from './store.js';
websocket_url.subscribe((value) => {
console.log(value);
try {
let webSocket = new WebSocket(value);
webSocket.addEventListener("open", (event) => {
console.log("Open");
});
webSocket.addEventListener("message", (event) => {
console.log(event);
});
} catch (e) {
console.log(e);
}
});
function set_websocket_url(event: Event & { target: HTMLInputElement }) {
websocket_url.set(event.target.value);
}
</script>

<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
<p>
Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation
</p>
<input on:input={set_websocket_url} />
3 changes: 3 additions & 0 deletions frontend/src/routes/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { writable } from 'svelte/store';

export const websocket_url = writable("");

0 comments on commit e2fff74

Please sign in to comment.