smcgateway-sv 0.4.10 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Clock.svelte CHANGED
@@ -7,9 +7,9 @@
7
7
  errorText = 'Connection lost'
8
8
  }: { class?: ClassValue, errorText?: string } = $props();
9
9
 
10
- let classes = $derived(`${className} ${gtime.ok ? '' : className + '-error'}`);
10
+ let classes = $derived(`${className} ${$gtime.ok ? '' : className + '-error'}`);
11
11
 
12
- let text = $derived(gtime.ok ? gtime.now.toLocaleString() : errorText);
12
+ let text = $derived($gtime.ok ? $gtime.now.toLocaleString() : errorText);
13
13
  </script>
14
14
 
15
15
  <div class={classes}>{text}</div>
@@ -9,7 +9,7 @@
9
9
  }: { module?: string; id?: string; class?: string; allName?: string } = $props();
10
10
 
11
11
  let channels = $derived.by(() => {
12
- let v = settings.all['channels'];
12
+ let v = $settings.all['channels'];
13
13
  if (v) {
14
14
  return Object.keys(v).map((k) => {
15
15
  return { module: k, name: v[k] };
package/dist/csv.d.ts CHANGED
@@ -1,7 +1,2 @@
1
- declare function tableToCSV(tableId: string): string | undefined;
2
- declare function downloadTableAsCSV(tableId: string, filename: string): void;
3
- declare const _default: {
4
- tableToCSV: typeof tableToCSV;
5
- downloadTableAsCSV: typeof downloadTableAsCSV;
6
- };
7
- export default _default;
1
+ export declare function tableToCSV(tableId: string): string | undefined;
2
+ export declare function downloadTableAsCSV(tableId: string, filename: string): void;
package/dist/csv.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Function to convert an HTML table to CSV
2
- function tableToCSV(tableId) {
2
+ export function tableToCSV(tableId) {
3
3
  const table = document.getElementById(tableId); // Get the table element by its ID
4
4
  if (!table) {
5
5
  console.error(`Table with ID '${tableId}' not found.`);
@@ -18,7 +18,7 @@ function tableToCSV(tableId) {
18
18
  return csvContent;
19
19
  }
20
20
  // Function to download the CSV file
21
- function downloadTableAsCSV(tableId, filename) {
21
+ export function downloadTableAsCSV(tableId, filename) {
22
22
  const csvContent = tableToCSV(tableId);
23
23
  if (!csvContent)
24
24
  return;
@@ -29,7 +29,3 @@ function downloadTableAsCSV(tableId, filename) {
29
29
  link.click();
30
30
  URL.revokeObjectURL(link.href); // Clean up
31
31
  }
32
- export default {
33
- tableToCSV,
34
- downloadTableAsCSV
35
- };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * gtime provides access to the current date/time on the GW device.
3
3
  */
4
- declare let gtime: {
4
+ declare let gtime: import("svelte/store").Readable<{
5
5
  now: Date;
6
6
  diff: number;
7
7
  ok: boolean;
8
- };
8
+ }>;
9
9
  declare const syncTimeToBrowser: () => Promise<string>;
10
10
  export { gtime, syncTimeToBrowser };
@@ -1,48 +1,77 @@
1
+ import { readable } from "svelte/store";
1
2
  const fetchIntervalSecs = 10;
3
+ let fetchTime = undefined;
2
4
  /**
3
5
  * gtime provides access to the current date/time on the GW device.
4
6
  */
5
- let gtime = $state({
7
+ let gtime = readable({
6
8
  now: new Date(),
7
9
  diff: 0,
8
10
  ok: true,
9
- });
10
- let ticks = 0; // Number of ticks since last fetch
11
- let timer = 0;
12
- const fetchTime = () => {
13
- const start = new Date().getTime();
14
- fetch("/api/date", { signal: AbortSignal.timeout(2000) })
15
- .then((resp) => {
16
- gtime.ok = false;
17
- if (resp.ok) {
18
- const end = new Date().getTime();
19
- resp.json().then((data) => {
20
- let time = new Date(data.str);
21
- gtime.now = time;
22
- gtime.diff = time.getTime() - start - (end - start);
23
- gtime.ok = true;
24
- });
25
- }
26
- }).catch(e => {
27
- console.log("fetch error", e);
28
- gtime.ok = false;
11
+ }, (set, update) => {
12
+ set({
13
+ now: new Date(),
14
+ diff: 0,
15
+ ok: true,
29
16
  });
30
- };
31
- fetchTime();
32
- setInterval(() => {
33
- gtime.now = new Date(gtime.now.getTime() + 1000);
34
- ticks++;
35
- if (ticks > fetchIntervalSecs) {
36
- ticks = 0;
37
- timer = setTimeout(fetchTime, 0);
38
- }
39
- }, 1000);
17
+ let ticks = 0; // Number of ticks since last fetch
18
+ const interval = setInterval(() => {
19
+ update((v) => {
20
+ v.now = new Date(v.now.getTime() + 1000);
21
+ return v;
22
+ });
23
+ ticks++;
24
+ if (ticks > fetchIntervalSecs) {
25
+ ticks = 0;
26
+ if (fetchTime)
27
+ fetchTime();
28
+ }
29
+ }, 1000);
30
+ fetchTime = () => {
31
+ const start = new Date().getTime();
32
+ fetch("/api/date", { signal: AbortSignal.timeout(2000) })
33
+ .then((resp) => {
34
+ if (resp.ok) {
35
+ const end = new Date().getTime();
36
+ resp.json().then((data) => {
37
+ let time = new Date(data.str);
38
+ update((v) => {
39
+ v.now = time;
40
+ v.diff = time.getTime() - start - (end - start);
41
+ v.ok = true;
42
+ return v;
43
+ });
44
+ });
45
+ }
46
+ else {
47
+ update((v) => {
48
+ v.ok = false;
49
+ return v;
50
+ });
51
+ }
52
+ }).catch(e => {
53
+ console.log("fetch error", e);
54
+ update((v) => {
55
+ v.ok = false;
56
+ return v;
57
+ });
58
+ });
59
+ };
60
+ fetchTime();
61
+ return () => {
62
+ fetchTime = undefined;
63
+ clearInterval(interval);
64
+ };
65
+ });
40
66
  const syncTimeToBrowser = async () => {
41
67
  const body = JSON.stringify({ "timestamp": Math.round(new Date().getTime() / 1000) });
42
68
  const resp = await fetch("/api/date", { method: "POST", body });
43
69
  if (resp.status === 200) {
44
- clearTimeout(timer);
45
- timer = setTimeout(fetchTime, 0);
70
+ if (fetchTime) {
71
+ fetchTime();
72
+ }
73
+ // clearTimeout(timer)
74
+ // timer = setTimeout(fetchTime, 0)
46
75
  return "ok";
47
76
  }
48
77
  throw new Error(resp.statusText);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { auth, type User } from "./auth.svelte";
2
- import { gtime } from "./gtime.svelte.js";
2
+ import { gtime, syncTimeToBrowser } from "./gtime.svelte.js";
3
3
  import { geofence, type GeoFence } from "./geofence.svelte.js";
4
4
  import { device, type Device } from "./devices.svelte.js";
5
5
  import { ghistory, type Log, type State } from "./ghistory.svelte.js";
@@ -11,8 +11,8 @@ import LoginForm from "./LoginForm.svelte";
11
11
  import { recording, type Recording } from "./recording.svelte.js";
12
12
  import AudioTimeLinePlayer from "./AudioTimeLinePlayer.svelte";
13
13
  import VoicePlayer from "./VoicePlayer.svelte";
14
- import csv from "./csv.js";
14
+ import { downloadTableAsCSV } from "./csv.js";
15
15
  import settings from "./settings.svelte.js";
16
16
  import SelectChannel from "./SelectChannel.svelte";
17
- export { auth, gtime, geofence, device, ghistory, InputDate, InputDatetime, InputDebounced, InputIdentUri, LoginForm, recording, AudioTimeLinePlayer, VoicePlayer, csv, settings, SelectChannel, };
17
+ export { auth, gtime, syncTimeToBrowser, geofence, device, ghistory, InputDate, InputDatetime, InputDebounced, InputIdentUri, LoginForm, recording, AudioTimeLinePlayer, VoicePlayer, downloadTableAsCSV, settings, SelectChannel, };
18
18
  export type { User, GeoFence, Device, Log, State, Recording };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Reexport your entry components here
2
2
  import { auth } from "./auth.svelte";
3
- import { gtime } from "./gtime.svelte.js";
3
+ import { gtime, syncTimeToBrowser } from "./gtime.svelte.js";
4
4
  import { geofence } from "./geofence.svelte.js";
5
5
  import { device } from "./devices.svelte.js";
6
6
  import { ghistory } from "./ghistory.svelte.js";
@@ -12,7 +12,7 @@ import LoginForm from "./LoginForm.svelte";
12
12
  import { recording } from "./recording.svelte.js";
13
13
  import AudioTimeLinePlayer from "./AudioTimeLinePlayer.svelte";
14
14
  import VoicePlayer from "./VoicePlayer.svelte";
15
- import csv from "./csv.js";
15
+ import { downloadTableAsCSV } from "./csv.js";
16
16
  import settings from "./settings.svelte.js";
17
17
  import SelectChannel from "./SelectChannel.svelte";
18
- export { auth, gtime, geofence, device, ghistory, InputDate, InputDatetime, InputDebounced, InputIdentUri, LoginForm, recording, AudioTimeLinePlayer, VoicePlayer, csv, settings, SelectChannel, };
18
+ export { auth, gtime, syncTimeToBrowser, geofence, device, ghistory, InputDate, InputDatetime, InputDebounced, InputIdentUri, LoginForm, recording, AudioTimeLinePlayer, VoicePlayer, downloadTableAsCSV, settings, SelectChannel, };
@@ -1,13 +1,11 @@
1
- declare class Settings {
2
- private _loaded;
1
+ declare class Store {
3
2
  all: {
4
3
  [key: string]: any;
5
4
  };
6
- constructor();
7
- loaded(): Promise<boolean>;
8
- getValue(path: string, defaultValue?: any): any;
5
+ getValue(path: string, _default?: any): any;
9
6
  getString(path: string, _default?: string): string;
10
7
  getNumber(path: string, _default?: number): number;
8
+ constructor(load?: boolean, onload?: (v: Store) => void);
11
9
  }
12
- declare const settings: Settings;
10
+ declare let settings: import("svelte/store").Readable<Store>;
13
11
  export default settings;
@@ -1,11 +1,33 @@
1
- class Settings {
2
- _loaded;
3
- all = $state({});
4
- constructor() {
5
- let resolveLoaded;
6
- this._loaded = new Promise((resolve) => {
7
- resolveLoaded = resolve;
8
- });
1
+ import { readable } from "svelte/store";
2
+ class Store {
3
+ all = {};
4
+ getValue(path, _default) {
5
+ return path.split('.').reduce((acc, key) => {
6
+ if (acc && typeof acc === 'object' && key in acc) {
7
+ return acc[key];
8
+ }
9
+ return _default;
10
+ }, this.all);
11
+ }
12
+ getString(path, _default = "") {
13
+ return path.split('.').reduce((acc, key) => {
14
+ if (acc && typeof acc === 'object' && key in acc) {
15
+ return acc[key];
16
+ }
17
+ return _default;
18
+ }, this.all).toString();
19
+ }
20
+ getNumber(path, _default = 0) {
21
+ const s = this.getString(path, "");
22
+ let v;
23
+ if (s.indexOf(".") > -1) {
24
+ return parseFloat(s) || _default;
25
+ }
26
+ return parseInt(s) || _default;
27
+ }
28
+ constructor(load = false, onload = (v) => { }) {
29
+ if (!load)
30
+ return;
9
31
  fetch("_settings", { signal: AbortSignal.timeout(5000) })
10
32
  .then(resp => {
11
33
  if (resp.status === 200) {
@@ -36,39 +58,16 @@ class Settings {
36
58
  }
37
59
  });
38
60
  }
39
- resolveLoaded(true);
61
+ onload(this);
40
62
  });
41
63
  }
42
- else {
43
- resolveLoaded(true); // resolve even if non-200
44
- }
45
64
  })
46
- .catch(() => resolveLoaded(true)); // resolve even on fetch failure
47
- }
48
- async loaded() {
49
- return this._loaded;
50
- }
51
- getValue(path, defaultValue) {
52
- return path.split('.').reduce((acc, key) => {
53
- if (acc && typeof acc === 'object' && key in acc) {
54
- return acc[key];
55
- }
56
- return defaultValue;
57
- }, this.all);
58
- }
59
- getString(path, _default = "") {
60
- return path.split('.').reduce((acc, key) => {
61
- if (acc && typeof acc === 'object' && key in acc) {
62
- return acc[key];
63
- }
64
- return _default;
65
- }, this.all).toString();
66
- }
67
- getNumber(path, _default = 0) {
68
- const s = this.getString(path, "");
69
- let v = parseFloat(s);
70
- return v || _default;
65
+ .catch((err) => console.error(err));
71
66
  }
72
67
  }
73
- const settings = new Settings();
68
+ let settings = readable(new Store(false), (set) => {
69
+ new Store(true, (s) => {
70
+ set(s);
71
+ });
72
+ });
74
73
  export default settings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smcgateway-sv",
3
- "version": "0.4.10",
3
+ "version": "0.5.0",
4
4
  "author": "Kevin Golding <kevin.golding@smc-gateway.com> (https://smc-gateway.com)",
5
5
  "license": "MIT",
6
6
  "scripts": {