Skip to content

Commit

Permalink
Automatic connect to moonraker in 5 sec interval
Browse files Browse the repository at this point in the history
  • Loading branch information
freakydude committed Nov 29, 2023
1 parent df42732 commit f436924
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@
let isConnected = client.isConnected;
let klippyState = moonraker.klippyState.state;
let isFullscreen = bootParams.fullscreen;
let wsUrl = bootParams.moonrakerWs;
let interval: NodeJS.Timeout;
$: {
if ($isConnected) {
clearInterval(interval);
} else {
clearInterval(interval);
interval = setInterval(async () => {
//await moonraker.disconnect();
await moonraker.connect($wsUrl);
}, 5000);
}
if ($isConnected === false || $klippyState !== 'ready') {
goto('/');
}
Expand Down
19 changes: 10 additions & 9 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { bootParams, client, commands, moonraker } from '$lib/base.svelte';
let wsUrl = bootParams.moonrakerWs;
let apiUrl = bootParams.moonrakerApi;
let isConnected = client.isConnected;
let klippyState = moonraker.klippyState.state;
let klippyStateMessage = moonraker.klippyState.message;
Expand Down Expand Up @@ -52,7 +52,15 @@
{:else}
<tr>
<td class="pr-2 text-end text-neutral-100">Moonraker</td>
<td class="text-purple-600">Disconnected </td>
<td class="text-purple-600">Connecting</td>
</tr>
<tr>
<td class="pr-2 text-end text-neutral-100">Api</td>
<td class="text-neutral-400">{$apiUrl}</td>
</tr>
<tr>
<td class="pr-2 text-end text-neutral-100">Websocket</td>
<td class="text-neutral-400">{$wsUrl}</td>
</tr>
{/if}
</table>
Expand Down Expand Up @@ -86,13 +94,6 @@
class="flex h-14 items-center justify-center rounded-l-lg bg-neutral-700 px-3 py-2 font-semibold text-neutral-50 drop-shadow-md active:bg-red-500"
>Printer State</a>
{/if}
{:else}
<button
class="flex h-14 items-center justify-center rounded-l-lg bg-neutral-700 px-3 py-2 font-semibold text-neutral-50 drop-shadow-md active:bg-red-500"
on:click|preventDefault="{async () => {
await moonraker.disconnect();
await moonraker.connect($wsUrl);
}}">Connect</button>
{/if}
</div>
</div>

0 comments on commit f436924

Please sign in to comment.