🙏 Adds mis components and services
This commit is contained in:
@@ -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))
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
import { writable } from 'svelte/store';
|
||||
Reference in New Issue
Block a user