🙏 Adds mis components and services

This commit is contained in:
Rune Harlyk
2023-05-10 22:34:48 +02:00
parent 07a99a6248
commit 8cf4c09543
7 changed files with 110 additions and 10 deletions
+23
View File
@@ -0,0 +1,23 @@
import { onMount } from "svelte";
import { writable, type Writable } from "svelte/store";
onMount(() => {
window.addEventListener("", () => {
screen.orientation.addEventListener("change", _handleOrientationChange);
})
})
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'
export const orientation:Writable<OrientationType> = writable('portrait-primary');
export const isPortrait = writable(true);
const _isPortrait = (orientation:OrientationType | undefined):boolean => {
return orientation === "portrait-primary" || orientation === "portrait-secondary";
}
const _handleOrientationChange = () => {
orientation.set(screen.orientation.type)
isPortrait.set(_isPortrait(screen.orientation.type))
}
+28
View File
@@ -0,0 +1,28 @@
import { writable, type Writable } from 'svelte/store';
export type WebSocketStatus = 'OPEN' | 'CONNECTING' | 'CLOSED'
export const isConnected = writable(false)
export const status:Writable<WebSocketStatus> = writable('CLOSED')
export const socket = writable(null)
export const connect = (url:string) => {
status.set('CONNECTING')
let _socket = new WebSocket(url);
_socket.onopen = _connected;
_socket.onclose = _disconnected;
socket.set(_socket)
}
const _connected = () => {
status.set('OPEN')
isConnected.set(true)
}
const _disconnected = () => {
status.set('CLOSED')
isConnected.set(false)
}
+1
View File
@@ -0,0 +1 @@
import { writable } from 'svelte/store';