Skip to content

Commit a242282

Browse files
committed
Base
1 parent f15ca4e commit a242282

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"compression": "^1.7.1",
14+
"dayjs": "^1.11.5",
1415
"express": "^4.18.1",
1516
"sass": "^1.55.0",
1617
"sirv": "^1.0.0",

src/components/Clock.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { readable } from 'svelte/store'
2+
import dayjs from 'dayjs'
3+
4+
function update() {
5+
return dayjs()
6+
}
7+
export default readable(update(), set => {
8+
let interval = setInterval(() => set(update()), 1000)
9+
return () => clearInterval(interval)
10+
})

src/components/payload/Row.svelte

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script lang="ts">
2+
import type Payload from "./types/Payload";
3+
export let data: Payload;
4+
5+
import dayjs from 'dayjs'
6+
</script>
7+
8+
<tr>
9+
<td>
10+
{dayjs(data.timestamp).format("DD/MM/YY hh:mm:ss a")}
11+
</td>
12+
<td>
13+
{data.code}
14+
</td>
15+
<td>
16+
<pre>{JSON.stringify(data.data, null, 4)}</pre>
17+
</td>
18+
</tr>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default interface Payload<T = any> {
2+
code: string
3+
data: T,
4+
timestamp: number
5+
}

src/routes/index.svelte

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { onMount } from "svelte";
44
55
import type { Socket } from "socket.io-client";
6+
import Row from "../components/payload/Row.svelte";
7+
import type Payload from "../components/payload/types/Payload";
68
let client: Socket;
79
810
let messages = [];
@@ -14,9 +16,15 @@
1416
);
1517
1618
console.log("Ready");
17-
client.on("p", function (data: { code: string; data: any }) {
19+
client.on("p", function (data: Payload) {
1820
updateType(data.code);
19-
messages = [data, ...messages];
21+
messages = [
22+
{
23+
...data,
24+
data: JSON.parse(data.data),
25+
},
26+
...messages,
27+
];
2028
});
2129
});
2230
@@ -56,9 +64,7 @@
5664
</div>
5765

5866
{#each messages.filter(({ code }) => activeTypes.includes(code)) as data}
59-
<pre>
60-
{JSON.stringify(data, null, 2)}
61-
</pre>
67+
<Row {data} />
6268
{/each}
6369

6470
<style lang="scss">

src/server.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as sapper from '@sapper/server';
66
import { Server as HTTPServer } from 'http'
77
import { Server as SocketIOServer } from 'socket.io'
88
import { Client as SLAPI } from 'presonus-studiolive-api'
9+
import type Payload from './components/payload/types/Payload';
910

1011
const { PORT, NODE_ENV } = process.env;
1112
const dev = NODE_ENV === 'development';
@@ -25,7 +26,8 @@ app
2526
let client = new SLAPI("192.168.0.19")
2627

2728
client.on('data', (data) => {
28-
io.emit('p', data)
29+
let payload: Payload = { code: data.code, data: JSON.stringify(data), timestamp: new Date().getTime() }
30+
io.emit('p', payload)
2931
})
3032

3133
server.listen(Number(PORT), '0.0.0.0', () => {

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,11 @@
968968
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1"
969969
integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==
970970

971+
"@rgossiaux/svelte-headlessui@^1.0.2":
972+
version "1.0.2"
973+
resolved "https://registry.yarnpkg.com/@rgossiaux/svelte-headlessui/-/svelte-headlessui-1.0.2.tgz#9493251a40cd56d8bdc8f0f64623d886bb872b1e"
974+
integrity sha512-sauopYTSivhzXe1kAvgawkhyYJcQlK8Li3p0d2OtcCIVprOzdbard5lbqWB4xHDv83zAobt2mR08oizO2poHLQ==
975+
971976
"@rollup/plugin-babel@^5.0.0":
972977
version "5.3.1"
973978
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz#04bc0608f4aa4b2e4b1aebf284344d0f68fda283"
@@ -1493,6 +1498,11 @@ cors@~2.8.5:
14931498
object-assign "^4"
14941499
vary "^1"
14951500

1501+
dayjs@^1.11.5:
1502+
version "1.11.5"
1503+
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.5.tgz#00e8cc627f231f9499c19b38af49f56dc0ac5e93"
1504+
integrity sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==
1505+
14961506
14971507
version "2.6.9"
14981508
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"

0 commit comments

Comments
 (0)